Bug 1600595: Part 5 - Make RecvReadbackAsyncPluginSurface use ReadbackSharedTexture r=mattwoodrow

Use the new utility function, introduced in Part 3, to implement async plugin surface's read to CPU texture.

Differential Revision: https://phabricator.services.mozilla.com/D57564

--HG--
extra : moz-landing-system : lando
This commit is contained in:
David Parks 2019-12-23 21:28:23 +00:00
parent 883c673715
commit 38dd73cd2b

View File

@ -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<DrawTarget> displayAsDT =
textures->mDisplayTextureData->BorrowDrawTarget();
RefPtr<SourceSurface> 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<ID3D11Device> device;
displayTexData->GetD3D11Texture()->GetDevice(getter_AddRefs(device));
if (!device) {
NS_WARNING("Failed to get D3D11 device for plugin display");
return IPC_OK();
}
RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(
gfx::BackendType::CAIRO, buffer.get<uint8_t>(), size,
ImageDataSerializer::ComputeRGBStride(format, size.width), format);
if (!dt) {
DeallocShmem(buffer);
UniquePtr<BufferTextureData> 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();
}