blob: 69b87493d56d2d477182a53dcb0dd4b3d381fa8e [file] [log] [blame]
bsalomon@google.com68b58c92013-01-17 16:50:08 +00001/*
2 * Copyright 2013 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 GrSimpleTextureEffect_DEFINED
9#define GrSimpleTextureEffect_DEFINED
10
11#include "GrSingleTextureEffect.h"
Robert Phillips901f29a2017-01-24 16:24:41 -050012#include "GrTextureProxy.h"
bsalomon@google.com68b58c92013-01-17 16:50:08 +000013
egdaniel605dd0f2014-11-12 08:35:25 -080014class GrInvariantOutput;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000015
16/**
17 * The output color of this effect is a modulation of the input color and a sample from a texture.
Brian Salomon514baff2016-11-17 15:17:07 -050018 * It allows explicit specification of the filtering and wrap modes (GrSamplerParams) and accepts
Brian Salomon2ebd0c82016-10-03 17:15:28 -040019 * a matrix that is used to compute texture coordinates from local coordinates.
bsalomon@google.com68b58c92013-01-17 16:50:08 +000020 */
21class GrSimpleTextureEffect : public GrSingleTextureEffect {
22public:
23 /* unfiltered, clamp mode */
bungeman06ca8ec2016-06-09 08:01:03 -070024 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
brianosman54f30c12016-07-18 10:53:52 -070025 sk_sp<GrColorSpaceXform> colorSpaceXform,
Brian Salomon2ebd0c82016-10-03 17:15:28 -040026 const SkMatrix& matrix) {
bungeman06ca8ec2016-06-09 08:01:03 -070027 return sk_sp<GrFragmentProcessor>(
brianosman54f30c12016-07-18 10:53:52 -070028 new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), matrix,
Brian Salomon514baff2016-11-17 15:17:07 -050029 GrSamplerParams::kNone_FilterMode));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000030 }
31
32 /* clamp mode */
bungeman06ca8ec2016-06-09 08:01:03 -070033 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
brianosman54f30c12016-07-18 10:53:52 -070034 sk_sp<GrColorSpaceXform> colorSpaceXform,
Brian Salomon739c5bf2016-11-07 09:53:44 -050035 const SkMatrix& matrix,
Brian Salomon514baff2016-11-17 15:17:07 -050036 GrSamplerParams::FilterMode filterMode) {
bungeman06ca8ec2016-06-09 08:01:03 -070037 return sk_sp<GrFragmentProcessor>(
Brian Salomon2ebd0c82016-10-03 17:15:28 -040038 new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), matrix, filterMode));
bsalomon@google.com68b58c92013-01-17 16:50:08 +000039 }
40
Robert Phillips40fd7c92017-01-30 08:06:27 -050041 static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
42 sk_sp<GrColorSpaceXform> colorSpaceXform,
43 const SkMatrix& matrix,
44 const GrSamplerParams& p) {
45 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(tex, std::move(colorSpaceXform),
46 matrix, p));
47 }
48
49 /* unfiltered, clamp mode */
Robert Phillips296b1cc2017-03-15 10:42:12 -040050 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
51 sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050052 sk_sp<GrColorSpaceXform> colorSpaceXform,
53 const SkMatrix& matrix) {
54 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040055 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
56 std::move(colorSpaceXform), matrix,
Robert Phillips40fd7c92017-01-30 08:06:27 -050057 GrSamplerParams::kNone_FilterMode));
58 }
59
60 /* clamp mode */
Robert Phillips296b1cc2017-03-15 10:42:12 -040061 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
62 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050063 sk_sp<GrColorSpaceXform> colorSpaceXform,
64 const SkMatrix& matrix,
65 GrSamplerParams::FilterMode filterMode) {
66 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040067 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
68 std::move(colorSpaceXform),
Robert Phillips901f29a2017-01-24 16:24:41 -050069 matrix, filterMode));
70 }
71
Robert Phillips296b1cc2017-03-15 10:42:12 -040072 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
73 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050074 sk_sp<GrColorSpaceXform> colorSpaceXform,
75 const SkMatrix& matrix,
76 const GrSamplerParams& p) {
Robert Phillips296b1cc2017-03-15 10:42:12 -040077 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider,
78 std::move(proxy),
Robert Phillips901f29a2017-01-24 16:24:41 -050079 std::move(colorSpaceXform),
80 matrix, p));
81 }
82
bsalomon@google.com68b58c92013-01-17 16:50:08 +000083 virtual ~GrSimpleTextureEffect() {}
84
mtklein36352bf2015-03-25 18:17:31 -070085 const char* name() const override { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000086
bsalomon@google.com68b58c92013-01-17 16:50:08 +000087private:
bsalomon4a339522015-10-06 08:40:50 -070088 GrSimpleTextureEffect(GrTexture* texture,
brianosman54f30c12016-07-18 10:53:52 -070089 sk_sp<GrColorSpaceXform> colorSpaceXform,
bsalomon@google.comc7818882013-03-20 19:19:53 +000090 const SkMatrix& matrix,
Brian Salomon514baff2016-11-17 15:17:07 -050091 GrSamplerParams::FilterMode filterMode)
Brian Salomon587e08f2017-01-27 10:59:27 -050092 : INHERITED(texture, std::move(colorSpaceXform), matrix, filterMode,
93 ModulationFlags(texture->config())) {
joshualitteb2a6762014-12-04 11:35:33 -080094 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +000095 }
96
bsalomon4a339522015-10-06 08:40:50 -070097 GrSimpleTextureEffect(GrTexture* texture,
Brian Salomon587e08f2017-01-27 10:59:27 -050098 sk_sp<GrColorSpaceXform>colorSpaceXform,
bsalomon@google.comc7818882013-03-20 19:19:53 +000099 const SkMatrix& matrix,
Brian Salomon514baff2016-11-17 15:17:07 -0500100 const GrSamplerParams& params)
Brian Salomon587e08f2017-01-27 10:59:27 -0500101 : INHERITED(texture, std::move(colorSpaceXform), matrix, params,
102 ModulationFlags(texture->config())) {
joshualitteb2a6762014-12-04 11:35:33 -0800103 this->initClassID<GrSimpleTextureEffect>();
bsalomon@google.comc7818882013-03-20 19:19:53 +0000104 }
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000105
Robert Phillips296b1cc2017-03-15 10:42:12 -0400106 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
107 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
108 GrSamplerParams::FilterMode);
Robert Phillips40fd7c92017-01-30 08:06:27 -0500109
Robert Phillips296b1cc2017-03-15 10:42:12 -0400110 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
111 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
112 const GrSamplerParams&);
Robert Phillips901f29a2017-01-24 16:24:41 -0500113
egdaniel57d3b032015-11-13 11:57:27 -0800114 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -0700115
Brian Salomon94efbf52016-11-29 13:43:05 -0500116 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -0700117
mtklein36352bf2015-03-25 18:17:31 -0700118 bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000119
joshualittb0a8a372014-09-23 09:50:21 -0700120 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000121
122 typedef GrSingleTextureEffect INHERITED;
123};
124
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000125#endif