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

Side by Side Diff: src/effects/SkMagnifierImageFilter.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 | « src/effects/SkLightingImageFilter.cpp ('k') | src/effects/SkMatrixConvolutionImageFilter.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 2012 The Android Open Source Project 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkMagnifierImageFilter.h" 9 #include "SkMagnifierImageFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 float fYInset; 85 float fYInset;
86 86
87 typedef GrSingleTextureEffect INHERITED; 87 typedef GrSingleTextureEffect INHERITED;
88 }; 88 };
89 89
90 // For brevity 90 // For brevity
91 typedef GrGLUniformManager::UniformHandle UniformHandle; 91 typedef GrGLUniformManager::UniformHandle UniformHandle;
92 92
93 class GrGLMagnifierEffect : public GrGLEffect { 93 class GrGLMagnifierEffect : public GrGLEffect {
94 public: 94 public:
95 GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef & effect); 95 GrGLMagnifierEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
96 96
97 virtual void emitCode(GrGLShaderBuilder*, 97 virtual void emitCode(GrGLShaderBuilder*,
98 const GrEffectStage&, 98 const GrDrawEffect&,
99 EffectKey, 99 EffectKey,
100 const char* vertexCoords,
101 const char* outputColor, 100 const char* outputColor,
102 const char* inputColor, 101 const char* inputColor,
103 const TextureSamplerArray&) SK_OVERRIDE; 102 const TextureSamplerArray&) SK_OVERRIDE;
104 103
105 virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& st age) SK_OVERRIDE; 104 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE;
106 105
107 static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&); 106 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
108 107
109 private: 108 private:
110
111 UniformHandle fOffsetVar; 109 UniformHandle fOffsetVar;
112 UniformHandle fZoomVar; 110 UniformHandle fZoomVar;
113 UniformHandle fInsetVar; 111 UniformHandle fInsetVar;
114 112
115 GrGLEffectMatrix fEffectMatrix; 113 GrGLEffectMatrix fEffectMatrix;
116 114
117 typedef GrGLEffect INHERITED; 115 typedef GrGLEffect INHERITED;
118 }; 116 };
119 117
120 GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef&) 118 GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
119 const GrDrawEffect& drawEffect)
121 : INHERITED(factory) 120 : INHERITED(factory)
122 , fOffsetVar(GrGLUniformManager::kInvalidUniformHandle) 121 , fOffsetVar(GrGLUniformManager::kInvalidUniformHandle)
123 , fZoomVar(GrGLUniformManager::kInvalidUniformHandle) 122 , fZoomVar(GrGLUniformManager::kInvalidUniformHandle)
124 , fInsetVar(GrGLUniformManager::kInvalidUniformHandle) { 123 , fInsetVar(GrGLUniformManager::kInvalidUniformHandle)
124 , fEffectMatrix(drawEffect.castEffect<GrMagnifierEffect>().coordsType()) {
125 } 125 }
126 126
127 void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder, 127 void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
128 const GrEffectStage&, 128 const GrDrawEffect&,
129 EffectKey key, 129 EffectKey key,
130 const char* vertexCoords,
131 const char* outputColor, 130 const char* outputColor,
132 const char* inputColor, 131 const char* inputColor,
133 const TextureSamplerArray& samplers) { 132 const TextureSamplerArray& samplers) {
134 const char* coords; 133 const char* coords;
135 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords); 134 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
136 fOffsetVar = builder->addUniform( 135 fOffsetVar = builder->addUniform(
137 GrGLShaderBuilder::kFragment_ShaderType | 136 GrGLShaderBuilder::kFragment_ShaderType |
138 GrGLShaderBuilder::kVertex_ShaderType, 137 GrGLShaderBuilder::kVertex_ShaderType,
139 kVec2f_GrSLType, "uOffset"); 138 kVec2f_GrSLType, "uOffset");
140 fZoomVar = builder->addUniform( 139 fZoomVar = builder->addUniform(
141 GrGLShaderBuilder::kFragment_ShaderType | 140 GrGLShaderBuilder::kFragment_ShaderType |
142 GrGLShaderBuilder::kVertex_ShaderType, 141 GrGLShaderBuilder::kVertex_ShaderType,
143 kVec2f_GrSLType, "uZoom"); 142 kVec2f_GrSLType, "uZoom");
144 fInsetVar = builder->addUniform( 143 fInsetVar = builder->addUniform(
145 GrGLShaderBuilder::kFragment_ShaderType | 144 GrGLShaderBuilder::kFragment_ShaderType |
(...skipping 26 matching lines...) Expand all
172 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample rs[0], "mix_coord"); 171 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, sample rs[0], "mix_coord");
173 builder->fsCodeAppend(";\n"); 172 builder->fsCodeAppend(";\n");
174 173
175 builder->fsCodeAppendf("\t\t%s = output_color;", outputColor); 174 builder->fsCodeAppendf("\t\t%s = output_color;", outputColor);
176 SkString modulate; 175 SkString modulate;
177 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); 176 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
178 builder->fsCodeAppend(modulate.c_str()); 177 builder->fsCodeAppend(modulate.c_str());
179 } 178 }
180 179
181 void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman, 180 void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman,
182 const GrEffectStage& stage) { 181 const GrDrawEffect& drawEffect) {
183 const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage) ; 182 const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
184 uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); 183 uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset());
185 uman.set2f(fZoomVar, zoom.x_zoom(), zoom.y_zoom()); 184 uman.set2f(fZoomVar, zoom.x_zoom(), zoom.y_zoom());
186 uman.set2f(fInsetVar, zoom.x_inset(), zoom.y_inset()); 185 uman.set2f(fInsetVar, zoom.x_inset(), zoom.y_inset());
187 fEffectMatrix.setData(uman, zoom.getMatrix(), stage.getCoordChangeMatrix(), zoom.texture(0)); 186 fEffectMatrix.setData(uman, zoom.getMatrix(), drawEffect, zoom.texture(0));
188 } 187 }
189 188
190 GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrEffectStage& stage, co nst GrGLCaps&) { 189 GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrDrawEffect& drawEffect ,
191 const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage) ; 190 const GrGLCaps&) {
191 const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
192 return GrGLEffectMatrix::GenKey(zoom.getMatrix(), 192 return GrGLEffectMatrix::GenKey(zoom.getMatrix(),
193 stage.getCoordChangeMatrix(), 193 drawEffect,
194 zoom.coordsType(),
194 zoom.texture(0)); 195 zoom.texture(0));
195 } 196 }
196 197
197 ///////////////////////////////////////////////////////////////////// 198 /////////////////////////////////////////////////////////////////////
198 199
199 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); 200 GR_DEFINE_EFFECT_TEST(GrMagnifierEffect);
200 201
201 GrEffectRef* GrMagnifierEffect::TestCreate(SkMWCRandom* random, 202 GrEffectRef* GrMagnifierEffect::TestCreate(SkMWCRandom* random,
202 GrContext* context, 203 GrContext* context,
203 GrTexture** textures) { 204 GrTexture** textures) {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 346
346 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1); 347 int x_val = SkMin32(SkScalarFloorToInt(x_interp), width - 1);
347 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1); 348 int y_val = SkMin32(SkScalarFloorToInt(y_interp), height - 1);
348 349
349 *dptr = sptr[y_val * width + x_val]; 350 *dptr = sptr[y_val * width + x_val];
350 dptr++; 351 dptr++;
351 } 352 }
352 } 353 }
353 return true; 354 return true;
354 } 355 }
OLDNEW
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | src/effects/SkMatrixConvolutionImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698