1 #pragma once 2 3 #include <mbgl/renderer/mode.hpp> 4 #include <mbgl/renderer/renderer.hpp> 5 #include <mbgl/renderer/render_source_observer.hpp> 6 #include <mbgl/renderer/render_light.hpp> 7 #include <mbgl/style/image.hpp> 8 #include <mbgl/style/source.hpp> 9 #include <mbgl/style/layer.hpp> 10 #include <mbgl/map/transform_state.hpp> 11 #include <mbgl/map/zoom_history.hpp> 12 #include <mbgl/text/cross_tile_symbol_index.hpp> 13 #include <mbgl/text/glyph_manager_observer.hpp> 14 #include <mbgl/text/placement.hpp> 15 16 #include <memory> 17 #include <string> 18 #include <vector> 19 20 namespace mbgl { 21 22 class RendererBackend; 23 class RendererObserver; 24 class RenderSource; 25 class RenderLayer; 26 class UpdateParameters; 27 class RenderStaticData; 28 class RenderedQueryOptions; 29 class SourceQueryOptions; 30 class FileSource; 31 class Scheduler; 32 class GlyphManager; 33 class ImageManager; 34 class LineAtlas; 35 class CrossTileSymbolIndex; 36 37 class Renderer::Impl : public GlyphManagerObserver, 38 public RenderSourceObserver{ 39 public: 40 Impl(RendererBackend&, float pixelRatio_, FileSource&, Scheduler&, GLContextMode, 41 const optional<std::string> programCacheDir, const optional<std::string> localFontFamily); 42 ~Impl() final; 43 markContextLost()44 void markContextLost() { 45 contextLost = true; 46 }; 47 48 void setObserver(RendererObserver*); 49 50 void render(const UpdateParameters&); 51 52 std::vector<Feature> queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&) const; 53 std::vector<Feature> querySourceFeatures(const std::string& sourceID, const SourceQueryOptions&) const; 54 std::vector<Feature> queryShapeAnnotations(const ScreenLineString&) const; 55 56 void reduceMemoryUse(); 57 void dumDebugLogs(); 58 59 private: 60 bool isLoaded() const; 61 bool hasTransitions(TimePoint) const; 62 63 RenderSource* getRenderSource(const std::string& id) const; 64 65 RenderLayer* getRenderLayer(const std::string& id); 66 const RenderLayer* getRenderLayer(const std::string& id) const; 67 68 void queryRenderedSymbols(std::unordered_map<std::string, std::vector<Feature>>& resultsByLayer, 69 const ScreenLineString& geometry, 70 const std::vector<const RenderLayer*>& layers, 71 const RenderedQueryOptions& options) const; 72 73 std::vector<Feature> queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&, const std::vector<const RenderLayer*>&) const; 74 75 // GlyphManagerObserver implementation. 76 void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override; 77 78 // RenderSourceObserver implementation. 79 void onTileChanged(RenderSource&, const OverscaledTileID&) override; 80 void onTileError(RenderSource&, const OverscaledTileID&, std::exception_ptr) override; 81 82 void updateFadingTiles(); 83 84 friend class Renderer; 85 86 RendererBackend& backend; 87 Scheduler& scheduler; 88 FileSource& fileSource; 89 90 RendererObserver* observer; 91 92 const GLContextMode contextMode; 93 const float pixelRatio; 94 const optional<std::string> programCacheDir; 95 96 enum class RenderState { 97 Never, 98 Partial, 99 Fully, 100 }; 101 102 RenderState renderState = RenderState::Never; 103 ZoomHistory zoomHistory; 104 TransformState transformState; 105 106 std::unique_ptr<GlyphManager> glyphManager; 107 std::unique_ptr<ImageManager> imageManager; 108 std::unique_ptr<LineAtlas> lineAtlas; 109 std::unique_ptr<RenderStaticData> staticData; 110 111 Immutable<std::vector<Immutable<style::Image::Impl>>> imageImpls; 112 Immutable<std::vector<Immutable<style::Source::Impl>>> sourceImpls; 113 Immutable<std::vector<Immutable<style::Layer::Impl>>> layerImpls; 114 115 std::unordered_map<std::string, std::unique_ptr<RenderSource>> renderSources; 116 std::unordered_map<std::string, std::unique_ptr<RenderLayer>> renderLayers; 117 RenderLight renderLight; 118 119 CrossTileSymbolIndex crossTileSymbolIndex; 120 std::unique_ptr<Placement> placement; 121 122 bool contextLost = false; 123 bool fadingTiles = false; 124 }; 125 126 } // namespace mbgl 127