Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Notify image requestors only when all dependencies are met
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Aug 23, 2017
1 parent a2b0a54 commit c69fbee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 4 additions & 6 deletions src/mbgl/renderer/image_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ void ImageManager::getImages(ImageRequestor& requestor, ImageDependencies depend
// Otherwise, delay notification until the sprite is loaded. At that point, if any of the
// dependencies are still unavailable, we'll just assume they are permanently missing.
bool hasAllDependencies = true;
if (!isLoaded()) {
for (const auto& dependency : dependencies) {
if (images.find(dependency) == images.end()) {
hasAllDependencies = false;
}
for (const auto& dependency : dependencies) {
if (images.find(dependency) == images.end()) {
hasAllDependencies = false;
}
}
if (isLoaded() || hasAllDependencies) {
if (isLoaded() && hasAllDependencies) {
notify(requestor, dependencies);
} else {
requestors.emplace(&requestor, std::move(dependencies));
Expand Down
7 changes: 4 additions & 3 deletions test/renderer/image_manager.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ TEST(ImageManager, NotifiesRequestorWhenSpriteIsLoaded) {
TEST(ImageManager, NotifiesRequestorImmediatelyIfDependenciesAreSatisfied) {
ImageManager imageManager;
StubImageRequestor requestor;
bool notified = false;
uint64_t imagesAvailableCount = 0;

requestor.imagesAvailable = [&] (ImageMap) {
notified = true;
++imagesAvailableCount;
};

imageManager.setLoaded(true);
imageManager.addImage(makeMutable<style::Image::Impl>("one", PremultipliedImage({ 16, 16 }), 2));
imageManager.getImages(requestor, {"one"});

ASSERT_TRUE(notified);
ASSERT_EQ(imagesAvailableCount, 1u);
}

0 comments on commit c69fbee

Please sign in to comment.