Bug 1248323: P1. Add support for YUV422 IOSurface. r=nical

Those are really UYVY 16bpp surface.

MozReview-Commit-ID: DWkqrF6Norj

--HG--
extra : rebase_source : 479500af560f61a3f6b6c4c3b0f64aeb92438a9a
This commit is contained in:
Jean-Yves Avenard 2016-02-23 13:26:27 +11:00
Родитель 4ca43175f3
Коммит 0f2fbc9d88
9 изменённых файлов: 42 добавлений и 3 удалений

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

@ -10,6 +10,7 @@
#include <dlfcn.h>
#include "mozilla/RefPtr.h"
#include "mozilla/Assertions.h"
#include "GLConsts.h"
using namespace mozilla;
// IOSurface signatures
@ -476,6 +477,21 @@ MacIOSurface::GetFormat()
OSType pixelFormat = GetPixelFormat();
if (pixelFormat == '420v') {
return SurfaceFormat::NV12;
} else if (pixelFormat == '2vuy') {
return SurfaceFormat::YUV422;
} else {
return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8;
}
}
SurfaceFormat
MacIOSurface::GetReadFormat()
{
OSType pixelFormat = GetPixelFormat();
if (pixelFormat == '420v') {
return SurfaceFormat::NV12;
} else if (pixelFormat == '2vuy') {
return SurfaceFormat::R8G8B8X8;
} else {
return HasAlpha() ? SurfaceFormat::R8G8B8A8 : SurfaceFormat::R8G8B8X8;
}
@ -500,6 +516,12 @@ MacIOSurface::CGLTexImageIOSurface2D(CGLContextObj ctx, size_t plane)
internalFormat = format = GL_LUMINANCE_ALPHA;
}
type = GL_UNSIGNED_BYTE;
} else if (pixelFormat == '2vuy') {
MOZ_ASSERT(plane == 0);
internalFormat = GL_RGB;
format = LOCAL_GL_YCBCR_422_APPLE;
type = GL_UNSIGNED_SHORT_8_8_APPLE;
} else {
MOZ_ASSERT(plane == 0);

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

@ -116,6 +116,8 @@ public:
void DecrementUseCount();
bool HasAlpha() { return mHasAlpha; }
mozilla::gfx::SurfaceFormat GetFormat();
mozilla::gfx::SurfaceFormat GetReadFormat();
// We would like to forward declare NSOpenGLContext, but it is an @interface
// and this file is also used from c++, so we use a void *.
CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, size_t plane = 0);

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

@ -54,6 +54,7 @@ enum class SurfaceFormat : int8_t {
// These ones are their own special cases.
YUV,
NV12,
YUV422,
// This represents the unknown format.
UNKNOWN,
@ -80,6 +81,7 @@ inline bool IsOpaque(SurfaceFormat aFormat)
case SurfaceFormat::R5G6B5_UINT16:
case SurfaceFormat::YUV:
case SurfaceFormat::NV12:
case SurfaceFormat::YUV422:
return true;
default:
return false;

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

@ -300,6 +300,7 @@ AppendToString(std::stringstream& aStream, mozilla::gfx::SurfaceFormat format,
case SurfaceFormat::A8: aStream << "SurfaceFormat::A8"; break;
case SurfaceFormat::YUV: aStream << "SurfaceFormat::YUV"; break;
case SurfaceFormat::NV12: aStream << "SurfaceFormat::NV12"; break;
case SurfaceFormat::YUV422: aStream << "SurfaceFormat::YUV422"; break;
case SurfaceFormat::UNKNOWN: aStream << "SurfaceFormat::UNKNOWN"; break;
default:
NS_ERROR("unknown surface format");

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

@ -331,7 +331,7 @@ ImageHost::Composite(LayerComposite* aLayer,
bool isAlphaPremultiplied =
!(img->mFrontBuffer->GetFlags() & TextureFlags::NON_PREMULTIPLIED);
RefPtr<TexturedEffect> effect =
CreateTexturedEffect(img->mFrontBuffer->GetFormat(),
CreateTexturedEffect(img->mFrontBuffer->GetReadFormat(),
img->mTextureSource.get(), aFilter, isAlphaPremultiplied,
GetRenderState());
if (!effect) {
@ -566,7 +566,7 @@ ImageHost::GenEffect(const gfx::Filter& aFilter)
isAlphaPremultiplied = false;
}
return CreateTexturedEffect(img->mFrontBuffer->GetFormat(),
return CreateTexturedEffect(img->mFrontBuffer->GetReadFormat(),
img->mTextureSource,
aFilter,
isAlphaPremultiplied,

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

@ -363,6 +363,11 @@ public:
* format and produce 3 "alpha" textures sources.
*/
virtual gfx::SurfaceFormat GetFormat() const = 0;
/**
* Return the format used for reading the texture.
* Apple's YCBCR_422 is R8G8B8X8.
*/
virtual gfx::SurfaceFormat GetReadFormat() const { return GetFormat(); }
/**
* Called during the transaction. The TextureSource may or may not be composited.

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

@ -867,7 +867,8 @@ CompositorOGL::GetShaderConfigFor(Effect *aEffect,
MOZ_ASSERT_IF(source->GetTextureTarget() == LOCAL_GL_TEXTURE_RECTANGLE_ARB,
source->GetFormat() == gfx::SurfaceFormat::R8G8B8A8 ||
source->GetFormat() == gfx::SurfaceFormat::R8G8B8X8 ||
source->GetFormat() == gfx::SurfaceFormat::R5G6B5_UINT16);
source->GetFormat() == gfx::SurfaceFormat::R5G6B5_UINT16 ||
source->GetFormat() == gfx::SurfaceFormat::YUV422 );
config = ShaderConfigFromTargetAndFormat(source->GetTextureTarget(),
source->GetFormat());
if (!texturedEffect->mPremultiplied) {

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

@ -80,6 +80,11 @@ MacIOSurfaceTextureHostOGL::GetFormat() const {
return mSurface->GetFormat();
}
gfx::SurfaceFormat
MacIOSurfaceTextureHostOGL::GetReadFormat() const {
return mSurface->GetReadFormat();
}
gfx::IntSize
MacIOSurfaceTextureHostOGL::GetSize() const {
if (!mSurface) {

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

@ -76,6 +76,7 @@ public:
virtual bool Lock() override;
virtual gfx::SurfaceFormat GetFormat() const override;
virtual gfx::SurfaceFormat GetReadFormat() const override;
virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override
{