blob: a8f9a6d52142e60b1abdf075c100a303af5d384d [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"
bsalomon@google.com77af6802013-10-02 13:04:56 +000013#include "GrCoordTransform.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000014
bsalomon@google.com34cccde2013-01-04 18:34:30 +000015class GrTexture;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000016
17/**
bsalomon@google.comc7818882013-03-20 19:19:53 +000018 * A base class for effects that draw a single texture with a texture matrix. This effect has no
19 * backend implementations. One must be provided by the subclass.
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:
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000023 virtual ~GrSingleTextureEffect();
24
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000025protected:
bsalomon@google.comc7818882013-03-20 19:19:53 +000026 /** unfiltered, clamp mode */
bsalomon@google.com77af6802013-10-02 13:04:56 +000027 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.comc7818882013-03-20 19:19:53 +000028 /** clamp mode */
skia.committer@gmail.com956b3102013-07-26 07:00:58 +000029 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000030 GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.comc7818882013-03-20 19:19:53 +000031 GrSingleTextureEffect(GrTexture*,
32 const SkMatrix&,
33 const GrTextureParams&,
bsalomon@google.com77af6802013-10-02 13:04:56 +000034 GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000035
bsalomon@google.com68b58c92013-01-17 16:50:08 +000036 /**
37 * Helper for subclass onIsEqual() functions.
38 */
bsalomon@google.com77af6802013-10-02 13:04:56 +000039 bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const {
bsalomon@google.com68b58c92013-01-17 16:50:08 +000040 // We don't have to check the accesses' swizzles because they are inferred from the texture.
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000041 return fTextureAccess == other.fTextureAccess &&
bsalomon@google.com77af6802013-10-02 13:04:56 +000042 fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) &&
43 fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000044 }
45
46 /**
47 * Can be used as a helper to implement subclass getConstantColorComponents(). It assumes that
48 * the subclass output color will be a modulation of the input color with a value read from the
49 * texture.
50 */
51 void updateConstantColorComponentsForModulation(GrColor* color, uint32_t* validFlags) const {
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000052 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color) &&
bsalomon@google.com68b58c92013-01-17 16:50:08 +000053 GrPixelConfigIsOpaque(this->texture(0)->config())) {
bsalomon@google.comb8eb2e82013-03-28 13:46:42 +000054 *validFlags = kA_GrColorComponentFlag;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000055 } else {
56 *validFlags = 0;
57 }
58 }
59
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000060private:
bsalomon@google.com77af6802013-10-02 13:04:56 +000061 GrCoordTransform fCoordTransform;
62 GrTextureAccess fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000063
bsalomon@google.coma469c282012-10-24 18:28:34 +000064 typedef GrEffect INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000065};
66
67#endif