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 committed Oct 20, 2021
1 parent faa45f4 commit cd51690
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 2 additions & 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,8 @@ ImageGeneratorRegistry::~ImageGeneratorRegistry() = default;

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

std::shared_ptr<ImageGenerator>
Expand Down
38 changes: 38 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,43 @@ 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 cd51690

Please sign in to comment.