blob: 57abe5f47423b07e81c08e948402b3afd2024b88 [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;
Greg Daniel9715b6c2019-12-10 15:03:10 -050017class GrSurfaceProxyView;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000018
19/**
20 * 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 -040021 * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000022 * coords are a custom attribute.
23 */
egdaniel309e3462014-12-09 10:35:58 -080024class GrBitmapTextGeoProc : public GrGeometryProcessor {
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000025public:
Brian Salomon7eae3e02018-08-07 14:02:38 +000026 static constexpr int kMaxTextures = 4;
Jim Van Vertha950b632017-09-12 11:54:11 -040027
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050028 static GrGeometryProcessor* Make(SkArenaAlloc* arena,
29 const GrShaderCaps& caps,
Brian Salomonccb61422020-01-09 10:46:36 -050030 const SkPMColor4f& color,
31 bool wideColor,
Greg Daniel9715b6c2019-12-10 15:03:10 -050032 const GrSurfaceProxyView* views,
33 int numActiveViews,
Brian Salomonccb61422020-01-09 10:46:36 -050034 GrSamplerState p,
35 GrMaskFormat format,
36 const SkMatrix& localMatrix,
37 bool usesW) {
Greg Daniel9715b6c2019-12-10 15:03:10 -050038 return arena->make<GrBitmapTextGeoProc>(caps, color, wideColor, views, numActiveViews,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050039 p, format, localMatrix, usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050040 }
41
Brian Salomond3b65972017-03-22 12:05:03 -040042 ~GrBitmapTextGeoProc() override {}
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000043
mtklein36352bf2015-03-25 18:17:31 -070044 const char* name() const override { return "Texture"; }
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000045
Brian Salomon92be2f72018-06-19 14:33:47 -040046 const Attribute& inPosition() const { return fInPosition; }
47 const Attribute& inColor() const { return fInColor; }
48 const Attribute& inTextureCoords() const { return fInTextureCoords; }
joshualitt02b05012015-02-11 06:56:30 -080049 GrMaskFormat maskFormat() const { return fMaskFormat; }
Brian Osmancf860852018-10-31 14:04:39 -040050 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040051 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte3ababe2015-05-15 07:56:07 -070052 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Jim Van Verthb515ae72018-05-23 16:44:55 -040053 bool usesW() const { return fUsesW; }
Brian Salomon2638f3d2019-10-22 12:20:37 -040054 const SkISize& atlasDimensions() const { return fAtlasDimensions; }
joshualitt249af152014-09-15 11:41:13 -070055
Brian Salomonccb61422020-01-09 10:46:36 -050056 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState);
Jim Van Vertheafa64b2017-09-18 10:05:00 -040057
Brian Salomon94efbf52016-11-29 13:43:05 -050058 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000059
Brian Salomon94efbf52016-11-29 13:43:05 -050060 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000061
62private:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050063 friend class ::SkArenaAlloc; // for access to ctor
64
Brian Osmanc906d252018-12-04 11:17:46 -050065 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
Brian Salomonccb61422020-01-09 10:46:36 -050066 const GrSurfaceProxyView* views, int numViews, GrSamplerState params,
67 GrMaskFormat format, const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050068
Brian Salomonf7dcd762018-07-30 14:48:15 -040069 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
Brian Salomon92be2f72018-06-19 14:33:47 -040070
Brian Osmancf860852018-10-31 14:04:39 -040071 SkPMColor4f fColor;
joshualitte3ababe2015-05-15 07:56:07 -070072 SkMatrix fLocalMatrix;
Jim Van Verthb515ae72018-05-23 16:44:55 -040073 bool fUsesW;
Brian Salomon2638f3d2019-10-22 12:20:37 -040074 SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[].
Jim Van Vertha950b632017-09-12 11:54:11 -040075 TextureSampler fTextureSamplers[kMaxTextures];
Brian Salomon92be2f72018-06-19 14:33:47 -040076 Attribute fInPosition;
77 Attribute fInColor;
78 Attribute fInTextureCoords;
joshualitt02b05012015-02-11 06:56:30 -080079 GrMaskFormat fMaskFormat;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000080
Brian Salomon0c26a9d2017-07-06 10:09:38 -040081 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000082
joshualitt249af152014-09-15 11:41:13 -070083 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000084};
85
86#endif