blob: c6912d37e04b961c3c5042006aa49f3b7191323d [file] [log] [blame]
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +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
egdaniel309e3462014-12-09 10:35:58 -08008#ifndef GrBitmapTextGeoProc_DEFINED
9#define GrBitmapTextGeoProc_DEFINED
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000010
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050011#include "src/core/SkArenaAlloc.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/GrGeometryProcessor.h"
13#include "src/gpu/GrProcessor.h"
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000014
egdaniel309e3462014-12-09 10:35:58 -080015class GrGLBitmapTextGeoProc;
Brian Salomon1127c0b2019-06-13 20:22:10 +000016class GrInvariantOutput;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000017
18/**
19 * The output color of this effect is a modulation of the input color and a sample from a texture.
Brian Salomon2bbdcc42017-09-07 12:36:34 -040020 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000021 * coords are a custom attribute.
22 */
egdaniel309e3462014-12-09 10:35:58 -080023class GrBitmapTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000024public:
Brian Salomon7eae3e02018-08-07 14:02:38 +000025 static constexpr int kMaxTextures = 4;
Jim Van Vertha950b632017-09-12 11:54:11 -040026
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050027 static GrGeometryProcessor* Make(SkArenaAlloc* arena,
28 const GrShaderCaps& caps,
29 const SkPMColor4f& color, bool wideColor,
30 const sk_sp<GrTextureProxy>* proxies,
31 int numActiveProxies,
32 const GrSamplerState& p, GrMaskFormat format,
33 const SkMatrix& localMatrix, bool usesW) {
34 return arena->make<GrBitmapTextGeoProc>(caps, color, wideColor, proxies, numActiveProxies,
35 p, format, localMatrix, usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050036 }
37
Brian Salomond3b65972017-03-22 12:05:03 -040038 ~GrBitmapTextGeoProc() override {}
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000039
mtklein36352bf2015-03-25 18:17:31 -070040 const char* name() const override { return "Texture"; }
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000041
Brian Salomon92be2f72018-06-19 14:33:47 -040042 const Attribute& inPosition() const { return fInPosition; }
43 const Attribute& inColor() const { return fInColor; }
44 const Attribute& inTextureCoords() const { return fInTextureCoords; }
joshualitt02b05012015-02-11 06:56:30 -080045 GrMaskFormat maskFormat() const { return fMaskFormat; }
Brian Osmancf860852018-10-31 14:04:39 -040046 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040047 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte3ababe2015-05-15 07:56:07 -070048 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Jim Van Verthb515ae72018-05-23 16:44:55 -040049 bool usesW() const { return fUsesW; }
Brian Salomon2638f3d2019-10-22 12:20:37 -040050 const SkISize& atlasDimensions() const { return fAtlasDimensions; }
joshualitt249af152014-09-15 11:41:13 -070051
Jim Van Verthcbeae032018-05-16 14:54:41 -040052 void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
Jim Van Vertheafa64b2017-09-18 10:05:00 -040053
Brian Salomon94efbf52016-11-29 13:43:05 -050054 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000055
Brian Salomon94efbf52016-11-29 13:43:05 -050056 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000057
58private:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050059 friend class ::SkArenaAlloc; // for access to ctor
60
Brian Osmanc906d252018-12-04 11:17:46 -050061 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
Brian Osmancf860852018-10-31 14:04:39 -040062 const sk_sp<GrTextureProxy>* proxies, int numProxies,
63 const GrSamplerState& params, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040064 const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050065
Brian Salomonf7dcd762018-07-30 14:48:15 -040066 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
Brian Salomon92be2f72018-06-19 14:33:47 -040067
Brian Osmancf860852018-10-31 14:04:39 -040068 SkPMColor4f fColor;
joshualitte3ababe2015-05-15 07:56:07 -070069 SkMatrix fLocalMatrix;
Jim Van Verthb515ae72018-05-23 16:44:55 -040070 bool fUsesW;
Brian Salomon2638f3d2019-10-22 12:20:37 -040071 SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[].
Jim Van Vertha950b632017-09-12 11:54:11 -040072 TextureSampler fTextureSamplers[kMaxTextures];
Brian Salomon92be2f72018-06-19 14:33:47 -040073 Attribute fInPosition;
74 Attribute fInColor;
75 Attribute fInTextureCoords;
joshualitt02b05012015-02-11 06:56:30 -080076 GrMaskFormat fMaskFormat;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000077
Brian Salomon0c26a9d2017-07-06 10:09:38 -040078 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000079
joshualitt249af152014-09-15 11:41:13 -070080 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000081};
82
83#endif