mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-14 22:05:44 +00:00
Bug 1331944 - Part 3. Refactor mozilla::wr::LockExternalImage to make it easier to add new types. r=jrmuizel
This commit is contained in:
parent
d9e413fa5a
commit
2f8b457e1e
@ -43,13 +43,13 @@ RenderBufferTextureHost::~RenderBufferTextureHost()
|
||||
MOZ_COUNT_DTOR_INHERITED(RenderBufferTextureHost, RenderTextureHost);
|
||||
}
|
||||
|
||||
bool
|
||||
RenderBufferTextureHost::Lock()
|
||||
wr::WrExternalImage
|
||||
RenderBufferTextureHost::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
|
||||
{
|
||||
if (!mLocked) {
|
||||
if (!GetBuffer()) {
|
||||
// We hit some problems to get the shmem.
|
||||
return false;
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
if (mFormat != gfx::SurfaceFormat::YUV) {
|
||||
mSurface = gfx::Factory::CreateWrappingDataSourceSurface(GetBuffer(),
|
||||
@ -57,11 +57,11 @@ RenderBufferTextureHost::Lock()
|
||||
mSize,
|
||||
mFormat);
|
||||
if (NS_WARN_IF(!mSurface)) {
|
||||
return false;
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
if (NS_WARN_IF(!mSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mMap))) {
|
||||
mSurface = nullptr;
|
||||
return false;
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
} else {
|
||||
const layers::YCbCrDescriptor& desc = mDescriptor.get_YCbCrDescriptor();
|
||||
@ -80,19 +80,20 @@ RenderBufferTextureHost::Lock()
|
||||
gfx::SurfaceFormat::A8);
|
||||
if (NS_WARN_IF(!mYSurface || !mCbSurface || !mCrSurface)) {
|
||||
mYSurface = mCbSurface = mCrSurface = nullptr;
|
||||
return false;
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
if (NS_WARN_IF(!mYSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mYMap) ||
|
||||
!mCbSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mCbMap) ||
|
||||
!mCrSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE, &mCrMap))) {
|
||||
mYSurface = mCbSurface = mCrSurface = nullptr;
|
||||
return false;
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
RenderBufferData data = GetBufferDataForRender(aChannelIndex);
|
||||
return RawDataToWrExternalImage(data.mData, data.mBufferSize);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -17,13 +17,8 @@ public:
|
||||
RenderBufferTextureHost(uint8_t* aBuffer,
|
||||
const layers::BufferDescriptor& aDescriptor);
|
||||
|
||||
virtual bool Lock() override;
|
||||
virtual void Unlock() override;
|
||||
|
||||
virtual RenderBufferTextureHost* AsBufferTextureHost() override
|
||||
{
|
||||
return this;
|
||||
}
|
||||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
|
||||
void Unlock() override;
|
||||
|
||||
class RenderBufferData
|
||||
{
|
||||
|
@ -59,17 +59,6 @@ RenderDXGITextureHostOGL::~RenderDXGITextureHostOGL()
|
||||
DeleteTextureHandle();
|
||||
}
|
||||
|
||||
void
|
||||
RenderDXGITextureHostOGL::SetGLContext(gl::GLContext* aContext)
|
||||
{
|
||||
if (mGL.get() != aContext) {
|
||||
// Release the texture handle in the previous gl context.
|
||||
DeleteTextureHandle();
|
||||
mGL = aContext;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
RenderDXGITextureHostOGL::EnsureLockable()
|
||||
{
|
||||
@ -182,27 +171,34 @@ RenderDXGITextureHostOGL::EnsureLockable()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
RenderDXGITextureHostOGL::Lock()
|
||||
wr::WrExternalImage
|
||||
RenderDXGITextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
|
||||
{
|
||||
if (mGL.get() != aGL) {
|
||||
// Release the texture handle in the previous gl context.
|
||||
DeleteTextureHandle();
|
||||
mGL = aGL;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
|
||||
if (!EnsureLockable()) {
|
||||
return false;
|
||||
return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (mLocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mKeyedMutex) {
|
||||
HRESULT hr = mKeyedMutex->AcquireSync(0, 100);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError() << "RenderDXGITextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
|
||||
return false;
|
||||
if (!mLocked) {
|
||||
if (mKeyedMutex) {
|
||||
HRESULT hr = mKeyedMutex->AcquireSync(0, 100);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError() << "RenderDXGITextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
|
||||
return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
}
|
||||
mLocked = true;
|
||||
|
||||
return true;
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
|
||||
size.width, size.height);
|
||||
}
|
||||
|
||||
void
|
||||
@ -289,17 +285,6 @@ RenderDXGIYCbCrTextureHostOGL::~RenderDXGIYCbCrTextureHostOGL()
|
||||
DeleteTextureHandle();
|
||||
}
|
||||
|
||||
void
|
||||
RenderDXGIYCbCrTextureHostOGL::SetGLContext(gl::GLContext* aContext)
|
||||
{
|
||||
if (mGL.get() != aContext) {
|
||||
// Release the texture handle in the previous gl context.
|
||||
DeleteTextureHandle();
|
||||
mGL = aContext;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
RenderDXGIYCbCrTextureHostOGL::EnsureLockable()
|
||||
{
|
||||
@ -367,29 +352,36 @@ RenderDXGIYCbCrTextureHostOGL::EnsureLockable()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
RenderDXGIYCbCrTextureHostOGL::Lock()
|
||||
wr::WrExternalImage
|
||||
RenderDXGIYCbCrTextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
|
||||
{
|
||||
if (mGL.get() != aGL) {
|
||||
// Release the texture handle in the previous gl context.
|
||||
DeleteTextureHandle();
|
||||
mGL = aGL;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
|
||||
if (!EnsureLockable()) {
|
||||
return false;
|
||||
return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (mLocked) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mKeyedMutexs[0]) {
|
||||
for (const auto& mutex : mKeyedMutexs) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 100);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError() << "RenderDXGIYCbCrTextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
|
||||
return false;
|
||||
if (!mLocked) {
|
||||
if (mKeyedMutexs[0]) {
|
||||
for (const auto& mutex : mKeyedMutexs) {
|
||||
HRESULT hr = mutex->AcquireSync(0, 100);
|
||||
if (hr != S_OK) {
|
||||
gfxCriticalError() << "RenderDXGIYCbCrTextureHostOGL AcquireSync timeout, hr=" << gfx::hexa(hr);
|
||||
return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
mLocked = true;
|
||||
}
|
||||
mLocked = true;
|
||||
|
||||
return true;
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
|
||||
size.width, size.height);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -23,10 +23,8 @@ public:
|
||||
gfx::SurfaceFormat aFormat,
|
||||
gfx::IntSize aSize);
|
||||
|
||||
virtual void SetGLContext(gl::GLContext* aContext) override;
|
||||
|
||||
virtual bool Lock() override;
|
||||
virtual void Unlock() override;
|
||||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
|
||||
void Unlock() override;
|
||||
|
||||
virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const;
|
||||
virtual GLuint GetGLHandle(uint8_t aChannelIndex) const;
|
||||
@ -63,9 +61,7 @@ public:
|
||||
explicit RenderDXGIYCbCrTextureHostOGL(WindowsHandle (&aHandles)[3],
|
||||
gfx::IntSize aSize);
|
||||
|
||||
virtual void SetGLContext(gl::GLContext* aContext) override;
|
||||
|
||||
virtual bool Lock() override;
|
||||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
|
||||
virtual void Unlock() override;
|
||||
|
||||
virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const;
|
||||
|
@ -71,11 +71,18 @@ RenderMacIOSurfaceTextureHostOGL::GetSize(uint8_t aChannelIndex) const
|
||||
mSurface->GetDevicePixelHeight(aChannelIndex));
|
||||
}
|
||||
|
||||
bool
|
||||
RenderMacIOSurfaceTextureHostOGL::Lock()
|
||||
wr::WrExternalImage
|
||||
RenderMacIOSurfaceTextureHostOGL::Lock(uint8_t aChannelIndex, gl::GLContext* aGL)
|
||||
{
|
||||
if (mGL.get() != aGL) {
|
||||
// release the texture handle in the previous gl context
|
||||
DeleteTextureHandle();
|
||||
mGL = aGL;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
|
||||
if (!mSurface || !mGL || !mGL->MakeCurrent()) {
|
||||
return false;
|
||||
return NativeTextureToWrExternalImage(0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (!mTextureHandles[0]) {
|
||||
@ -89,7 +96,9 @@ RenderMacIOSurfaceTextureHostOGL::Lock()
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
gfx::IntSize size = GetSize(aChannelIndex);
|
||||
return NativeTextureToWrExternalImage(GetGLHandle(aChannelIndex), 0, 0,
|
||||
size.width, size.height);
|
||||
}
|
||||
|
||||
void
|
||||
@ -98,17 +107,6 @@ RenderMacIOSurfaceTextureHostOGL::Unlock()
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
RenderMacIOSurfaceTextureHostOGL::SetGLContext(gl::GLContext* aContext)
|
||||
{
|
||||
if (mGL.get() != aContext) {
|
||||
// release the texture handle in the previous gl context
|
||||
DeleteTextureHandle();
|
||||
mGL = aContext;
|
||||
mGL->MakeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
RenderMacIOSurfaceTextureHostOGL::DeleteTextureHandle()
|
||||
{
|
||||
|
@ -23,10 +23,8 @@ class RenderMacIOSurfaceTextureHostOGL final : public RenderTextureHostOGL
|
||||
public:
|
||||
explicit RenderMacIOSurfaceTextureHostOGL(MacIOSurface* aSurface);
|
||||
|
||||
virtual bool Lock() override;
|
||||
virtual void Unlock() override;
|
||||
|
||||
virtual void SetGLContext(gl::GLContext* aContext) override;
|
||||
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
|
||||
void Unlock() override;
|
||||
|
||||
virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const override;
|
||||
virtual GLuint GetGLHandle(uint8_t aChannelIndex) const override;
|
||||
|
@ -12,6 +12,11 @@
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace gl {
|
||||
class GLContext;
|
||||
}
|
||||
|
||||
namespace wr {
|
||||
|
||||
class RenderBufferTextureHost;
|
||||
@ -24,12 +29,9 @@ class RenderTextureHost
|
||||
public:
|
||||
RenderTextureHost();
|
||||
|
||||
virtual bool Lock() = 0;
|
||||
virtual wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) = 0;
|
||||
virtual void Unlock() = 0;
|
||||
|
||||
virtual RenderBufferTextureHost* AsBufferTextureHost() { return nullptr; }
|
||||
virtual RenderTextureHostOGL* AsTextureHostOGL() { return nullptr; }
|
||||
|
||||
protected:
|
||||
virtual ~RenderTextureHost();
|
||||
};
|
||||
|
@ -21,13 +21,9 @@ class RenderTextureHostOGL : public RenderTextureHost
|
||||
public:
|
||||
RenderTextureHostOGL();
|
||||
|
||||
virtual void SetGLContext(gl::GLContext* aContext) = 0;
|
||||
|
||||
virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const = 0;
|
||||
virtual GLuint GetGLHandle(uint8_t aChannelIndex) const = 0;
|
||||
|
||||
virtual RenderTextureHostOGL* AsTextureHostOGL() override { return this; }
|
||||
|
||||
protected:
|
||||
virtual ~RenderTextureHostOGL();
|
||||
};
|
||||
|
@ -22,37 +22,8 @@ wr::WrExternalImage LockExternalImage(void* aObj, wr::WrExternalImageId aId, uin
|
||||
{
|
||||
RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
|
||||
RenderTextureHost* texture = renderer->GetRenderTexture(aId);
|
||||
|
||||
if (texture->AsBufferTextureHost()) {
|
||||
RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
|
||||
MOZ_ASSERT(bufferTexture);
|
||||
|
||||
if (bufferTexture->Lock()) {
|
||||
RenderBufferTextureHost::RenderBufferData data =
|
||||
bufferTexture->GetBufferDataForRender(aChannelIndex);
|
||||
|
||||
return RawDataToWrExternalImage(data.mData, data.mBufferSize);
|
||||
} else {
|
||||
return RawDataToWrExternalImage(nullptr, 0);
|
||||
}
|
||||
} else {
|
||||
// texture handle case
|
||||
RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL();
|
||||
MOZ_ASSERT(textureOGL);
|
||||
|
||||
textureOGL->SetGLContext(renderer->mGL);
|
||||
gfx::IntSize size = textureOGL->GetSize(aChannelIndex);
|
||||
if (textureOGL->Lock()) {
|
||||
return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(aChannelIndex),
|
||||
0, 0,
|
||||
size.width, size.height);
|
||||
} else {
|
||||
// Just use 0 for the gl handle if the lock() was failed.
|
||||
return NativeTextureToWrExternalImage(0,
|
||||
0, 0,
|
||||
size.width, size.height);
|
||||
}
|
||||
}
|
||||
MOZ_ASSERT(texture);
|
||||
return texture->Lock(aChannelIndex, renderer->mGL);
|
||||
}
|
||||
|
||||
void UnlockExternalImage(void* aObj, wr::WrExternalImageId aId, uint8_t aChannelIndex)
|
||||
|
Loading…
Reference in New Issue
Block a user