#include #include #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { using namespace style; namespace { inline const CustomDrawableLayer::Impl& impl(const Immutable& impl) { assert(impl->getTypeInfo() == CustomDrawableLayer::Impl::staticTypeInfo()); return static_cast(*impl); } } // namespace RenderCustomDrawableLayer::RenderCustomDrawableLayer(Immutable _impl) : RenderLayer(makeMutable(std::move(_impl))), host(impl(baseImpl).host) { assert(gfx::BackendScope::exists()); host->initialize(); } RenderCustomDrawableLayer::~RenderCustomDrawableLayer() { assert(gfx::BackendScope::exists()); host->deinitialize(); } void RenderCustomDrawableLayer::evaluate(const PropertyEvaluationParameters&) { passes = RenderPass::Translucent; // It is fine to not update `evaluatedProperties`, as `baseImpl` should never be updated for this layer. } bool RenderCustomDrawableLayer::hasTransition() const { return false; } bool RenderCustomDrawableLayer::hasCrossfade() const { return false; } void RenderCustomDrawableLayer::prepare(const LayerPrepareParameters&) {} void RenderCustomDrawableLayer::update(gfx::ShaderRegistry& shaders, gfx::Context& context, const TransformState& state, const std::shared_ptr& updateParameters, const PaintParameters&, const RenderTree& renderTree, UniqueChangeRequestVec& changes) { // check if host changed and update bool hostChanged = (host != impl(baseImpl).host); if (hostChanged) { // deinitialize the previous one before initializing the new one. if (host) { host->deinitialize(); } host = impl(baseImpl).host; host->initialize(); } // delegate the call to the custom layer if (host) { CustomDrawableLayerHost::Interface interface( *this, layerGroup, shaders, context, state, updateParameters, renderTree, changes); host->update(interface); } } } // namespace mbgl