blob: 42fd203f161972e07211c79a92fad992bf232930 [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
joshualittb0a8a372014-09-23 09:50:21 -070011#include "GrProcessor.h"
joshualitt249af152014-09-15 11:41:13 -070012#include "GrGeometryProcessor.h"
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000013
egdaniel309e3462014-12-09 10:35:58 -080014class GrGLBitmapTextGeoProc;
egdaniel605dd0f2014-11-12 08:35:25 -080015class GrInvariantOutput;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000016
17/**
18 * 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 -040019 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000020 * coords are a custom attribute.
21 */
egdaniel309e3462014-12-09 10:35:58 -080022class GrBitmapTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000023public:
Brian Salomon7eae3e02018-08-07 14:02:38 +000024 static constexpr int kMaxTextures = 4;
Jim Van Vertha950b632017-09-12 11:54:11 -040025
Brian Osman936fe7d2018-10-30 15:30:35 -040026 static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps, const GrColor4h& color,
Robert Phillips4bc70112018-03-01 10:24:02 -050027 const sk_sp<GrTextureProxy>* proxies,
Jim Van Verthcbeae032018-05-16 14:54:41 -040028 int numActiveProxies,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040029 const GrSamplerState& p, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040030 const SkMatrix& localMatrix, bool usesW) {
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050031 return sk_sp<GrGeometryProcessor>(
Brian Osman4a3f5c82018-09-18 16:16:38 -040032 new GrBitmapTextGeoProc(caps, color, proxies, numActiveProxies, p, format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040033 localMatrix, usesW));
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050034 }
35
Brian Salomond3b65972017-03-22 12:05:03 -040036 ~GrBitmapTextGeoProc() override {}
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000037
mtklein36352bf2015-03-25 18:17:31 -070038 const char* name() const override { return "Texture"; }
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000039
Brian Salomon92be2f72018-06-19 14:33:47 -040040 const Attribute& inPosition() const { return fInPosition; }
41 const Attribute& inColor() const { return fInColor; }
42 const Attribute& inTextureCoords() const { return fInTextureCoords; }
joshualitt02b05012015-02-11 06:56:30 -080043 GrMaskFormat maskFormat() const { return fMaskFormat; }
Brian Osman936fe7d2018-10-30 15:30:35 -040044 const GrColor4h& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040045 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte3ababe2015-05-15 07:56:07 -070046 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Jim Van Verthb515ae72018-05-23 16:44:55 -040047 bool usesW() const { return fUsesW; }
Brian Salomon7eae3e02018-08-07 14:02:38 +000048 const SkISize& atlasSize() const { return fAtlasSize; }
joshualitt249af152014-09-15 11:41:13 -070049
Jim Van Verthcbeae032018-05-16 14:54:41 -040050 void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
Jim Van Vertheafa64b2017-09-18 10:05:00 -040051
Brian Salomon94efbf52016-11-29 13:43:05 -050052 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000053
Brian Salomon94efbf52016-11-29 13:43:05 -050054 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000055
56private:
Brian Osman936fe7d2018-10-30 15:30:35 -040057 GrBitmapTextGeoProc(const GrShaderCaps&, const GrColor4h&, const sk_sp<GrTextureProxy>* proxies,
Brian Osman4a3f5c82018-09-18 16:16:38 -040058 int numProxies, const GrSamplerState& params, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040059 const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050060
Brian Salomon92be2f72018-06-19 14:33:47 -040061 const Attribute& onVertexAttribute(int i) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -040062 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
Brian Salomon92be2f72018-06-19 14:33:47 -040063
Brian Osman1be2b7c2018-10-29 16:07:15 -040064 GrColor4h fColor;
joshualitte3ababe2015-05-15 07:56:07 -070065 SkMatrix fLocalMatrix;
Jim Van Verthb515ae72018-05-23 16:44:55 -040066 bool fUsesW;
Brian Salomon7eae3e02018-08-07 14:02:38 +000067 SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
Jim Van Vertha950b632017-09-12 11:54:11 -040068 TextureSampler fTextureSamplers[kMaxTextures];
Brian Salomon92be2f72018-06-19 14:33:47 -040069 Attribute fInPosition;
70 Attribute fInColor;
71 Attribute fInTextureCoords;
joshualitt02b05012015-02-11 06:56:30 -080072 GrMaskFormat fMaskFormat;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000073
Brian Salomon0c26a9d2017-07-06 10:09:38 -040074 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000075
joshualitt249af152014-09-15 11:41:13 -070076 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000077};
78
79#endif