blob: 55e59258a8152009c2404fecd529a75b18511180 [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 Osmancf860852018-10-31 14:04:39 -040026 static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps, const SkPMColor4f& 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 Osmancf860852018-10-31 14:04:39 -040044 const SkPMColor4f& 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 Osmancf860852018-10-31 14:04:39 -040057 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&,
58 const sk_sp<GrTextureProxy>* proxies, int numProxies,
59 const GrSamplerState& params, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040060 const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050061
Brian Salomon92be2f72018-06-19 14:33:47 -040062 const Attribute& onVertexAttribute(int i) const override;
Brian Salomonf7dcd762018-07-30 14:48:15 -040063 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
Brian Salomon92be2f72018-06-19 14:33:47 -040064
Brian Osmancf860852018-10-31 14:04:39 -040065 SkPMColor4f fColor;
joshualitte3ababe2015-05-15 07:56:07 -070066 SkMatrix fLocalMatrix;
Jim Van Verthb515ae72018-05-23 16:44:55 -040067 bool fUsesW;
Brian Salomon7eae3e02018-08-07 14:02:38 +000068 SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
Jim Van Vertha950b632017-09-12 11:54:11 -040069 TextureSampler fTextureSamplers[kMaxTextures];
Brian Salomon92be2f72018-06-19 14:33:47 -040070 Attribute fInPosition;
71 Attribute fInColor;
72 Attribute fInTextureCoords;
joshualitt02b05012015-02-11 06:56:30 -080073 GrMaskFormat fMaskFormat;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000074
Brian Salomon0c26a9d2017-07-06 10:09:38 -040075 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000076
joshualitt249af152014-09-15 11:41:13 -070077 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000078};
79
80#endif