Bug 1666055 - Disable buffer textures as external compositor surfaces on MacOS. r=lsalzman

When using the native RenderCompositor+SWGL on MacOS, we don't support passing buffer textures directly to the compositor.

Differential Revision: https://phabricator.services.mozilla.com/D93179
This commit is contained in:
Matt Woodrow
2020-10-14 07:56:47 +00:00
parent 5e6d4a7772
commit d517b70ca2
21 changed files with 117 additions and 76 deletions

View File

@@ -245,16 +245,15 @@ void GPUVideoTextureHost::PushResourceUpdates(
void GPUVideoTextureHost::PushDisplayItems( void GPUVideoTextureHost::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) {
MOZ_ASSERT(EnsureWrappedTextureHost(), "Image isn't valid yet"); MOZ_ASSERT(EnsureWrappedTextureHost(), "Image isn't valid yet");
MOZ_ASSERT(aImageKeys.length() > 0); MOZ_ASSERT(aImageKeys.length() > 0);
if (!EnsureWrappedTextureHost()) { if (!EnsureWrappedTextureHost()) {
return; return;
} }
EnsureWrappedTextureHost()->PushDisplayItems( EnsureWrappedTextureHost()->PushDisplayItems(aBuilder, aBounds, aClip,
aBuilder, aBounds, aClip, aFilter, aImageKeys, aPreferCompositorSurface); aFilter, aImageKeys, aFlags);
} }
void GPUVideoTextureHost::UnbindTextureSource() { void GPUVideoTextureHost::UnbindTextureSource() {

View File

@@ -68,7 +68,7 @@ class GPUVideoTextureHost : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
void UnbindTextureSource() override; void UnbindTextureSource() override;
void NotifyNotUsed() override; void NotifyNotUsed() override;

View File

@@ -741,15 +741,18 @@ void BufferTextureHost::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
const wr::LayoutRect& aClip, const wr::LayoutRect& aClip,
wr::ImageRendering aFilter, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) { PushDisplayItemFlagSet aFlags) {
// SWGL should always try to bypass shaders and composite directly. // SWGL should always try to bypass shaders and composite directly.
bool useExternalSurface = gfx::gfxVars::UseSoftwareWebRender(); bool preferCompositorSurface =
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE);
bool useExternalSurface =
aFlags.contains(PushDisplayItemFlag::SUPPORTS_EXTERNAL_BUFFER_TEXTURES);
if (GetFormat() != gfx::SurfaceFormat::YUV) { if (GetFormat() != gfx::SurfaceFormat::YUV) {
MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(aImageKeys.length() == 1);
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface, useExternalSurface); preferCompositorSurface, useExternalSurface);
} else { } else {
MOZ_ASSERT(aImageKeys.length() == 3); MOZ_ASSERT(aImageKeys.length() == 3);
const YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor(); const YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
@@ -757,8 +760,8 @@ void BufferTextureHost::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2], aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2],
wr::ToWrColorDepth(desc.colorDepth()), wr::ToWrColorDepth(desc.colorDepth()),
wr::ToWrYuvColorSpace(desc.yUVColorSpace()), wr::ToWrYuvColorSpace(desc.yUVColorSpace()),
wr::ToWrColorRange(desc.colorRange()), aFilter, wr::ToWrColorRange(desc.colorRange()), aFilter, preferCompositorSurface,
aPreferCompositorSurface, useExternalSurface); useExternalSurface);
} }
} }

View File

