• 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 "GrColorSpaceXform.h"
13 #include "GrCoordTransform.h"
14 
15 class GrTextureProxy;
16 class SkMatrix;
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:
dumpInfo()24     SkString dumpInfo() const override {
25         SkString str;
26         str.appendf("Texture: %d", fTextureSampler.proxy()->uniqueID().asUInt());
27         return str;
28     }
29 
colorSpaceXform()30     GrColorSpaceXform* colorSpaceXform() const { return fColorSpaceXform.get(); }
31 
32 protected:
33     /** unfiltered, clamp mode */
34     GrSingleTextureEffect(OptimizationFlags, sk_sp<GrTextureProxy>,
35                           sk_sp<GrColorSpaceXform>, const SkMatrix&);
36     /** clamp mode */
37     GrSingleTextureEffect(OptimizationFlags, sk_sp<GrTextureProxy>,
38                           sk_sp<GrColorSpaceXform>, const SkMatrix&,
39                           GrSamplerParams::FilterMode filterMode);
40     GrSingleTextureEffect(OptimizationFlags, sk_sp<GrTextureProxy>,
41                           sk_sp<GrColorSpaceXform>, const SkMatrix&, const GrSamplerParams&);
42 
43     /**
44      * Can be used as a helper to decide which fragment processor OptimizationFlags should be set.
45      * This assumes that the subclass output color will be a modulation of the input color with a
46      * value read from the texture and that the texture contains premultiplied color or alpha values
47      * that are in range.
48      */
ModulationFlags(GrPixelConfig config)49     static OptimizationFlags ModulationFlags(GrPixelConfig config) {
50         if (GrPixelConfigIsOpaque(config)) {
51             return kCompatibleWithCoverageAsAlpha_OptimizationFlag |
52                    kPreservesOpaqueInput_OptimizationFlag;
53         } else {
54             return kCompatibleWithCoverageAsAlpha_OptimizationFlag;
55         }
56     }
57 
58 private:
59     GrCoordTransform         fCoordTransform;
60     TextureSampler           fTextureSampler;
61     sk_sp<GrColorSpaceXform> fColorSpaceXform;
62 
63     typedef GrFragmentProcessor INHERITED;
64 };
65 
66 #endif
67