Bug 1347062 - P5: use texture handle directly with webrender. r=nical,sotaro

MozReview-Commit-ID: 1XLiFcpFEeu
This commit is contained in:
JerryShih 2017-03-31 22:29:15 +08:00
Родитель b0ffca2f70
Коммит 15fde99d2c
3 изменённых файлов: 45 добавлений и 13 удалений

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

@ -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<DataSourceSurface> dSurf = host->GetAsSurface();

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

@ -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<RendererOGL*>(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)

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

@ -44,6 +44,9 @@ inline Epoch NewEpoch(uint32_t aEpoch) {
inline Maybe<WrImageFormat>
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).