blob: 3c29c4a58535e99315eb19560a8e2c1516666dac [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrGeometryProcessor.h"
12#include "src/gpu/GrProcessor.h"
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000013
egdaniel309e3462014-12-09 10:35:58 -080014class GrGLBitmapTextGeoProc;
Brian Salomon1127c0b2019-06-13 20:22:10 +000015class 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 Osmanc906d252018-12-04 11:17:46 -050026 static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps,
27 const SkPMColor4f& color, bool wideColor,
Robert Phillips4bc70112018-03-01 10:24:02 -050028 const sk_sp<GrTextureProxy>* proxies,
Jim Van Verthcbeae032018-05-16 14:54:41 -040029 int numActiveProxies,
Brian Salomon2bbdcc42017-09-07 12:36:34 -040030 const GrSamplerState& p, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040031 const SkMatrix& localMatrix, bool usesW) {
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050032 return sk_sp<GrGeometryProcessor>(
Brian Osmanc906d252018-12-04 11:17:46 -050033 new GrBitmapTextGeoProc(caps, color, wideColor, proxies, numActiveProxies, p, format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040034 localMatrix, usesW));
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050035 }
36
Brian Salomond3b65972017-03-22 12:05:03 -040037 ~GrBitmapTextGeoProc() override {}
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000038
mtklein36352bf2015-03-25 18:17:31 -070039 const char* name() const override { return "Texture"; }
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000040
Brian Salomon92be2f72018-06-19 14:33:47 -040041 const Attribute& inPosition() const { return fInPosition; }
42 const Attribute& inColor() const { return fInColor; }
43 const Attribute& inTextureCoords() const { return fInTextureCoords; }
joshualitt02b05012015-02-11 06:56:30 -080044 GrMaskFormat maskFormat() const { return fMaskFormat; }
Brian Osmancf860852018-10-31 14:04:39 -040045 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040046 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte3ababe2015-05-15 07:56:07 -070047 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Jim Van Verthb515ae72018-05-23 16:44:55 -040048 bool usesW() const { return fUsesW; }
Brian Salomon7eae3e02018-08-07 14:02:38 +000049 const SkISize& atlasSize() const { return fAtlasSize; }
joshualitt249af152014-09-15 11:41:13 -070050
Jim Van Verthcbeae032018-05-16 14:54:41 -040051 void addNewProxies(const sk_sp<GrTextureProxy>*, int numActiveProxies, const GrSamplerState&);
Jim Van Vertheafa64b2017-09-18 10:05:00 -040052
Brian Salomon94efbf52016-11-29 13:43:05 -050053 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000054
Brian Salomon94efbf52016-11-29 13:43:05 -050055 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000056
57private:
Brian Osmanc906d252018-12-04 11:17:46 -050058 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
Brian Osmancf860852018-10-31 14:04:39 -040059 const sk_sp<GrTextureProxy>* proxies, int numProxies,
60 const GrSamplerState& params, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040061 const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050062
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