blob: 0b01ac79a3c5f101b016c017b5ae8250d42c5edc [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.
Robert Phillipseee4d6e2017-06-05 09:26:07 -040031 if (!proxy->instantiate(resourceProvider)) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040032 return nullptr;
33 }
34
Robert Phillips40fd7c92017-01-30 08:06:27 -050035 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040036 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
37 std::move(colorSpaceXform), matrix,
Robert Phillips40fd7c92017-01-30 08:06:27 -050038 GrSamplerParams::kNone_FilterMode));
39 }
40
41 /* clamp mode */
Robert Phillips296b1cc2017-03-15 10:42:12 -040042 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
43 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050044 sk_sp<GrColorSpaceXform> colorSpaceXform,
45 const SkMatrix& matrix,
46 GrSamplerParams::FilterMode filterMode) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040047 // MDB TODO: remove this instantiation once instantiation is pushed past the
48 // TextureSamplers. Instantiation failure in the TextureSampler is difficult to
49 // recover from.
Robert Phillipseee4d6e2017-06-05 09:26:07 -040050 if (!proxy->instantiate(resourceProvider)) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040051 return nullptr;
52 }
53
Robert Phillips901f29a2017-01-24 16:24:41 -050054 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040055 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
56 std::move(colorSpaceXform),
Robert Phillips901f29a2017-01-24 16:24:41 -050057 matrix, filterMode));
58 }
59
Robert Phillips296b1cc2017-03-15 10:42:12 -040060 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
61 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050062 sk_sp<GrColorSpaceXform> colorSpaceXform,
63 const SkMatrix& matrix,
64 const GrSamplerParams& p) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040065 // MDB TODO: remove this instantiation once instantiation is pushed past the
66 // TextureSamplers. Instantiation failure in the TextureSampler is difficult to
67 // recover from.
Robert Phillipseee4d6e2017-06-05 09:26:07 -040068 if (!proxy->instantiate(resourceProvider)) {
Robert Phillipsdd3b3f42017-04-24 10:57:28 -040069 return nullptr;
70 }
71
Robert Phillips296b1cc2017-03-15 10:42:12 -040072 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider,
73 std::move(proxy),
Robert Phillips901f29a2017-01-24 16:24:41 -050074 std::move(colorSpaceXform),
75 matrix, p));
76 }
77
Brian Salomond3b65972017-03-22 12:05:03 -040078 ~GrSimpleTextureEffect() override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000079
mtklein36352bf2015-03-25 18:17:31 -070080 const char* name() const override { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000081
bsalomon@google.com68b58c92013-01-17 16:50:08 +000082private:
Robert Phillips296b1cc2017-03-15 10:42:12 -040083 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
84 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
85 GrSamplerParams::FilterMode);
Robert Phillips40fd7c92017-01-30 08:06:27 -050086
Robert Phillips296b1cc2017-03-15 10:42:12 -040087 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
88 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
89 const GrSamplerParams&);
Robert Phillips901f29a2017-01-24 16:24:41 -050090
egdaniel57d3b032015-11-13 11:57:27 -080091 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070092
Brian Salomon94efbf52016-11-29 13:43:05 -050093 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070094
mtklein36352bf2015-03-25 18:17:31 -070095 bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000096
joshualittb0a8a372014-09-23 09:50:21 -070097 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000098
99 typedef GrSingleTextureEffect INHERITED;
100};
101
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000102#endif