Bug 1362049 - Handle multiple-channel format for RenderMacIOSurfaceTextureHostOGL. v4. r=mattwoodrow

We could use NV12 or YCbCr-planar format for video playback. There will be up to 3 channels in the MacIOSurface.

MozReview-Commit-ID: 77RYntphjYy
This commit is contained in:
JerryShih 2017-05-18 22:59:08 +08:00
Родитель 006c192621
Коммит b4f6e9c835
2 изменённых файлов: 63 добавлений и 16 удалений

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

@ -12,12 +12,34 @@
namespace mozilla {
namespace wr {
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;
}
RenderMacIOSurfaceTextureHostOGL::RenderMacIOSurfaceTextureHostOGL(MacIOSurface* aSurface)
: mTextureHandle(0)
: mSurface(aSurface)
, mTextureHandles{ 0, 0, 0 }
{
MOZ_COUNT_CTOR_INHERITED(RenderMacIOSurfaceTextureHostOGL, RenderTextureHostOGL);
mSurface = aSurface;
}
RenderMacIOSurfaceTextureHostOGL::~RenderMacIOSurfaceTextureHostOGL()
@ -26,6 +48,29 @@ RenderMacIOSurfaceTextureHostOGL::~RenderMacIOSurfaceTextureHostOGL()
DeleteTextureHandle();
}
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));
}
bool
RenderMacIOSurfaceTextureHostOGL::Lock()
{
@ -33,17 +78,15 @@ RenderMacIOSurfaceTextureHostOGL::Lock()
return false;
}
if (!mTextureHandle) {
// xxx: should we need to handle the PlaneCount 3 iosurface?
MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
if (!mTextureHandles[0]) {
MOZ_ASSERT(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext());
mGL->fGenTextures(1, &mTextureHandle);
mGL->fActiveTexture(LOCAL_GL_TEXTURE0);
gl::ScopedBindTexture texture(mGL, mTextureHandle, LOCAL_GL_TEXTURE_RECTANGLE_ARB);
mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
mGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext(), 0);
// 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]));
}
}
return true;
@ -68,10 +111,14 @@ RenderMacIOSurfaceTextureHostOGL::SetGLContext(gl::GLContext* aContext)
void
RenderMacIOSurfaceTextureHostOGL::DeleteTextureHandle()
{
if (mTextureHandle != 0 && mGL && mGL->MakeCurrent()) {
mGL->fDeleteTextures(1, &mTextureHandle);
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;
}
}
mTextureHandle = 0;
}
} // namespace wr

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

@ -42,7 +42,7 @@ private:
RefPtr<MacIOSurface> mSurface;
RefPtr<gl::GLContext> mGL;
GLuint mTextureHandle;
GLuint mTextureHandles[3];
};
} // namespace wr