blob: 8edec81a83cb9048ec4208b8987354aa505e0eed [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) {
28 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040029 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
30 std::move(colorSpaceXform), matrix,
Robert Phillips40fd7c92017-01-30 08:06:27 -050031 GrSamplerParams::kNone_FilterMode));
32 }
33
34 /* clamp mode */
Robert Phillips296b1cc2017-03-15 10:42:12 -040035 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
36 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050037 sk_sp<GrColorSpaceXform> colorSpaceXform,
38 const SkMatrix& matrix,
39 GrSamplerParams::FilterMode filterMode) {
40 return sk_sp<GrFragmentProcessor>(
Robert Phillips296b1cc2017-03-15 10:42:12 -040041 new GrSimpleTextureEffect(resourceProvider, std::move(proxy),
42 std::move(colorSpaceXform),
Robert Phillips901f29a2017-01-24 16:24:41 -050043 matrix, filterMode));
44 }
45
Robert Phillips296b1cc2017-03-15 10:42:12 -040046 static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
47 sk_sp<GrTextureProxy> proxy,
Robert Phillips901f29a2017-01-24 16:24:41 -050048 sk_sp<GrColorSpaceXform> colorSpaceXform,
49 const SkMatrix& matrix,
50 const GrSamplerParams& p) {
Robert Phillips296b1cc2017-03-15 10:42:12 -040051 return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(resourceProvider,
52 std::move(proxy),
Robert Phillips901f29a2017-01-24 16:24:41 -050053 std::move(colorSpaceXform),
54 matrix, p));
55 }
56
Brian Salomond3b65972017-03-22 12:05:03 -040057 ~GrSimpleTextureEffect() override {}
bsalomon@google.com68b58c92013-01-17 16:50:08 +000058
mtklein36352bf2015-03-25 18:17:31 -070059 const char* name() const override { return "SimpleTexture"; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000060
bsalomon@google.com68b58c92013-01-17 16:50:08 +000061private:
Robert Phillips296b1cc2017-03-15 10:42:12 -040062 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
63 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
64 GrSamplerParams::FilterMode);
Robert Phillips40fd7c92017-01-30 08:06:27 -050065
Robert Phillips296b1cc2017-03-15 10:42:12 -040066 GrSimpleTextureEffect(GrResourceProvider*, sk_sp<GrTextureProxy>,
67 sk_sp<GrColorSpaceXform>, const SkMatrix& matrix,
68 const GrSamplerParams&);
Robert Phillips901f29a2017-01-24 16:24:41 -050069
egdaniel57d3b032015-11-13 11:57:27 -080070 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
wangyixb1daa862015-08-18 11:29:31 -070071
Brian Salomon94efbf52016-11-29 13:43:05 -050072 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
wangyix4b3050b2015-08-04 07:59:37 -070073
mtklein36352bf2015-03-25 18:17:31 -070074 bool onIsEqual(const GrFragmentProcessor& other) const override { return true; }
bsalomon@google.com68b58c92013-01-17 16:50:08 +000075
joshualittb0a8a372014-09-23 09:50:21 -070076 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
bsalomon@google.com68b58c92013-01-17 16:50:08 +000077
78 typedef GrSingleTextureEffect INHERITED;
79};
80
bsalomon@google.com68b58c92013-01-17 16:50:08 +000081#endif