@@ -690,6 +690,17 @@ class TextureHost : public AtomicRefCountedWithFinalize<TextureHost> {
MOZ_ASSERT_UNREACHABLE("Unimplemented"); MOZ_ASSERT_UNREACHABLE("Unimplemented");
} }
enum class PushDisplayItemFlag {
// Passed if the caller wants these display items to be promoted
// to compositor surfaces if possible.
PREFER_COMPOSITOR_SURFACE,
// Passed in the RenderCompositor supports BufferTextureHosts
// being used directly as external compositor surfaces.
SUPPORTS_EXTERNAL_BUFFER_TEXTURES,
};
using PushDisplayItemFlagSet = EnumSet<PushDisplayItemFlag>;
// Put all necessary WR commands into DisplayListBuilder for this textureHost // Put all necessary WR commands into DisplayListBuilder for this textureHost
// rendering. // rendering.
virtual void PushDisplayItems(wr::DisplayListBuilder& aBuilder, virtual void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
@@ -697,7 +708,7 @@ class TextureHost : public AtomicRefCountedWithFinalize<TextureHost> {
const wr::LayoutRect& aClip, const wr::LayoutRect& aClip,
wr::ImageRendering aFilter, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aKeys, const Range<wr::ImageKey>& aKeys,
const bool aPreferCompositorSurface) { PushDisplayItemFlagSet aFlags) {
MOZ_ASSERT_UNREACHABLE( MOZ_ASSERT_UNREACHABLE(
"No PushDisplayItems() implementation for this TextureHost type."); "No PushDisplayItems() implementation for this TextureHost type.");
} }
@@ -845,7 +856,7 @@ class BufferTextureHost : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
void ReadUnlock() override; void ReadUnlock() override;
bool IsDirectMap() override { bool IsDirectMap() override {

View File

@@ -1051,8 +1051,9 @@ void DXGITextureHostD3D11::PushResourceUpdates(
void DXGITextureHostD3D11::PushDisplayItems( void DXGITextureHostD3D11::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) { bool preferCompositorSurface =
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE);
if (!gfx::gfxVars::UseWebRenderANGLE()) { if (!gfx::gfxVars::UseWebRenderANGLE()) {
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE"); MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
return; return;
@@ -1073,7 +1074,7 @@ void DXGITextureHostD3D11::PushDisplayItems(
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface); preferCompositorSurface);
break; break;
} }
case gfx::SurfaceFormat::P010: case gfx::SurfaceFormat::P010:
@@ -1091,7 +1092,7 @@ void DXGITextureHostD3D11::PushDisplayItems(
GetFormat() == gfx::SurfaceFormat::NV12 ? wr::ColorDepth::Color8 GetFormat() == gfx::SurfaceFormat::NV12 ? wr::ColorDepth::Color8
: wr::ColorDepth::Color16, : wr::ColorDepth::Color16,
wr::ToWrYuvColorSpace(mYUVColorSpace), wr::ToWrYuvColorSpace(mYUVColorSpace),
wr::ToWrColorRange(mColorRange), aFilter, aPreferCompositorSurface, wr::ToWrColorRange(mColorRange), aFilter, preferCompositorSurface,
supportsExternalCompositing); supportsExternalCompositing);
break; break;
} }
@@ -1305,8 +1306,7 @@ void DXGIYCbCrTextureHostD3D11::PushResourceUpdates(
void DXGIYCbCrTextureHostD3D11::PushDisplayItems( void DXGIYCbCrTextureHostD3D11::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) {
if (!gfx::gfxVars::UseWebRenderANGLE()) { if (!gfx::gfxVars::UseWebRenderANGLE()) {
MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE"); MOZ_ASSERT_UNREACHABLE("unexpected to be called without ANGLE");
return; return;
@@ -1323,7 +1323,8 @@ void DXGIYCbCrTextureHostD3D11::PushDisplayItems(
aBuilder.PushYCbCrPlanarImage( aBuilder.PushYCbCrPlanarImage(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2], aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2],
wr::ToWrColorDepth(mColorDepth), wr::ToWrYuvColorSpace(mYUVColorSpace), wr::ToWrColorDepth(mColorDepth), wr::ToWrYuvColorSpace(mYUVColorSpace),
wr::ToWrColorRange(mColorRange), aFilter, aPreferCompositorSurface); wr::ToWrColorRange(mColorRange), aFilter,
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE));
} }
bool DXGIYCbCrTextureHostD3D11::AcquireTextureSource( bool DXGIYCbCrTextureHostD3D11::AcquireTextureSource(

View File

@@ -360,7 +360,7 @@ class DXGITextureHostD3D11 : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
protected: protected:
bool LockInternal(); bool LockInternal();
@@ -429,7 +429,7 @@ class DXGIYCbCrTextureHostD3D11 : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
private: private:
bool EnsureTextureSource(); bool EnsureTextureSource();

View File

@@ -765,7 +765,7 @@ RefPtr<TextureHost> GetNullPluginTextureHost() {
const wr::LayoutRect& aClip, const wr::LayoutRect& aClip,
wr::ImageRendering aFilter, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override {} PushDisplayItemFlagSet aFlags) override {}
}; };
static StaticRefPtr<TextureHost> sNullPluginTextureHost; static StaticRefPtr<TextureHost> sNullPluginTextureHost;

