Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Fix bug where native image decoders aren't working in release mode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored Oct 20, 2021
1 parent 6b3423e commit 2cad9d2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ui/painting/image_generator_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <algorithm>

#include "flutter/fml/trace_event.h"
#include "flutter/lib/ui/painting/image_generator_registry.h"
#include "third_party/skia/include/codec/SkCodec.h"
#include "third_party/skia/include/core/SkImageGenerator.h"
Expand Down Expand Up @@ -48,8 +47,7 @@ ImageGeneratorRegistry::~ImageGeneratorRegistry() = default;

void ImageGeneratorRegistry::AddFactory(ImageGeneratorFactory factory,
int32_t priority) {
image_generator_factories_.insert(
{factory, priority, fml::tracing::TraceNonce()});
image_generator_factories_.insert({factory, priority, ++nonce_});
}

std::shared_ptr<ImageGenerator>
Expand Down
1 change: 1 addition & 0 deletions lib/ui/painting/image_generator_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ImageGeneratorRegistry {

using FactorySet = std::set<PrioritizedFactory, Compare>;
FactorySet image_generator_factories_;
size_t nonce_;
fml::WeakPtrFactory<ImageGeneratorRegistry> weak_factory_;
};

Expand Down
37 changes: 37 additions & 0 deletions lib/ui/painting/image_generator_registry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,42 @@ TEST_F(ShellTest, DefaultGeneratorsTakePrecedentOverNegativePriority) {
ASSERT_EQ(result->GetInfo().width(), 3024);
}

TEST_F(ShellTest, DefaultGeneratorsTakePrecedentOverZeroPriority) {
ImageGeneratorRegistry registry;

registry.AddFactory(
[](sk_sp<SkData> buffer) {
return std::make_unique<FakeImageGenerator>(1337);
},
0);

// Fetch the generator and query for basic info.
auto result = registry.CreateCompatibleGenerator(LoadValidImageFixture());
// If the real width of the image pops out, then the default generator was
// returned rather than the fake one.
ASSERT_EQ(result->GetInfo().width(), 3024);
}

TEST_F(ShellTest, ImageGeneratorsWithSamePriorityCascadeChronologically) {
ImageGeneratorRegistry registry;

// Add 2 factories with the same high priority.
registry.AddFactory(
[](sk_sp<SkData> buffer) {
return std::make_unique<FakeImageGenerator>(1337);
},
5);
registry.AddFactory(
[](sk_sp<SkData> buffer) {
return std::make_unique<FakeImageGenerator>(7777);
},
5);

// Feed empty data so that Skia's image generators will reject it, but ours
// won't.
auto result = registry.CreateCompatibleGenerator(SkData::MakeEmpty());
ASSERT_EQ(result->GetInfo().width(), 1337);
}

} // namespace testing
} // namespace flutter

0 comments on commit 2cad9d2

Please sign in to comment.