#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class ChangeRequest; class RendererObserver; class RenderSource; class UpdateParameters; class RenderStaticData; class RenderedQueryOptions; class SourceQueryOptions; class GlyphManager; class ImageManager; class LineAtlas; class PatternAtlas; class CrossTileSymbolIndex; class RenderTree; namespace gfx { class ShaderRegistry; class Drawable; using DrawablePtr = std::shared_ptr; class DynamicTextureAtlas; using DynamicTextureAtlasPtr = std::shared_ptr; } // namespace gfx namespace style { class LayerProperties; } // namespace style using ImmutableLayer = Immutable; class RenderOrchestrator final : public GlyphManagerObserver, public ImageManagerObserver, public RenderSourceObserver { public: RenderOrchestrator(bool backgroundLayerAsColor_, TaggedScheduler& threadPool_, const std::optional& localFontFamily_); ~RenderOrchestrator() override; #if MLN_RENDER_BACKEND_OPENGL void enableAndroidEmulatorGoldfishMitigation(bool enable) { androidGoldfishMitigationEnabled = enable; } #endif void markContextLost() { contextLost = true; }; // TODO: Introduce RenderOrchestratorObserver. void setObserver(RendererObserver*); std::unique_ptr createRenderTree(const std::shared_ptr&, gfx::DynamicTextureAtlasPtr); std::vector queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&) const; std::vector querySourceFeatures(const std::string& sourceID, const SourceQueryOptions&) const; std::vector queryShapeAnnotations(const ScreenLineString&) const; FeatureExtensionValue queryFeatureExtensions(const std::string& sourceID, const Feature& feature, const std::string& extension, const std::string& extensionField, const std::optional>& args) const; void setFeatureState(const std::string& sourceID, const std::optional& layerID, const std::string& featureID, const FeatureState& state); void getFeatureState(FeatureState& state, const std::string& sourceID, const std::optional& layerID, const std::string& featureID) const; void removeFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, const std::optional& featureID, const std::optional& stateKey); void setTileCacheEnabled(bool); bool getTileCacheEnabled() const; void reduceMemoryUse(); void dumpDebugLogs(); void collectPlacedSymbolData(bool); const std::vector& getPlacedSymbolsData() const; void clearData(); void update(const std::shared_ptr&); bool addLayerGroup(LayerGroupBasePtr); bool removeLayerGroup(const LayerGroupBasePtr&); size_t numLayerGroups() const noexcept; void updateLayerIndex(LayerGroupBasePtr, int32_t newIndex); template void visitLayerGroups(Func f) { for (auto& pair : layerGroupsByLayerIndex) { if (pair.second) { try { f(*pair.second); } catch (...) { observer->onRenderError(std::current_exception()); } } } } template void visitLayerGroupsReversed(Func f) { for (auto rit = layerGroupsByLayerIndex.rbegin(); rit != layerGroupsByLayerIndex.rend(); ++rit) { if (rit->second) { try { f(*rit->second); } catch (...) { observer->onRenderError(std::current_exception()); } } } } void updateLayers(gfx::ShaderRegistry&, gfx::Context&, const TransformState&, const std::shared_ptr&, const PaintParameters& paintParameters, const RenderTree&); void processChanges(); bool addRenderTarget(RenderTargetPtr); bool removeRenderTarget(const RenderTargetPtr&); template void visitRenderTargets(Func f) { for (auto& renderTarget : renderTargets) { f(*renderTarget); } } void updateDebugLayerGroups(const RenderTree& renderTree, PaintParameters& parameters); template void visitDebugLayerGroups(Func f) { for (auto& pair : debugLayerGroups) { if (pair.second) { f(*pair.second); } } } const ZoomHistory& getZoomHistory() const { return zoomHistory; } private: bool isLoaded() const; bool hasTransitions(TimePoint) const; RenderSource* getRenderSource(const std::string& id) const; RenderLayer* getRenderLayer(const std::string& id); const RenderLayer* getRenderLayer(const std::string& id) const; void queryRenderedSymbols(std::unordered_map>& resultsByLayer, const ScreenLineString& geometry, const std::unordered_map& layers, const RenderedQueryOptions& options) const; std::vector queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&, const std::unordered_map&) const; // GlyphManagerObserver implementation. void onGlyphsLoaded(const FontStack&, const GlyphRange&) override; void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override; void onGlyphsRequested(const FontStack&, const GlyphRange&) override; // RenderSourceObserver implementation. void onTileChanged(RenderSource&, const OverscaledTileID&) override; void onTileError(RenderSource&, const OverscaledTileID&, std::exception_ptr) override; void onTileAction(RenderSource&, TileOperation, const OverscaledTileID&, const std::string&) override; void onSymbolError(RenderSource&, const std::string&) override; // ImageManagerObserver implementation void onStyleImageMissing(const std::string&, const std::function&) override; void onRemoveUnusedStyleImages(const std::vector&) override; /// Move changes into the pending set, clearing the provided collection void addChanges(UniqueChangeRequestVec&); RendererObserver* observer; ZoomHistory zoomHistory; TransformState transformState; std::shared_ptr glyphManager; std::shared_ptr imageManager; std::unique_ptr lineAtlas; std::unique_ptr patternAtlas; Immutable>> imageImpls; Immutable>> sourceImpls; Immutable>> layerImpls; std::unordered_map> renderSources; std::unordered_map> renderLayers; RenderLight renderLight; CrossTileSymbolIndex crossTileSymbolIndex; PlacementController placementController; const bool backgroundLayerAsColor; bool contextLost = false; bool placedSymbolDataCollected = false; bool tileCacheEnabled = true; #if MLN_RENDER_BACKEND_OPENGL bool androidGoldfishMitigationEnabled{false}; #endif // Vectors with reserved capacity of layerImpls->size() to avoid // reallocation on each frame. std::vector> filteredLayersForSource; RenderLayerReferences orderedLayers; RenderLayerReferences layersNeedPlacement; TaggedScheduler threadPool; std::vector> pendingChanges; using LayerGroupMap = std::multimap; LayerGroupMap layerGroupsByLayerIndex; std::vector renderTargets; RenderItem::DebugLayerGroupMap debugLayerGroups; }; } // namespace mbgl