Bug 1383786 - Make it possible to update TextureHost image keys. r=sotaro

This commit is contained in:
Nicolas Silva 2017-09-22 14:51:46 +02:00
Родитель fd98ed2e47
Коммит 7822739981
12 изменённых файлов: 93 добавлений и 100 удалений

Просмотреть файл

@ -119,13 +119,13 @@ GPUVideoTextureHost::NumSubTextures() const
}
void
GPUVideoTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
GPUVideoTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
{
MOZ_ASSERT(mWrappedTextureHost);
mWrappedTextureHost->AddWRImage(aResources, aImageKeys, aExtID);
mWrappedTextureHost->PushResourceUpdates(aResources, aOp, aImageKeys, aExtID);
}
void

Просмотреть файл

@ -50,8 +50,9 @@ public:
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,

Просмотреть файл

@ -577,38 +577,31 @@ BufferTextureHost::NumSubTextures() const
}
void
BufferTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
BufferTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
{
auto method = aOp == TextureHost::ADD_IMAGE ? &wr::ResourceUpdateQueue::AddExternalImage
: &wr::ResourceUpdateQueue::UpdateExternalImage;
auto bufferType = wr::WrExternalImageBufferType::ExternalBuffer;
if (GetFormat() != gfx::SurfaceFormat::YUV) {
MOZ_ASSERT(aImageKeys.length() == 1);
wr::ImageDescriptor descriptor(GetSize(),
ImageDataSerializer::ComputeRGBStride(GetFormat(), GetSize().width),
GetFormat());
aResources.AddExternalImageBuffer(aImageKeys[0], descriptor, aExtID);
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
} else {
MOZ_ASSERT(aImageKeys.length() == 3);
const layers::YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
wr::ImageDescriptor yDescriptor(desc.ySize(), desc.ySize().width, gfx::SurfaceFormat::A8);
wr::ImageDescriptor cbcrDescriptor(desc.cbCrSize(), desc.cbCrSize().width, gfx::SurfaceFormat::A8);
aResources.AddExternalImage(aImageKeys[0],
yDescriptor,
aExtID,
wr::WrExternalImageBufferType::ExternalBuffer,
0);
aResources.AddExternalImage(aImageKeys[1],
cbcrDescriptor,
aExtID,
wr::WrExternalImageBufferType::ExternalBuffer,
1);
aResources.AddExternalImage(aImageKeys[2],
cbcrDescriptor,
aExtID,
wr::WrExternalImageBufferType::ExternalBuffer,
2);
(aResources.*method)(aImageKeys[0], yDescriptor, aExtID, bufferType, 0);
(aResources.*method)(aImageKeys[1], cbcrDescriptor, aExtID, bufferType, 1);
(aResources.*method)(aImageKeys[2], cbcrDescriptor, aExtID, bufferType, 2);
}
}

Просмотреть файл

@ -625,13 +625,18 @@ public:
/// For example in a lot of YUV cases it will be 3
virtual uint32_t NumSubTextures() const { return 1; }
enum ResourceUpdateOp {
ADD_IMAGE,
UPDATE_IMAGE,
};
// Add all necessary TextureHost informations to the resource update queue.
// Then, WR will use this informations to read from the TextureHost.
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
{
MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this TextureHost type.");
MOZ_ASSERT_UNREACHABLE("Unimplemented");
}
// Put all necessary WR commands into DisplayListBuilder for this textureHost rendering.
@ -741,8 +746,9 @@ public:
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,

Просмотреть файл

