19 const sk_sp<SkImage>&
image,
21 const std::shared_ptr<const SyncSwitch>& is_gpu_disabled_sync_switch) {
23 SkImageInfo surface_info = SkImageInfo::MakeN32Premul(
image->dimensions());
25 is_gpu_disabled_sync_switch->Execute(
26 typename SyncSwitch::Handlers()
27 .SetIfTrue([&
surface, &surface_info] {
28 surface = SkSurfaces::Raster(surface_info);
30 .SetIfFalse([&
surface, &surface_info, resource_context] {
31 if (resource_context) {
32 surface = SkSurfaces::RenderTarget(
33 resource_context.
get(), skgpu::Budgeted::kNo, surface_info);
35 surface = SkSurfaces::Raster(surface_info);
40 FML_LOG(ERROR) <<
"Could not create a surface to copy the texture into.";
45 if (resource_context) {
46 resource_context->flushAndSubmit();
49 auto snapshot =
surface->makeImageSnapshot();
51 if (snapshot ==
nullptr) {
52 FML_LOG(ERROR) <<
"Could not snapshot image to encode.";
56 return snapshot->makeRasterImage(resource_context.
get());