• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef GrSingleTextureEffect_DEFINED
9 #define GrSingleTextureEffect_DEFINED
10 
11 #include "GrFragmentProcessor.h"
12 #include "GrCoordTransform.h"
13 #include "GrInvariantOutput.h"
14 #include "SkMatrix.h"
15 
16 class GrTexture;
17 
18 /**
19  * A base class for effects that draw a single texture with a texture matrix. This effect has no
20  * backend implementations. One must be provided by the subclass.
21  */
22 class GrSingleTextureEffect : public GrFragmentProcessor {
23 public:
24     ~GrSingleTextureEffect() override;
25 
dumpInfo()26     SkString dumpInfo() const override {
27         SkString str;
28         str.appendf("Texture: %d", fTextureAccess.getTexture()->getUniqueID());
29         return str;
30     }
31 
32 protected:
33     /** unfiltered, clamp mode */
34     GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
35     /** clamp mode */
36     GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
37                           GrCoordSet = kLocal_GrCoordSet);
38     GrSingleTextureEffect(GrTexture*,
39                           const SkMatrix&,
40                           const GrTextureParams&,
41                           GrCoordSet = kLocal_GrCoordSet);
42 
43     /**
44      * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
45      * the subclass output color will be a modulation of the input color with a value read from the
46      * texture.
47      */
updateInvariantOutputForModulation(GrInvariantOutput * inout)48     void updateInvariantOutputForModulation(GrInvariantOutput* inout) const {
49         if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
50             inout->mulByUnknownSingleComponent();
51         } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
52             inout->mulByUnknownOpaqueFourComponents();
53         } else {
54             inout->mulByUnknownFourComponents();
55         }
56     }
57 
58 private:
59     GrCoordTransform fCoordTransform;
60     GrTextureAccess  fTextureAccess;
61 
62     typedef GrFragmentProcessor INHERITED;
63 };
64 
65 #endif
66