Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
image_generator_registry.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <algorithm>
6#include <utility>
7
9#include "third_party/skia/include/codec/SkBmpDecoder.h"
10#include "third_party/skia/include/codec/SkCodec.h"
11#include "third_party/skia/include/codec/SkGifDecoder.h"
12#include "third_party/skia/include/codec/SkIcoDecoder.h"
13#include "third_party/skia/include/codec/SkJpegDecoder.h"
14#include "third_party/skia/include/codec/SkPngDecoder.h"
15#include "third_party/skia/include/codec/SkWbmpDecoder.h"
16#include "third_party/skia/include/codec/SkWebpDecoder.h"
17#include "third_party/skia/include/core/SkImageGenerator.h"
18#ifdef FML_OS_MACOSX
19#include "third_party/skia/include/ports/SkImageGeneratorCG.h"
20#elif FML_OS_WIN
21#include "third_party/skia/include/ports/SkImageGeneratorWIC.h"
22#endif
23
25
26#include <mutex>
27
28namespace {
29void RegisterSkiaCodecs() {
30 // These are in the order they will be attempted to be decoded from.
31 // If we have data to back it up, we can order these by "frequency used in
32 // the wild" for a very small performance bump, but for now we mirror the
33 // order Skia had them in.
34 SkCodecs::Register(SkPngDecoder::Decoder());
35 SkCodecs::Register(SkJpegDecoder::Decoder());
36 SkCodecs::Register(SkWebpDecoder::Decoder());
37 SkCodecs::Register(SkGifDecoder::Decoder());
38 SkCodecs::Register(SkBmpDecoder::Decoder());
39 SkCodecs::Register(SkWbmpDecoder::Decoder());
40 SkCodecs::Register(SkIcoDecoder::Decoder());
41}
42
43} // namespace
44
45namespace flutter {
46
49 [](sk_sp<SkData> buffer) {
51 },
52 0);
53
54 static std::once_flag register_skia_codecs;
55 std::call_once(register_skia_codecs, RegisterSkiaCodecs);
57 [](sk_sp<SkData> buffer) {
59 },
60 0);
61
62 // todo(bdero): https://github.com/flutter/flutter/issues/82603
63#ifdef FML_OS_MACOSX
65 [](sk_sp<SkData> buffer) {
66 auto generator =
67 SkImageGeneratorCG::MakeFromEncodedCG(std::move(buffer));
69 std::move(generator));
70 },
71 0);
72#elif FML_OS_WIN
74 [](sk_sp<SkData> buffer) {
75 auto generator = SkImageGeneratorWIC::MakeFromEncodedWIC(buffer);
77 std::move(generator));
78 },
79 0);
80#endif
81}
82
84
86 int32_t priority) {
87 image_generator_factories_.insert({std::move(factory), priority, ++nonce_});
88}
89
90std::shared_ptr<ImageGenerator>
92 if (!image_generator_factories_.size()) {
93 FML_LOG(WARNING)
94 << "There are currently no image decoders installed. If you're writing "
95 "your own platform embedding, you can register new image decoders "
96 "via `ImageGeneratorRegistry::AddFactory` on the "
97 "`ImageGeneratorRegistry` provided by the engine. Otherwise, please "
98 "file a bug on https://github.com/flutter/flutter/issues.";
99 }
100
101 for (auto& factory : image_generator_factories_) {
102 std::shared_ptr<ImageGenerator> result = factory.callback(buffer);
103 if (result) {
104 return result;
105 }
106 }
107 return nullptr;
108}
109
112 return weak_factory_.GetWeakPtr();
113}
114
115} // namespace flutter
static std::unique_ptr< ImageGenerator > MakeFromData(sk_sp< SkData > data)
static std::unique_ptr< ImageGenerator > MakeFromData(sk_sp< SkData > data)
static std::unique_ptr< ImageGenerator > MakeFromGenerator(std::unique_ptr< SkImageGenerator > generator)
fml::TaskRunnerAffineWeakPtr< ImageGeneratorRegistry > GetWeakPtr() const
std::shared_ptr< ImageGenerator > CreateCompatibleGenerator(const sk_sp< SkData > &buffer)
Walks the list of image generator builders in descending priority order until a compatible ImageGener...
void AddFactory(ImageGeneratorFactory factory, int32_t priority)
Install a new factory for image generators.
#define FML_LOG(severity)
Definition logging.h:101
std::function< std::shared_ptr< ImageGenerator >(sk_sp< SkData > buffer)> ImageGeneratorFactory
ImageGeneratorFactory is the top level primitive for specifying an image decoder in Flutter....
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set profile Make the profiler discard new samples once the profiler sample buffer is full When this flag is not the profiler sample buffer is used as a ring buffer
Definition switch_defs.h:98