blob: 4169e404691cebd41de42cfed5e782a765e85746 [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
bsalomon6251d172014-10-15 10:50:36 -070011#include "GrFragmentProcessor.h"
bsalomon@google.com77af6802013-10-02 13:04:56 +000012#include "GrCoordTransform.h"
egdaniel605dd0f2014-11-12 08:35:25 -080013#include "GrInvariantOutput.h"
14#include "SkMatrix.h"
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000015
bsalomon@google.com34cccde2013-01-04 18:34:30 +000016class GrTexture;
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000017
18/**
bsalomon@google.comc7818882013-03-20 19:19:53 +000019 * 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.
tomhudson@google.comaa72eab2012-07-19 18:01:07 +000021 */
joshualittb0a8a372014-09-23 09:50:21 -070022class GrSingleTextureEffect : public GrFragmentProcessor {
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000023public:
robertphillipse004bfc2015-11-16 09:06:59 -080024 ~GrSingleTextureEffect() override;
25
26 SkString dumpInfo() const override {
27 SkString str;
28 str.appendf("Texture: %d", fTextureAccess.getTexture()->getUniqueID());
29 return str;
30 }
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000031
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000032protected:
bsalomon@google.comc7818882013-03-20 19:19:53 +000033 /** unfiltered, clamp mode */
bsalomon4a339522015-10-06 08:40:50 -070034 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
joshualitt5f10b5c2015-07-09 10:24:35 -070035 /** clamp mode */
bsalomon4a339522015-10-06 08:40:50 -070036 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
joshualitt5f10b5c2015-07-09 10:24:35 -070037 GrCoordSet = kLocal_GrCoordSet);
bsalomon4a339522015-10-06 08:40:50 -070038 GrSingleTextureEffect(GrTexture*,
bsalomon@google.comc7818882013-03-20 19:19:53 +000039 const SkMatrix&,
40 const GrTextureParams&,
bsalomon@google.com77af6802013-10-02 13:04:56 +000041 GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000042
bsalomon@google.com68b58c92013-01-17 16:50:08 +000043 /**
egdaniel1a8ecdf2014-10-03 06:24:12 -070044 * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
bsalomon@google.com68b58c92013-01-17 16:50:08 +000045 * the subclass output color will be a modulation of the input color with a value read from the
46 * texture.
47 */
egdaniel605dd0f2014-11-12 08:35:25 -080048 void updateInvariantOutputForModulation(GrInvariantOutput* inout) const {
egdanielf8449ba2014-11-25 10:24:56 -080049 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
joshualitt56995b52014-12-11 15:44:02 -080050 inout->mulByUnknownSingleComponent();
egdanielf8449ba2014-11-25 10:24:56 -080051 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
joshualitt56995b52014-12-11 15:44:02 -080052 inout->mulByUnknownOpaqueFourComponents();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000053 } else {
joshualitt56995b52014-12-11 15:44:02 -080054 inout->mulByUnknownFourComponents();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000055 }
56 }
57
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000058private:
bsalomon@google.com77af6802013-10-02 13:04:56 +000059 GrCoordTransform fCoordTransform;
60 GrTextureAccess fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000061
joshualittb0a8a372014-09-23 09:50:21 -070062 typedef GrFragmentProcessor INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000063};
64
65#endif