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