Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
flutter::ImageEncodingImpeller Class Reference

#include <image_encoding_impeller.h>

Static Public Member Functions

static int GetColorSpace (const std::shared_ptr< impeller::Texture > &texture)
 
static void ConvertDlImageToSkImage (const sk_sp< DlImage > &dl_image, std::function< void(fml::StatusOr< sk_sp< SkImage > >)> encode_task, const std::shared_ptr< impeller::Context > &impeller_context)
 
static void ConvertImageToRaster (const sk_sp< DlImage > &dl_image, std::function< void(fml::StatusOr< sk_sp< SkImage > >)> encode_task, const fml::RefPtr< fml::TaskRunner > &raster_task_runner, const fml::RefPtr< fml::TaskRunner > &io_task_runner, const std::shared_ptr< const fml::SyncSwitch > &is_gpu_disabled_sync_switch, const std::shared_ptr< impeller::Context > &impeller_context)
 

Detailed Description

Definition at line 19 of file image_encoding_impeller.h.

Member Function Documentation

◆ ConvertDlImageToSkImage()

void flutter::ImageEncodingImpeller::ConvertDlImageToSkImage ( const sk_sp< DlImage > &  dl_image,
std::function< void(fml::StatusOr< sk_sp< SkImage > >)>  encode_task,
const std::shared_ptr< impeller::Context > &  impeller_context 
)
static

Converts a DlImage to a SkImage. This should be called from the thread that corresponds to dl_image->owning_context() when gpu access is guaranteed. See also: ConvertImageToRaster. Visible for testing.

Definition at line 124 of file image_encoding_impeller.cc.

127 {
128 auto texture = dl_image->impeller_texture();
129
130 if (impeller_context == nullptr) {
132 "Impeller context was null."));
133 return;
134 }
135
136 if (texture == nullptr) {
137 encode_task(
139 return;
140 }
141
142 auto dimensions = dl_image->dimensions();
143 auto color_type = ToSkColorType(texture->GetTextureDescriptor().format);
144
145 if (dimensions.isEmpty()) {
147 "Image dimensions were empty."));
148 return;
149 }
150
151 if (!color_type.has_value()) {
153 "Failed to get color type from pixel format."));
154 return;
155 }
156
159 buffer_desc.readback = true; // set to false for testing.
160 buffer_desc.size =
161 texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
162 auto buffer =
163 impeller_context->GetResourceAllocator()->CreateBuffer(buffer_desc);
164 auto command_buffer = impeller_context->CreateCommandBuffer();
165 command_buffer->SetLabel("BlitTextureToBuffer Command Buffer");
166 auto pass = command_buffer->CreateBlitPass();
167 pass->SetLabel("BlitTextureToBuffer Blit Pass");
168 pass->AddCopy(texture, buffer);
169 pass->EncodeCommands(impeller_context->GetResourceAllocator());
170 auto completion = [buffer, color_type = color_type.value(), dimensions,
171 encode_task = std::move(encode_task)](
174 encode_task(fml::Status(fml::StatusCode::kUnknown, ""));
175 return;
176 }
177 buffer->Invalidate();
178 auto sk_image = ConvertBufferToSkImage(buffer, color_type, dimensions);
179 encode_task(sk_image);
180 };
181
182 if (!impeller_context->GetCommandQueue()
183 ->Submit({command_buffer}, completion)
184 .ok()) {
185 FML_LOG(ERROR) << "Failed to submit commands.";
186 }
187}
#define FML_LOG(severity)
Definition: logging.h:82
FlTexture * texture
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
uint32_t color_type
#define ERROR(message)
Definition: elf_loader.cc:260

◆ ConvertImageToRaster()

void flutter::ImageEncodingImpeller::ConvertImageToRaster ( const sk_sp< DlImage > &  dl_image,
std::function< void(fml::StatusOr< sk_sp< SkImage > >)>  encode_task,
const fml::RefPtr< fml::TaskRunner > &  raster_task_runner,
const fml::RefPtr< fml::TaskRunner > &  io_task_runner,
const std::shared_ptr< const fml::SyncSwitch > &  is_gpu_disabled_sync_switch,
const std::shared_ptr< impeller::Context > &  impeller_context 
)
static

Converts a DlImage to a SkImage. encode_task is executed with the resulting SkImage.

Definition at line 189 of file image_encoding_impeller.cc.

195 {
196 auto original_encode_task = std::move(encode_task);
197 encode_task = [original_encode_task = std::move(original_encode_task),
198 io_task_runner](fml::StatusOr<sk_sp<SkImage>> image) mutable {
200 io_task_runner,
201 [original_encode_task = std::move(original_encode_task),
202 image = std::move(image)]() { original_encode_task(image); });
203 };
204
205 if (dl_image->owning_context() != DlImage::OwningContext::kRaster) {
206 DoConvertImageToRasterImpellerWithRetry(dl_image, std::move(encode_task),
207 is_gpu_disabled_sync_switch,
208 impeller_context,
209 /*retry_runner=*/nullptr);
210 return;
211 }
212
213 raster_task_runner->PostTask([dl_image, encode_task = std::move(encode_task),
214 io_task_runner, is_gpu_disabled_sync_switch,
215 impeller_context,
216 raster_task_runner]() mutable {
217 DoConvertImageToRasterImpellerWithRetry(
218 dl_image, std::move(encode_task), is_gpu_disabled_sync_switch,
219 impeller_context, raster_task_runner);
220 });
221}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
Definition: task_runner.cc:55
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ GetColorSpace()

int flutter::ImageEncodingImpeller::GetColorSpace ( const std::shared_ptr< impeller::Texture > &  texture)
static

Definition at line 223 of file image_encoding_impeller.cc.

224 {
225 const impeller::TextureDescriptor& desc = texture->GetTextureDescriptor();
226 switch (desc.format) {
227 case impeller::PixelFormat::kB10G10R10XR: // intentional_fallthrough
230 default:
231 return ColorSpace::kSRGB;
232 }
233}
@ kExtendedSRGB
Definition: image.h:18
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...

The documentation for this class was generated from the following files: