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

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

Issue 977273003: Merged https://codereview.chromium.org/922273002/ to M41 (Closed) Base URL: https://skia.googlesource.com/skia.git@m41
Patch Set: Created 5 years, 9 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 "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/GrGLProcessor.h" 13 #include "gl/GrGLProcessor.h"
14 #include "gl/builders/GrGLProgramBuilder.h" 14 #include "gl/builders/GrGLProgramBuilder.h"
15 15
16 namespace { 16 namespace {
17 17
18 class YUVtoRGBEffect : public GrFragmentProcessor { 18 class YUVtoRGBEffect : public GrFragmentProcessor {
19 public: 19 public:
20 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, 20 static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture,
21 GrTexture* vTexture, SkYUVColorSpace colo rSpace) { 21 GrTexture* vTexture, SkISize sizes[3],
22 return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, colorSp ace)); 22 SkYUVColorSpace colorSpace) {
23 SkScalar w[3], h[3];
24 w[0] = SkIntToScalar(sizes[0].fWidth) / SkIntToScalar(yTexture->width() );
25 h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height( ));
26 w[1] = SkIntToScalar(sizes[1].fWidth) / SkIntToScalar(uTexture->width() );
27 h[1] = SkIntToScalar(sizes[1].fHeight) / SkIntToScalar(uTexture->height( ));
28 w[2] = SkIntToScalar(sizes[2].fWidth) / SkIntToScalar(vTexture->width() );
29 h[2] = SkIntToScalar(sizes[2].fHeight) / SkIntToScalar(vTexture->height( ));
30 SkMatrix yuvMatrix[3];
31 yuvMatrix[0] = GrCoordTransform::MakeDivByTextureWHMatrix(yTexture);
32 yuvMatrix[1] = yuvMatrix[0];
33 yuvMatrix[1].preScale(w[1] / w[0], h[1] / h[0]);
34 yuvMatrix[2] = yuvMatrix[0];
35 yuvMatrix[2].preScale(w[2] / w[0], h[2] / h[0]);
36 return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, yuvMatr ix, colorSpace));
23 } 37 }
24 38
25 virtual const char* name() const SK_OVERRIDE { return "YUV to RGB"; } 39 virtual const char* name() const SK_OVERRIDE { return "YUV to RGB"; }
26 40
27 SkYUVColorSpace getColorSpace() const { 41 SkYUVColorSpace getColorSpace() const {
28 return fColorSpace; 42 return fColorSpace;
29 } 43 }
30 44
31 class GLProcessor : public GrGLFragmentProcessor { 45 class GLProcessor : public GrGLFragmentProcessor {
32 public: 46 public:
(...skipping 13 matching lines...) Expand all
46 const TextureSamplerArray& samplers) SK_OVERRIDE { 60 const TextureSamplerArray& samplers) SK_OVERRIDE {
47 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder (); 61 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder ();
48 62
49 const char* yuvMatrix = NULL; 63 const char* yuvMatrix = NULL;
50 fMatrixUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility, 64 fMatrixUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
51 kMat44f_GrSLType, kDefault_GrSLPrec ision, 65 kMat44f_GrSLType, kDefault_GrSLPrec ision,
52 "YUVMatrix", &yuvMatrix); 66 "YUVMatrix", &yuvMatrix);
53 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", outputColor); 67 fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", outputColor);
54 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coord s[0].getType()); 68 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coord s[0].getType());
55 fsBuilder->codeAppend(".r,\n\t\t"); 69 fsBuilder->codeAppend(".r,\n\t\t");
56 fsBuilder->appendTextureLookup(samplers[1], coords[0].c_str(), coord s[0].getType()); 70 fsBuilder->appendTextureLookup(samplers[1], coords[1].c_str(), coord s[1].getType());
57 fsBuilder->codeAppend(".r,\n\t\t"); 71 fsBuilder->codeAppend(".r,\n\t\t");
58 fsBuilder->appendTextureLookup(samplers[2], coords[0].c_str(), coord s[0].getType()); 72 fsBuilder->appendTextureLookup(samplers[2], coords[2].c_str(), coord s[2].getType());
59 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix); 73 fsBuilder->codeAppendf(".r,\n\t\t1.0) * %s;\n", yuvMatrix);
60 } 74 }
61 75
62 virtual void setData(const GrGLProgramDataManager& pdman, 76 virtual void setData(const GrGLProgramDataManager& pdman,
63 const GrProcessor& processor) SK_OVERRIDE { 77 const GrProcessor& processor) SK_OVERRIDE {
64 const YUVtoRGBEffect& yuvEffect = processor.cast<YUVtoRGBEffect>(); 78 const YUVtoRGBEffect& yuvEffect = processor.cast<YUVtoRGBEffect>();
65 switch (yuvEffect.getColorSpace()) { 79 switch (yuvEffect.getColorSpace()) {
66 case kJPEG_SkYUVColorSpace: 80 case kJPEG_SkYUVColorSpace:
67 pdman.setMatrix4f(fMatrixUni, kJPEGConversionMatrix); 81 pdman.setMatrix4f(fMatrixUni, kJPEGConversionMatrix);
68 break; 82 break;
(...skipping 13 matching lines...) Expand all
82 GrProcessorKeyBuilder* b) const SK_OVERRIDE { 96 GrProcessorKeyBuilder* b) const SK_OVERRIDE {
83 GLProcessor::GenKey(*this, caps, b); 97 GLProcessor::GenKey(*this, caps, b);
84 } 98 }
85 99
86 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { 100 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE {
87 return SkNEW_ARGS(GLProcessor, (*this)); 101 return SkNEW_ARGS(GLProcessor, (*this));
88 } 102 }
89 103
90 private: 104 private:
91 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture , 105 YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture ,
92 SkYUVColorSpace colorSpace) 106 SkMatrix yuvMatrix[3], SkYUVColorSpace colorSpace)
93 : fCoordTransform(kLocal_GrCoordSet, 107 : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kN one_FilterMode)
94 GrCoordTransform::MakeDivByTextureWHMatrix(yTexture),
95 yTexture, GrTextureParams::kNone_FilterMode)
96 , fYAccess(yTexture) 108 , fYAccess(yTexture)
109 , fUTransform(kLocal_GrCoordSet, yuvMatrix[1], uTexture, GrTextureParams::kN one_FilterMode)
97 , fUAccess(uTexture) 110 , fUAccess(uTexture)
111 , fVTransform(kLocal_GrCoordSet, yuvMatrix[2], vTexture, GrTextureParams::kN one_FilterMode)
98 , fVAccess(vTexture) 112 , fVAccess(vTexture)
99 , fColorSpace(colorSpace) { 113 , fColorSpace(colorSpace) {
100 this->initClassID<YUVtoRGBEffect>(); 114 this->initClassID<YUVtoRGBEffect>();
101 this->addCoordTransform(&fCoordTransform); 115 this->addCoordTransform(&fYTransform);
102 this->addTextureAccess(&fYAccess); 116 this->addTextureAccess(&fYAccess);
117 this->addCoordTransform(&fUTransform);
103 this->addTextureAccess(&fUAccess); 118 this->addTextureAccess(&fUAccess);
119 this->addCoordTransform(&fVTransform);
104 this->addTextureAccess(&fVAccess); 120 this->addTextureAccess(&fVAccess);
105 } 121 }
106 122
107 virtual bool onIsEqual(const GrFragmentProcessor& sBase) const SK_OVERRIDE { 123 virtual bool onIsEqual(const GrFragmentProcessor& sBase) const SK_OVERRIDE {
108 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>(); 124 const YUVtoRGBEffect& s = sBase.cast<YUVtoRGBEffect>();
109 return fColorSpace == s.getColorSpace(); 125 return fColorSpace == s.getColorSpace();
110 } 126 }
111 127
112 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE { 128 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE {
113 // YUV is opaque 129 // YUV is opaque
114 inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A, 130 inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A,
115 GrInvariantOutput::kWillNot_ReadInput); 131 GrInvariantOutput::kWillNot_ReadInput);
116 } 132 }
117 133
118 GrCoordTransform fCoordTransform; 134 GrCoordTransform fYTransform;
119 GrTextureAccess fYAccess; 135 GrTextureAccess fYAccess;
136 GrCoordTransform fUTransform;
120 GrTextureAccess fUAccess; 137 GrTextureAccess fUAccess;
138 GrCoordTransform fVTransform;
121 GrTextureAccess fVAccess; 139 GrTextureAccess fVAccess;
122 SkYUVColorSpace fColorSpace; 140 SkYUVColorSpace fColorSpace;
123 141
124 typedef GrFragmentProcessor INHERITED; 142 typedef GrFragmentProcessor INHERITED;
125 }; 143 };
126 144
127 const GrGLfloat YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = { 145 const GrGLfloat YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = {
128 1.0f, 0.0f, 1.402f, -0.701f, 146 1.0f, 0.0f, 1.402f, -0.701f,
129 1.0f, -0.34414f, -0.71414f, 0.529f, 147 1.0f, -0.34414f, -0.71414f, 0.529f,
130 1.0f, 1.772f, 0.0f, -0.886f, 148 1.0f, 1.772f, 0.0f, -0.886f,
131 0.0f, 0.0f, 0.0f, 1.0}; 149 0.0f, 0.0f, 0.0f, 1.0};
132 const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = { 150 const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = {
133 1.164f, 0.0f, 1.596f, -0.87075f, 151 1.164f, 0.0f, 1.596f, -0.87075f,
134 1.164f, -0.391f, -0.813f, 0.52925f, 152 1.164f, -0.391f, -0.813f, 0.52925f,
135 1.164f, 2.018f, 0.0f, -1.08175f, 153 1.164f, 2.018f, 0.0f, -1.08175f,
136 0.0f, 0.0f, 0.0f, 1.0}; 154 0.0f, 0.0f, 0.0f, 1.0};
137 } 155 }
138 156
139 ////////////////////////////////////////////////////////////////////////////// 157 //////////////////////////////////////////////////////////////////////////////
140 158
141 GrFragmentProcessor* 159 GrFragmentProcessor*
142 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT exture, 160 GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vT exture,
143 SkYUVColorSpace colorSpace) { 161 SkISize sizes[3], SkYUVColorSpace colorSpace) {
144 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, colorSpace); 162 SkASSERT(yTexture && uTexture && vTexture && sizes);
163 return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpac e);
145 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698