Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
pixel_deferred_image_gpu_impeller.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
6
9
10namespace flutter {
11
12sk_sp<PixelDeferredImageGPUImpeller> PixelDeferredImageGPUImpeller::Make(
13 sk_sp<SkImage> image,
15 fml::RefPtr<fml::TaskRunner> raster_task_runner) {
16 return sk_sp<PixelDeferredImageGPUImpeller>(new PixelDeferredImageGPUImpeller(
17 PixelDeferredImageGPUImpeller::ImageWrapper::Make(
18 std::move(image), std::move(snapshot_delegate),
19 std::move(raster_task_runner))));
20}
21
22PixelDeferredImageGPUImpeller::PixelDeferredImageGPUImpeller(
23 std::shared_ptr<ImageWrapper> wrapper)
24 : wrapper_(std::move(wrapper)) {}
25
27
28std::shared_ptr<impeller::Texture>
30 const std::shared_ptr<impeller::Context>& context) const {
31 if (!wrapper_) {
32 return nullptr;
33 }
34 return wrapper_->texture();
35}
36
38 return false;
39}
40
42 return true;
43}
44
46 return wrapper_ ? wrapper_->size() : DlISize();
47}
48
51 if (wrapper_) {
52 if (wrapper_->texture()) {
53 size += wrapper_->texture()
54 ->GetTextureDescriptor()
55 .GetByteSizeOfBaseMipLevel();
56 } else {
57 size += wrapper_->size().Area() * 4;
58 }
59 }
60 return size;
61}
62
64 if (!wrapper_) {
66 }
67 std::shared_ptr<impeller::Texture> texture = wrapper_->texture();
68 if (!texture) {
70 }
71 switch (texture->GetTextureDescriptor().format) {
75 default:
77 }
78}
79
80std::optional<std::string> PixelDeferredImageGPUImpeller::get_error() const {
81 return wrapper_ ? wrapper_->get_error() : std::nullopt;
82}
83
84std::shared_ptr<PixelDeferredImageGPUImpeller::ImageWrapper>
85PixelDeferredImageGPUImpeller::ImageWrapper::Make(
86 sk_sp<SkImage> image,
88 fml::RefPtr<fml::TaskRunner> raster_task_runner) {
89 auto wrapper = std::shared_ptr<ImageWrapper>(new ImageWrapper(
90 image, std::move(snapshot_delegate), std::move(raster_task_runner)));
91 wrapper->SnapshotImage(std::move(image));
92 return wrapper;
93}
94
95PixelDeferredImageGPUImpeller::ImageWrapper::ImageWrapper(
96 const sk_sp<SkImage>& image,
98 fml::RefPtr<fml::TaskRunner> raster_task_runner)
99 : size_(DlISize(image->width(), image->height())),
100 snapshot_delegate_(std::move(snapshot_delegate)),
101 raster_task_runner_(std::move(raster_task_runner)) {}
102
103PixelDeferredImageGPUImpeller::ImageWrapper::~ImageWrapper() = default;
104
105void PixelDeferredImageGPUImpeller::ImageWrapper::SnapshotImage(
106 sk_sp<SkImage> image) {
108 raster_task_runner_,
110 [weak_this = weak_from_this(), image = std::move(image)]() mutable {
111 TRACE_EVENT0("flutter", "SnapshotImage (impeller)");
112 auto wrapper = weak_this.lock();
113 if (!wrapper) {
114 return;
115 }
116 FML_DCHECK(!wrapper->texture_) << "should only execute once.";
117 auto snapshot_delegate = wrapper->snapshot_delegate_;
118 if (!snapshot_delegate) {
119 return;
120 }
121
122 // Use MakeImpellerTextureImage directly.
123 auto snapshot_texture = snapshot_delegate->MakeImpellerTextureImage(
125 if (!snapshot_texture) {
126 std::scoped_lock lock(wrapper->error_mutex_);
127 wrapper->error_ = "Failed to create snapshot.";
128 return;
129 }
130 wrapper->texture_ = snapshot_texture;
131 }));
132}
133
134std::optional<std::string>
135PixelDeferredImageGPUImpeller::ImageWrapper::get_error() const {
136 std::scoped_lock lock(error_mutex_);
137 return error_;
138}
139
140} // namespace flutter
std::shared_ptr< impeller::Texture > GetImpellerTexture(const std::shared_ptr< impeller::Context > &context) const override
DlColorSpace GetColorSpace() const override
Gets the color space of the image.
bool isOpaque() const override
If the pixel format of this image ignores alpha, this returns true. This method might conservatively ...
static sk_sp< PixelDeferredImageGPUImpeller > Make(sk_sp< SkImage > image, fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate, fml::RefPtr< fml::TaskRunner > raster_task_runner)
bool isUIThreadSafe() const override
If the underlying platform image held by this object has no threading requirements for the release of...
std::optional< std::string > get_error() const override
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
FlutterVulkanImage * image
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > snapshot_delegate_
#define FML_DCHECK(condition)
Definition logging.h:122
FlTexture * texture
impeller::ISize32 DlISize
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
DlColorSpace
Definition dl_color.h:13
internal::CopyableLambda< T > MakeCopyable(T lambda)
Definition ref_ptr.h:261
int32_t height
int32_t width
#define TRACE_EVENT0(category_group, name)