@@ -395,82 +395,82 @@ std::optional<DecompressedImage> Playground::DecodeImageRGBA(
395395 return image;
396396}
397397
398- namespace {
399- std::shared_ptr<Texture> CreateTextureForDecompressedImage (
398+ static std::shared_ptr<Texture> CreateTextureForDecompressedImage (
400399 const std::shared_ptr<Context>& context,
401400 DecompressedImage& decompressed_image,
402401 bool enable_mipmapping) {
403402 // TODO(https://github.com/flutter/flutter/issues/123468): copying buffers to
404403 // 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 ());
404+ if (context->GetCapabilities ()->SupportsBufferToTextureBlits ()) {
405+ impeller::TextureDescriptor texture_descriptor;
406+ texture_descriptor.storage_mode = impeller::StorageMode::kDevicePrivate ;
407+ texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
408+ texture_descriptor.size = decompressed_image.GetSize ();
409+ texture_descriptor.mip_count =
410+ enable_mipmapping ? decompressed_image.GetSize ().MipCount () : 1u ;
411+
412+ auto dest_texture =
413+ context->GetResourceAllocator ()->CreateTexture (texture_descriptor);
414+ if (!dest_texture) {
415+ FML_DLOG (ERROR) << " Could not create Impeller texture." ;
416+ return nullptr ;
417+ }
422418
423- dest_texture-> SetLabel (
424- impeller::SPrintF ( " ui.Image(%p) " , dest_texture. get ()). c_str ());
419+ auto buffer = context-> GetResourceAllocator ()-> CreateBufferWithCopy (
420+ *decompressed_image. GetAllocation (). get ());
425421
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" );
422+ dest_texture->SetLabel (
423+ impeller::SPrintF (" ui.Image(%p)" , dest_texture.get ()).c_str ());
432424
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- }
425+ auto command_buffer = context->CreateCommandBuffer ();
426+ if (!command_buffer) {
427+ FML_DLOG (ERROR)
428+ << " Could not create command buffer for mipmap generation." ;
429+ return nullptr ;
430+ }
431+ command_buffer->SetLabel (" Mipmap Command Buffer" );
443432
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
451- auto texture_descriptor = TextureDescriptor{};
452- texture_descriptor.storage_mode = StorageMode::kHostVisible ;
453- texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
454- texture_descriptor.size = decompressed_image.GetSize ();
455- texture_descriptor.mip_count =
456- enable_mipmapping ? decompressed_image.GetSize ().MipCount () : 1u ;
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+ }
457443
458- auto texture =
459- context->GetResourceAllocator ()->CreateTexture (texture_descriptor);
460- if (!texture) {
461- VALIDATION_LOG << " Could not allocate texture for fixture." ;
462- return nullptr ;
463- }
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 { // Doesn't support buffer-to-texture blits.
451+ auto texture_descriptor = TextureDescriptor{};
452+ texture_descriptor.storage_mode = StorageMode::kHostVisible ;
453+ texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt ;
454+ texture_descriptor.size = decompressed_image.GetSize ();
455+ texture_descriptor.mip_count =
456+ enable_mipmapping ? decompressed_image.GetSize ().MipCount () : 1u ;
457+
458+ auto texture =
459+ context->GetResourceAllocator ()->CreateTexture (texture_descriptor);
460+ if (!texture) {
461+ VALIDATION_LOG << " Could not allocate texture for fixture." ;
462+ return nullptr ;
463+ }
464464
465- auto uploaded = texture->SetContents (decompressed_image.GetAllocation ());
466- if (!uploaded) {
467- VALIDATION_LOG << " Could not upload texture to device memory for fixture." ;
468- return nullptr ;
465+ auto uploaded = texture->SetContents (decompressed_image.GetAllocation ());
466+ if (!uploaded) {
467+ VALIDATION_LOG
468+ << " Could not upload texture to device memory for fixture." ;
469+ return nullptr ;
470+ }
471+ return texture;
469472 }
470- return texture;
471- #endif // FML_OS_MACOS
472473}
473- } // namespace
474474
475475std::shared_ptr<Texture> Playground::CreateTextureForMapping (
476476 const std::shared_ptr<Context>& context,
0 commit comments