diff --git a/gfx/layers/composite/GPUVideoTextureHost.cpp b/gfx/layers/composite/GPUVideoTextureHost.cpp index 252fa46349cf..7a33d05d72ea 100644 --- a/gfx/layers/composite/GPUVideoTextureHost.cpp +++ b/gfx/layers/composite/GPUVideoTextureHost.cpp @@ -119,13 +119,13 @@ GPUVideoTextureHost::NumSubTextures() const } void -GPUVideoTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) +GPUVideoTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { MOZ_ASSERT(mWrappedTextureHost); - mWrappedTextureHost->PushResourceUpdates(aResources, aOp, aImageKeys, aExtID); + + mWrappedTextureHost->AddWRImage(aResources, aImageKeys, aExtID); } void diff --git a/gfx/layers/composite/GPUVideoTextureHost.h b/gfx/layers/composite/GPUVideoTextureHost.h index aabccc33a063..bad3dfea4951 100644 --- a/gfx/layers/composite/GPUVideoTextureHost.h +++ b/gfx/layers/composite/GPUVideoTextureHost.h @@ -50,10 +50,9 @@ public: virtual uint32_t NumSubTextures() const override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index bb4f34b9bb5e..e20e74532126 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -577,31 +577,38 @@ BufferTextureHost::NumSubTextures() const } void -BufferTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) +BufferTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& 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.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0); + aResources.AddExternalImageBuffer(aImageKeys[0], descriptor, aExtID); } 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.*method)(aImageKeys[0], yDescriptor, aExtID, bufferType, 0); - (aResources.*method)(aImageKeys[1], cbcrDescriptor, aExtID, bufferType, 1); - (aResources.*method)(aImageKeys[2], cbcrDescriptor, aExtID, bufferType, 2); + 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); } } diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 76f3ef64231a..9bc06766469e 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -625,18 +625,13 @@ 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. - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) + // Then, WR will use this informations to read from the TextureHost. + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { - MOZ_ASSERT_UNREACHABLE("Unimplemented"); + MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this TextureHost type."); } // Put all necessary WR commands into DisplayListBuilder for this textureHost rendering. @@ -746,10 +741,9 @@ public: virtual uint32_t NumSubTextures() const override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index d82a8da37f7c..8ff7c4cd81c1 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -1063,15 +1063,11 @@ DXGITextureHostD3D11::NumSubTextures() const } void -DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; +DXGITextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { 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: @@ -1081,7 +1077,11 @@ DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, MOZ_ASSERT(aImageKeys.length() == 1); wr::ImageDescriptor descriptor(GetSize(), GetFormat()); - (aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0); + aResources.AddExternalImage(aImageKeys[0], + descriptor, + aExtID, + wr::WrExternalImageBufferType::Texture2DHandle, + 0); break; } case gfx::SurfaceFormat::NV12: { @@ -1089,8 +1089,16 @@ DXGITextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, wr::ImageDescriptor descriptor0(GetSize(), gfx::SurfaceFormat::A8); wr::ImageDescriptor descriptor1(GetSize() / 2, gfx::SurfaceFormat::R8G8); - (aResources.*method)(aImageKeys[0], descriptor0, aExtID, bufferType, 0); - (aResources.*method)(aImageKeys[1], descriptor1, aExtID, bufferType, 1); + aResources.AddExternalImage(aImageKeys[0], + descriptor0, + aExtID, + wr::WrExternalImageBufferType::TextureExternalHandle, + 0); + aResources.AddExternalImage(aImageKeys[1], + descriptor1, + aExtID, + wr::WrExternalImageBufferType::TextureExternalHandle, + 1); break; } default: { @@ -1295,10 +1303,9 @@ DXGIYCbCrTextureHostD3D11::CreateRenderTexture(const wr::ExternalImageId& aExter } void -DXGIYCbCrTextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; +DXGIYCbCrTextureHostD3D11::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { // TODO - This implementation is very slow (read-back, copy on the copy and re-upload). @@ -1324,11 +1331,7 @@ DXGIYCbCrTextureHostD3D11::PushResourceUpdates(wr::ResourceUpdateQueue& aResourc wr::ImageDescriptor descriptor(size, map.mStride, dataSourceSurface->GetFormat()); wr::Vec_u8 imgBytes; imgBytes.PushBytes(Range(map.mData, size.height * map.mStride)); - if (aOp == TextureHost::ADD_IMAGE) { - aResources.AddImage(aImageKeys[0], descriptor, imgBytes); - } else { - aResource.UpdateImage(aImageKeys[0], descriptor, imgBytes); - } + aResources.AddImage(aImageKeys[0], descriptor, imgBytes); dataSourceSurface->Unmap(); } diff --git a/gfx/layers/d3d11/TextureD3D11.h b/gfx/layers/d3d11/TextureD3D11.h index 3d4b3b3d9826..ca7fd6355d48 100644 --- a/gfx/layers/d3d11/TextureD3D11.h +++ b/gfx/layers/d3d11/TextureD3D11.h @@ -337,10 +337,9 @@ public: virtual uint32_t NumSubTextures() const override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aAPI, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, @@ -398,10 +397,9 @@ public: virtual void CreateRenderTexture(const wr::ExternalImageId& aExternalImageId) override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, diff --git a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp index aa01f897837f..671d0edb5f16 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp +++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp @@ -147,17 +147,12 @@ MacIOSurfaceTextureHostOGL::NumSubTextures() const } void -MacIOSurfaceTextureHostOGL::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; +MacIOSurfaceTextureHostOGL::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { 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: @@ -166,7 +161,11 @@ MacIOSurfaceTextureHostOGL::PushResourceUpdates(wr::ResourceUpdateQueue& aResour MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(mSurface->GetPlaneCount() == 0); wr::ImageDescriptor descriptor(GetSize(), GetFormat()); - (aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0); + aResources.AddExternalImage(aImageKeys[0], + descriptor, + aExtID, + wr::WrExternalImageBufferType::TextureRectHandle, + 0); break; } case gfx::SurfaceFormat::YUV422: { @@ -177,7 +176,11 @@ MacIOSurfaceTextureHostOGL::PushResourceUpdates(wr::ResourceUpdateQueue& aResour MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(mSurface->GetPlaneCount() == 0); wr::ImageDescriptor descriptor(GetSize(), gfx::SurfaceFormat::R8G8B8X8); - (aResources.*method)(aImageKeys[0], descriptor, aExtID, bufferType, 0); + aResources.AddExternalImage(aImageKeys[0], + descriptor, + aExtID, + wr::WrExternalImageBufferType::TextureRectHandle, + 0); break; } case gfx::SurfaceFormat::NV12: { @@ -187,8 +190,16 @@ MacIOSurfaceTextureHostOGL::PushResourceUpdates(wr::ResourceUpdateQueue& aResour gfx::SurfaceFormat::A8); wr::ImageDescriptor descriptor1(gfx::IntSize(mSurface->GetDevicePixelWidth(1), mSurface->GetDevicePixelHeight(1)), gfx::SurfaceFormat::R8G8); - (aResources.*method)(aImageKeys[0], descriptor0, aExtID, bufferType, 0); - (aResources.*method)(aImageKeys[1], descriptor1, aExtID, bufferType, 1); + aResources.AddExternalImage(aImageKeys[0], + descriptor0, + aExtID, + wr::WrExternalImageBufferType::TextureRectHandle, + 0); + aResources.AddExternalImage(aImageKeys[1], + descriptor1, + aExtID, + wr::WrExternalImageBufferType::TextureRectHandle, + 1); break; } default: { diff --git a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h index 8254fe25b2ae..9a23106cae31 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h +++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h @@ -66,10 +66,9 @@ public: virtual uint32_t NumSubTextures() const override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, diff --git a/gfx/layers/wr/AsyncImagePipelineManager.cpp b/gfx/layers/wr/AsyncImagePipelineManager.cpp index 6f2cca32ab44..f2482c6087af 100644 --- a/gfx/layers/wr/AsyncImagePipelineManager.cpp +++ b/gfx/layers/wr/AsyncImagePipelineManager.cpp @@ -178,9 +178,8 @@ AsyncImagePipelineManager::GenerateImageKeyForTextureHost(wr::ResourceUpdateQueu aKeys.AppendElement(GenerateImageKey()); } MOZ_ASSERT(!aKeys.IsEmpty()); - Range keys(&aKeys[0], aKeys.Length()); - wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE, - keys, wrTexture->GetExternalImageKey()); + Range keys(&aKeys[0], aKeys.Length()); + wrTexture->AddWRImage(aResources, keys, wrTexture->GetExternalImageKey()); return true; } else { RefPtr dSurf = aTexture->GetAsSurface(); diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 044018d5c842..a516521285a6 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -329,7 +329,7 @@ bool WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey aKey, wr::ResourceUpdateQueue& aResources) { - Range keys(&aKey, 1); + Range keys(&aKey, 1); // Check if key is obsoleted. if (keys[0].mNamespace != mIdNamespace) { return true; @@ -349,8 +349,7 @@ WebRenderBridgeParent::AddExternalImage(wr::ExternalImageId aExtId, wr::ImageKey } WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost(); if (wrTexture) { - wrTexture->PushResourceUpdates(aResources, TextureHost::ADD_IMAGE, keys, - wrTexture->GetExternalImageKey()); + wrTexture->AddWRImage(aResources, keys, wrTexture->GetExternalImageKey()); return true; } } diff --git a/gfx/layers/wr/WebRenderTextureHost.cpp b/gfx/layers/wr/WebRenderTextureHost.cpp index 0425eb34a8e2..ec50a3bbfdcc 100644 --- a/gfx/layers/wr/WebRenderTextureHost.cpp +++ b/gfx/layers/wr/WebRenderTextureHost.cpp @@ -142,15 +142,14 @@ WebRenderTextureHost::NumSubTextures() const } void -WebRenderTextureHost::PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) +WebRenderTextureHost::AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) { MOZ_ASSERT(mWrappedTextureHost); MOZ_ASSERT(mExternalImageId == aExtID); - mWrappedTextureHost->PushResourceUpdates(aResources, aOp, aImageKeys, aExtID); + mWrappedTextureHost->AddWRImage(aResources, aImageKeys, aExtID); } void diff --git a/gfx/layers/wr/WebRenderTextureHost.h b/gfx/layers/wr/WebRenderTextureHost.h index f9af8696f657..ea92aec83165 100644 --- a/gfx/layers/wr/WebRenderTextureHost.h +++ b/gfx/layers/wr/WebRenderTextureHost.h @@ -65,10 +65,9 @@ public: virtual uint32_t NumSubTextures() const override; - virtual void PushResourceUpdates(wr::ResourceUpdateQueue& aResources, - ResourceUpdateOp aOp, - const Range& aImageKeys, - const wr::ExternalImageId& aExtID) override; + virtual void AddWRImage(wr::ResourceUpdateQueue& aResources, + Range& aImageKeys, + const wr::ExternalImageId& aExtID) override; virtual void PushExternalImage(wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,