diff options
-rw-r--r-- | src/mbgl/renderer/image_manager.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/image_manager.hpp | 15 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/tile/geometry_tile.hpp | 2 | ||||
-rw-r--r-- | test/renderer/image_manager.test.cpp | 10 |
5 files changed, 25 insertions, 11 deletions
diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp index f373167493..8e584ffd34 100644 --- a/src/mbgl/renderer/image_manager.cpp +++ b/src/mbgl/renderer/image_manager.cpp @@ -288,4 +288,11 @@ gfx::TextureBinding ImageManager::textureBinding(gfx::Context& context) { return { atlasTexture->getResource(), gfx::TextureFilterType::Linear }; } +ImageRequestor::ImageRequestor(ImageManager& imageManager_) : imageManager(imageManager_) { +} + +ImageRequestor::~ImageRequestor() { + imageManager.removeRequestor(*this); +} + } // namespace mbgl diff --git a/src/mbgl/renderer/image_manager.hpp b/src/mbgl/renderer/image_manager.hpp index f52808b614..61f3f3c276 100644 --- a/src/mbgl/renderer/image_manager.hpp +++ b/src/mbgl/renderer/image_manager.hpp @@ -19,11 +19,7 @@ namespace gfx { class Context; } // namespace gfx -class ImageRequestor { -public: - virtual ~ImageRequestor() = default; - virtual void onImagesAvailable(ImageMap icons, ImageMap patterns, ImageVersionMap versionMap, uint64_t imageCorrelationID) = 0; -}; +class ImageRequestor; /* ImageManager does two things: @@ -105,4 +101,13 @@ private: bool dirty = true; }; +class ImageRequestor { +public: + explicit ImageRequestor(ImageManager&); + virtual ~ImageRequestor(); + virtual void onImagesAvailable(ImageMap icons, ImageMap patterns, ImageVersionMap versionMap, uint64_t imageCorrelationID) = 0; +private: + ImageManager& imageManager; +}; + } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 792586e73d..029c761e53 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -42,6 +42,7 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_, std::string sourceID_, const TileParameters& parameters) : Tile(Kind::Geometry, id_), + ImageRequestor(parameters.imageManager), sourceID(std::move(sourceID_)), mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), worker(parameters.workerScheduler, @@ -60,7 +61,6 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_, GeometryTile::~GeometryTile() { glyphManager.removeRequestor(*this); - imageManager.removeRequestor(*this); markObsolete(); } diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index 18f94b9a1f..975c7aab0e 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -22,7 +22,7 @@ class TileParameters; class GlyphAtlas; class ImageAtlas; -class GeometryTile : public Tile, public GlyphRequestor, ImageRequestor { +class GeometryTile : public Tile, public GlyphRequestor, public ImageRequestor { public: GeometryTile(const OverscaledTileID&, std::string sourceID, diff --git a/test/renderer/image_manager.test.cpp b/test/renderer/image_manager.test.cpp index d124e67e10..51b257094a 100644 --- a/test/renderer/image_manager.test.cpp +++ b/test/renderer/image_manager.test.cpp @@ -108,6 +108,8 @@ TEST(ImageManager, RemoveReleasesBinPackRect) { class StubImageRequestor : public ImageRequestor { public: + StubImageRequestor(ImageManager& imageManager) : ImageRequestor(imageManager) {} + void onImagesAvailable(ImageMap icons, ImageMap patterns, std::unordered_map<std::string, uint32_t> versionMap, uint64_t imageCorrelationID_) final { if (imagesAvailable && imageCorrelationID == imageCorrelationID_) imagesAvailable(icons, patterns, versionMap); } @@ -118,7 +120,7 @@ public: TEST(ImageManager, NotifiesRequestorWhenSpriteIsLoaded) { ImageManager imageManager; - StubImageRequestor requestor; + StubImageRequestor requestor(imageManager); bool notified = false; ImageManagerObserver observer; @@ -142,7 +144,7 @@ TEST(ImageManager, NotifiesRequestorWhenSpriteIsLoaded) { TEST(ImageManager, NotifiesRequestorImmediatelyIfDependenciesAreSatisfied) { ImageManager imageManager; - StubImageRequestor requestor; + StubImageRequestor requestor(imageManager); bool notified = false; requestor.imagesAvailable = [&] (ImageMap, ImageMap, std::unordered_map<std::string, uint32_t>) { @@ -170,7 +172,7 @@ class StubImageManagerObserver : public ImageManagerObserver { TEST(ImageManager, OnStyleImageMissingBeforeSpriteLoaded) { ImageManager imageManager; - StubImageRequestor requestor; + StubImageRequestor requestor(imageManager); StubImageManagerObserver observer; imageManager.setObserver(&observer); @@ -203,7 +205,7 @@ TEST(ImageManager, OnStyleImageMissingBeforeSpriteLoaded) { TEST(ImageManager, OnStyleImageMissingAfterSpriteLoaded) { ImageManager imageManager; - StubImageRequestor requestor; + StubImageRequestor requestor(imageManager); StubImageManagerObserver observer; imageManager.setObserver(&observer); |