@@ -400,6 +400,54 @@ std::shared_ptr<Texture> CreateTextureForDecompressedImage(
400400 const std::shared_ptr<Context>& context,
401401 DecompressedImage& decompressed_image,
402402 bool enable_mipmapping) {
403+ // TODO(https://github.com/flutter/flutter/issues/123468): copying buffers to
404+ // textures is not implemented for GLES/Vulkan.
405+ #if FML_OS_MACOSX
406+ impeller::TextureDescriptor texture_descriptor;
407+ texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate ;
408+ texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
409+ texture_descriptor.size = decompressed_image.GetSize ();
410+ texture_descriptor.mip_count =
411+ enable_mipmapping ? decompressed_image.GetSize ().MipCount () : 1u ;
412+
413+ auto dest_texture =
414+ context->GetResourceAllocator ()->CreateTexture (texture_descriptor);
415+ if (!dest_texture) {
416+ FML_DLOG (ERROR) << " Could not create Impeller texture." ;
417+ return nullptr ;
418+ }
419+
420+ auto buffer = context->GetResourceAllocator ()->CreateBufferWithCopy (
421+ *decompressed_image.GetAllocation ().get ());
422+
423+ dest_texture->SetLabel (
424+ impeller::SPrintF (" ui.Image(%p)" , dest_texture.get ()).c_str ());
425+
426+ auto command_buffer = context->CreateCommandBuffer ();
427+ if (!command_buffer) {
428+ FML_DLOG (ERROR) << " Could not create command buffer for mipmap generation." ;
429+ return nullptr ;
430+ }
431+ command_buffer->SetLabel (" Mipmap Command Buffer" );
432+
433+ auto blit_pass = command_buffer->CreateBlitPass ();
434+ if (!blit_pass) {
435+ FML_DLOG (ERROR) << " Could not create blit pass for mipmap generation." ;
436+ return nullptr ;
437+ }
438+ blit_pass->SetLabel (" Mipmap Blit Pass" );
439+ blit_pass->AddCopy (buffer->AsBufferView (), dest_texture);
440+ if (enable_mipmapping) {
441+ blit_pass->GenerateMipmap (dest_texture);
442+ }
443+
444+ blit_pass->EncodeCommands (context->GetResourceAllocator ());
445+ if (!command_buffer->SubmitCommands ()) {
446+ FML_DLOG (ERROR) << " Failed to submit blit pass command buffer." ;
447+ return nullptr ;
448+ }
449+ return dest_texture;
450+ #else
403451 auto texture_descriptor = TextureDescriptor{};
404452 texture_descriptor.storage_mode = StorageMode::kHostVisible ;
405453 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
@@ -420,6 +468,7 @@ std::shared_ptr<Texture> CreateTextureForDecompressedImage(
420468 return nullptr ;
421469 }
422470 return texture;
471+ #endif // FML_OS_MACOS
423472}
424473} // namespace
425474
0 commit comments