Bug 1210357 - Handle VP9 colorspace BT.709 r=mattwoodrow,bas.schouten

This commit is contained in:
Sotaro Ikeda
2016-10-18 10:09:00 -07:00
parent 46805b751d
commit 1e67b0bbc2
23 changed files with 9930 additions and 9810 deletions

View File

@@ -1319,6 +1319,7 @@ CompositorOGL::DrawGeometry(const Geometry& aGeometry,
program->SetYCbCrTextureUnits(Y, Cb, Cr);
program->SetTextureTransform(Matrix4x4());
program->SetYUVColorSpace(effectYCbCr->mYUVColorSpace);
if (maskType != MaskType::MaskNone) {
BindMaskForProgram(program, sourceMask, LOCAL_GL_TEXTURE3, maskQuadTransform);

View File

@@ -7,6 +7,7 @@
#include <sstream> // for ostringstream
#include "gfxEnv.h"
#include "gfxRect.h" // for gfxRect
#include "gfxUtils.h"
#include "mozilla/DebugOnly.h" // for DebugOnly
#include "mozilla/layers/Compositor.h" // for BlendOpIsMixBlendMode
#include "nsAString.h"
@@ -58,6 +59,7 @@ AddUniforms(ProgramProfileOGL& aProfile)
"uSSEdges",
"uViewportSize",
"uVisibleCenter",
"uYuvColorMatrix",
nullptr
};
@@ -375,6 +377,7 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
fs << "uniform sampler2D uYTexture;" << endl;
fs << "uniform sampler2D uCbTexture;" << endl;
fs << "uniform sampler2D uCrTexture;" << endl;
fs << "uniform mat3 uYuvColorMatrix;" << endl;
} else if (aConfig.mFeatures & ENABLE_TEXTURE_NV12) {
fs << "uniform " << sampler2D << " uYTexture;" << endl;
fs << "uniform " << sampler2D << " uCbTexture;" << endl;
@@ -433,22 +436,11 @@ ProgramProfileOGL::GetProfileFor(ShaderConfigOGL aConfig)
}
}
/* From Rec601:
[R] [1.1643835616438356, 0.0, 1.5960267857142858] [ Y - 16]
[G] = [1.1643835616438358, -0.3917622900949137, -0.8129676472377708] x [Cb - 128]
[B] [1.1643835616438356, 2.017232142857143, 8.862867620416422e-17] [Cr - 128]
For [0,1] instead of [0,255], and to 5 places:
[R] [1.16438, 0.00000, 1.59603] [ Y - 0.06275]
[G] = [1.16438, -0.39176, -0.81297] x [Cb - 0.50196]
[B] [1.16438, 2.01723, 0.00000] [Cr - 0.50196]
*/
fs << " y = (y - 0.06275) * 1.16438;" << endl;
fs << " y = y - 0.06275;" << endl;
fs << " cb = cb - 0.50196;" << endl;
fs << " cr = cr - 0.50196;" << endl;
fs << " color.r = y + 1.59603*cr;" << endl;
fs << " color.g = y - 0.39176*cb - 0.81297*cr;" << endl;
fs << " color.b = y + 2.01723*cb;" << endl;
fs << " vec3 yuv = vec3(y, cb, cr);" << endl;
fs << " color.rgb = uYuvColorMatrix * yuv;" << endl;
fs << " color.a = 1.0;" << endl;
} else if (aConfig.mFeatures & ENABLE_TEXTURE_COMPONENT_ALPHA) {
if (aConfig.mFeatures & ENABLE_TEXTURE_RECT) {
@@ -971,5 +963,12 @@ ShaderProgramOGL::SetBlurRadius(float aRX, float aRY)
SetArrayUniform(KnownUniform::BlurGaussianKernel, GAUSSIAN_KERNEL_HALF_WIDTH, gaussianKernel);
}
void
ShaderProgramOGL::SetYUVColorSpace(YUVColorSpace aYUVColorSpace)
{
float* yuvToRgb = gfxUtils::Get3x3YuvColorMatrix(aYUVColorSpace);
SetMatrix3fvUniform(KnownUniform::YuvColorMatrix, yuvToRgb);
}
} // namespace layers
} // namespace mozilla

View File

@@ -8,6 +8,7 @@
#include "GLContext.h" // for fast inlines of glUniform*
#include "gfxTypes.h"
#include "ImageTypes.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Pair.h" // for Pair
#include "mozilla/RefPtr.h" // for RefPtr
@@ -81,6 +82,7 @@ public:
SSEdges,
ViewportSize,
VisibleCenter,
YuvColorMatrix,
KnownUniformCount
};
@@ -146,6 +148,7 @@ public:
case 2:
case 3:
case 4:
case 9:
case 16:
if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
memcpy(mValue.f16v, fp, sizeof(float) * cnt);
@@ -154,7 +157,7 @@ public:
return false;
}
NS_NOTREACHED("cnt must be 1 2 3 4 or 16");
NS_NOTREACHED("cnt must be 1 2 3 4 9 or 16");
return false;
}
@@ -476,6 +479,8 @@ public:
SetUniform(KnownUniform::CbCrTexCoordMultiplier, 2, f);
}
void SetYUVColorSpace(YUVColorSpace aYUVColorSpace);
// Set whether we want the component alpha shader to return the color
// vector (pass 1, false) or the alpha vector (pass2, true). With support
// for multiple render targets we wouldn't need two passes here.
@@ -595,6 +600,16 @@ protected:
}
}
void SetMatrix3fvUniform(KnownUniform::KnownUniformName aKnownUniform, const float *aFloatValues) {
ASSERT_THIS_PROGRAM;
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
if (ku.UpdateUniform(9, aFloatValues)) {
mGL->fUniformMatrix3fv(ku.mLocation, 1, false, ku.mValue.f16v);
}
}
void SetMatrixUniform(KnownUniform::KnownUniformName aKnownUniform, const gfx::Matrix4x4& aMatrix) {
SetMatrixUniform(aKnownUniform, &aMatrix._11);
}