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

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

Issue 1428543003: Create GLSL base class for ProgramDataManager (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add space Created 5 years, 1 month 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
« no previous file with comments | « src/gpu/effects/GrTextureDomain.cpp ('k') | src/gpu/gl/GrGLFragmentProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "GrYUVtoRGBEffect.h" 8 #include "GrYUVtoRGBEffect.h"
9 9
10 #include "GrCoordTransform.h" 10 #include "GrCoordTransform.h"
11 #include "GrInvariantOutput.h" 11 #include "GrInvariantOutput.h"
12 #include "GrProcessor.h" 12 #include "GrProcessor.h"
13 #include "gl/GrGLFragmentProcessor.h" 13 #include "gl/GrGLFragmentProcessor.h"
14 #include "gl/builders/GrGLProgramBuilder.h" 14 #include "gl/builders/GrGLProgramBuilder.h"
15 #include "glsl/GrGLSLProgramDataManager.h"
15 16
16 namespace { 17 namespace {
17 18
18 class YUVtoRGBEffect : public GrFragmentProcessor { 19 class YUVtoRGBEffect : public GrFragmentProcessor {
19 public: 20 public:
20 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, 21 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture,
21 GrTexture* vTexture, const SkISize sizes[ 3], 22 GrTexture* vTexture, const SkISize sizes[ 3],
22 SkYUVColorSpace colorSpace) { 23 SkYUVColorSpace colorSpace) {
23 SkScalar w[3], h[3]; 24 SkScalar w[3], h[3];
24 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width() ); 25 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width() );
(...skipping 20 matching lines...) Expand all
45 } 46 }
46 47
47 const char* name() const override { return "YUV to RGB"; } 48 const char* name() const override { return "YUV to RGB"; }
48 49
49 SkYUVColorSpace getColorSpace() const { 50 SkYUVColorSpace getColorSpace() const {
50 return fColorSpace; 51 return fColorSpace;
51 } 52 }
52 53
53 class GLProcessor : public GrGLFragmentProcessor { 54 class GLProcessor : public GrGLFragmentProcessor {
54 public: 55 public:
55 static const GrGLfloat kJPEGConversionMatrix[16]; 56 static const float kJPEGConversionMatrix[16];
56 static const GrGLfloat kRec601ConversionMatrix[16]; 57 static const float kRec601ConversionMatrix[16];
57 static const GrGLfloat kRec709ConversionMatrix[16]; 58 static const float kRec709ConversionMatrix[16];
58 59
59 // this class always generates the same code. 60 // this class always generates the same code.
60 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder*) {} 61 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder*) {}
61 62
62 GLProcessor(const GrProcessor&) {} 63 GLProcessor(const GrProcessor&) {}
63 64
64 virtual void emitCode(EmitArgs& args) override { 65 virtual void emitCode(EmitArgs& args) override {
65 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBui lder(); 66 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBui lder();
66 67
67 const char* yuvMatrix = nullptr; 68 const char* yuvMatrix = nullptr;
68 fMatrixUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment _Visibility, 69 fMatrixUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment _Visibility,
69 kMat44f_GrSLType, kDefault_GrSLPrec ision, 70 kMat44f_GrSLType, kDefault_GrSLPrec ision,
70 "YUVMatrix", &yuvMatrix); 71 "YUVMatrix", &yuvMatrix);
71 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor); 72 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor);
72 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_ str(), 73 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_ str(),
73 args.fCoords[0].getType()); 74 args.fCoords[0].getType());
74 fsBuilder->codeAppend(".r,\n\t\t"); 75 fsBuilder->codeAppend(".r,\n\t\t");
75 fsBuilder->appendTextureLookup(args.fSamplers[1], args.fCoords[1].c_ str(), 76 fsBuilder->appendTextureLookup(args.fSamplers[1], args.fCoords[1].c_ str(),
76 args.fCoords[1].getType()); 77 args.fCoords[1].getType());
77 fsBuilder->codeAppend(".r,\n\t\t"); 78 fsBuilder->codeAppend(".r,\n\t\t");
78 fsBuilder->appendTextureLookup(args.fSamplers[2], args.fCoords[2].c_ str(), 79 fsBuilder->appendTextureLookup(args.fSamplers[2], args.fCoords[2].c_ str(),
79 args.fCoords[2].getType()); 80 args.fCoords[2].getType());
80 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix); 81 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix);
81 } 82 }
82 83
83 protected: 84 protected:
84 virtual void onSetData(const GrGLProgramDataManager& pdman, 85 virtual void onSetData(const GrGLSLProgramDataManager& pdman,
85 const GrProcessor& processor) override { 86 const GrProcessor& processor) override {
86 const YUVtoRGBEffect& yuvEffect = processor.cast<YUVtoRGBEffect>(); 87 const YUVtoRGBEffect& yuvEffect = processor.cast<YUVtoRGBEffect>();
87 switch (yuvEffect.getColorSpace()) { 88 switch (yuvEffect.getColorSpace()) {
88 case kJPEG_SkYUVColorSpace: 89 case kJPEG_SkYUVColorSpace:
89 pdman.setMatrix4f(fMatrixUni, kJPEGConversionMatrix); 90 pdman.setMatrix4f(fMatrixUni, kJPEGConversionMatrix);
90 break; 91 break;
91 case kRec601_SkYUVColorSpace: 92 case kRec601_SkYUVColorSpace:
92 pdman.setMatrix4f(fMatrixUni, kRec601ConversionMatrix); 93 pdman.setMatrix4f(fMatrixUni, kRec601ConversionMatrix);
93 break; 94 break;
94 case kRec709_SkYUVColorSpace: 95 case kRec709_SkYUVColorSpace:
95 pdman.setMatrix4f(fMatrixUni, kRec709ConversionMatrix); 96 pdman.setMatrix4f(fMatrixUni, kRec709ConversionMatrix);
96 break; 97 break;
97 } 98 }
98 } 99 }
99 100
100 private: 101 private:
101 GrGLProgramDataManager::UniformHandle fMatrixUni; 102 GrGLSLProgramDataManager::UniformHandle fMatrixUni;
102 103
103 typedef GrGLFragmentProcessor INHERITED; 104 typedef GrGLFragmentProcessor INHERITED;
104 }; 105 };
105 106
106 private: 107 private:
107 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture , 108 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture ,
108 const SkMatrix yuvMatrix[3], GrTextureParams::FilterMode uvFi lterMode, 109 const SkMatrix yuvMatrix[3], GrTextureParams::FilterMode uvFi lterMode,
109 SkYUVColorSpace colorSpace) 110 SkYUVColorSpace colorSpace)
110 : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kN one_FilterMode) 111 : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kN one_FilterMode)
111 , fYAccess(yTexture) 112 , fYAccess(yTexture)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 GrTextureAccess fYAccess; 146 GrTextureAccess fYAccess;
146 GrCoordTransform fUTransform; 147 GrCoordTransform fUTransform;
147 GrTextureAccess fUAccess; 148 GrTextureAccess fUAccess;
148 GrCoordTransform fVTransform; 149 GrCoordTransform fVTransform;
149 GrTextureAccess fVAccess; 150 GrTextureAccess fVAccess;
150 SkYUVColorSpace fColorSpace; 151 SkYUVColorSpace fColorSpace;
151 152
152 typedef GrFragmentProcessor INHERITED; 153 typedef GrFragmentProcessor INHERITED;
153 }; 154 };
154 155
155 const GrGLfloat YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = { 156 const float YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = {
156 1.0f, 0.0f, 1.402f, -0.701f, 157 1.0f, 0.0f, 1.402f, -0.701f,
157 1.0f, -0.34414f, -0.71414f, 0.529f, 158 1.0f, -0.34414f, -0.71414f, 0.529f,
158 1.0f, 1.772f, 0.0f, -0.886f, 159 1.0f, 1.772f, 0.0f, -0.886f,
159 0.0f, 0.0f, 0.0f, 1.0}; 160 0.0f, 0.0f, 0.0f, 1.0};
160 const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = { 161 const float YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = {
161 1.164f, 0.0f, 1.596f, -0.87075f, 162 1.164f, 0.0f, 1.596f, -0.87075f,
162 1.164f, -0.391f, -0.813f, 0.52925f, 163 1.164f, -0.391f, -0.813f, 0.52925f,
163 1.164f, 2.018f, 0.0f, -1.08175f, 164 1.164f, 2.018f, 0.0f, -1.08175f,
164 0.0f, 0.0f, 0.0f, 1.0}; 165 0.0f, 0.0f, 0.0f, 1.0};
165 const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec709ConversionMatrix[16] = { 166 const float YUVtoRGBEffect::GLProcessor::kRec709ConversionMatrix[16] = {
166 1.164f, 0.0f, 1.793f, -0.96925f, 167 1.164f, 0.0f, 1.793f, -0.96925f,
167 1.164f, -0.213f, -0.533f, 0.30025f, 168 1.164f, -0.213f, -0.533f, 0.30025f,
168 1.164f, 2.112f, 0.0f, -1.12875f, 169 1.164f, 2.112f, 0.0f, -1.12875f,
169 0.0f, 0.0f, 0.0f, 1.0f}; 170 0.0f, 0.0f, 0.0f, 1.0f};
170 } 171 }
171 172
172 ////////////////////////////////////////////////////////////////////////////// 173 //////////////////////////////////////////////////////////////////////////////
173 174
174 GrFragmentProcessor* 175 GrFragmentProcessor*
175 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT exture, 176 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT exture,
176 const SkISize sizes[3], SkYUVColorSpace colorSpace) { 177 const SkISize sizes[3], SkYUVColorSpace colorSpace) {
177 SkASSERT(yTexture && uTexture && vTexture && sizes); 178 SkASSERT(yTexture && uTexture && vTexture && sizes);
178 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac e); 179 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac e);
179 } 180 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureDomain.cpp ('k') | src/gpu/gl/GrGLFragmentProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698