From 15fde99d2c78e283e71609f813101146df446847 Mon Sep 17 00:00:00 2001 From: JerryShih Date: Fri, 31 Mar 2017 22:29:15 +0800 Subject: [PATCH] Bug 1347062 - P5: use texture handle directly with webrender. r=nical,sotaro MozReview-Commit-ID: 1XLiFcpFEeu --- gfx/layers/wr/WebRenderBridgeParent.cpp | 30 +++++++++++++++++-------- gfx/webrender_bindings/RendererOGL.cpp | 25 +++++++++++++++++---- gfx/webrender_bindings/WebRenderTypes.h | 3 +++ 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index a2a12a7b3d41..294f706d99d1 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -344,15 +344,27 @@ WebRenderBridgeParent::ProcessWebRenderCommands(const gfx::IntSize &aSize, } WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost(); if (wrTexture) { - // XXX handling YUV - gfx::SurfaceFormat format = - wrTexture->GetFormat() == SurfaceFormat::YUV ? SurfaceFormat::B8G8R8A8 : wrTexture->GetFormat(); - wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetRGBStride(), format); - mApi->AddExternalImageBuffer(key, - descriptor, - wrTexture->GetExternalImageKey()); - mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost()); - keysToDelete.push_back(key); + if (wrTexture->IsWrappingNativeHandle()) { + // XXX only for MacIOSurface right now. + // XXX remove the redundant codes for both native handle and yuv case. + wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetReadFormat()); + mApi->AddExternalImageHandle(key, + descriptor, + wrTexture->GetExternalImageKey()); + mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost()); + keysToDelete.push_back(key); + } else { + // XXX handling YUV + gfx::SurfaceFormat format = + wrTexture->GetFormat() == SurfaceFormat::YUV ? SurfaceFormat::B8G8R8A8 : wrTexture->GetFormat(); + wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetRGBStride(), format); + mApi->AddExternalImageBuffer(key, + descriptor, + wrTexture->GetExternalImageKey()); + mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost()); + keysToDelete.push_back(key); + } + break; } RefPtr dSurf = host->GetAsSurface(); diff --git a/gfx/webrender_bindings/RendererOGL.cpp b/gfx/webrender_bindings/RendererOGL.cpp index d65d8b662018..781fe0c88955 100644 --- a/gfx/webrender_bindings/RendererOGL.cpp +++ b/gfx/webrender_bindings/RendererOGL.cpp @@ -9,7 +9,8 @@ #include "mozilla/gfx/Logging.h" #include "mozilla/layers/CompositorBridgeParent.h" #include "mozilla/layers/CompositorThread.h" -#include "mozilla/webrender/RenderTextureHost.h" +#include "mozilla/webrender/RenderBufferTextureHost.h" +#include "mozilla/webrender/RenderTextureHostOGL.h" #include "mozilla/widget/CompositorWidget.h" namespace mozilla { @@ -19,10 +20,26 @@ WrExternalImage LockExternalImage(void* aObj, WrExternalImageId aId) { RendererOGL* renderer = reinterpret_cast(aObj); RenderTextureHost* texture = renderer->GetRenderTexture(aId.id); - MOZ_ASSERT(texture); - texture->Lock(); - return RawDataToWrExternalImage(texture->GetDataForRender(), texture->GetBufferSizeForRender()); + if (texture->AsBufferTextureHost()) { + RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost(); + MOZ_ASSERT(bufferTexture); + bufferTexture->Lock(); + + return RawDataToWrExternalImage(bufferTexture->GetDataForRender(), + bufferTexture->GetBufferSizeForRender()); + } else { + // texture handle case + RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL(); + MOZ_ASSERT(textureOGL); + gfx::IntSize size = textureOGL->GetSize(); + textureOGL->SetGLContext(renderer->mGL); + textureOGL->Lock(); + + return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(), + 0, 0, + size.width, size.height); + } } void UnlockExternalImage(void* aObj, WrExternalImageId aId) diff --git a/gfx/webrender_bindings/WebRenderTypes.h b/gfx/webrender_bindings/WebRenderTypes.h index 5727b790faf9..bbaa41737473 100644 --- a/gfx/webrender_bindings/WebRenderTypes.h +++ b/gfx/webrender_bindings/WebRenderTypes.h @@ -44,6 +44,9 @@ inline Epoch NewEpoch(uint32_t aEpoch) { inline Maybe SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat) { switch (aFormat) { + case gfx::SurfaceFormat::R8G8B8X8: + // TODO: use RGBA + opaque flag + return Some(WrImageFormat::RGBA8); case gfx::SurfaceFormat::B8G8R8X8: // TODO: WebRender will have a BGRA + opaque flag for this but does not // have it yet (cf. issue #732).