| 1 | /* |
| 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 | |
| 8 | #ifndef GrBitmapTextGeoProc_DEFINED |
| 9 | #define GrBitmapTextGeoProc_DEFINED |
| 10 | |
| 11 | #include "src/core/SkArenaAlloc.h" |
| 12 | #include "src/gpu/GrGeometryProcessor.h" |
| 13 | #include "src/gpu/GrProcessor.h" |
| 14 | |
| 15 | class GrGLBitmapTextGeoProc; |
| 16 | class GrInvariantOutput; |
| 17 | class GrSurfaceProxyView; |
| 18 | |
| 19 | /** |
| 20 | * The output color of this effect is a modulation of the input color and a sample from a texture. |
| 21 | * It allows explicit specification of the filtering and wrap modes (GrSamplerState). The input |
| 22 | * coords are a custom attribute. |
| 23 | */ |
| 24 | class GrBitmapTextGeoProc : public GrGeometryProcessor { |
| 25 | public: |
| 26 | static constexpr int kMaxTextures = 4; |
| 27 | |
| 28 | static GrGeometryProcessor* Make(SkArenaAlloc* arena, |
| 29 | const GrShaderCaps& caps, |
| 30 | const SkPMColor4f& color, |
| 31 | bool wideColor, |
| 32 | const GrSurfaceProxyView* views, |
| 33 | int numActiveViews, |
| 34 | GrSamplerState p, |
| 35 | GrMaskFormat format, |
| 36 | const SkMatrix& localMatrix, |
| 37 | bool usesW) { |
| 38 | return arena->make<GrBitmapTextGeoProc>(caps, color, wideColor, views, numActiveViews, |
| 39 | p, format, localMatrix, usesW); |
| 40 | } |
| 41 | |
| 42 | ~GrBitmapTextGeoProc() override {} |
| 43 | |
| 44 | const char* name() const override { return "Texture" ; } |
| 45 | |
| 46 | const Attribute& inPosition() const { return fInPosition; } |
| 47 | const Attribute& inColor() const { return fInColor; } |
| 48 | const Attribute& inTextureCoords() const { return fInTextureCoords; } |
| 49 | GrMaskFormat maskFormat() const { return fMaskFormat; } |
| 50 | const SkPMColor4f& color() const { return fColor; } |
| 51 | bool hasVertexColor() const { return fInColor.isInitialized(); } |
| 52 | const SkMatrix& localMatrix() const { return fLocalMatrix; } |
| 53 | bool usesW() const { return fUsesW; } |
| 54 | const SkISize& atlasDimensions() const { return fAtlasDimensions; } |
| 55 | |
| 56 | void addNewViews(const GrSurfaceProxyView*, int numActiveViews, GrSamplerState); |
| 57 | |
| 58 | void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override; |
| 59 | |
| 60 | GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps& caps) const override; |
| 61 | |
| 62 | private: |
| 63 | friend class ::SkArenaAlloc; // for access to ctor |
| 64 | |
| 65 | GrBitmapTextGeoProc(const GrShaderCaps&, const SkPMColor4f&, bool wideColor, |
| 66 | const GrSurfaceProxyView* views, int numViews, GrSamplerState params, |
| 67 | GrMaskFormat format, const SkMatrix& localMatrix, bool usesW); |
| 68 | |
| 69 | const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; } |
| 70 | |
| 71 | SkPMColor4f fColor; |
| 72 | SkMatrix fLocalMatrix; |
| 73 | bool fUsesW; |
| 74 | SkISize fAtlasDimensions; // dimensions for all textures used with fTextureSamplers[]. |
| 75 | TextureSampler fTextureSamplers[kMaxTextures]; |
| 76 | Attribute fInPosition; |
| 77 | Attribute fInColor; |
| 78 | Attribute fInTextureCoords; |
| 79 | GrMaskFormat fMaskFormat; |
| 80 | |
| 81 | GR_DECLARE_GEOMETRY_PROCESSOR_TEST |
| 82 | |
| 83 | typedef GrGeometryProcessor INHERITED; |
| 84 | }; |
| 85 | |
| 86 | #endif |
| 87 | |