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

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

Issue 778453002: Remove backend factories (Closed) Base URL: https://skia.googlesource.com/skia.git@unichoice
Patch Set: more clang warnings Created 6 years 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/effects/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.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 Google Inc. 2 * Copyright 2013 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 "SkDisplacementMapEffect.h" 8 #include "SkDisplacementMapEffect.h"
9 #include "SkReadBuffer.h" 9 #include "SkReadBuffer.h"
10 #include "SkWriteBuffer.h" 10 #include "SkWriteBuffer.h"
11 #include "SkUnPreMultiply.h" 11 #include "SkUnPreMultiply.h"
12 #include "SkColorPriv.h" 12 #include "SkColorPriv.h"
13 #if SK_SUPPORT_GPU 13 #if SK_SUPPORT_GPU
14 #include "GrContext.h" 14 #include "GrContext.h"
15 #include "GrCoordTransform.h" 15 #include "GrCoordTransform.h"
16 #include "GrInvariantOutput.h" 16 #include "GrInvariantOutput.h"
17 #include "gl/GrGLProcessor.h" 17 #include "gl/GrGLProcessor.h"
18 #include "gl/builders/GrGLProgramBuilder.h" 18 #include "gl/builders/GrGLProgramBuilder.h"
19 #include "GrTBackendProcessorFactory.h"
20 #endif 19 #endif
21 20
22 namespace { 21 namespace {
23 22
24 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most 23 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most
25 24
26 template<SkDisplacementMapEffect::ChannelSelectorType type> 25 template<SkDisplacementMapEffect::ChannelSelectorType type>
27 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { 26 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) {
28 SkDEBUGFAIL("Unknown channel selector"); 27 SkDEBUGFAIL("Unknown channel selector");
29 return 0; 28 return 0;
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 279 }
281 *dst = bounds; 280 *dst = bounds;
282 return true; 281 return true;
283 } 282 }
284 283
285 /////////////////////////////////////////////////////////////////////////////// 284 ///////////////////////////////////////////////////////////////////////////////
286 285
287 #if SK_SUPPORT_GPU 286 #if SK_SUPPORT_GPU
288 class GrGLDisplacementMapEffect : public GrGLFragmentProcessor { 287 class GrGLDisplacementMapEffect : public GrGLFragmentProcessor {
289 public: 288 public:
290 GrGLDisplacementMapEffect(const GrBackendProcessorFactory&, 289 GrGLDisplacementMapEffect(const GrProcessor&);
291 const GrProcessor&);
292 virtual ~GrGLDisplacementMapEffect(); 290 virtual ~GrGLDisplacementMapEffect();
293 291
294 virtual void emitCode(GrGLFPBuilder*, 292 virtual void emitCode(GrGLFPBuilder*,
295 const GrFragmentProcessor&, 293 const GrFragmentProcessor&,
296 const char* outputColor, 294 const char* outputColor,
297 const char* inputColor, 295 const char* inputColor,
298 const TransformedCoordsArray&, 296 const TransformedCoordsArray&,
299 const TextureSamplerArray&) SK_OVERRIDE; 297 const TextureSamplerArray&) SK_OVERRIDE;
300 298
301 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*); 299 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe yBuilder*);
(...skipping 19 matching lines...) Expand all
321 return SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector, 319 return SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector,
322 yChannelSelector, 320 yChannelSelector,
323 scale, 321 scale,
324 displacement, 322 displacement,
325 offsetMatrix, 323 offsetMatrix,
326 color)); 324 color));
327 } 325 }
328 326
329 virtual ~GrDisplacementMapEffect(); 327 virtual ~GrDisplacementMapEffect();
330 328
331 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR IDE; 329 virtual void getGLProcessorKey(const GrGLCaps& caps,
330 GrProcessorKeyBuilder* b) const SK_OVERRIDE {
331 GrGLDisplacementMapEffect::GenKey(*this, caps, b);
332 }
333
334 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE {
335 return SkNEW_ARGS(GrGLDisplacementMapEffect, (*this));
336 }
337
332 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const 338 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const
333 { return fXChannelSelector; } 339 { return fXChannelSelector; }
334 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const 340 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const
335 { return fYChannelSelector; } 341 { return fYChannelSelector; }
336 const SkVector& scale() const { return fScale; } 342 const SkVector& scale() const { return fScale; }
337 343
338 typedef GrGLDisplacementMapEffect GLProcessor; 344 virtual const char* name() const SK_OVERRIDE { return "DisplacementMap"; }
339 static const char* Name() { return "DisplacementMap"; }
340 345
341 private: 346 private:
342 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; 347 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
343 348
344 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE; 349 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE;
345 350
346 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne lSelector, 351 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne lSelector,
347 SkDisplacementMapEffect::ChannelSelectorType yChanne lSelector, 352 SkDisplacementMapEffect::ChannelSelectorType yChanne lSelector,
348 const SkVector& scale, 353 const SkVector& scale,
349 GrTexture* displacement, const SkMatrix& offsetMatri x, 354 GrTexture* displacement, const SkMatrix& offsetMatri x,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 GrTexture* displacement, 454 GrTexture* displacement,
450 const SkMatrix& offsetMatrix, 455 const SkMatrix& offsetMatrix,
451 GrTexture* color) 456 GrTexture* color)
452 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement) 457 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement)
453 , fDisplacementAccess(displacement) 458 , fDisplacementAccess(displacement)
454 , fColorTransform(kLocal_GrCoordSet, color) 459 , fColorTransform(kLocal_GrCoordSet, color)
455 , fColorAccess(color) 460 , fColorAccess(color)
456 , fXChannelSelector(xChannelSelector) 461 , fXChannelSelector(xChannelSelector)
457 , fYChannelSelector(yChannelSelector) 462 , fYChannelSelector(yChannelSelector)
458 , fScale(scale) { 463 , fScale(scale) {
464 this->initClassID<GrDisplacementMapEffect>();
459 this->addCoordTransform(&fDisplacementTransform); 465 this->addCoordTransform(&fDisplacementTransform);
460 this->addTextureAccess(&fDisplacementAccess); 466 this->addTextureAccess(&fDisplacementAccess);
461 this->addCoordTransform(&fColorTransform); 467 this->addCoordTransform(&fColorTransform);
462 this->addTextureAccess(&fColorAccess); 468 this->addTextureAccess(&fColorAccess);
463 } 469 }
464 470
465 GrDisplacementMapEffect::~GrDisplacementMapEffect() { 471 GrDisplacementMapEffect::~GrDisplacementMapEffect() {
466 } 472 }
467 473
468 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 474 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
469 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); 475 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>();
470 return fXChannelSelector == s.fXChannelSelector && 476 return fXChannelSelector == s.fXChannelSelector &&
471 fYChannelSelector == s.fYChannelSelector && 477 fYChannelSelector == s.fYChannelSelector &&
472 fScale == s.fScale; 478 fScale == s.fScale;
473 } 479 }
474 480
475 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c onst {
476 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta nce();
477 }
478
479 void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { 481 void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
480 // Any displacement offset bringing a pixel out of bounds will output a colo r of (0,0,0,0), 482 // Any displacement offset bringing a pixel out of bounds will output a colo r of (0,0,0,0),
481 // so the only way we'd get a constant alpha is if the input color image has a constant alpha 483 // so the only way we'd get a constant alpha is if the input color image has a constant alpha
482 // and no displacement offset push any texture coordinates out of bounds OR if the constant 484 // and no displacement offset push any texture coordinates out of bounds OR if the constant
483 // alpha is 0. Since this isn't trivial to compute at this point, let's assu me the output is 485 // alpha is 0. Since this isn't trivial to compute at this point, let's assu me the output is
484 // not of constant color when a displacement effect is applied. 486 // not of constant color when a displacement effect is applied.
485 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); 487 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
486 } 488 }
487 489
488 /////////////////////////////////////////////////////////////////////////////// 490 ///////////////////////////////////////////////////////////////////////////////
(...skipping 18 matching lines...) Expand all
507 SkVector scale = SkVector::Make(random->nextRangeScalar(0, 100.0f), 509 SkVector scale = SkVector::Make(random->nextRangeScalar(0, 100.0f),
508 random->nextRangeScalar(0, 100.0f)); 510 random->nextRangeScalar(0, 100.0f));
509 511
510 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s cale, 512 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s cale,
511 textures[texIdxDispl], SkMatrix::I(), 513 textures[texIdxDispl], SkMatrix::I(),
512 textures[texIdxColor]); 514 textures[texIdxColor]);
513 } 515 }
514 516
515 /////////////////////////////////////////////////////////////////////////////// 517 ///////////////////////////////////////////////////////////////////////////////
516 518
517 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendProcessorFac tory& factory, 519 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc)
518 const GrProcessor& proc) 520 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
519 : INHERITED(factory)
520 , fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
521 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) { 521 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) {
522 } 522 }
523 523
524 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { 524 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
525 } 525 }
526 526
527 void GrGLDisplacementMapEffect::emitCode(GrGLFPBuilder* builder, 527 void GrGLDisplacementMapEffect::emitCode(GrGLFPBuilder* builder,
528 const GrFragmentProcessor&, 528 const GrFragmentProcessor&,
529 const char* outputColor, 529 const char* outputColor,
530 const char* inputColor, 530 const char* inputColor,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, 615 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc,
616 const GrGLCaps&, GrProcessorKeyBuilder* b ) { 616 const GrGLCaps&, GrProcessorKeyBuilder* b ) {
617 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 617 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
618 618
619 uint32_t xKey = displacementMap.xChannelSelector(); 619 uint32_t xKey = displacementMap.xChannelSelector();
620 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 620 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
621 621
622 b->add32(xKey | yKey); 622 b->add32(xKey | yKey);
623 } 623 }
624 #endif 624 #endif
OLDNEW
« no previous file with comments | « src/effects/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698