blob: fad2c212399b7ae1e04ec4b099b1764f59e87b84 [file] [log] [blame]
tomhudson@google.comd0c1a062012-07-12 17:23:52 +00001/*
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
bsalomon@google.coma469c282012-10-24 18:28:34 +000011#include "GrEffect.h"
bsalomon@google.comb9086a02012-11-01 18:02:54 +000012#include "SkMatrix.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000013
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000014class GrGLSingleTextureEffect;
bsalomon@google.com34cccde2013-01-04 18:34:30 +000015class GrTexture;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000016
17/**
bsalomon@google.com17fc6512012-11-02 21:45:01 +000018 * An effect that draws a single texture with a texture matrix; commonly used as a base class. The
19 * output color is the texture color is modulated against the input color.
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000020 */
bsalomon@google.coma469c282012-10-24 18:28:34 +000021class GrSingleTextureEffect : public GrEffect {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000022public:
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000023 /* unfiltered, clamp mode */
24 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
25 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix)));
26 return CreateEffectPtr(effect);
27 }
bsalomon@google.comc3a58f32012-11-01 15:40:47 +000028
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000029 /* clamp mode */
30 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
31 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, bilerp)));
32 return CreateEffectPtr(effect);
33 }
34
35 static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) {
36 SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, p)));
37 return CreateEffectPtr(effect);
38 }
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000039
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000040 virtual ~GrSingleTextureEffect();
41
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000042 static const char* Name() { return "Single Texture"; }
43
bsalomon@google.com371e1052013-01-11 21:08:55 +000044 /** Note that if this class is sub-classed, the subclass may have to override this function.
45 */
46 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
47
bsalomon@google.comb9086a02012-11-01 18:02:54 +000048 const SkMatrix& getMatrix() const { return fMatrix; }
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000049
bsalomon@google.com422e81a2012-10-25 14:11:03 +000050 typedef GrGLSingleTextureEffect GLEffect;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000051
bsalomon@google.com396e61f2012-10-25 19:00:29 +000052 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000053
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000054 virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE {
55 const GrSingleTextureEffect& ste = static_cast<const GrSingleTextureEffect&>(effect);
56 return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix());
57 }
bsalomon@google.com17fc6512012-11-02 21:45:01 +000058
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000059protected:
60 GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
61 GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
62 GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
63
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000064private:
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000065
bsalomon@google.comf271cc72012-10-24 19:35:13 +000066 GR_DECLARE_EFFECT_TEST;
bsalomon@google.com0a7672f2012-08-03 18:12:20 +000067
bsalomon@google.com6d003d12012-09-11 15:45:20 +000068 GrTextureAccess fTextureAccess;
bsalomon@google.comb9086a02012-11-01 18:02:54 +000069 SkMatrix fMatrix;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000070
bsalomon@google.coma469c282012-10-24 18:28:34 +000071 typedef GrEffect INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000072};
73
74#endif