5#include "flutter/lib/ui/painting/image_encoding_impeller.h"
7#include "flutter/lib/ui/painting/image.h"
36 const std::shared_ptr<impeller::DeviceBuffer>&
buffer,
42 auto func = [](
void*
addr,
void* context) {
44 static_cast<std::shared_ptr<impeller::DeviceBuffer>*
>(context);
49 bitmap.installPixels(image_info,
buffer->OnGetContents(),
51 new std::shared_ptr<impeller::DeviceBuffer>(
buffer));
58[[nodiscard]]
fml::Status DoConvertImageToRasterImpeller(
61 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch,
62 const std::shared_ptr<impeller::Context>& impeller_context) {
64 is_gpu_disabled_sync_switch->Execute(
70 .SetIfFalse([&dl_image, &encode_task, &impeller_context] {
72 dl_image, encode_task, impeller_context);
80void DoConvertImageToRasterImpellerWithRetry(
83 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch,
84 const std::shared_ptr<impeller::Context>& impeller_context,
86 fml::Status status = DoConvertImageToRasterImpeller(
87 dl_image, encode_task, is_gpu_disabled_sync_switch, impeller_context);
92 impeller_context->StoreTaskForGPU(
93 [dl_image, encode_task = std::move(encode_task),
94 is_gpu_disabled_sync_switch, impeller_context,
95 retry_runner]()
mutable {
96 auto retry_task = [dl_image, encode_task = std::move(encode_task),
97 is_gpu_disabled_sync_switch, impeller_context] {
98 fml::Status retry_status = DoConvertImageToRasterImpeller(
99 dl_image, encode_task, is_gpu_disabled_sync_switch,
101 if (!retry_status.
ok()) {
104 encode_task(retry_status);
127 const std::shared_ptr<impeller::Context>& impeller_context) {
128 auto texture = dl_image->impeller_texture();
130 if (impeller_context ==
nullptr) {
132 "Impeller context was null."));
142 auto dimensions = dl_image->dimensions();
147 "Image dimensions were empty."));
153 "Failed to get color type from pixel format."));
161 texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
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");
169 pass->EncodeCommands(impeller_context->GetResourceAllocator());
171 encode_task = std::move(encode_task)](
179 encode_task(sk_image);
182 if (!impeller_context->GetCommandQueue()
183 ->Submit({command_buffer}, completion)
194 const std::shared_ptr<const fml::SyncSwitch>& is_gpu_disabled_sync_switch,
195 const std::shared_ptr<impeller::Context>& impeller_context) {
196 auto original_encode_task = std::move(encode_task);
197 encode_task = [original_encode_task = std::move(original_encode_task),
201 [original_encode_task = std::move(original_encode_task),
206 DoConvertImageToRasterImpellerWithRetry(dl_image, std::move(encode_task),
207 is_gpu_disabled_sync_switch,
213 raster_task_runner->
PostTask([dl_image, encode_task = std::move(encode_task),
214 io_task_runner, is_gpu_disabled_sync_switch,
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);
224 const std::shared_ptr<impeller::Texture>&
texture) {
226 switch (
desc.format) {
231 return ColorSpace::kSRGB;
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
@ kBGRA_10101010_XR_SkColorType
pixel with 10 bits each for blue, green, red, alpha; in 64-bit word, extended range
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kBGR_101010x_XR_SkColorType
pixel with 10 bits each for blue, green, red; in 32-bit word, extended range
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)
fml::StatusCode code() const
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual void PostTask(const fml::closure &task) override
#define FML_LOG(severity)
Dart_NativeFunction function
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
sk_sp< const SkImage > image
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
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 Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank trace to Write the timeline trace to a file at the specified path The file will be in Perfetto s proto format
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
static size_t bytes_per_pixel(skcms_PixelFormat fmt)
constexpr int32_t width() const
int bytesPerPixel() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
Represents the 2 code paths available when calling |SyncSwitch::Execute|.
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...