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

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

Issue 582963002: Solo gp (Closed) Base URL: https://skia.googlesource.com/skia.git@no_peb
Patch Set: rebase Created 6 years, 3 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
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.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 2012 Google Inc. 2 * Copyright 2012 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 "gl/builders/GrGLProgramBuilder.h" 8 #include "gl/builders/GrGLProgramBuilder.h"
9 #include "GrTextureDomain.h" 9 #include "GrTextureDomain.h"
10 #include "GrSimpleTextureEffect.h" 10 #include "GrSimpleTextureEffect.h"
11 #include "GrTBackendEffectFactory.h" 11 #include "GrTBackendProcessorFactory.h"
12 #include "gl/GrGLEffect.h" 12 #include "gl/GrGLProcessor.h"
13 #include "SkFloatingPoint.h" 13 #include "SkFloatingPoint.h"
14 14
15 15
16 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) 16 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
17 : fIndex(index) { 17 : fIndex(index) {
18 18
19 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 19 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
20 if (domain.contains(kFullRect) && kClamp_Mode == mode) { 20 if (domain.contains(kFullRect) && kClamp_Mode == mode) {
21 fMode = kIgnore_Mode; 21 fMode = kIgnore_Mode;
22 } else { 22 } else {
(...skipping 14 matching lines...) Expand all
37 SkASSERT(fDomain.fTop <= fDomain.fBottom); 37 SkASSERT(fDomain.fTop <= fDomain.fBottom);
38 } 38 }
39 } 39 }
40 40
41 ////////////////////////////////////////////////////////////////////////////// 41 //////////////////////////////////////////////////////////////////////////////
42 42
43 void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, 43 void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder,
44 const GrTextureDomain& textureDoma in, 44 const GrTextureDomain& textureDoma in,
45 const char* outColor, 45 const char* outColor,
46 const SkString& inCoords, 46 const SkString& inCoords,
47 const GrGLEffect::TextureSampler s ampler, 47 const GrGLProcessor::TextureSample r sampler,
48 const char* inModulateColor) { 48 const char* inModulateColor) {
49 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); 49 SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
50 SkDEBUGCODE(fMode = textureDomain.mode();) 50 SkDEBUGCODE(fMode = textureDomain.mode();)
51 51
52 GrGLProgramBuilder* program = builder->getProgramBuilder(); 52 GrGLProgramBuilder* program = builder->getProgramBuilder();
53 53
54 if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) { 54 if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) {
55 const char* name; 55 const char* name;
56 SkString uniName("TexDom"); 56 SkString uniName("TexDom");
57 if (textureDomain.fIndex >= 0) { 57 if (textureDomain.fIndex >= 0) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { 158 if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) {
159 pdman.set4fv(fDomainUni, 1, values); 159 pdman.set4fv(fDomainUni, 1, values);
160 memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); 160 memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat));
161 } 161 }
162 } 162 }
163 } 163 }
164 164
165 165
166 ////////////////////////////////////////////////////////////////////////////// 166 //////////////////////////////////////////////////////////////////////////////
167 167
168 class GrGLTextureDomainEffect : public GrGLEffect { 168 class GrGLTextureDomainEffect : public GrGLFragmentProcessor {
169 public: 169 public:
170 GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrEffect&); 170 GrGLTextureDomainEffect(const GrBackendProcessorFactory&, const GrProcessor& );
171 171
172 virtual void emitCode(GrGLProgramBuilder*, 172 virtual void emitCode(GrGLProgramBuilder*,
173 const GrEffect&, 173 const GrFragmentProcessor&,
174 const GrEffectKey&, 174 const GrProcessorKey&,
175 const char* outputColor, 175 const char* outputColor,
176 const char* inputColor, 176 const char* inputColor,
177 const TransformedCoordsArray&, 177 const TransformedCoordsArray&,
178 const TextureSamplerArray&) SK_OVERRIDE; 178 const TextureSamplerArray&) SK_OVERRIDE;
179 179
180 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER RIDE; 180 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O VERRIDE;
181 181
182 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild er*); 182 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
183 183
184 private: 184 private:
185 GrTextureDomain::GLDomain fGLDomain; 185 GrTextureDomain::GLDomain fGLDomain;
186 typedef GrGLEffect INHERITED; 186 typedef GrGLFragmentProcessor INHERITED;
187 }; 187 };
188 188
189 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& f actory, 189 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendProcessorFactory & factory,
190 const GrEffect&) 190 const GrProcessor&)
191 : INHERITED(factory) { 191 : INHERITED(factory) {
192 } 192 }
193 193
194 void GrGLTextureDomainEffect::emitCode(GrGLProgramBuilder* builder, 194 void GrGLTextureDomainEffect::emitCode(GrGLProgramBuilder* builder,
195 const GrEffect& effect, 195 const GrFragmentProcessor& fp,
196 const GrEffectKey& key, 196 const GrProcessorKey& key,
197 const char* outputColor, 197 const char* outputColor,
198 const char* inputColor, 198 const char* inputColor,
199 const TransformedCoordsArray& coords, 199 const TransformedCoordsArray& coords,
200 const TextureSamplerArray& samplers) { 200 const TextureSamplerArray& samplers) {
201 const GrTextureDomainEffect& textureDomainEffect = effect.cast<GrTextureDoma inEffect>(); 201 const GrTextureDomainEffect& textureDomainEffect = fp.cast<GrTextureDomainEf fect>();
202 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); 202 const GrTextureDomain& domain = textureDomainEffect.textureDomain();
203 203
204 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 204 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
205 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); 205 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0);
206 fGLDomain.sampleTexture(fsBuilder, domain, outputColor, coords2D, samplers[0 ], inputColor); 206 fGLDomain.sampleTexture(fsBuilder, domain, outputColor, coords2D, samplers[0 ], inputColor);
207 } 207 }
208 208
209 void GrGLTextureDomainEffect::setData(const GrGLProgramDataManager& pdman, 209 void GrGLTextureDomainEffect::setData(const GrGLProgramDataManager& pdman,
210 const GrEffect& effect) { 210 const GrProcessor& processor) {
211 const GrTextureDomainEffect& textureDomainEffect = effect.cast<GrTextureDoma inEffect>(); 211 const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureD omainEffect>();
212 const GrTextureDomain& domain = textureDomainEffect.textureDomain(); 212 const GrTextureDomain& domain = textureDomainEffect.textureDomain();
213 fGLDomain.setData(pdman, domain, effect.texture(0)->origin()); 213 fGLDomain.setData(pdman, domain, processor.texture(0)->origin());
214 } 214 }
215 215
216 void GrGLTextureDomainEffect::GenKey(const GrEffect& effect, const GrGLCaps&, 216 void GrGLTextureDomainEffect::GenKey(const GrProcessor& processor, const GrGLCap s&,
217 GrEffectKeyBuilder* b) { 217 GrProcessorKeyBuilder* b) {
218 const GrTextureDomain& domain = effect.cast<GrTextureDomainEffect>().texture Domain(); 218 const GrTextureDomain& domain = processor.cast<GrTextureDomainEffect>().text ureDomain();
219 b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); 219 b->add32(GrTextureDomain::GLDomain::DomainKey(domain));
220 } 220 }
221 221
222 222
223 /////////////////////////////////////////////////////////////////////////////// 223 ///////////////////////////////////////////////////////////////////////////////
224 224
225 GrEffect* GrTextureDomainEffect::Create(GrTexture* texture, 225 GrFragmentProcessor* GrTextureDomainEffect::Create(GrTexture* texture,
226 const SkMatrix& matrix, 226 const SkMatrix& matrix,
227 const SkRect& domain, 227 const SkRect& domain,
228 GrTextureDomain::Mode mode, 228 GrTextureDomain::Mode mode,
229 GrTextureParams::FilterMode filterMod e, 229 GrTextureParams::FilterMode f ilterMode,
230 GrCoordSet coordSet) { 230 GrCoordSet coordSet) {
231 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; 231 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
232 if (GrTextureDomain::kIgnore_Mode == mode || 232 if (GrTextureDomain::kIgnore_Mode == mode ||
233 (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { 233 (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) {
234 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); 234 return GrSimpleTextureEffect::Create(texture, matrix, filterMode);
235 } else { 235 } else {
236 236
237 return SkNEW_ARGS(GrTextureDomainEffect, (texture, 237 return SkNEW_ARGS(GrTextureDomainEffect, (texture,
238 matrix, 238 matrix,
239 domain, 239 domain,
240 mode, 240 mode,
(...skipping 11 matching lines...) Expand all
252 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) 252 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet)
253 , fTextureDomain(domain, mode) { 253 , fTextureDomain(domain, mode) {
254 SkASSERT(mode != GrTextureDomain::kRepeat_Mode || 254 SkASSERT(mode != GrTextureDomain::kRepeat_Mode ||
255 filterMode == GrTextureParams::kNone_FilterMode); 255 filterMode == GrTextureParams::kNone_FilterMode);
256 } 256 }
257 257
258 GrTextureDomainEffect::~GrTextureDomainEffect() { 258 GrTextureDomainEffect::~GrTextureDomainEffect() {
259 259
260 } 260 }
261 261
262 const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { 262 const GrBackendFragmentProcessorFactory& GrTextureDomainEffect::getFactory() con st {
263 return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); 263 return GrTBackendFragmentProcessorFactory<GrTextureDomainEffect>::getInstanc e();
264 } 264 }
265 265
266 bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { 266 bool GrTextureDomainEffect::onIsEqual(const GrProcessor& sBase) const {
267 const GrTextureDomainEffect& s = sBase.cast<GrTextureDomainEffect>(); 267 const GrTextureDomainEffect& s = sBase.cast<GrTextureDomainEffect>();
268 return this->hasSameTextureParamsMatrixAndSourceCoords(s) && 268 return this->hasSameTextureParamsMatrixAndSourceCoords(s) &&
269 this->fTextureDomain == s.fTextureDomain; 269 this->fTextureDomain == s.fTextureDomain;
270 } 270 }
271 271
272 void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { 272 void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
273 if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper 273 if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper
274 *validFlags = 0; 274 *validFlags = 0;
275 } else { 275 } else {
276 this->updateConstantColorComponentsForModulation(color, validFlags); 276 this->updateConstantColorComponentsForModulation(color, validFlags);
277 } 277 }
278 } 278 }
279 279
280 /////////////////////////////////////////////////////////////////////////////// 280 ///////////////////////////////////////////////////////////////////////////////
281 281
282 GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); 282 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTextureDomainEffect);
283 283
284 GrEffect* GrTextureDomainEffect::TestCreate(SkRandom* random, 284 GrFragmentProcessor* GrTextureDomainEffect::TestCreate(SkRandom* random,
285 GrContext*, 285 GrContext*,
286 const GrDrawTargetCaps&, 286 const GrDrawTargetCaps&,
287 GrTexture* textures[]) { 287 GrTexture* textures[]) {
288 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : 288 int texIdx = random->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
289 GrEffectUnitTest::kAlphaTextureIdx; 289 GrProcessorUnitTest::kAlphaTextureIdx;
290 SkRect domain; 290 SkRect domain;
291 domain.fLeft = random->nextUScalar1(); 291 domain.fLeft = random->nextUScalar1();
292 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); 292 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1);
293 domain.fTop = random->nextUScalar1(); 293 domain.fTop = random->nextUScalar1();
294 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); 294 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1);
295 GrTextureDomain::Mode mode = 295 GrTextureDomain::Mode mode =
296 (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCoun t); 296 (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCoun t);
297 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); 297 const SkMatrix& matrix = GrProcessorUnitTest::TestMatrix(random);
298 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? random->nextBool() : f alse; 298 bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? random->nextBool() : f alse;
299 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo rdSet; 299 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo rdSet;
300 return GrTextureDomainEffect::Create(textures[texIdx], 300 return GrTextureDomainEffect::Create(textures[texIdx],
301 matrix, 301 matrix,
302 domain, 302 domain,
303 mode, 303 mode,
304 bilerp ? GrTextureParams::kBilerp_Filte rMode : GrTextureParams::kNone_FilterMode, 304 bilerp ? GrTextureParams::kBilerp_Filte rMode : GrTextureParams::kNone_FilterMode,
305 coords); 305 coords);
306 } 306 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698