diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 36b87e479211..40ba66595790 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -18,6 +18,7 @@ #include "mozilla/ipc/ProtocolUtils.h" #include "mozilla/ipc/Transport.h" // for Transport #include "mozilla/media/MediaSystemResourceManagerParent.h" // for MediaSystemResourceManagerParent +#include "mozilla/layers/BufferTexture.h" #include "mozilla/layers/CompositableTransactionParent.h" #include "mozilla/layers/LayerManagerComposite.h" #include "mozilla/layers/LayersMessages.h" // for EditReply @@ -586,36 +587,40 @@ mozilla::ipc::IPCResult ImageBridgeParent::RecvReadbackAsyncPluginSurface( } auto& textures = itTextures->value(); - MOZ_RELEASE_ASSERT(textures->mDisplayTextureData); - RefPtr displayAsDT = - textures->mDisplayTextureData->BorrowDrawTarget(); - RefPtr source = displayAsDT->Snapshot(); - if (!source) { + D3D11TextureData* displayTexData = textures->mDisplayTextureData.get(); + MOZ_RELEASE_ASSERT(displayTexData); + if ((!displayTexData) || (!displayTexData->GetD3D11Texture())) { + NS_WARNING("Error in plugin display texture"); return IPC_OK(); } - SurfaceFormat format = source->GetFormat(); - IntSize size = source->GetSize(); - size_t length = ImageDataSerializer::ComputeRGBBufferSize(size, format); + MOZ_ASSERT(displayTexData->GetSurfaceFormat() == SurfaceFormat::B8G8R8A8 || + displayTexData->GetSurfaceFormat() == SurfaceFormat::B8G8R8X8); - Shmem buffer; - if (!length || - !AllocShmem(length, Shmem::SharedMemory::TYPE_BASIC, &buffer)) { + RefPtr device; + displayTexData->GetD3D11Texture()->GetDevice(getter_AddRefs(device)); + if (!device) { + NS_WARNING("Failed to get D3D11 device for plugin display"); return IPC_OK(); } - RefPtr dt = Factory::CreateDrawTargetForData( - gfx::BackendType::CAIRO, buffer.get(), size, - ImageDataSerializer::ComputeRGBStride(format, size.width), format); - if (!dt) { - DeallocShmem(buffer); + UniquePtr shmemTexData(BufferTextureData::Create( + displayTexData->GetSize(), displayTexData->GetSurfaceFormat(), + gfx::BackendType::SKIA, LayersBackend::LAYERS_NONE, + displayTexData->GetTextureFlags(), TextureAllocationFlags::ALLOC_DEFAULT, + this)); + if (!shmemTexData) { + NS_WARNING("Could not create BufferTextureData"); return IPC_OK(); } - dt->CopySurface(source, IntRect(0, 0, size.width, size.height), IntPoint()); - dt->Flush(); + if (!gfx::Factory::ReadbackSharedTexture(shmemTexData.get(), + displayTexData->GetD3D11Texture())) { + NS_WARNING("Failed to read plugin texture into Shmem"); + return IPC_OK(); + } - *aResult = SurfaceDescriptorBuffer(RGBDescriptor(size, format, true), - MemoryOrShmem(std::move(buffer))); + // Take the Shmem from the TextureData. + shmemTexData->Serialize(*aResult); #endif // defined(OS_WIN) return IPC_OK(); }