blob: 9df0cffa5a8dcc73e72574b82a26de2c2f2062c0 [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:
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000024 virtual ~GrSingleTextureEffect();
25
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000026protected:
bsalomon@google.comc7818882013-03-20 19:19:53 +000027 /** unfiltered, clamp mode */
bsalomon@google.com77af6802013-10-02 13:04:56 +000028 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.comc7818882013-03-20 19:19:53 +000029 /** clamp mode */
skia.committer@gmail.com956b3102013-07-26 07:00:58 +000030 GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
bsalomon@google.com77af6802013-10-02 13:04:56 +000031 GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.comc7818882013-03-20 19:19:53 +000032 GrSingleTextureEffect(GrTexture*,
33 const SkMatrix&,
34 const GrTextureParams&,
bsalomon@google.com77af6802013-10-02 13:04:56 +000035 GrCoordSet = kLocal_GrCoordSet);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +000036
bsalomon@google.com68b58c92013-01-17 16:50:08 +000037 /**
egdaniel1a8ecdf2014-10-03 06:24:12 -070038 * Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
bsalomon@google.com68b58c92013-01-17 16:50:08 +000039 * the subclass output color will be a modulation of the input color with a value read from the
40 * texture.
41 */
egdaniel605dd0f2014-11-12 08:35:25 -080042 void updateInvariantOutputForModulation(GrInvariantOutput* inout) const {
egdanielf8449ba2014-11-25 10:24:56 -080043 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) {
joshualitt56995b52014-12-11 15:44:02 -080044 inout->mulByUnknownSingleComponent();
egdanielf8449ba2014-11-25 10:24:56 -080045 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) {
joshualitt56995b52014-12-11 15:44:02 -080046 inout->mulByUnknownOpaqueFourComponents();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000047 } else {
joshualitt56995b52014-12-11 15:44:02 -080048 inout->mulByUnknownFourComponents();
bsalomon@google.com68b58c92013-01-17 16:50:08 +000049 }
50 }
51
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000052private:
bsalomon@google.com77af6802013-10-02 13:04:56 +000053 GrCoordTransform fCoordTransform;
54 GrTextureAccess fTextureAccess;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000055
joshualittb0a8a372014-09-23 09:50:21 -070056 typedef GrFragmentProcessor INHERITED;
tomhudson@google.comd0c1a062012-07-12 17:23:52 +000057};
58
59#endif