View File

@@ -185,8 +185,9 @@ void DMABUFTextureHostOGL::PushResourceUpdates(
void DMABUFTextureHostOGL::PushDisplayItems( void DMABUFTextureHostOGL::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) { bool preferCompositorSurface =
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE);
switch (mSurface->GetFormat()) { switch (mSurface->GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8: case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8: case gfx::SurfaceFormat::R8G8B8A8:
@@ -196,7 +197,7 @@ void DMABUFTextureHostOGL::PushDisplayItems(
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface); preferCompositorSurface);
break; break;
} }
case gfx::SurfaceFormat::NV12: { case gfx::SurfaceFormat::NV12: {
@@ -208,7 +209,7 @@ void DMABUFTextureHostOGL::PushDisplayItems(
wr::ColorDepth::Color8, wr::ColorDepth::Color8,
wr::ToWrYuvColorSpace(GetYUVColorSpace()), wr::ToWrYuvColorSpace(GetYUVColorSpace()),
wr::ToWrColorRange(GetColorRange()), aFilter, wr::ToWrColorRange(GetColorRange()), aFilter,
aPreferCompositorSurface); preferCompositorSurface);
break; break;
} }
case gfx::SurfaceFormat::YUV: { case gfx::SurfaceFormat::YUV: {
@@ -220,7 +221,7 @@ void DMABUFTextureHostOGL::PushDisplayItems(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2], aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2],
wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()), wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()),
wr::ToWrColorRange(GetColorRange()), aFilter, wr::ToWrColorRange(GetColorRange()), aFilter,
aPreferCompositorSurface); preferCompositorSurface);
break; break;
} }
default: { default: {

View File

@@ -65,7 +65,7 @@ class DMABUFTextureHostOGL : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
private: private:
GLTextureSource* CreateTextureSourceForPlane(size_t aPlane); GLTextureSource* CreateTextureSourceForPlane(size_t aPlane);

View File

@@ -224,8 +224,9 @@ void MacIOSurfaceTextureHostOGL::PushResourceUpdates(
void MacIOSurfaceTextureHostOGL::PushDisplayItems( void MacIOSurfaceTextureHostOGL::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) { bool preferCompositorSurface =
aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE);
switch (GetFormat()) { switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8: case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8: case gfx::SurfaceFormat::R8G8B8A8:
@@ -236,7 +237,7 @@ void MacIOSurfaceTextureHostOGL::PushDisplayItems(
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface, preferCompositorSurface,
/* aSupportsExternalCompositing */ true); /* aSupportsExternalCompositing */ true);
break; break;
} }
@@ -248,8 +249,8 @@ void MacIOSurfaceTextureHostOGL::PushDisplayItems(
aBuilder.PushYCbCrInterleavedImage( aBuilder.PushYCbCrInterleavedImage(
aBounds, aClip, true, aImageKeys[0], wr::ColorDepth::Color8, aBounds, aClip, true, aImageKeys[0], wr::ColorDepth::Color8,
wr::ToWrYuvColorSpace(GetYUVColorSpace()), wr::ToWrYuvColorSpace(GetYUVColorSpace()),
wr::ToWrColorRange(GetColorRange()), aFilter, wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
aPreferCompositorSurface, /* aSupportsExternalCompositing */ true); /* aSupportsExternalCompositing */ true);
break; break;
} }
case gfx::SurfaceFormat::NV12: { case gfx::SurfaceFormat::NV12: {
@@ -260,8 +261,8 @@ void MacIOSurfaceTextureHostOGL::PushDisplayItems(
aBuilder.PushNV12Image( aBuilder.PushNV12Image(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aBounds, aClip, true, aImageKeys[0], aImageKeys[1],
wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()), wr::ColorDepth::Color8, wr::ToWrYuvColorSpace(GetYUVColorSpace()),
wr::ToWrColorRange(GetColorRange()), aFilter, wr::ToWrColorRange(GetColorRange()), aFilter, preferCompositorSurface,
aPreferCompositorSurface, /* aSupportsExternalCompositing */ true); /* aSupportsExternalCompositing */ true);
break; break;
} }
default: { default: {

View File

@@ -77,7 +77,7 @@ class MacIOSurfaceTextureHostOGL : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
gfx::YUVColorSpace GetYUVColorSpace() const override; gfx::YUVColorSpace GetYUVColorSpace() const override;
gfx::ColorRange GetColorRange() const override; gfx::ColorRange GetColorRange() const override;

View File

@@ -699,17 +699,18 @@ void SurfaceTextureHost::PushDisplayItems(wr::DisplayListBuilder& aBuilder,
const wr::LayoutRect& aClip, const wr::LayoutRect& aClip,
wr::ImageRendering aFilter, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) { PushDisplayItemFlagSet aFlags) {
switch (GetFormat()) { switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8: case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8: case gfx::SurfaceFormat::R8G8B8A8:
case gfx::SurfaceFormat::B8G8R8A8: case gfx::SurfaceFormat::B8G8R8A8:
case gfx::SurfaceFormat::B8G8R8X8: { case gfx::SurfaceFormat::B8G8R8X8: {
MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(aImageKeys.length() == 1);
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(
aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface); aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE));
break; break;
} }
default: { default: {
@@ -994,18 +995,18 @@ void AndroidHardwareBufferTextureHost::PushResourceUpdates(
void AndroidHardwareBufferTextureHost::PushDisplayItems( void AndroidHardwareBufferTextureHost::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) {
switch (GetFormat()) { switch (GetFormat()) {
case gfx::SurfaceFormat::R8G8B8X8: case gfx::SurfaceFormat::R8G8B8X8:
case gfx::SurfaceFormat::R8G8B8A8: case gfx::SurfaceFormat::R8G8B8A8:
case gfx::SurfaceFormat::B8G8R8A8: case gfx::SurfaceFormat::B8G8R8A8:
case gfx::SurfaceFormat::B8G8R8X8: { case gfx::SurfaceFormat::B8G8R8X8: {
MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(aImageKeys.length() == 1);
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(
aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface); aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE));
break; break;
} }
default: { default: {
@@ -1199,13 +1200,13 @@ void EGLImageTextureHost::PushResourceUpdates(
void EGLImageTextureHost::PushDisplayItems( void EGLImageTextureHost::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) {
MOZ_ASSERT(aImageKeys.length() == 1); MOZ_ASSERT(aImageKeys.length() == 1);
aBuilder.PushImage(aBounds, aClip, true, aFilter, aImageKeys[0], aBuilder.PushImage(
aBounds, aClip, true, aFilter, aImageKeys[0],
!(mFlags & TextureFlags::NON_PREMULTIPLIED), !(mFlags & TextureFlags::NON_PREMULTIPLIED),
wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f}, wr::ColorF{1.0f, 1.0f, 1.0f, 1.0f},
aPreferCompositorSurface); aFlags.contains(PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE));
} }
// //

View File

@@ -448,7 +448,7 @@ class SurfaceTextureHost : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
// gecko does not need deferred deletion with WebRender // gecko does not need deferred deletion with WebRender
// GPU/hardware task end could be checked by android fence. // GPU/hardware task end could be checked by android fence.
@@ -521,7 +521,7 @@ class AndroidHardwareBufferTextureHost : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
void SetAcquireFence(mozilla::ipc::FileDescriptor&& aFenceFd) override; void SetAcquireFence(mozilla::ipc::FileDescriptor&& aFenceFd) override;
@@ -637,7 +637,7 @@ class EGLImageTextureHost final : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
protected: protected:
const EGLImage mImage; const EGLImage mImage;

View File

@@ -434,14 +434,19 @@ void AsyncImagePipelineManager::ApplyAsyncImageForPipeline(
if (aPipeline->mUseExternalImage) { if (aPipeline->mUseExternalImage) {
MOZ_ASSERT(aPipeline->mCurrentTexture->AsWebRenderTextureHost()); MOZ_ASSERT(aPipeline->mCurrentTexture->AsWebRenderTextureHost());
Range<wr::ImageKey> range_keys(&keys[0], keys.Length()); Range<wr::ImageKey> range_keys(&keys[0], keys.Length());
bool prefer_compositor_surface = TextureHost::PushDisplayItemFlagSet flags;
IsOpaque(aPipeline->mCurrentTexture->GetFormat()) || if (IsOpaque(aPipeline->mCurrentTexture->GetFormat()) ||
bool(aPipeline->mCurrentTexture->GetFlags() & bool(aPipeline->mCurrentTexture->GetFlags() &
TextureFlags::IS_OPAQUE); TextureFlags::IS_OPAQUE)) {
flags += TextureHost::PushDisplayItemFlag::PREFER_COMPOSITOR_SURFACE;
}
if (mApi->SupportsExternalBufferTextures()) {
flags +=
TextureHost::PushDisplayItemFlag::SUPPORTS_EXTERNAL_BUFFER_TEXTURES;
}
aPipeline->mCurrentTexture->PushDisplayItems( aPipeline->mCurrentTexture->PushDisplayItems(
builder, wr::ToLayoutRect(rect), wr::ToLayoutRect(rect), builder, wr::ToLayoutRect(rect), wr::ToLayoutRect(rect),
aPipeline->mFilter, range_keys, aPipeline->mFilter, range_keys, flags);
/* aPreferCompositorSurface */ prefer_compositor_surface);
HoldExternalImage(aPipelineId, aEpoch, aPipeline->mCurrentTexture); HoldExternalImage(aPipelineId, aEpoch, aPipeline->mCurrentTexture);
} else { } else {
MOZ_ASSERT(keys.Length() == 1); MOZ_ASSERT(keys.Length() == 1);

View File

@@ -207,12 +207,11 @@ void WebRenderTextureHost::PushResourceUpdates(
void WebRenderTextureHost::PushDisplayItems( void WebRenderTextureHost::PushDisplayItems(
wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds, wr::DisplayListBuilder& aBuilder, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys, PushDisplayItemFlagSet aFlags) {
const bool aPreferCompositorSurface) {
MOZ_ASSERT(aImageKeys.length() > 0); MOZ_ASSERT(aImageKeys.length() > 0);
mWrappedTextureHost->PushDisplayItems(aBuilder, aBounds, aClip, aFilter, mWrappedTextureHost->PushDisplayItems(aBuilder, aBounds, aClip, aFilter,
aImageKeys, aPreferCompositorSurface); aImageKeys, aFlags);
} }
bool WebRenderTextureHost::NeedsYFlip() const { bool WebRenderTextureHost::NeedsYFlip() const {

View File

@@ -85,7 +85,7 @@ class WebRenderTextureHost : public TextureHost {
const wr::LayoutRect& aBounds, const wr::LayoutRect& aBounds,
const wr::LayoutRect& aClip, wr::ImageRendering aFilter, const wr::LayoutRect& aClip, wr::ImageRendering aFilter,
const Range<wr::ImageKey>& aImageKeys, const Range<wr::ImageKey>& aImageKeys,
const bool aPreferCompositorSurface) override; PushDisplayItemFlagSet aFlags) override;
bool NeedsYFlip() const override; bool NeedsYFlip() const override;

View File

@@ -78,6 +78,10 @@ class RenderCompositor {
virtual bool UseTripleBuffering() const { return false; } virtual bool UseTripleBuffering() const { return false; }
// True if AttachExternalImage supports being used with an external
// image that maps to a RenderBufferTextureHost
virtual bool SupportsExternalBufferTextures() const { return false; }
virtual LayoutDeviceIntSize GetBufferSize() = 0; virtual LayoutDeviceIntSize GetBufferSize() = 0;
widget::CompositorWidget* GetWidget() const { return mWidget; } widget::CompositorWidget* GetWidget() const { return mWidget; }

View File

@@ -35,6 +35,8 @@ class RenderCompositorSWGL : public RenderCompositor {
LayoutDeviceIntSize GetBufferSize() override; LayoutDeviceIntSize GetBufferSize() override;
bool SupportsExternalBufferTextures() const override { return true; }
// Interface for wr::Compositor // Interface for wr::Compositor
CompositorCapabilities GetCompositorCapabilities() override; CompositorCapabilities GetCompositorCapabilities() override;

View File

@@ -35,7 +35,7 @@
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
# include "GLLibraryEGL.h" # include "GLLibraryEGL.h"
# include "mozilla/webrender/RenderAndroidSurfaceTextureHostOGL.h" # include "mozilla/webrender/RenderAndroidSurfaceTextureHost.h"
#endif #endif
#ifdef MOZ_WIDGET_GTK #ifdef MOZ_WIDGET_GTK

View File

@@ -59,6 +59,7 @@ class NewRenderer : public RendererEvent {
NewRenderer(wr::DocumentHandle** aDocHandle, NewRenderer(wr::DocumentHandle** aDocHandle,
layers::CompositorBridgeParent* aBridge, int32_t* aMaxTextureSize, layers::CompositorBridgeParent* aBridge, int32_t* aMaxTextureSize,
bool* aUseANGLE, bool* aUseDComp, bool* aUseTripleBuffering, bool* aUseANGLE, bool* aUseDComp, bool* aUseTripleBuffering,
bool* aSupportsExternalBufferTextures,
RefPtr<widget::CompositorWidget>&& aWidget, RefPtr<widget::CompositorWidget>&& aWidget,
layers::SynchronousTask* aTask, LayoutDeviceIntSize aSize, layers::SynchronousTask* aTask, LayoutDeviceIntSize aSize,
layers::SyncHandle* aHandle, nsACString* aError) layers::SyncHandle* aHandle, nsACString* aError)
@@ -67,6 +68,7 @@ class NewRenderer : public RendererEvent {
mUseANGLE(aUseANGLE), mUseANGLE(aUseANGLE),
mUseDComp(aUseDComp), mUseDComp(aUseDComp),
mUseTripleBuffering(aUseTripleBuffering), mUseTripleBuffering(aUseTripleBuffering),
mSupportsExternalBufferTextures(aSupportsExternalBufferTextures),
mBridge(aBridge), mBridge(aBridge),
mCompositorWidget(std::move(aWidget)), mCompositorWidget(std::move(aWidget)),
mTask(aTask), mTask(aTask),
@@ -93,6 +95,8 @@ class NewRenderer : public RendererEvent {
*mUseANGLE = compositor->UseANGLE(); *mUseANGLE = compositor->UseANGLE();
*mUseDComp = compositor->UseDComp(); *mUseDComp = compositor->UseDComp();
*mUseTripleBuffering = compositor->UseTripleBuffering(); *mUseTripleBuffering = compositor->UseTripleBuffering();
*mSupportsExternalBufferTextures =
compositor->SupportsExternalBufferTextures();
// Only allow the panic on GL error functionality in nightly builds, // Only allow the panic on GL error functionality in nightly builds,
// since it (deliberately) crashes the GPU process if any GL call // since it (deliberately) crashes the GPU process if any GL call
@@ -179,6 +183,7 @@ class NewRenderer : public RendererEvent {
bool* mUseANGLE; bool* mUseANGLE;
bool* mUseDComp; bool* mUseDComp;
bool* mUseTripleBuffering; bool* mUseTripleBuffering;
bool* mSupportsExternalBufferTextures;
layers::CompositorBridgeParent* mBridge; layers::CompositorBridgeParent* mBridge;
RefPtr<widget::CompositorWidget> mCompositorWidget; RefPtr<widget::CompositorWidget> mCompositorWidget;
layers::SynchronousTask* mTask; layers::SynchronousTask* mTask;
@@ -345,15 +350,16 @@ already_AddRefed<WebRenderAPI> WebRenderAPI::Create(
bool useANGLE = false; bool useANGLE = false;
bool useDComp = false; bool useDComp = false;
bool useTripleBuffering = false; bool useTripleBuffering = false;
bool supportsExternalBufferTextures = false;
layers::SyncHandle syncHandle = 0; layers::SyncHandle syncHandle = 0;
// Dispatch a synchronous task because the DocumentHandle object needs to be // Dispatch a synchronous task because the DocumentHandle object needs to be
// created on the render thread. If need be we could delay waiting on this // created on the render thread. If need be we could delay waiting on this
// task until the next time we need to access the DocumentHandle object. // task until the next time we need to access the DocumentHandle object.
layers::SynchronousTask task("Create Renderer"); layers::SynchronousTask task("Create Renderer");
auto event = MakeUnique<NewRenderer>(&docHandle, aBridge, &maxTextureSize, auto event = MakeUnique<NewRenderer>(
&useANGLE, &useDComp, &docHandle, aBridge, &maxTextureSize, &useANGLE, &useDComp,
&useTripleBuffering, std::move(aWidget), &useTripleBuffering, &supportsExternalBufferTextures, std::move(aWidget),
&task, aSize, &syncHandle, &aError); &task, aSize, &syncHandle, &aError);
RenderThread::Get()->RunEvent(aWindowId, std::move(event)); RenderThread::Get()->RunEvent(aWindowId, std::move(event));
@@ -365,7 +371,8 @@ already_AddRefed<WebRenderAPI> WebRenderAPI::Create(
return RefPtr<WebRenderAPI>( return RefPtr<WebRenderAPI>(
new WebRenderAPI(docHandle, aWindowId, maxTextureSize, useANGLE, new WebRenderAPI(docHandle, aWindowId, maxTextureSize, useANGLE,
useDComp, useTripleBuffering, syncHandle)) useDComp, useTripleBuffering,
supportsExternalBufferTextures, syncHandle))
.forget(); .forget();
} }
@@ -373,9 +380,9 @@ already_AddRefed<WebRenderAPI> WebRenderAPI::Clone() {
wr::DocumentHandle* docHandle = nullptr; wr::DocumentHandle* docHandle = nullptr;
wr_api_clone(mDocHandle, &docHandle); wr_api_clone(mDocHandle, &docHandle);
RefPtr<WebRenderAPI> renderApi = RefPtr<WebRenderAPI> renderApi = new WebRenderAPI(
new WebRenderAPI(docHandle, mId, mMaxTextureSize, mUseANGLE, mUseDComp, docHandle, mId, mMaxTextureSize, mUseANGLE, mUseDComp,
mUseTripleBuffering, mSyncHandle); mUseTripleBuffering, mSupportsExternalBufferTextures, mSyncHandle);
renderApi->mRootApi = this; // Hold root api renderApi->mRootApi = this; // Hold root api
renderApi->mRootDocumentApi = this; renderApi->mRootDocumentApi = this;
@@ -389,6 +396,7 @@ wr::WrIdNamespace WebRenderAPI::GetNamespace() {
WebRenderAPI::WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId, WebRenderAPI::WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId,
uint32_t aMaxTextureSize, bool aUseANGLE, uint32_t aMaxTextureSize, bool aUseANGLE,
bool aUseDComp, bool aUseTripleBuffering, bool aUseDComp, bool aUseTripleBuffering,
bool aSupportsExternalBufferTextures,
layers::SyncHandle aSyncHandle) layers::SyncHandle aSyncHandle)
: mDocHandle(aHandle), : mDocHandle(aHandle),
mId(aId), mId(aId),
@@ -396,6 +404,7 @@ WebRenderAPI::WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId,
mUseANGLE(aUseANGLE), mUseANGLE(aUseANGLE),
mUseDComp(aUseDComp), mUseDComp(aUseDComp),
mUseTripleBuffering(aUseTripleBuffering), mUseTripleBuffering(aUseTripleBuffering),
mSupportsExternalBufferTextures(aSupportsExternalBufferTextures),
mCaptureSequence(false), mCaptureSequence(false),
mSyncHandle(aSyncHandle) {} mSyncHandle(aSyncHandle) {}

View File

@@ -273,6 +273,9 @@ class WebRenderAPI final {
bool GetUseANGLE() const { return mUseANGLE; } bool GetUseANGLE() const { return mUseANGLE; }
bool GetUseDComp() const { return mUseDComp; } bool GetUseDComp() const { return mUseDComp; }
bool GetUseTripleBuffering() const { return mUseTripleBuffering; } bool GetUseTripleBuffering() const { return mUseTripleBuffering; }
bool SupportsExternalBufferTextures() const {
return mSupportsExternalBufferTextures;
}
layers::SyncHandle GetSyncHandle() const { return mSyncHandle; } layers::SyncHandle GetSyncHandle() const { return mSyncHandle; }
void Capture(); void Capture();
@@ -305,7 +308,8 @@ class WebRenderAPI final {
protected: protected:
WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId, WebRenderAPI(wr::DocumentHandle* aHandle, wr::WindowId aId,
uint32_t aMaxTextureSize, bool aUseANGLE, bool aUseDComp, uint32_t aMaxTextureSize, bool aUseANGLE, bool aUseDComp,
bool aUseTripleBuffering, layers::SyncHandle aSyncHandle); bool aUseTripleBuffering, bool aSupportsExternalBufferTextures,
layers::SyncHandle aSyncHandle);
~WebRenderAPI(); ~WebRenderAPI();
// Should be used only for shutdown handling // Should be used only for shutdown handling
@@ -319,6 +323,7 @@ class WebRenderAPI final {
bool mUseANGLE; bool mUseANGLE;
bool mUseDComp; bool mUseDComp;
bool mUseTripleBuffering; bool mUseTripleBuffering;
bool mSupportsExternalBufferTextures;
bool mCaptureSequence; bool mCaptureSequence;
layers::SyncHandle mSyncHandle; layers::SyncHandle mSyncHandle;