Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: src/gpu/effects/GrYUVtoRGBEffect.cpp

Issue 516463005: Add support for the Rec601 YUV color space to GrYUVtoRGBEffect. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove misleading comment Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrYUVtoRGBEffect.h" 9 #include "GrYUVtoRGBEffect.h"
10 10
11 #include "GrCoordTransform.h" 11 #include "GrCoordTransform.h"
12 #include "GrEffect.h" 12 #include "GrEffect.h"
13 #include "gl/GrGLEffect.h" 13 #include "gl/GrGLEffect.h"
14 #include "GrTBackendEffectFactory.h" 14 #include "GrTBackendEffectFactory.h"
15 15
16 namespace { 16 namespace {
17 17
18 class YUVtoRGBEffect : public GrEffect { 18 class YUVtoRGBEffect : public GrEffect {
19 public: 19 public:
20 static GrEffect* Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture) { 20 static GrEffect* Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture,
21 return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture)); 21 GrYUVtoRGBEffect::YUVColorSpace colorSpace) {
22 return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, colorSp ace));
22 } 23 }
23 24
24 static const char* Name() { return "YUV to RGB"; } 25 static const char* Name() { return "YUV to RGB"; }
25 26
26 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 27 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
27 return GrTBackendEffectFactory<YUVtoRGBEffect>::getInstance(); 28 return GrTBackendEffectFactory<YUVtoRGBEffect>::getInstance();
28 } 29 }
29 30
30 virtual void getConstantColorComponents(GrColor* color, 31 virtual void getConstantColorComponents(GrColor* color,
31 uint32_t* validFlags) const SK_OVERR IDE { 32 uint32_t* validFlags) const SK_OVERR IDE {
32 // YUV is opaque 33 // YUV is opaque
33 *color = 0xFF; 34 *color = 0xFF;
34 *validFlags = kA_GrColorComponentFlag; 35 *validFlags = kA_GrColorComponentFlag;
35 } 36 }
36 37
38 GrYUVtoRGBEffect::YUVColorSpace getYUVColorSpace() const {
39 return fColorSpace;
40 }
41
37 class GLEffect : public GrGLEffect { 42 class GLEffect : public GrGLEffect {
38 public: 43 public:
39 // this class always generates the same code. 44 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&,
40 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil der*) {} 45 GrEffectKeyBuilder* builder) {
46 const YUVtoRGBEffect& yuvEffect = drawEffect.castEffect<YUVtoRGBEffe ct>();
47 builder->add32(yuvEffect.getYUVColorSpace());
48 }
41 49
42 GLEffect(const GrBackendEffectFactory& factory, 50 GLEffect(const GrBackendEffectFactory& factory,
43 const GrDrawEffect&) 51 const GrDrawEffect&)
44 : INHERITED(factory) { 52 : INHERITED(factory) {
45 } 53 }
46 54
47 virtual void emitCode(GrGLProgramBuilder* builder, 55 virtual void emitCode(GrGLProgramBuilder* builder,
48 const GrDrawEffect&, 56 const GrDrawEffect& drawEffect,
49 const GrEffectKey&, 57 const GrEffectKey&,
50 const char* outputColor, 58 const char* outputColor,
51 const char* inputColor, 59 const char* inputColor,
52 const TransformedCoordsArray& coords, 60 const TransformedCoordsArray& coords,
53 const TextureSamplerArray& samplers) SK_OVERRIDE { 61 const TextureSamplerArray& samplers) SK_OVERRIDE {
54 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui lder(); 62 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui lder();
55 const char* yuvMatrix = "yuvMatrix"; 63 const char* yuvMatrix = "yuvMatrix";
56 fsBuilder->codeAppendf("\tconst mat4 %s = mat4(1.0, 0.0, 1.402, -0.701,\n\t\t\t" 64 const YUVtoRGBEffect& yuvEffect = drawEffect.castEffect<YUVtoRGBEffe ct>();
57 "1.0, -0.344, -0.714, 0.529,\n\t\t\t" 65
58 "1.0, 1.772, 0.0, -0.886,\n\t\t\t" 66 switch (yuvEffect.getYUVColorSpace()) {
59 "0.0, 0.0, 0.0, 1.0);\n", 67 case GrYUVtoRGBEffect::kJPEG:
60 yuvMatrix); 68 fsBuilder->codeAppendf("\tconst mat4 %s = "
69 "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
70 "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
71 "1.0, 1.772, 0.0, -0.886 ,\n\t\t\t"
72 "0.0, 0.0, 0.0, 1.0); \n",
73 yuvMatrix);
74 break;
75 case GrYUVtoRGBEffect::kRec601:
76 fsBuilder->codeAppendf("\tconst mat4 %s = "
77 "mat4(1.164, 0.0, 1.596, -1.08175 ,\n\t\t\t"
78 "1.164, -0.391, -0.813, 0.529,\ n\t\t\t"
79 "1.164, 2.018, 0.0, -1.08175 ,\n\t\t\t"
80 "0.0, 0.0, 0.0, 1.0);\n ",
81 yuvMatrix);
82 break;
83 }
61 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", outputColor); 84 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", outputColor);
62 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coord s[0].type()); 85 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coord s[0].type());
63 fsBuilder->codeAppend(".r,\n\t\t"); 86 fsBuilder->codeAppend(".r,\n\t\t");
64 fsBuilder->appendTextureLookup(samplers[1], coords[0].c_str(), coord s[0].type()); 87 fsBuilder->appendTextureLookup(samplers[1], coords[0].c_str(), coord s[0].type());
65 fsBuilder->codeAppend(".r,\n\t\t"); 88 fsBuilder->codeAppend(".r,\n\t\t");
66 fsBuilder->appendTextureLookup(samplers[2], coords[0].c_str(), coord s[0].type()); 89 fsBuilder->appendTextureLookup(samplers[2], coords[0].c_str(), coord s[0].type());
67 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix); 90 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix);
68 } 91 }
69 92
70 typedef GrGLEffect INHERITED; 93 typedef GrGLEffect INHERITED;
71 }; 94 };
72 95
73 private: 96 private:
74 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture ) 97 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture ,
98 GrYUVtoRGBEffect::YUVColorSpace colorSpace)
75 : fCoordTransform(kLocal_GrCoordSet, MakeDivByTextureWHMatrix(yTexture), yTe xture) 99 : fCoordTransform(kLocal_GrCoordSet, MakeDivByTextureWHMatrix(yTexture), yTe xture)
76 , fYAccess(yTexture) 100 , fYAccess(yTexture)
77 , fUAccess(uTexture) 101 , fUAccess(uTexture)
78 , fVAccess(vTexture) { 102 , fVAccess(vTexture)
103 , fColorSpace(colorSpace) {
79 this->addCoordTransform(&fCoordTransform); 104 this->addCoordTransform(&fCoordTransform);
80 this->addTextureAccess(&fYAccess); 105 this->addTextureAccess(&fYAccess);
81 this->addTextureAccess(&fUAccess); 106 this->addTextureAccess(&fUAccess);
82 this->addTextureAccess(&fVAccess); 107 this->addTextureAccess(&fVAccess);
83 this->setWillNotUseInputColor(); 108 this->setWillNotUseInputColor();
84 } 109 }
85 110
86 virtual bool onIsEqual(const GrEffect& sBase) const { 111 virtual bool onIsEqual(const GrEffect& sBase) const {
87 const YUVtoRGBEffect& s = CastEffect<YUVtoRGBEffect>(sBase); 112 const YUVtoRGBEffect& s = CastEffect<YUVtoRGBEffect>(sBase);
88 return fYAccess.getTexture() == s.fYAccess.getTexture() && 113 return fYAccess.getTexture() == s.fYAccess.getTexture() &&
89 fUAccess.getTexture() == s.fUAccess.getTexture() && 114 fUAccess.getTexture() == s.fUAccess.getTexture() &&
90 fVAccess.getTexture() == s.fVAccess.getTexture(); 115 fVAccess.getTexture() == s.fVAccess.getTexture();
91 } 116 }
92 117
93 GrCoordTransform fCoordTransform; 118 GrCoordTransform fCoordTransform;
94 GrTextureAccess fYAccess; 119 GrTextureAccess fYAccess;
95 GrTextureAccess fUAccess; 120 GrTextureAccess fUAccess;
96 GrTextureAccess fVAccess; 121 GrTextureAccess fVAccess;
122 GrYUVtoRGBEffect::YUVColorSpace fColorSpace;
97 123
98 typedef GrEffect INHERITED; 124 typedef GrEffect INHERITED;
99 }; 125 };
100 126
101 } 127 }
102 128
103 ////////////////////////////////////////////////////////////////////////////// 129 //////////////////////////////////////////////////////////////////////////////
104 130
105 GrEffect* GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrT exture* vTexture) { 131 GrEffect* GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrT exture* vTexture,
106 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture); 132 GrYUVtoRGBEffect::YUVColorSpace colorSpace) {
133 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, colorSpace);
107 } 134 }
OLDNEW
« src/gpu/effects/GrYUVtoRGBEffect.h ('K') | « src/gpu/effects/GrYUVtoRGBEffect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698