blob: 3e0af65fcb54e284b060565c7b41c959dce15b42 [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
bsalomon@google.com34cccde2013-01-04 18:34:30 +000014class GrTexture;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000015
16/**
bsalomon@google.comc7818882013-03-20 19:19:53 +000017 * A base class for effects that draw a single texture with a texture matrix. This effect has no
18 * backend implementations. One must be provided by the subclass.
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000019 */
bsalomon@google.coma469c282012-10-24 18:28:34 +000020class GrSingleTextureEffect : public GrEffect {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000021public:
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000022 virtual ~GrSingleTextureEffect();
23
bsalomon@google.comb9086a02012-11-01 18:02:54 +000024 const SkMatrix& getMatrix() const { return fMatrix; }
bsalomon@google.comd8b5fac2012-11-01 17:02:46 +000025
bsalomon@google.comc7818882013-03-20 19:19:53 +000026 /** Indicates whether the matrix operates on local coords or positions */
27 CoordsType coordsType() const { return fCoordsType; }
28
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000029protected:
bsalomon@google.comc7818882013-03-20 19:19:53 +000030 /** unfiltered, clamp mode */
31 GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_CoordsType);
32 /** clamp mode */
33 GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp, CoordsType = kLocal_CoordsType);
34 GrSingleTextureEffect(GrTexture*,
35 const SkMatrix&,
36 const GrTextureParams&,
37 CoordsType = kLocal_CoordsType);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000038
bsalomon@google.com68b58c92013-01-17 16:50:08 +000039 /**
40 * Helper for subclass onIsEqual() functions.
41 */
bsalomon@google.comc7818882013-03-20 19:19:53 +000042 bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& other) const {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000043 const GrTextureAccess& otherAccess = other.fTextureAccess;
44 // We don't have to check the accesses' swizzles because they are inferred from the texture.
45 return fTextureAccess.getTexture() == otherAccess.getTexture() &&
46 fTextureAccess.getParams() == otherAccess.getParams() &&
bsalomon@google.comc7818882013-03-20 19:19:53 +000047 this->getMatrix().cheapEqualTo(other.getMatrix()) &&
48 fCoordsType == other.fCoordsType;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000049 }
50
51 /**
52 * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
53 * the subclass output color will be a modulation of the input color with a value read from the
54 * texture.
55 */
56 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000057 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
bsalomon@google.com68b58c92013-01-17 16:50:08 +000058 GrPixelConfigIsOpaque(this->texture(0)->config())) {
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000059 *validFlags = kA_GrColorComponentFlag;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000060 } else {
61 *validFlags = 0;
62 }
63 }
64
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000065private:
bsalomon@google.com6d003d12012-09-11 15:45:20 +000066 GrTextureAccess fTextureAccess;
bsalomon@google.comb9086a02012-11-01 18:02:54 +000067 SkMatrix fMatrix;
bsalomon@google.comc7818882013-03-20 19:19:53 +000068 CoordsType fCoordsType;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000069
bsalomon@google.coma469c282012-10-24 18:28:34 +000070 typedef GrEffect INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000071};
72
73#endif