OLD | NEW |
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 "GrYUVtoRGBEffect.h" | 8 #include "GrYUVtoRGBEffect.h" |
9 | 9 |
10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 return new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFil
terMode, | 45 return new YUVtoRGBEffect(yTexture, uTexture, vTexture, yuvMatrix, uvFil
terMode, |
46 colorSpace); | 46 colorSpace); |
47 } | 47 } |
48 | 48 |
49 const char* name() const override { return "YUV to RGB"; } | 49 const char* name() const override { return "YUV to RGB"; } |
50 | 50 |
51 SkYUVColorSpace getColorSpace() const { | 51 SkYUVColorSpace getColorSpace() const { |
52 return fColorSpace; | 52 return fColorSpace; |
53 } | 53 } |
54 | 54 |
55 class GLProcessor : public GrGLSLFragmentProcessor { | 55 class GLSLProcessor : public GrGLSLFragmentProcessor { |
56 public: | 56 public: |
57 static const float kJPEGConversionMatrix[16]; | 57 static const float kJPEGConversionMatrix[16]; |
58 static const float kRec601ConversionMatrix[16]; | 58 static const float kRec601ConversionMatrix[16]; |
59 static const float kRec709ConversionMatrix[16]; | 59 static const float kRec709ConversionMatrix[16]; |
60 | 60 |
61 // this class always generates the same code. | 61 // this class always generates the same code. |
62 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} | 62 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} |
63 | 63 |
64 GLProcessor(const GrProcessor&) {} | 64 GLSLProcessor(const GrProcessor&) {} |
65 | 65 |
66 virtual void emitCode(EmitArgs& args) override { | 66 virtual void emitCode(EmitArgs& args) override { |
67 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB
uilder(); | 67 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB
uilder(); |
68 | 68 |
69 const char* yuvMatrix = nullptr; | 69 const char* yuvMatrix = nullptr; |
70 fMatrixUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 70 fMatrixUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
71 kMat44f_GrSLType, kDefault_Gr
SLPrecision, | 71 kMat44f_GrSLType, kDefault_Gr
SLPrecision, |
72 "YUVMatrix", &yuvMatrix); | 72 "YUVMatrix", &yuvMatrix); |
73 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor); | 73 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor); |
74 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_
str(), | 74 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_
str(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 , fColorSpace(colorSpace) { | 118 , fColorSpace(colorSpace) { |
119 this->initClassID<YUVtoRGBEffect>(); | 119 this->initClassID<YUVtoRGBEffect>(); |
120 this->addCoordTransform(&fYTransform); | 120 this->addCoordTransform(&fYTransform); |
121 this->addTextureAccess(&fYAccess); | 121 this->addTextureAccess(&fYAccess); |
122 this->addCoordTransform(&fUTransform); | 122 this->addCoordTransform(&fUTransform); |
123 this->addTextureAccess(&fUAccess); | 123 this->addTextureAccess(&fUAccess); |
124 this->addCoordTransform(&fVTransform); | 124 this->addCoordTransform(&fVTransform); |
125 this->addTextureAccess(&fVAccess); | 125 this->addTextureAccess(&fVAccess); |
126 } | 126 } |
127 | 127 |
128 GrGLSLFragmentProcessor* onCreateGLInstance() const override { return new GL
Processor(*this); } | 128 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
| 129 return new GLSLProcessor(*this); |
| 130 } |
129 | 131 |
130 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 132 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
131 GrProcessorKeyBuilder* b) const override { | 133 GrProcessorKeyBuilder* b) const override
{ |
132 GLProcessor::GenKey(*this, caps, b); | 134 GLSLProcessor::GenKey(*this, caps, b); |
133 } | 135 } |
134 | 136 |
135 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 137 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
136 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); | 138 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); |
137 return fColorSpace == s.getColorSpace(); | 139 return fColorSpace == s.getColorSpace(); |
138 } | 140 } |
139 | 141 |
140 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 142 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
141 // YUV is opaque | 143 // YUV is opaque |
142 inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A, | 144 inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A, |
143 GrInvariantOutput::kWillNot_ReadInput); | 145 GrInvariantOutput::kWillNot_ReadInput); |
144 } | 146 } |
145 | 147 |
146 GrCoordTransform fYTransform; | 148 GrCoordTransform fYTransform; |
147 GrTextureAccess fYAccess; | 149 GrTextureAccess fYAccess; |
148 GrCoordTransform fUTransform; | 150 GrCoordTransform fUTransform; |
149 GrTextureAccess fUAccess; | 151 GrTextureAccess fUAccess; |
150 GrCoordTransform fVTransform; | 152 GrCoordTransform fVTransform; |
151 GrTextureAccess fVAccess; | 153 GrTextureAccess fVAccess; |
152 SkYUVColorSpace fColorSpace; | 154 SkYUVColorSpace fColorSpace; |
153 | 155 |
154 typedef GrFragmentProcessor INHERITED; | 156 typedef GrFragmentProcessor INHERITED; |
155 }; | 157 }; |
156 | 158 |
157 const float YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = { | 159 const float YUVtoRGBEffect::GLSLProcessor::kJPEGConversionMatrix[16] = { |
158 1.0f, 0.0f, 1.402f, -0.701f, | 160 1.0f, 0.0f, 1.402f, -0.701f, |
159 1.0f, -0.34414f, -0.71414f, 0.529f, | 161 1.0f, -0.34414f, -0.71414f, 0.529f, |
160 1.0f, 1.772f, 0.0f, -0.886f, | 162 1.0f, 1.772f, 0.0f, -0.886f, |
161 0.0f, 0.0f, 0.0f, 1.0}; | 163 0.0f, 0.0f, 0.0f, 1.0}; |
162 const float YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = { | 164 const float YUVtoRGBEffect::GLSLProcessor::kRec601ConversionMatrix[16] = { |
163 1.164f, 0.0f, 1.596f, -0.87075f, | 165 1.164f, 0.0f, 1.596f, -0.87075f, |
164 1.164f, -0.391f, -0.813f, 0.52925f, | 166 1.164f, -0.391f, -0.813f, 0.52925f, |
165 1.164f, 2.018f, 0.0f, -1.08175f, | 167 1.164f, 2.018f, 0.0f, -1.08175f, |
166 0.0f, 0.0f, 0.0f, 1.0}; | 168 0.0f, 0.0f, 0.0f, 1.0}; |
167 const float YUVtoRGBEffect::GLProcessor::kRec709ConversionMatrix[16] = { | 169 const float YUVtoRGBEffect::GLSLProcessor::kRec709ConversionMatrix[16] = { |
168 1.164f, 0.0f, 1.793f, -0.96925f, | 170 1.164f, 0.0f, 1.793f, -0.96925f, |
169 1.164f, -0.213f, -0.533f, 0.30025f, | 171 1.164f, -0.213f, -0.533f, 0.30025f, |
170 1.164f, 2.112f, 0.0f, -1.12875f, | 172 1.164f, 2.112f, 0.0f, -1.12875f, |
171 0.0f, 0.0f, 0.0f, 1.0f}; | 173 0.0f, 0.0f, 0.0f, 1.0f}; |
172 } | 174 } |
173 | 175 |
174 ////////////////////////////////////////////////////////////////////////////// | 176 ////////////////////////////////////////////////////////////////////////////// |
175 | 177 |
176 GrFragmentProcessor* | 178 GrFragmentProcessor* |
177 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, | 179 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, |
178 const SkISize sizes[3], SkYUVColorSpace colorSpace) { | 180 const SkISize sizes[3], SkYUVColorSpace colorSpace) { |
179 SkASSERT(yTexture && uTexture && vTexture && sizes); | 181 SkASSERT(yTexture && uTexture && vTexture && sizes); |
180 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); | 182 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); |
181 } | 183 } |
OLD | NEW |