Flutter Engine
 
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/SkCodec.h"
10#include "third_party/skia/include/core/SkImageGenerator.h"
11#ifdef FML_OS_MACOSX
12#include "third_party/skia/include/ports/SkImageGeneratorCG.h"
13#elif FML_OS_WIN
14#include "third_party/skia/include/ports/SkImageGeneratorWIC.h"
15#endif
16
18
19namespace flutter {
20
23 [](sk_sp<SkData> buffer) {
25 },
26 0);
27
29 [](sk_sp<SkData> buffer) {
31 },
32 0);
33
34 // todo(bdero): https://github.com/flutter/flutter/issues/82603
35#ifdef FML_OS_MACOSX
37 [](sk_sp<SkData> buffer) {
38 auto generator =
39 SkImageGeneratorCG::MakeFromEncodedCG(std::move(buffer));
41 std::move(generator));
42 },
43 0);
44#elif FML_OS_WIN
46 [](sk_sp<SkData> buffer) {
47 auto generator = SkImageGeneratorWIC::MakeFromEncodedWIC(buffer);
49 std::move(generator));
50 },
51 0);
52#endif
53}
54
56
58 int32_t priority) {
59 image_generator_factories_.insert({std::move(factory), priority, ++nonce_});
60}
61
62std::shared_ptr<ImageGenerator>
64 if (!image_generator_factories_.size()) {
65 FML_LOG(WARNING)
66 << "There are currently no image decoders installed. If you're writing "
67 "your own platform embedding, you can register new image decoders "
68 "via `ImageGeneratorRegistry::AddFactory` on the "
69 "`ImageGeneratorRegistry` provided by the engine. Otherwise, please "
70 "file a bug on https://github.com/flutter/flutter/issues.";
71 }
72
73 for (auto& factory : image_generator_factories_) {
74 std::shared_ptr<ImageGenerator> result = factory.callback(buffer);
75 if (result) {
76 return result;
77 }
78 }
79 return nullptr;
80}
81
84 return weak_factory_.GetWeakPtr();
85}
86
87} // 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