From 07c0c63fda08a638591d7f911d7f9ddc0ef4d2aa Mon Sep 17 00:00:00 2001 From: Alexander Shalamov Date: Fri, 7 Feb 2020 16:43:26 +0200 Subject: [PATCH] [core] Clear tile pyramid for custom source only if there is a significant change Clear tile pyramid only if updated source has different tile options, zoom range or initialization state for a custom tile loader. --- .../renderer/sources/render_custom_geometry_source.cpp | 9 ++++++++- src/mbgl/style/sources/custom_geometry_source.cpp | 7 +++---- src/mbgl/style/sources/custom_geometry_source_impl.cpp | 4 ++++ src/mbgl/style/sources/custom_geometry_source_impl.hpp | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp index ea6f5c310..a54802b21 100644 --- a/src/mbgl/renderer/sources/render_custom_geometry_source.cpp +++ b/src/mbgl/renderer/sources/render_custom_geometry_source.cpp @@ -23,7 +23,14 @@ void RenderCustomGeometrySource::update(Immutable baseImpl_ const TileParameters& parameters) { if (baseImpl != baseImpl_) { std::swap(baseImpl, baseImpl_); - tilePyramid.clearAll(); + + // Clear tile pyramid only if updated source has different tile options, + // zoom range or initialization state for a custom tile loader. + auto newImpl = staticImmutableCast(baseImpl); + auto currentImpl = staticImmutableCast(baseImpl_); + if (*newImpl != *currentImpl) { + tilePyramid.clearAll(); + } } enabled = needsRendering; diff --git a/src/mbgl/style/sources/custom_geometry_source.cpp b/src/mbgl/style/sources/custom_geometry_source.cpp index 113298dd3..44401c1a8 100644 --- a/src/mbgl/style/sources/custom_geometry_source.cpp +++ b/src/mbgl/style/sources/custom_geometry_source.cpp @@ -14,11 +14,10 @@ namespace mbgl { namespace style { -CustomGeometrySource::CustomGeometrySource(std::string id, - const CustomGeometrySource::Options options) +CustomGeometrySource::CustomGeometrySource(std::string id, CustomGeometrySource::Options options) : Source(makeMutable(std::move(id), options)), - loader(std::make_unique>(Scheduler::GetBackground(), options.fetchTileFunction, options.cancelTileFunction)) { -} + loader(std::make_unique>( + Scheduler::GetBackground(), options.fetchTileFunction, options.cancelTileFunction)) {} CustomGeometrySource::~CustomGeometrySource() = default; diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.cpp b/src/mbgl/style/sources/custom_geometry_source_impl.cpp index 95da37727..e456bd871 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.cpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.cpp @@ -13,6 +13,10 @@ CustomGeometrySource::Impl::Impl(std::string id_, CustomGeometrySource::Options CustomGeometrySource::Impl::Impl(const Impl& impl, ActorRef loaderRef_) : Source::Impl(impl), tileOptions(impl.tileOptions), zoomRange(impl.zoomRange), loaderRef(loaderRef_) {} +bool CustomGeometrySource::Impl::operator!=(const Impl& other) const noexcept { + return tileOptions != other.tileOptions || zoomRange != other.zoomRange || bool(loaderRef) != bool(other.loaderRef); +} + optional CustomGeometrySource::Impl::getAttribution() const { return {}; } diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.hpp b/src/mbgl/style/sources/custom_geometry_source_impl.hpp index 1ae77b02e..04e301f19 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.hpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.hpp @@ -18,6 +18,7 @@ public: Immutable getTileOptions() const; Range getZoomRange() const; optional> getTileLoader() const; + bool operator!=(const Impl&) const noexcept; private: Immutable tileOptions;