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

Side by Side Diff: src/effects/SkBicubicImageFilter.cpp

Issue 12531015: Adds local coords to GrEffect system. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « include/gpu/GrTBackendEffectFactory.h ('k') | src/effects/SkBlendImageFilter.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 /* 1 /*
2 * Copyright 2013 The Android Open Source Project 2 * Copyright 2013 The Android Open Source Project
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 "SkBicubicImageFilter.h" 8 #include "SkBicubicImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 float fCoefficients[16]; 178 float fCoefficients[16];
179 179
180 GR_DECLARE_EFFECT_TEST; 180 GR_DECLARE_EFFECT_TEST;
181 181
182 typedef GrSingleTextureEffect INHERITED; 182 typedef GrSingleTextureEffect INHERITED;
183 }; 183 };
184 184
185 class GrGLBicubicEffect : public GrGLEffect { 185 class GrGLBicubicEffect : public GrGLEffect {
186 public: 186 public:
187 GrGLBicubicEffect(const GrBackendEffectFactory& factory, 187 GrGLBicubicEffect(const GrBackendEffectFactory& factory,
188 const GrEffectRef& effect); 188 const GrDrawEffect&);
189 virtual void emitCode(GrGLShaderBuilder*, 189 virtual void emitCode(GrGLShaderBuilder*,
190 const GrEffectStage&, 190 const GrDrawEffect&,
191 EffectKey, 191 EffectKey,
192 const char* vertexCoords,
193 const char* outputColor, 192 const char* outputColor,
194 const char* inputColor, 193 const char* inputColor,
195 const TextureSamplerArray&) SK_OVERRIDE; 194 const TextureSamplerArray&) SK_OVERRIDE;
196 195
197 static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&); 196 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
198 197
199 virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVE RRIDE; 198 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
200 199
201 private: 200 private:
202 typedef GrGLUniformManager::UniformHandle UniformHandle; 201 typedef GrGLUniformManager::UniformHandle UniformHandle;
203 202
204 UniformHandle fCoefficientsUni; 203 UniformHandle fCoefficientsUni;
205 UniformHandle fImageIncrementUni; 204 UniformHandle fImageIncrementUni;
206 205
207 GrGLEffectMatrix fEffectMatrix; 206 GrGLEffectMatrix fEffectMatrix;
208 207
209 typedef GrGLEffect INHERITED; 208 typedef GrGLEffect INHERITED;
210 }; 209 };
211 210
212 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, 211 GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory,
213 const GrEffectRef& effect) 212 const GrDrawEffect& drawEffect)
214 : INHERITED(factory) 213 : INHERITED(factory)
215 , fCoefficientsUni(GrGLUniformManager::kInvalidUniformHandle) 214 , fCoefficientsUni(GrGLUniformManager::kInvalidUniformHandle)
216 , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) { 215 , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
216 , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
217 } 217 }
218 218
219 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder, 219 void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
220 const GrEffectStage&, 220 const GrDrawEffect&,
221 EffectKey key, 221 EffectKey key,
222 const char* vertexCoords,
223 const char* outputColor, 222 const char* outputColor,
224 const char* inputColor, 223 const char* inputColor,
225 const TextureSamplerArray& samplers) { 224 const TextureSamplerArray& samplers) {
226 const char* coords; 225 const char* coords;
227 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); 226 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
228 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy pe, 227 fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderTy pe,
229 kMat44f_GrSLType, "Coefficients"); 228 kMat44f_GrSLType, "Coefficients");
230 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type, 229 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type,
231 kVec2f_GrSLType, "ImageIncrement"); 230 kVec2f_GrSLType, "ImageIncrement");
232 231
233 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); 232 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
234 const char* coeff = builder->getUniformCStr(fCoefficientsUni); 233 const char* coeff = builder->getUniformCStr(fCoefficientsUni);
235 234
236 SkString cubicBlendName; 235 SkString cubicBlendName;
237 236
(...skipping 24 matching lines...) Expand all
262 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType , 261 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType ,
263 samplers[0], 262 samplers[0],
264 coord.c_str()); 263 coord.c_str());
265 builder->fsCodeAppend(";\n"); 264 builder->fsCodeAppend(";\n");
266 } 265 }
267 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); 266 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);
268 } 267 }
269 builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff); 268 builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
270 } 269 }
271 270
272 GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const Gr GLCaps&) { 271 GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
273 const GrBicubicEffect& m = GetEffectFromStage<GrBicubicEffect>(s); 272 const GrBicubicEffect& bicubic = drawEffect.castEffect<GrBicubicEffect>();
274 EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(), 273 EffectKey matrixKey = GrGLEffectMatrix::GenKey(bicubic.getMatrix(),
275 s.getCoordChangeMatrix(), 274 drawEffect,
276 m.texture(0)); 275 bicubic.coordsType(),
276 bicubic.texture(0));
277 return matrixKey; 277 return matrixKey;
278 } 278 }
279 279
280 void GrGLBicubicEffect::setData(const GrGLUniformManager& uman, 280 void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
281 const GrEffectStage& stage) { 281 const GrDrawEffect& drawEffect) {
282 const GrBicubicEffect& effect = GetEffectFromStage<GrBicubicEffect>(stage); 282 const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>();
283 GrTexture& texture = *effect.texture(0); 283 GrTexture& texture = *effect.texture(0);
284 float imageIncrement[2]; 284 float imageIncrement[2];
285 imageIncrement[0] = 1.0f / texture.width(); 285 imageIncrement[0] = 1.0f / texture.width();
286 imageIncrement[1] = 1.0f / texture.height(); 286 imageIncrement[1] = 1.0f / texture.height();
287 uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement); 287 uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
288 uman.setMatrix4f(fCoefficientsUni, effect.coefficients()); 288 uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
289 fEffectMatrix.setData(uman, 289 fEffectMatrix.setData(uman,
290 effect.getMatrix(), 290 effect.getMatrix(),
291 stage.getCoordChangeMatrix(), 291 drawEffect,
292 effect.texture(0)); 292 effect.texture(0));
293 } 293 }
294 294
295 GrBicubicEffect::GrBicubicEffect(GrTexture* texture, 295 GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
296 const SkScalar coefficients[16]) 296 const SkScalar coefficients[16])
297 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) { 297 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) {
298 for (int y = 0; y < 4; y++) { 298 for (int y = 0; y < 4; y++) {
299 for (int x = 0; x < 4; x++) { 299 for (int x = 0; x < 4; x++) {
300 // Convert from row-major scalars to column-major floats. 300 // Convert from row-major scalars to column-major floats.
301 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]); 301 fCoefficients[x * 4 + y] = SkScalarToFloat(coefficients[y * 4 + x]);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 GrPaint paint; 362 GrPaint paint;
363 paint.colorStage(0)->setEffect(GrBicubicEffect::Create(srcTexture, fCoeffici ents))->unref(); 363 paint.colorStage(0)->setEffect(GrBicubicEffect::Create(srcTexture, fCoeffici ents))->unref();
364 SkRect srcRect; 364 SkRect srcRect;
365 srcBM.getBounds(&srcRect); 365 srcBM.getBounds(&srcRect);
366 context->drawRectToRect(paint, dstRect, srcRect); 366 context->drawRectToRect(paint, dstRect, srcRect);
367 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul t); 367 return SkImageFilterUtils::WrapTexture(dst, desc.fWidth, desc.fHeight, resul t);
368 } 368 }
369 #endif 369 #endif
370 370
371 /////////////////////////////////////////////////////////////////////////////// 371 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« no previous file with comments | « include/gpu/GrTBackendEffectFactory.h ('k') | src/effects/SkBlendImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698