2017-03-31 17:29:14 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "RenderMacIOSurfaceTextureHostOGL.h"
|
|
|
|
|
|
|
|
#include "GLContextCGL.h"
|
|
|
|
#include "mozilla/gfx/Logging.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace wr {
|
|
|
|
|
2017-05-18 17:59:08 +03:00
|
|
|
static CGLError
|
|
|
|
CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL, MacIOSurface* aSurface, GLuint* aTexture)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aGL && aSurface && aTexture);
|
|
|
|
|
|
|
|
aGL->fGenTextures(1, aTexture);
|
|
|
|
aGL->fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, *aTexture);
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
CGLError result = kCGLNoError;
|
|
|
|
gfx::SurfaceFormat readFormat = gfx::SurfaceFormat::UNKNOWN;
|
|
|
|
result = aSurface->CGLTexImageIOSurface2D(aGL,
|
|
|
|
gl::GLContextCGL::Cast(aGL)->GetCGLContext(),
|
|
|
|
aPlaneID,
|
|
|
|
&readFormat);
|
|
|
|
// If this is a yuv format, the Webrender only supports YUV422 interleaving format.
|
|
|
|
MOZ_ASSERT(aSurface->GetFormat() != gfx::SurfaceFormat::YUV422 || readFormat == gfx::SurfaceFormat::YUV422);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
RenderMacIOSurfaceTextureHostOGL::RenderMacIOSurfaceTextureHostOGL(MacIOSurface* aSurface)
|
2017-05-18 17:59:08 +03:00
|
|
|
: mSurface(aSurface)
|
|
|
|
, mTextureHandles{ 0, 0, 0 }
|
2017-03-31 17:29:14 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR_INHERITED(RenderMacIOSurfaceTextureHostOGL, RenderTextureHostOGL);
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::~RenderMacIOSurfaceTextureHostOGL()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR_INHERITED(RenderMacIOSurfaceTextureHostOGL, RenderTextureHostOGL);
|
|
|
|
DeleteTextureHandle();
|
|
|
|
}
|
|
|
|
|
2017-05-18 17:59:08 +03:00
|
|
|
GLuint
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::GetGLHandle(uint8_t aChannelIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSurface);
|
|
|
|
MOZ_ASSERT((mSurface->GetPlaneCount() == 0) ? (aChannelIndex == mSurface->GetPlaneCount())
|
|
|
|
: (aChannelIndex < mSurface->GetPlaneCount()));
|
|
|
|
return mTextureHandles[aChannelIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntSize
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::GetSize(uint8_t aChannelIndex) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSurface);
|
|
|
|
MOZ_ASSERT((mSurface->GetPlaneCount() == 0) ? (aChannelIndex == mSurface->GetPlaneCount())
|
|
|
|
: (aChannelIndex < mSurface->GetPlaneCount()));
|
|
|
|
|
|
|
|
if (!mSurface) {
|
|
|
|
return gfx::IntSize();
|
|
|
|
}
|
|
|
|
return gfx::IntSize(mSurface->GetDevicePixelWidth(aChannelIndex),
|
|
|
|
mSurface->GetDevicePixelHeight(aChannelIndex));
|
|
|
|
}
|
|
|
|
|
2017-10-30 16:52:07 +03:00
|
|
|
bool
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::Lock()
|
2017-03-31 17:29:14 +03:00
|
|
|
{
|
|
|
|
if (!mSurface || !mGL || !mGL->MakeCurrent()) {
|
2017-10-30 16:52:07 +03:00
|
|
|
return false;
|
2017-03-31 17:29:14 +03:00
|
|
|
}
|
|
|
|
|
2017-05-18 17:59:08 +03:00
|
|
|
if (!mTextureHandles[0]) {
|
2017-03-31 17:29:14 +03:00
|
|
|
MOZ_ASSERT(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext());
|
|
|
|
|
2017-05-18 17:59:08 +03:00
|
|
|
// The result of GetPlaneCount() is 0 for single plane format, but it will
|
|
|
|
// be 2 if the format has 2 planar data.
|
|
|
|
CreateTextureForPlane(0, mGL, mSurface, &(mTextureHandles[0]));
|
|
|
|
for (size_t i = 1; i < mSurface->GetPlaneCount(); ++i) {
|
|
|
|
CreateTextureForPlane(i, mGL, mSurface, &(mTextureHandles[i]));
|
|
|
|
}
|
2017-03-31 17:29:14 +03:00
|
|
|
}
|
|
|
|
|
2017-10-30 16:52:07 +03:00
|
|
|
return true;
|
2017-03-31 17:29:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::Unlock()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-10-30 16:52:07 +03:00
|
|
|
void
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::SetGLContext(gl::GLContext* aContext)
|
|
|
|
{
|
|
|
|
if (mGL.get() != aContext) {
|
|
|
|
// release the texture handle in the previous gl context
|
|
|
|
DeleteTextureHandle();
|
|
|
|
mGL = aContext;
|
|
|
|
mGL->MakeCurrent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 17:29:14 +03:00
|
|
|
void
|
|
|
|
RenderMacIOSurfaceTextureHostOGL::DeleteTextureHandle()
|
|
|
|
{
|
2017-05-18 17:59:08 +03:00
|
|
|
if (mTextureHandles[0] != 0 && mGL && mGL->MakeCurrent()) {
|
|
|
|
// Calling glDeleteTextures on 0 isn't an error. So, just make them a single
|
|
|
|
// call.
|
|
|
|
mGL->fDeleteTextures(3, mTextureHandles);
|
|
|
|
for (size_t i = 0; i < 3; ++i) {
|
|
|
|
mTextureHandles[i] = 0;
|
|
|
|
}
|
2017-03-31 17:29:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wr
|
|
|
|
} // namespace mozilla
|