Bug 1383786 - Simplify generating image keys for TextureHosts. r=sotaro

This commit is contained in:
Nicolas Silva 2017-09-22 14:51:42 +02:00
parent 71a8cbdccf
commit fd98ed2e47
11 changed files with 36 additions and 98 deletions

View File

@ -111,14 +111,11 @@ GPUVideoTextureHost::CreateRenderTexture(const wr::ExternalImageId& aExternalIma
mWrappedTextureHost->CreateRenderTexture(aExternalImageId);
}
void
GPUVideoTextureHost::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
uint32_t
GPUVideoTextureHost::NumSubTextures() const
{
MOZ_ASSERT(mWrappedTextureHost);
MOZ_ASSERT(aImageKeys.IsEmpty());
mWrappedTextureHost->GetWRImageKeys(aImageKeys, aImageKeyAllocator);
return mWrappedTextureHost->NumSubTextures();
}
void

View File

@ -48,8 +48,7 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,

View File

@ -566,23 +566,14 @@ BufferTextureHost::CreateRenderTexture(const wr::ExternalImageId& aExternalImage
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId), texture.forget());
}
void
BufferTextureHost::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
uint32_t
BufferTextureHost::NumSubTextures() const
{
MOZ_ASSERT(aImageKeys.IsEmpty());
if (GetFormat() != gfx::SurfaceFormat::YUV) {
// 1 image key
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 1);
} else {
// 3 image key
aImageKeys.AppendElement(aImageKeyAllocator());
aImageKeys.AppendElement(aImageKeyAllocator());
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 3);
if (GetFormat() == gfx::SurfaceFormat::YUV) {
return 3;
}
return 1;
}
void

View File

@ -621,17 +621,9 @@ public:
MOZ_RELEASE_ASSERT(false, "No CreateRenderTexture() implementation for this TextureHost type.");
}
// Create all necessary image keys for this textureHost rendering.
// @param aImageKeys - [out] The set of ImageKeys used for this textureHost
// composing.
// @param aImageKeyAllocator - [in] The function which is used for creating
// the new ImageKey.
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
{
MOZ_ASSERT(aImageKeys.IsEmpty());
MOZ_ASSERT_UNREACHABLE("No GetWRImageKeys() implementation for this TextureHost type.");
}
/// Returns the number of actual textures that will be used to render this.
/// For example in a lot of YUV cases it will be 3
virtual uint32_t NumSubTextures() const { return 1; }
// Add all necessary TextureHost informations to the resource update queue.
// Then, WR will use this informations to read from the TextureHost.
@ -747,8 +739,7 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,

View File

@ -1042,31 +1042,22 @@ DXGITextureHostD3D11::CreateRenderTexture(const wr::ExternalImageId& aExternalIm
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId), texture.forget());
}
void
DXGITextureHostD3D11::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
uint32_t
DXGITextureHostD3D11::NumSubTextures() const
{
MOZ_ASSERT(aImageKeys.IsEmpty());
switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8:
case gfx::SurfaceFormat::B8G8R8A8:
case gfx::SurfaceFormat::B8G8R8X8: {
// 1 image key
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 1);
break;
return 1;
}
case gfx::SurfaceFormat::NV12: {
// 2 image key
aImageKeys.AppendElement(aImageKeyAllocator());
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 2);
break;
return 2;
}
default: {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
MOZ_ASSERT_UNREACHABLE("unexpected format");
return 1;
}
}
}
@ -1311,17 +1302,6 @@ DXGIYCbCrTextureHostD3D11::CreateRenderTexture(const wr::ExternalImageId& aExter
// We use AddImage() directly. It's no corresponding RenderTextureHost.
}
void
DXGIYCbCrTextureHostD3D11::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
{
MOZ_ASSERT(aImageKeys.IsEmpty());
// 1 image key
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 1);
}
void
DXGIYCbCrTextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,

View File

@ -335,8 +335,7 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aAPI,
Range<const wr::ImageKey>& aImageKeys,
@ -398,9 +397,6 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,
const wr::ExternalImageId& aExtID) override;

View File

@ -125,37 +125,23 @@ MacIOSurfaceTextureHostOGL::CreateRenderTexture(const wr::ExternalImageId& aExte
wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId), texture.forget());
}
void
MacIOSurfaceTextureHostOGL::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
uint32_t
MacIOSurfaceTextureHostOGL::NumSubTextures() const
{
MOZ_ASSERT(aImageKeys.IsEmpty());
switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8:
case gfx::SurfaceFormat::B8G8R8A8:
case gfx::SurfaceFormat::B8G8R8X8: {
// 1 image key
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 1);
break;
}
case gfx::SurfaceFormat::YUV422: {
// 1 image key
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 1);
break;
return 1;
}
case gfx::SurfaceFormat::NV12: {
// 2 image key
aImageKeys.AppendElement(aImageKeyAllocator());
aImageKeys.AppendElement(aImageKeyAllocator());
MOZ_ASSERT(aImageKeys.Length() == 2);
break;
return 2;
}
default: {
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
MOZ_ASSERT_UNREACHABLE("unexpected format");
return 1;
}
}
}

View File

@ -64,8 +64,7 @@ public:
virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override;
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,

View File

@ -173,7 +173,10 @@ AsyncImagePipelineManager::GenerateImageKeyForTextureHost(wr::ResourceUpdateQueu
WebRenderTextureHost* wrTexture = aTexture->AsWebRenderTextureHost();
if (!gfxEnv::EnableWebRenderRecording() && wrTexture) {
wrTexture->GetWRImageKeys(aKeys, std::bind(&AsyncImagePipelineManager::GenerateImageKey, this));
auto numKeys = wrTexture->NumSubTextures();
for (uint32_t i = 0; i < numKeys; ++i) {
aKeys.AppendElement(GenerateImageKey());
}
MOZ_ASSERT(!aKeys.IsEmpty());
Range<const wr::ImageKey> keys(&aKeys[0], aKeys.Length());
wrTexture->AddWRImage(aResources, keys, wrTexture->GetExternalImageKey());

View File

@ -134,14 +134,11 @@ WebRenderTextureHost::GetRGBStride()
return ImageDataSerializer::ComputeRGBStride(format, GetSize().width);
}
void
WebRenderTextureHost::GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator)
uint32_t
WebRenderTextureHost::NumSubTextures() const
{
MOZ_ASSERT(mWrappedTextureHost);
MOZ_ASSERT(aImageKeys.IsEmpty());
mWrappedTextureHost->GetWRImageKeys(aImageKeys, aImageKeyAllocator);
return mWrappedTextureHost->NumSubTextures();
}
void

View File

@ -63,8 +63,7 @@ public:
int32_t GetRGBStride();
virtual void GetWRImageKeys(nsTArray<wr::ImageKey>& aImageKeys,
const std::function<wr::ImageKey()>& aImageKeyAllocator) override;
virtual uint32_t NumSubTextures() const override;
virtual void AddWRImage(wr::ResourceUpdateQueue& aResources,
Range<const wr::ImageKey>& aImageKeys,