Flutter Engine
 
Loading...
Searching...
No Matches
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 fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > &snapshot_delegate, 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 fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > &snapshot_delegate, 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 21 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 fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > &  snapshot_delegate,
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 135 of file image_encoding_impeller.cc.

139 {
140 auto texture = dl_image->impeller_texture();
141
142 if (impeller_context == nullptr) {
144 "Impeller context was null."));
145 return;
146 }
147
148 if (texture == nullptr) {
149 encode_task(
151 return;
152 }
153
154 auto dimensions = dl_image->GetSize();
155 auto color_type = ToSkColorType(texture->GetTextureDescriptor().format);
156
157 if (dimensions.IsEmpty()) {
159 "Image dimensions were empty."));
160 return;
161 }
162
163 if (!color_type.has_value()) {
165 "Failed to get color type from pixel format."));
166 return;
167 }
168
169 // Ensure that this thread has a context that can execute rendering
170 // commands. The thread may not already have a context if the raster
171 // task runner was assigned to a new thread and no previous rendering
172 // task has run on that thread.
173 if (snapshot_delegate) {
174 if (!snapshot_delegate->MakeRenderContextCurrent()) {
176 "Failed to bind the render context."));
177 return;
178 }
179 }
180
183 buffer_desc.readback = true; // set to false for testing.
184 buffer_desc.size =
185 texture->GetTextureDescriptor().GetByteSizeOfBaseMipLevel();
186 auto buffer =
187 impeller_context->GetResourceAllocator()->CreateBuffer(buffer_desc);
188 if (!buffer) {
190 "Failed to allocate destination buffer."));
191 return;
192 }
193
194 auto command_buffer = impeller_context->CreateCommandBuffer();
195 command_buffer->SetLabel("BlitTextureToBuffer Command Buffer");
196 auto pass = command_buffer->CreateBlitPass();
197 pass->SetLabel("BlitTextureToBuffer Blit Pass");
198 pass->AddCopy(texture, buffer);
199 pass->EncodeCommands();
200 auto completion = [buffer, color_type = color_type.value(), dimensions,
201 encode_task = std::move(encode_task)](
204 encode_task(fml::Status(fml::StatusCode::kUnknown, ""));
205 return;
206 }
207 buffer->Invalidate();
208 auto sk_image =
209 ConvertBufferToSkImage(buffer, color_type, ToSkISize(dimensions));
210 encode_task(sk_image);
211 };
212
213 if (!impeller_context->GetCommandQueue()
214 ->Submit({command_buffer}, completion)
215 .ok()) {
216 FML_LOG(ERROR) << "Failed to submit commands.";
217 }
218
219 impeller_context->DisposeThreadLocalCachedResources();
220}
#define FML_LOG(severity)
Definition logging.h:101
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 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
const SkISize & ToSkISize(const DlISize &size)
uint32_t color_type

References flutter::buffer, color_type, FML_LOG, impeller::CommandBuffer::kCompleted, fml::kFailedPrecondition, impeller::kHostVisible, fml::kUnimplemented, fml::kUnknown, impeller::DeviceBufferDescriptor::readback, impeller::DeviceBufferDescriptor::size, impeller::DeviceBufferDescriptor::storage_mode, texture, and flutter::ToSkISize().

◆ 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 fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > &  snapshot_delegate,
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 222 of file image_encoding_impeller.cc.

229 {
230 auto original_encode_task = std::move(encode_task);
231 encode_task = [original_encode_task = std::move(original_encode_task),
232 io_task_runner](fml::StatusOr<sk_sp<SkImage>> image) mutable {
234 io_task_runner,
235 [original_encode_task = std::move(original_encode_task),
236 image = std::move(image)]() { original_encode_task(image); });
237 };
238
239 if (dl_image->owning_context() != DlImage::OwningContext::kRaster) {
240 DoConvertImageToRasterImpellerWithRetry(
241 dl_image, std::move(encode_task),
242 /*snapshot_delegate=*/{}, is_gpu_disabled_sync_switch, impeller_context,
243 /*retry_runner=*/nullptr);
244 return;
245 }
246
247 raster_task_runner->PostTask([dl_image, encode_task = std::move(encode_task),
248 io_task_runner, snapshot_delegate,
249 is_gpu_disabled_sync_switch, impeller_context,
250 raster_task_runner]() mutable {
251 DoConvertImageToRasterImpellerWithRetry(
252 dl_image, std::move(encode_task), snapshot_delegate,
253 is_gpu_disabled_sync_switch, impeller_context, raster_task_runner);
254 });
255}
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
virtual void PostTask(const fml::closure &task) override
FlutterVulkanImage * image

References image, flutter::DlImage::kRaster, and fml::TaskRunner::RunNowOrPostTask().

◆ GetColorSpace()

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

Definition at line 257 of file image_encoding_impeller.cc.

258 {
259 const impeller::TextureDescriptor& desc = texture->GetTextureDescriptor();
260 switch (desc.format) {
261 case impeller::PixelFormat::kB10G10R10XR: // intentional_fallthrough
264 default:
265 return ColorSpace::kSRGB;
266 }
267}
@ kExtendedSRGB
Definition image.h:18
@ kSRGB
Definition image.h:17
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...

References impeller::TextureDescriptor::format, impeller::kB10G10R10XR, flutter::kExtendedSRGB, impeller::kR16G16B16A16Float, flutter::kSRGB, and texture.

Referenced by flutter::CanvasImage::colorSpace().


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