blob: 6f3716e15ec63883ae3300ad5fa113f3485963c6 [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,
30 const SkPMColor4f& color, bool wideColor,
Greg Daniel9715b6c2019-12-10 15:03:10 -050031 const GrSurfaceProxyView* views,
32 int numActiveViews,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050033 const GrSamplerState& p, GrMaskFormat format,
34 const SkMatrix& localMatrix, bool usesW) {
Greg Daniel9715b6c2019-12-10 15:03:10 -050035 return arena->make<GrBitmapTextGeoProc>(caps, color, wideColor, views, numActiveViews,
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050036 p, format, localMatrix, usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050037 }
38
Brian Salomond3b65972017-03-22 12:05:03 -040039 ~GrBitmapTextGeoProc() override {}
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000040
mtklein36352bf2015-03-25 18:17:31 -070041 const char* name() const override { return "Texture"; }
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000042
Brian Salomon92be2f72018-06-19 14:33:47 -040043 const Attribute& inPosition() const { return fInPosition; }
44 const Attribute& inColor() const { return fInColor; }
45 const Attribute& inTextureCoords() const { return fInTextureCoords; }
joshualitt02b05012015-02-11 06:56:30 -080046 GrMaskFormat maskFormat() const { return fMaskFormat; }
Brian Osmancf860852018-10-31 14:04:39 -040047 const SkPMColor4f& color() const { return fColor; }
Brian Salomon92be2f72018-06-19 14:33:47 -040048 bool hasVertexColor() const { return fInColor.isInitialized(); }
joshualitte3ababe2015-05-15 07:56:07 -070049 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Jim Van Verthb515ae72018-05-23 16:44:55 -040050 bool usesW() const { return fUsesW; }
Brian Salomon2638f3d2019-10-22 12:20:37 -040051 const SkISize& atlasDimensions() const { return fAtlasDimensions; }
joshualitt249af152014-09-15 11:41:13 -070052
Greg Daniel9715b6c2019-12-10 15:03:10 -050053 void addNewViews(const GrSurfaceProxyView*, int numActiveViews, const GrSamplerState&);
Jim Van Vertheafa64b2017-09-18 10:05:00 -040054
Brian Salomon94efbf52016-11-29 13:43:05 -050055 void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000056
Brian Salomon94efbf52016-11-29 13:43:05 -050057 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000058
59private:
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050060 friend class ::SkArenaAlloc; // for access to ctor
61
Brian Osmanc906d252018-12-04 11:17:46 -050062 GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor,
Greg Daniel9715b6c2019-12-10 15:03:10 -050063 const GrSurfaceProxyView* views, int numViews,
Brian Osmancf860852018-10-31 14:04:39 -040064 const GrSamplerState& params, GrMaskFormat format,
Jim Van Verthb515ae72018-05-23 16:44:55 -040065 const SkMatrix& localMatrix, bool usesW);
Robert Phillipsdbc8eeb2017-02-21 10:04:31 -050066
Brian Salomonf7dcd762018-07-30 14:48:15 -040067 const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
Brian Salomon92be2f72018-06-19 14:33:47 -040068
Brian Osmancf860852018-10-31 14:04:39 -040069 SkPMColor4f fColor;
joshualitte3ababe2015-05-15 07:56:07 -070070 SkMatrix fLocalMatrix;
Jim Van Verthb515ae72018-05-23 16:44:55 -040071 bool fUsesW;
Brian Salomon2638f3d2019-10-22 12:20:37 -040072 SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[].
Jim Van Vertha950b632017-09-12 11:54:11 -040073 TextureSampler fTextureSamplers[kMaxTextures];
Brian Salomon92be2f72018-06-19 14:33:47 -040074 Attribute fInPosition;
75 Attribute fInColor;
76 Attribute fInTextureCoords;
joshualitt02b05012015-02-11 06:56:30 -080077 GrMaskFormat fMaskFormat;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000078
Brian Salomon0c26a9d2017-07-06 10:09:38 -040079 GR_DECLARE_GEOMETRY_PROCESSOR_TEST
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000080
joshualitt249af152014-09-15 11:41:13 -070081 typedef GrGeometryProcessor INHERITED;
commit-bot@chromium.org76eaf742013-09-30 18:41:38 +000082};
83
84#endif