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

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

Issue 24853002: Make GPU coord transforms automatic (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.h ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "GrBicubicEffect.h" 1 #include "GrBicubicEffect.h"
2 2
3 #define DS(x) SkDoubleToScalar(x) 3 #define DS(x) SkDoubleToScalar(x)
4 4
5 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = { 5 const SkScalar GrBicubicEffect::gMitchellCoefficients[16] = {
6 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0), 6 DS( 1.0 / 18.0), DS(-9.0 / 18.0), DS( 15.0 / 18.0), DS( -7.0 / 18.0),
7 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0), 7 DS(16.0 / 18.0), DS( 0.0 / 18.0), DS(-36.0 / 18.0), DS( 21.0 / 18.0),
8 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0), 8 DS( 1.0 / 18.0), DS( 9.0 / 18.0), DS( 27.0 / 18.0), DS(-21.0 / 18.0),
9 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0), 9 DS( 0.0 / 18.0), DS( 0.0 / 18.0), DS( -6.0 / 18.0), DS( 7.0 / 18.0),
10 }; 10 };
11 11
12 12
13 class GrGLBicubicEffect : public GrGLEffect { 13 class GrGLBicubicEffect : public GrGLEffect {
14 public: 14 public:
15 GrGLBicubicEffect(const GrBackendEffectFactory& factory, 15 GrGLBicubicEffect(const GrBackendEffectFactory& factory,
16 const GrDrawEffect&); 16 const GrDrawEffect&);
17 virtual void emitCode(GrGLShaderBuilder*, 17 virtual void emitCode(GrGLShaderBuilder*,
18 const GrDrawEffect&, 18 const GrDrawEffect&,
19 EffectKey, 19 EffectKey,
20 const char* outputColor, 20 const char* outputColor,
21 const char* inputColor, 21 const char* inputColor,
22 const TransformedCoordsArray&,
22 const TextureSamplerArray&) SK_OVERRIDE; 23 const TextureSamplerArray&) SK_OVERRIDE;
23 24
24 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
25
26 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; 25 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
27 26
28 private: 27 private:
29 typedef GrGLUniformManager::UniformHandle UniformHandle; 28 typedef GrGLUniformManager::UniformHandle UniformHandle;
30 29
31 UniformHandle fCoefficientsUni; 30 UniformHandle fCoefficientsUni;
32 UniformHandle fImageIncrementUni; 31 UniformHandle fImageIncrementUni;
33 32
34 GrGLEffectMatrix fEffectMatrix;
35
36 typedef GrGLEffect INHERITED; 33 typedef GrGLEffect INHERITED;
37 }; 34 };
38 35
39 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, 36 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, cons t GrDrawEffect&)
40 const GrDrawEffect& drawEffect) 37 : INHERITED(factory) {
41 : INHERITED(factory)
42 , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
43 } 38 }
44 39
45 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder, 40 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
46 const GrDrawEffect&, 41 const GrDrawEffect&,
47 EffectKey key, 42 EffectKey key,
48 const char* outputColor, 43 const char* outputColor,
49 const char* inputColor, 44 const char* inputColor,
45 const TransformedCoordsArray& coords,
50 const TextureSamplerArray& samplers) { 46 const TextureSamplerArray& samplers) {
51 SkString coords; 47 SkString coords2D = builder->ensureFSCoords2D(coords, 0);
52 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
53 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty, 48 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibili ty,
54 kMat44f_GrSLType, "Coefficients"); 49 kMat44f_GrSLType, "Coefficients");
55 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity, 50 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
56 kVec2f_GrSLType, "ImageIncrement"); 51 kVec2f_GrSLType, "ImageIncrement");
57 52
58 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 53 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
59 const char* coeff = builder->getUniformCStr(fCoefficientsUni); 54 const char* coeff = builder->getUniformCStr(fCoefficientsUni);
60 55
61 SkString cubicBlendName; 56 SkString cubicBlendName;
62 57
63 static const GrGLShaderVar gCubicBlendArgs[] = { 58 static const GrGLShaderVar gCubicBlendArgs[] = {
64 GrGLShaderVar("coefficients", kMat44f_GrSLType), 59 GrGLShaderVar("coefficients", kMat44f_GrSLType),
65 GrGLShaderVar("t", kFloat_GrSLType), 60 GrGLShaderVar("t", kFloat_GrSLType),
66 GrGLShaderVar("c0", kVec4f_GrSLType), 61 GrGLShaderVar("c0", kVec4f_GrSLType),
67 GrGLShaderVar("c1", kVec4f_GrSLType), 62 GrGLShaderVar("c1", kVec4f_GrSLType),
68 GrGLShaderVar("c2", kVec4f_GrSLType), 63 GrGLShaderVar("c2", kVec4f_GrSLType),
69 GrGLShaderVar("c3", kVec4f_GrSLType), 64 GrGLShaderVar("c3", kVec4f_GrSLType),
70 }; 65 };
71 builder->fsEmitFunction(kVec4f_GrSLType, 66 builder->fsEmitFunction(kVec4f_GrSLType,
72 "cubicBlend", 67 "cubicBlend",
73 SK_ARRAY_COUNT(gCubicBlendArgs), 68 SK_ARRAY_COUNT(gCubicBlendArgs),
74 gCubicBlendArgs, 69 gCubicBlendArgs,
75 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n" 70 "\tvec4 ts = vec4(1.0, t, t * t, t * t * t);\n"
76 "\tvec4 c = coefficients * ts;\n" 71 "\tvec4 c = coefficients * ts;\n"
77 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3; \n", 72 "\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3; \n",
78 &cubicBlendName); 73 &cubicBlendName);
79 builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords. c_str(), imgInc); 74 builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords2 D.c_str(), imgInc);
80 builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc); 75 builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc);
81 for (int y = 0; y < 4; ++y) { 76 for (int y = 0; y < 4; ++y) {
82 for (int x = 0; x < 4; ++x) { 77 for (int x = 0; x < 4; ++x) {
83 SkString coord; 78 SkString coord;
84 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1); 79 coord.printf("coord + %s * vec2(%d, %d)", imgInc, x - 1, y - 1);
85 builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y); 80 builder->fsCodeAppendf("\tvec4 s%d%d = ", x, y);
86 builder->fsAppendTextureLookup(samplers[0], coord.c_str()); 81 builder->fsAppendTextureLookup(samplers[0], coord.c_str());
87 builder->fsCodeAppend(";\n"); 82 builder->fsCodeAppend(";\n");
88 } 83 }
89 builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d) ;\n", y, cubicBlendName.c_str(), coeff, y, y, y, y); 84 builder->fsCodeAppendf("\tvec4 s%d = %s(%s, f.x, s0%d, s1%d, s2%d, s3%d) ;\n", y, cubicBlendName.c_str(), coeff, y, y, y, y);
90 } 85 }
91 builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff); 86 builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
92 } 87 }
93 88
94 GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
95 const GrBicubicEffect& bicubic = drawEffect.castEffect<GrBicubicEffect>();
96 EffectKey matrixKey = GrGLEffectMatrix::GenKey(bicubic.getMatrix(),
97 drawEffect,
98 bicubic.coordsType(),
99 bicubic.texture(0));
100 return matrixKey;
101 }
102
103 void GrGLBicubicEffect::setData(const GrGLUniformManager& uman, 89 void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
104 const GrDrawEffect& drawEffect) { 90 const GrDrawEffect& drawEffect) {
105 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>(); 91 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>();
106 GrTexture& texture = *effect.texture(0); 92 GrTexture& texture = *effect.texture(0);
107 float imageIncrement[2]; 93 float imageIncrement[2];
108 imageIncrement[0] = 1.0f / texture.width(); 94 imageIncrement[0] = 1.0f / texture.width();
109 imageIncrement[1] = 1.0f / texture.height(); 95 imageIncrement[1] = 1.0f / texture.height();
110 uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement); 96 uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
111 uman.setMatrix4f(fCoefficientsUni, effect.coefficients()); 97 uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
112 fEffectMatrix.setData(uman,
113 effect.getMatrix(),
114 drawEffect,
115 effect.texture(0));
116 } 98 }
117 99
118 GrBicubicEffect::GrBicubicEffect(GrTexture* texture, 100 GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
119 const SkScalar coefficients[16]) 101 const SkScalar coefficients[16])
120 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) { 102 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) {
121 for (int y = 0; y < 4; y++) { 103 for (int y = 0; y < 4; y++) {
122 for (int x = 0; x < 4; x++) { 104 for (int x = 0; x < 4; x++) {
123 // Convert from row-major scalars to column-major floats. 105 // Convert from row-major scalars to column-major floats.
124 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]); 106 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]);
125 } 107 }
126 } 108 }
127 } 109 }
128 110
129 GrBicubicEffect::GrBicubicEffect(GrTexture* texture, 111 GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
130 const SkScalar coefficients[16], 112 const SkScalar coefficients[16],
131 const SkMatrix &matrix, 113 const SkMatrix &matrix,
132 const GrTextureParams &params, 114 const GrTextureParams &params,
133 CoordsType coordsType) 115 GrCoordSet coordSet)
134 : INHERITED(texture, MakeDivByTextureWHMatrix(texture), params, coordsType) { 116 : INHERITED(texture, MakeDivByTextureWHMatrix(texture), params, coordSet) {
135 for (int y = 0; y < 4; y++) { 117 for (int y = 0; y < 4; y++) {
136 for (int x = 0; x < 4; x++) { 118 for (int x = 0; x < 4; x++) {
137 // Convert from row-major scalars to column-major floats. 119 // Convert from row-major scalars to column-major floats.
138 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]); 120 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]);
139 } 121 }
140 } 122 }
141 } 123 }
142 124
143 GrBicubicEffect::~GrBicubicEffect() { 125 GrBicubicEffect::~GrBicubicEffect() {
144 } 126 }
(...skipping 21 matching lines...) Expand all
166 const GrDrawTargetCaps&, 148 const GrDrawTargetCaps&,
167 GrTexture* textures[]) { 149 GrTexture* textures[]) {
168 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 150 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
169 GrEffectUnitTest::kAlphaTextureIdx; 151 GrEffectUnitTest::kAlphaTextureIdx;
170 SkScalar coefficients[16]; 152 SkScalar coefficients[16];
171 for (int i = 0; i < 16; i++) { 153 for (int i = 0; i < 16; i++) {
172 coefficients[i] = random->nextSScalar1(); 154 coefficients[i] = random->nextSScalar1();
173 } 155 }
174 return GrBicubicEffect::Create(textures[texIdx], coefficients); 156 return GrBicubicEffect::Create(textures[texIdx], coefficients);
175 } 157 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrBicubicEffect.h ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698