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 "GrYUVEffect.h" | 8 #include "GrYUVEffect.h" |
9 | 9 |
10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 const char* name() const override { return "YUV to RGB"; } | 92 const char* name() const override { return "YUV to RGB"; } |
93 | 93 |
94 SkYUVColorSpace getColorSpace() const { return fColorSpace; } | 94 SkYUVColorSpace getColorSpace() const { return fColorSpace; } |
95 | 95 |
96 class GLSLProcessor : public GrGLSLFragmentProcessor { | 96 class GLSLProcessor : public GrGLSLFragmentProcessor { |
97 public: | 97 public: |
98 // this class always generates the same code. | 98 // this class always generates the same code. |
99 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} | 99 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} |
100 | 100 |
101 GLSLProcessor(const GrProcessor&) {} | |
102 | |
103 void emitCode(EmitArgs& args) override { | 101 void emitCode(EmitArgs& args) override { |
104 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 102 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
105 | 103 |
106 const char* colorSpaceMatrix = nullptr; | 104 const char* colorSpaceMatrix = nullptr; |
107 fMatrixUni = args.fUniformHandler->addUniform( | 105 fMatrixUni = args.fUniformHandler->addUniform( |
108 GrGLSLUniformHandler::k
Fragment_Visibility, | 106 GrGLSLUniformHandler::k
Fragment_Visibility, |
109 kMat44f_GrSLType, kDefa
ult_GrSLPrecision, | 107 kMat44f_GrSLType, kDefa
ult_GrSLPrecision, |
110 "ColorSpaceMatrix", &co
lorSpaceMatrix); | 108 "ColorSpaceMatrix", &co
lorSpaceMatrix); |
111 fragBuilder->codeAppendf("%s = vec4(", args.fOutputColor); | 109 fragBuilder->codeAppendf("%s = vec4(", args.fOutputColor); |
112 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].
c_str(), | 110 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].
c_str(), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 this->initClassID<YUVtoRGBEffect>(); | 155 this->initClassID<YUVtoRGBEffect>(); |
158 this->addCoordTransform(&fYTransform); | 156 this->addCoordTransform(&fYTransform); |
159 this->addTextureAccess(&fYAccess); | 157 this->addTextureAccess(&fYAccess); |
160 this->addCoordTransform(&fUTransform); | 158 this->addCoordTransform(&fUTransform); |
161 this->addTextureAccess(&fUAccess); | 159 this->addTextureAccess(&fUAccess); |
162 this->addCoordTransform(&fVTransform); | 160 this->addCoordTransform(&fVTransform); |
163 this->addTextureAccess(&fVAccess); | 161 this->addTextureAccess(&fVAccess); |
164 } | 162 } |
165 | 163 |
166 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { | 164 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
167 return new GLSLProcessor(*this); | 165 return new GLSLProcessor; |
168 } | 166 } |
169 | 167 |
170 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { | 168 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { |
171 GLSLProcessor::GenKey(*this, caps, b); | 169 GLSLProcessor::GenKey(*this, caps, b); |
172 } | 170 } |
173 | 171 |
174 bool onIsEqual(const GrFragmentProcessor& sBase) const override { | 172 bool onIsEqual(const GrFragmentProcessor& sBase) const override { |
175 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); | 173 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); |
176 return fColorSpace == s.getColorSpace(); | 174 return fColorSpace == s.getColorSpace(); |
177 } | 175 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 216 } |
219 | 217 |
220 const char* name() const override { return "RGBToYUV"; } | 218 const char* name() const override { return "RGBToYUV"; } |
221 | 219 |
222 SkYUVColorSpace getColorSpace() const { return fColorSpace; } | 220 SkYUVColorSpace getColorSpace() const { return fColorSpace; } |
223 | 221 |
224 OutputChannels outputChannels() const { return fOutputChannels; } | 222 OutputChannels outputChannels() const { return fOutputChannels; } |
225 | 223 |
226 class GLSLProcessor : public GrGLSLFragmentProcessor { | 224 class GLSLProcessor : public GrGLSLFragmentProcessor { |
227 public: | 225 public: |
228 GLSLProcessor(const GrProcessor&) : fLastColorSpace(-1), fLastOutputChan
nels(-1) {} | 226 GLSLProcessor() : fLastColorSpace(-1), fLastOutputChannels(-1) {} |
229 | 227 |
230 void emitCode(EmitArgs& args) override { | 228 void emitCode(EmitArgs& args) override { |
231 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 229 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
232 OutputChannels oc = args.fFp.cast<RGBToYUVEffect>().outputChannels()
; | 230 OutputChannels oc = args.fFp.cast<RGBToYUVEffect>().outputChannels()
; |
233 | 231 |
234 SkString outputColor("rgbColor"); | 232 SkString outputColor("rgbColor"); |
235 this->emitChild(0, args.fInputColor, &outputColor, args); | 233 this->emitChild(0, args.fInputColor, &outputColor, args); |
236 | 234 |
237 const char* uniName; | 235 const char* uniName; |
238 switch (oc) { | 236 switch (oc) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 311 } |
314 GrGLSLProgramDataManager::UniformHandle fRGBToYUVUni; | 312 GrGLSLProgramDataManager::UniformHandle fRGBToYUVUni; |
315 int fLastColorSpace; | 313 int fLastColorSpace; |
316 int fLastOutputChannels; | 314 int fLastOutputChannels; |
317 | 315 |
318 typedef GrGLSLFragmentProcessor INHERITED; | 316 typedef GrGLSLFragmentProcessor INHERITED; |
319 }; | 317 }; |
320 | 318 |
321 private: | 319 private: |
322 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { | 320 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { |
323 return new GLSLProcessor(*this); | 321 return new GLSLProcessor; |
324 } | 322 } |
325 | 323 |
326 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { | 324 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override { |
327 // kY, kU, and kV all generate the same code, just upload different coef
ficients. | 325 // kY, kU, and kV all generate the same code, just upload different coef
ficients. |
328 if (kU_OutputChannels == fOutputChannels || kV_OutputChannels == fOutput
Channels) { | 326 if (kU_OutputChannels == fOutputChannels || kV_OutputChannels == fOutput
Channels) { |
329 b->add32(kY_OutputChannels); | 327 b->add32(kY_OutputChannels); |
330 } else { | 328 } else { |
331 b->add32(fOutputChannels); | 329 b->add32(fOutputChannels); |
332 } | 330 } |
333 } | 331 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 GrYUVEffect::CreateRGBToU(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { | 380 GrYUVEffect::CreateRGBToU(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { |
383 SkASSERT(rgbFP); | 381 SkASSERT(rgbFP); |
384 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kU_OutputChanne
ls); | 382 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kU_OutputChanne
ls); |
385 } | 383 } |
386 | 384 |
387 const GrFragmentProcessor* | 385 const GrFragmentProcessor* |
388 GrYUVEffect::CreateRGBToV(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { | 386 GrYUVEffect::CreateRGBToV(const GrFragmentProcessor* rgbFP, SkYUVColorSpace colo
rSpace) { |
389 SkASSERT(rgbFP); | 387 SkASSERT(rgbFP); |
390 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kV_OutputChanne
ls); | 388 return new RGBToYUVEffect(rgbFP, colorSpace, RGBToYUVEffect::kV_OutputChanne
ls); |
391 } | 389 } |
OLD | NEW |