1 #pragma once 2 3 #include <mbgl/tile/tile_id.hpp> 4 #include <mbgl/tile/tile_observer.hpp> 5 #include <mbgl/util/mat4.hpp> 6 #include <mbgl/util/geo.hpp> 7 #include <mbgl/util/feature.hpp> 8 #include <mbgl/style/source_impl.hpp> 9 #include <mbgl/style/layer_impl.hpp> 10 11 #include <unordered_map> 12 #include <vector> 13 #include <map> 14 #include <memory> 15 16 namespace mbgl { 17 18 class PaintParameters; 19 class TransformState; 20 class RenderTile; 21 class RenderLayer; 22 class RenderedQueryOptions; 23 class SourceQueryOptions; 24 class Tile; 25 class RenderSourceObserver; 26 class TileParameters; 27 class CollisionIndex; 28 29 class RenderSource : protected TileObserver { 30 public: 31 static std::unique_ptr<RenderSource> create(Immutable<style::Source::Impl>); 32 33 // Check whether this source is of the given subtype. 34 template <class T> 35 bool is() const; 36 37 // Dynamically cast this source to the given subtype. 38 template <class T> as()39 T* as() { 40 return is<T>() ? reinterpret_cast<T*>(this) : nullptr; 41 } 42 43 template <class T> as() const44 const T* as() const { 45 return is<T>() ? reinterpret_cast<const T*>(this) : nullptr; 46 } 47 48 bool isEnabled() const; 49 virtual bool isLoaded() const = 0; 50 51 virtual void update(Immutable<style::Source::Impl>, 52 const std::vector<Immutable<style::Layer::Impl>>&, 53 bool needsRendering, 54 bool needsRelayout, 55 const TileParameters&) = 0; 56 57 virtual void startRender(PaintParameters&) = 0; 58 virtual void finishRender(PaintParameters&) = 0; 59 60 // Returns an unsorted list of RenderTiles. 61 virtual std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() = 0; 62 63 virtual std::unordered_map<std::string, std::vector<Feature>> 64 queryRenderedFeatures(const ScreenLineString& geometry, 65 const TransformState& transformState, 66 const std::vector<const RenderLayer*>& layers, 67 const RenderedQueryOptions& options, 68 const mat4& projMatrix) const = 0; 69 70 virtual std::vector<Feature> 71 querySourceFeatures(const SourceQueryOptions&) const = 0; 72 73 virtual void reduceMemoryUse() = 0; 74 75 virtual void dumpDebugLogs() const = 0; 76 77 void setObserver(RenderSourceObserver*); 78 79 Immutable<style::Source::Impl> baseImpl; 80 81 protected: 82 RenderSource(Immutable<style::Source::Impl>); 83 RenderSourceObserver* observer; 84 85 bool enabled = false; 86 87 void onTileChanged(Tile&) override; 88 void onTileError(Tile&, std::exception_ptr) final; 89 }; 90 91 } // namespace mbgl 92