@ -1063,11 +1063,15 @@ DXGITextureHostD3D11::NumSubTextures() const
}
void
DXGITextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
{
MOZ_ASSERT(mHandle);
auto method = aOp == TextureHost::ADD_IMAGE ? &wr::ResourceUpdateQueue::AddExternalImage
: &wr::ResourceUpdateQueue::UpdateExternalImage;
auto bufferType = wr::WrExternalImageBufferType::TextureExternalHandle;
switch (mFormat) {
case gfx::SurfaceFormat::R8G8B8X8:
@ -1077,11 +1081,7 @@ DXGITextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
MOZ_ASSERT(aImageKeys.length() == 1);
wr::ImageDescriptor descriptor(GetSize(), GetFormat());
aResources.AddExternalImage(aImageKeys[0],
descriptor,
aExtID,
wr::WrExternalImageBufferType::Texture2DHandle,
0);
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
break;
}
case gfx::SurfaceFormat::NV12: {
@ -1089,16 +1089,8 @@ DXGITextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
wr::ImageDescriptor descriptor0(GetSize(), gfx::SurfaceFormat::A8);
wr::ImageDescriptor descriptor1(GetSize() / 2, gfx::SurfaceFormat::R8G8);
aResources.AddExternalImage(aImageKeys[0],
descriptor0,
aExtID,
wr::WrExternalImageBufferType::TextureExternalHandle,
0);
aResources.AddExternalImage(aImageKeys[1],
descriptor1,
aExtID,
wr::WrExternalImageBufferType::TextureExternalHandle,
1);
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, bufferType, 0);
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, bufferType, 1);
break;
}
default: {
@ -1303,9 +1295,10 @@ DXGIYCbCrTextureHostD3D11::CreateRenderTexture(const wr::ExternalImageId& aExter
}
void
DXGIYCbCrTextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
DXGIYCbCrTextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
{
// TODO - This implementation is very slow (read-back, copy on the copy and re-upload).
@ -1331,7 +1324,11 @@ DXGIYCbCrTextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
wr::ImageDescriptor descriptor(size, map.mStride, dataSourceSurface->GetFormat());
wr::Vec_u8 imgBytes;
imgBytes.PushBytes(Range<uint8_t>(map.mData, size.height * map.mStride));
if (aOp == TextureHost::ADD_IMAGE) {
aResources.AddImage(aImageKeys[0], descriptor, imgBytes);
} else {
aResource.UpdateImage(aImageKeys[0], descriptor, imgBytes);
}
dataSourceSurface->Unmap();
}

Просмотреть файл

@ -337,8 +337,9 @@ public:
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aAPI,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,
@ -397,8 +398,9 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,

Просмотреть файл

@ -147,12 +147,17 @@ MacIOSurfaceTextureHostOGL::NumSubTextures() const
}
void
MacIOSurfaceTextureHostOGL::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
MacIOSurfaceTextureHostOGL::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
{
MOZ_ASSERT(mSurface);
auto method = aOp == TextureHost::ADD_IMAGE ? &wr::ResourceUpdateQueue::AddExternalImage
: &wr::ResourceUpdateQueue::UpdateExternalImage;
auto bufferType = wr::WrExternalImageBufferType::TextureRectHandle;
switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8:
@ -161,11 +166,7 @@ MacIOSurfaceTextureHostOGL::AddWRImage(wr::ResourceUpdateQueue& aResources,
MOZ_ASSERT(aImageKeys.length() == 1);
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
wr::ImageDescriptor descriptor(GetSize(), GetFormat());
aResources.AddExternalImage(aImageKeys[0],
descriptor,
aExtID,
wr::WrExternalImageBufferType::TextureRectHandle,
0);
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
break;
}
case gfx::SurfaceFormat::YUV422: {
@ -176,11 +177,7 @@ MacIOSurfaceTextureHostOGL::AddWRImage(wr::ResourceUpdateQueue& aResources,
MOZ_ASSERT(aImageKeys.length() == 1);
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
wr::ImageDescriptor descriptor(GetSize(), gfx::SurfaceFormat::R8G8B8X8);
aResources.AddExternalImage(aImageKeys[0],
descriptor,
aExtID,
wr::WrExternalImageBufferType::TextureRectHandle,
0);
(aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0);
break;
}
case gfx::SurfaceFormat::NV12: {
@ -190,16 +187,8 @@ MacIOSurfaceTextureHostOGL::AddWRImage(wr::ResourceUpdateQueue& aResources,
gfx::SurfaceFormat::A8);
wr::ImageDescriptor descriptor1(gfx::IntSize(mSurface->GetDevicePixelWidth(1), mSurface->GetDevicePixelHeight(1)),
gfx::SurfaceFormat::R8G8);
aResources.AddExternalImage(aImageKeys[0],
descriptor0,
aExtID,
wr::WrExternalImageBufferType::TextureRectHandle,
0);
aResources.AddExternalImage(aImageKeys[1],
descriptor1,
aExtID,
wr::WrExternalImageBufferType::TextureRectHandle,
1);
(aResources.*method)(aImageKeys[0], descriptor0, aExtID, bufferType, 0);
(aResources.*method)(aImageKeys[1], descriptor1, aExtID, bufferType, 1);
break;
}
default: {

Просмотреть файл

@ -66,8 +66,9 @@ public:
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,

Просмотреть файл

@ -178,8 +178,9 @@ AsyncImagePipelineManager::GenerateImageKeyForTextureHost(wr::ResourceUpdateQueu
aKeys.AppendElement(GenerateImageKey());
}
MOZ_ASSERT(!aKeys.IsEmpty());
Range<const wr::ImageKey> keys(&aKeys[0], aKeys.Length());
wrTexture->AddWRImage(aResources, keys, wrTexture->GetExternalImageKey());
Range<wr::ImageKey> keys(&aKeys[0], aKeys.Length());
wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE,
keys, wrTexture->GetExternalImageKey());
return true;
} else {
RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface();

Просмотреть файл

@ -329,7 +329,7 @@ bool
WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey,
wr::ResourceUpdateQueue& aResources)
{
Range<const wr::ImageKey> keys(&aKey, 1);
Range<wr::ImageKey> keys(&aKey, 1);
// Check if key is obsoleted.
if (keys[0].mNamespace != mIdNamespace) {
return true;
@ -349,7 +349,8 @@ WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey
}
WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost();
if (wrTexture) {
wrTexture->AddWRImage(aResources, keys, wrTexture->GetExternalImageKey());
wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE, keys,
wrTexture->GetExternalImageKey());
return true;
}
}

Просмотреть файл

@ -142,14 +142,15 @@ WebRenderTextureHost::NumSubTextures() const
}
void
WebRenderTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
WebRenderTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID)
{
MOZ_ASSERT(mWrappedTextureHost);
MOZ_ASSERT(mExternalImageId == aExtID);
mWrappedTextureHost->AddWRImage(aResources, aImageKeys, aExtID);
mWrappedTextureHost->PushResourceUpdates(aResources, aOp, aImageKeys, aExtID);
}
void

Просмотреть файл

@ -65,8 +65,9 @@ public:
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources,
ResourceUpdateOp aOp,
const Range<wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;
virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder,