Chromium Code Reviews

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: cleanup Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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...)
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...)
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"; } 345
346 virtual uint32_t classID() const {
347 static uint32_t id = GenClassID();
348 return id;
349 }
340 350
341 private: 351 private:
342 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; 352 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE;
343 353
344 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE; 354 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE RRIDE;
345 355
346 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne lSelector, 356 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne lSelector,
347 SkDisplacementMapEffect::ChannelSelectorType yChanne lSelector, 357 SkDisplacementMapEffect::ChannelSelectorType yChanne lSelector,
348 const SkVector& scale, 358 const SkVector& scale,
349 GrTexture* displacement, const SkMatrix& offsetMatri x, 359 GrTexture* displacement, const SkMatrix& offsetMatri x,
(...skipping 115 matching lines...)
465 GrDisplacementMapEffect::~GrDisplacementMapEffect() { 475 GrDisplacementMapEffect::~GrDisplacementMapEffect() {
466 } 476 }
467 477
468 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const { 478 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
469 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); 479 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>();
470 return fXChannelSelector == s.fXChannelSelector && 480 return fXChannelSelector == s.fXChannelSelector &&
471 fYChannelSelector == s.fYChannelSelector && 481 fYChannelSelector == s.fYChannelSelector &&
472 fScale == s.fScale; 482 fScale == s.fScale;
473 } 483 }
474 484
475 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c onst {
476 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta nce();
477 }
478
479 void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { 485 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), 486 // 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 487 // 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 488 // 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 489 // 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. 490 // not of constant color when a displacement effect is applied.
485 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); 491 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
486 } 492 }
487 493
488 /////////////////////////////////////////////////////////////////////////////// 494 ///////////////////////////////////////////////////////////////////////////////
(...skipping 18 matching lines...)
507 SkVector scale = SkVector::Make(random->nextRangeScalar(0, 100.0f), 513 SkVector scale = SkVector::Make(random->nextRangeScalar(0, 100.0f),
508 random->nextRangeScalar(0, 100.0f)); 514 random->nextRangeScalar(0, 100.0f));
509 515
510 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s cale, 516 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s cale,
511 textures[texIdxDispl], SkMatrix::I(), 517 textures[texIdxDispl], SkMatrix::I(),
512 textures[texIdxColor]); 518 textures[texIdxColor]);
513 } 519 }
514 520
515 /////////////////////////////////////////////////////////////////////////////// 521 ///////////////////////////////////////////////////////////////////////////////
516 522
517 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendProcessorFac tory& factory, 523 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc)
518 const GrProcessor& proc) 524 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
519 : INHERITED(factory)
520 , fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
521 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) { 525 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) {
522 } 526 }
523 527
524 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { 528 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
525 } 529 }
526 530
527 void GrGLDisplacementMapEffect::emitCode(GrGLFPBuilder* builder, 531 void GrGLDisplacementMapEffect::emitCode(GrGLFPBuilder* builder,
528 const GrFragmentProcessor&, 532 const GrFragmentProcessor&,
529 const char* outputColor, 533 const char* outputColor,
530 const char* inputColor, 534 const char* inputColor,
(...skipping 84 matching lines...)
615 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, 619 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc,
616 const GrGLCaps&, GrProcessorKeyBuilder* b ) { 620 const GrGLCaps&, GrProcessorKeyBuilder* b ) {
617 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 621 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
618 622
619 uint32_t xKey = displacementMap.xChannelSelector(); 623 uint32_t xKey = displacementMap.xChannelSelector();
620 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 624 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
621 625
622 b->add32(xKey | yKey); 626 b->add32(xKey | yKey);
623 } 627 }
624 #endif 628 #endif
OLDNEW

Powered by Google App Engine