blob: 7d5232c3e0b37452751ee1b1daaf6d7529d1430c [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 */
Robert Phillips296b1cc2017-03-15 10:42:12 -040024 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
25 sk_sp<GrTextureProxy> proxy,
Robert Phillips40fd7c92017-01-30 08:06:27 -050026 sk_sp<GrColorSpaceXform> colorSpaceXform,
27 const SkMatrix& matrix) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040028 // MDB TODO: remove this instantiation once instantiation is pushed past the
29 // TextureSamplers. Instantiation failure in the TextureSampler is difficult to
30 // recover from.
31 GrTexture* temp = proxy->instantiate(resourceProvider);
32 if (!temp) {
33 return nullptr;
34 }
35
Robert Phillips40fd7c92017-01-30 08:06:27 -050036 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040037 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
38 std::move(colorSpaceXform), matrix,
Robert Phillips40fd7c92017-01-30 08:06:27 -050039 GrSamplerParams::kNone_FilterMode));
40 }
41
42 /* clamp mode */
Robert Phillips296b1cc2017-03-15 10:42:12 -040043 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
44 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050045 sk_sp<GrColorSpaceXform> colorSpaceXform,
46 const SkMatrix& matrix,
47 GrSamplerParams::FilterMode filterMode) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040048 // MDB TODO: remove this instantiation once instantiation is pushed past the
49 // TextureSamplers. Instantiation failure in the TextureSampler is difficult to
50 // recover from.
51 GrTexture* temp = proxy->instantiate(resourceProvider);
52 if (!temp) {
53 return nullptr;
54 }
55
Robert Phillips901f29a2017-01-24 16:24:41 -050056 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040057 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
58 std::move(colorSpaceXform),
Robert Phillips901f29a2017-01-24 16:24:41 -050059 matrix, filterMode));
60 }
61
Robert Phillips296b1cc2017-03-15 10:42:12 -040062 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
63 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050064 sk_sp<GrColorSpaceXform> colorSpaceXform,
65 const SkMatrix& matrix,
66 const GrSamplerParams& p) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040067 // MDB TODO: remove this instantiation once instantiation is pushed past the
68 // TextureSamplers. Instantiation failure in the TextureSampler is difficult to
69 // recover from.
70 GrTexture* temp = proxy->instantiate(resourceProvider);
71 if (!temp) {
72 return nullptr;
73 }
74
Robert Phillips296b1cc2017-03-15 10:42:12 -040075 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider,
76 std::move(proxy),
Robert Phillips901f29a2017-01-24 16:24:41 -050077 std::move(colorSpaceXform),
78 matrix, p));
79 }
80
Brian Salomond3b65972017-03-22 12:05:03 -040081 ~GrSimpleTextureEffect() override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000082
mtklein36352bf2015-03-25 18:17:31 -070083 const char* name() const override { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000084
bsalomon@google.com68b58c92013-01-17 16:50:08 +000085private:
Robert Phillips296b1cc2017-03-15 10:42:12 -040086 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
87 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
88 GrSamplerParams::FilterMode);
Robert Phillips40fd7c92017-01-30 08:06:27 -050089
Robert Phillips296b1cc2017-03-15 10:42:12 -040090 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
91 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
92 const GrSamplerParams&);
Robert Phillips901f29a2017-01-24 16:24:41 -050093
egdaniel57d3b032015-11-13 11:57:27 -080094 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070095
Brian Salomon94efbf52016-11-29 13:43:05 -050096 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070097
mtklein36352bf2015-03-25 18:17:31 -070098 bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000099
joshualittb0a8a372014-09-23 09:50:21 -0700100 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000101
102 typedef GrSingleTextureEffect INHERITED;
103};
104
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000105#endif