Index: src/gpu/effects/GrYUVtoRGBEffect.cpp |
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp |
index 41d75c30ef8f9e6d00ca79b5cda1e1a607195cc0..002b0b4c7656440848291a23d1135084ba1df8ae 100644 |
--- a/src/gpu/effects/GrYUVtoRGBEffect.cpp |
+++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp |
@@ -17,8 +17,9 @@ namespace { |
class YUVtoRGBEffect : public GrEffect { |
public: |
- static GrEffect* Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture) { |
- return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture)); |
+ static GrEffect* Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture, |
+ GrYUVtoRGBEffect::YUVColorSpace colorSpace) { |
+ return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, colorSpace)); |
} |
static const char* Name() { return "YUV to RGB"; } |
@@ -34,10 +35,17 @@ public: |
*validFlags = kA_GrColorComponentFlag; |
} |
+ GrYUVtoRGBEffect::YUVColorSpace getYUVColorSpace() const { |
+ return fColorSpace; |
+ } |
+ |
class GLEffect : public GrGLEffect { |
public: |
- // this class always generates the same code. |
- static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*) {} |
+ static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
+ GrEffectKeyBuilder* builder) { |
+ const YUVtoRGBEffect& yuvEffect = drawEffect.castEffect<YUVtoRGBEffect>(); |
+ builder->add32(yuvEffect.getYUVColorSpace()); |
+ } |
GLEffect(const GrBackendEffectFactory& factory, |
const GrDrawEffect&) |
@@ -45,7 +53,7 @@ public: |
} |
virtual void emitCode(GrGLProgramBuilder* builder, |
- const GrDrawEffect&, |
+ const GrDrawEffect& drawEffect, |
const GrEffectKey&, |
const char* outputColor, |
const char* inputColor, |
@@ -53,11 +61,26 @@ public: |
const TextureSamplerArray& samplers) SK_OVERRIDE { |
GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
const char* yuvMatrix = "yuvMatrix"; |
- fsBuilder->codeAppendf("\tconst mat4 %s = mat4(1.0, 0.0, 1.402, -0.701,\n\t\t\t" |
- "1.0, -0.344, -0.714, 0.529,\n\t\t\t" |
- "1.0, 1.772, 0.0, -0.886,\n\t\t\t" |
- "0.0, 0.0, 0.0, 1.0);\n", |
- yuvMatrix); |
+ const YUVtoRGBEffect& yuvEffect = drawEffect.castEffect<YUVtoRGBEffect>(); |
+ |
+ switch (yuvEffect.getYUVColorSpace()) { |
+ case GrYUVtoRGBEffect::kJPEG: |
+ fsBuilder->codeAppendf("\tconst mat4 %s = " |
+ "mat4(1.0, 0.0, 1.402, -0.701,\n\t\t\t" |
Stephen White
2014/08/28 15:11:06
Not new to this patch, but I wonder if it's worth
rileya (GONE FROM CHROMIUM)
2014/08/28 21:05:57
I'll need to refresh on how exactly uniforms get p
|
+ "1.0, -0.34414, -0.71414, 0.529,\n\t\t\t" |
rileya (GONE FROM CHROMIUM)
2014/08/28 01:03:27
I added a couple decimal points to the original JP
|
+ "1.0, 1.772, 0.0, -0.886,\n\t\t\t" |
+ "0.0, 0.0, 0.0, 1.0);\n", |
+ yuvMatrix); |
+ break; |
+ case GrYUVtoRGBEffect::kRec601: |
+ fsBuilder->codeAppendf("\tconst mat4 %s = " |
+ "mat4(1.164, 0.0, 1.596, -1.08175,\n\t\t\t" |
+ "1.164, -0.391, -0.813, 0.529,\n\t\t\t" |
+ "1.164, 2.018, 0.0, -1.08175,\n\t\t\t" |
+ "0.0, 0.0, 0.0, 1.0);\n", |
+ yuvMatrix); |
+ break; |
+ } |
fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", outputColor); |
fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type()); |
fsBuilder->codeAppend(".r,\n\t\t"); |
@@ -71,11 +94,13 @@ public: |
}; |
private: |
- YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture) |
+ YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture, |
+ GrYUVtoRGBEffect::YUVColorSpace colorSpace) |
: fCoordTransform(kLocal_GrCoordSet, MakeDivByTextureWHMatrix(yTexture), yTexture) |
, fYAccess(yTexture) |
, fUAccess(uTexture) |
- , fVAccess(vTexture) { |
+ , fVAccess(vTexture) |
+ , fColorSpace(colorSpace) { |
this->addCoordTransform(&fCoordTransform); |
this->addTextureAccess(&fYAccess); |
this->addTextureAccess(&fUAccess); |
@@ -94,6 +119,7 @@ private: |
GrTextureAccess fYAccess; |
GrTextureAccess fUAccess; |
GrTextureAccess fVAccess; |
+ GrYUVtoRGBEffect::YUVColorSpace fColorSpace; |
typedef GrEffect INHERITED; |
}; |
@@ -102,6 +128,7 @@ private: |
////////////////////////////////////////////////////////////////////////////// |
-GrEffect* GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture) { |
- return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture); |
+GrEffect* GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture, |
+ GrYUVtoRGBEffect::YUVColorSpace colorSpace) { |
+ return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, colorSpace); |
} |