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" |
| 11 #include "GrFragmentProcessor.h" |
11 #include "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
12 #include "GrProcessor.h" | 13 #include "GrProcessor.h" |
13 #include "glsl/GrGLSLFragmentProcessor.h" | 14 #include "glsl/GrGLSLFragmentProcessor.h" |
14 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
15 #include "glsl/GrGLSLProgramBuilder.h" | |
16 #include "glsl/GrGLSLProgramDataManager.h" | 16 #include "glsl/GrGLSLProgramDataManager.h" |
| 17 #include "glsl/GrGLSLUniformHandler.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 class YUVtoRGBEffect : public GrFragmentProcessor { | 21 class YUVtoRGBEffect : public GrFragmentProcessor { |
21 public: | 22 public: |
22 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, | 23 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, |
23 GrTexture* vTexture, const SkISize sizes[
3], | 24 GrTexture* vTexture, const SkISize sizes[
3], |
24 SkYUVColorSpace colorSpace) { | 25 SkYUVColorSpace colorSpace) { |
25 SkScalar w[3], h[3]; | 26 SkScalar w[3], h[3]; |
26 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); | 27 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width()
); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 61 |
61 // this class always generates the same code. | 62 // this class always generates the same code. |
62 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} | 63 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder*) {} |
63 | 64 |
64 GLSLProcessor(const GrProcessor&) {} | 65 GLSLProcessor(const GrProcessor&) {} |
65 | 66 |
66 virtual void emitCode(EmitArgs& args) override { | 67 virtual void emitCode(EmitArgs& args) override { |
67 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 68 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
68 | 69 |
69 const char* yuvMatrix = nullptr; | 70 const char* yuvMatrix = nullptr; |
70 fMatrixUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 71 fMatrixUni = args.fUniformHandler->addUniform( |
71 kMat44f_GrSLType, kDefault_Gr
SLPrecision, | 72 GrGLSLUniformHandler::k
Fragment_Visibility, |
72 "YUVMatrix", &yuvMatrix); | 73 kMat44f_GrSLType, kDefa
ult_GrSLPrecision, |
| 74 "YUVMatrix", &yuvMatrix
); |
73 fragBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor); | 75 fragBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor); |
74 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].
c_str(), | 76 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].
c_str(), |
75 args.fCoords[0].getType()); | 77 args.fCoords[0].getType()); |
76 fragBuilder->codeAppend(".r,\n\t\t"); | 78 fragBuilder->codeAppend(".r,\n\t\t"); |
77 fragBuilder->appendTextureLookup(args.fSamplers[1], args.fCoords[1].
c_str(), | 79 fragBuilder->appendTextureLookup(args.fSamplers[1], args.fCoords[1].
c_str(), |
78 args.fCoords[1].getType()); | 80 args.fCoords[1].getType()); |
79 fragBuilder->codeAppend(".r,\n\t\t"); | 81 fragBuilder->codeAppend(".r,\n\t\t"); |
80 fragBuilder->appendTextureLookup(args.fSamplers[2], args.fCoords[2].
c_str(), | 82 fragBuilder->appendTextureLookup(args.fSamplers[2], args.fCoords[2].
c_str(), |
81 args.fCoords[2].getType()); | 83 args.fCoords[2].getType()); |
82 fragBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix); | 84 fragBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 } | 176 } |
175 | 177 |
176 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
177 | 179 |
178 GrFragmentProcessor* | 180 GrFragmentProcessor* |
179 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, | 181 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT
exture, |
180 const SkISize sizes[3], SkYUVColorSpace colorSpace) { | 182 const SkISize sizes[3], SkYUVColorSpace colorSpace) { |
181 SkASSERT(yTexture && uTexture && vTexture && sizes); | 183 SkASSERT(yTexture && uTexture && vTexture && sizes); |
182 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); | 184 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac
e); |
183 } | 185 } |
OLD | NEW |