blob: f023dd66dad589b112fad1de0cebe33f5fe14b5a [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;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000015
16/**
17 * 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 -040018 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000019 * coords are a custom attribute.
20 */
egdaniel309e3462014-12-09 10:35:58 -080021class GrBitmapTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000022public:
Brian Salomon7eae3e02018-08-07 14:02:38 +000023 static constexpr int kMaxTextures = 4;
Jim Van Vertha950b632017-09-12 11:54:11 -040024
Brian Osmanc906d252018-12-04 11:17:46 -050025 static sk_sp<GrGeometryProcessor> Make(const GrShaderCaps& caps,
26 const SkPMColor4f& color, bool wideColor,
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 Osmanc906d252018-12-04 11:17:46 -050032 new GrBitmapTextGeoProc(caps, color, wideColor, 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 Osmanc906d252018-12-04 11:17:46 -050057 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
Brian Osmancf860852018-10-31 14:04:39 -040058 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 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 Osmancf860852018-10-31 14:04:39 -040064 SkPMColor4f 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