blob: 47893266da67b8fae534ed48c6761faefc917ee3 [file] [log] [blame]
Chris Dalton1a325d22017-07-14 15:17:41 -06001/*
2 * Copyright 2017 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
Chris Dalton383a2ef2018-01-08 17:21:41 -05008#ifndef GrCCPathProcessor_DEFINED
9#define GrCCPathProcessor_DEFINED
Chris Dalton1a325d22017-07-14 15:17:41 -060010
Chris Dalton27059d32018-01-23 14:06:50 -070011#include "GrCaps.h"
Chris Dalton1a325d22017-07-14 15:17:41 -060012#include "GrGeometryProcessor.h"
13#include "SkPath.h"
14#include <array>
15
16class GrOnFlushResourceProvider;
Chris Daltond925f2d2018-05-07 19:19:06 -060017class GrOpFlushState;
18class GrPipeline;
Chris Dalton1a325d22017-07-14 15:17:41 -060019
20/**
Chris Dalton383a2ef2018-01-08 17:21:41 -050021 * This class draws AA paths using the coverage count masks produced by GrCCCoverageProcessor.
Chris Dalton1a325d22017-07-14 15:17:41 -060022 *
23 * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and
24 * fill rule.
25 *
Chris Daltond925f2d2018-05-07 19:19:06 -060026 * To draw paths, the caller must set up an instance buffer as detailed below, then call drawPaths()
27 * providing its own instance buffer alongside the buffers found by calling FindIndexBuffer/
28 * FindVertexBuffer.
Chris Dalton1a325d22017-07-14 15:17:41 -060029 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050030class GrCCPathProcessor : public GrGeometryProcessor {
Chris Dalton1a325d22017-07-14 15:17:41 -060031public:
Chris Dalton1a325d22017-07-14 15:17:41 -060032 enum class InstanceAttribs {
33 kDevBounds,
34 kDevBounds45,
Chris Dalton1a325d22017-07-14 15:17:41 -060035 kAtlasOffset,
36 kColor
37 };
38 static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor;
39
40 struct Instance {
Chris Dalton13235d82018-05-23 22:51:22 +000041 SkRect fDevBounds;
Chris Daltona3e92712017-12-04 11:45:51 -070042 SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space.
43 // | 1 1 |
Chris Daltona3e92712017-12-04 11:45:51 -070044 std::array<int16_t, 2> fAtlasOffset;
45 uint32_t fColor;
Chris Dalton1a325d22017-07-14 15:17:41 -060046
Chris Dalton13235d82018-05-23 22:51:22 +000047 GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
Chris Dalton1a325d22017-07-14 15:17:41 -060048 };
49
Chris Dalton1c548942018-05-22 13:09:48 -060050 GR_STATIC_ASSERT(4 * 10 == sizeof(Instance));
Chris Dalton1a325d22017-07-14 15:17:41 -060051
Chris Dalton5d2de082017-12-19 10:40:23 -070052 static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*);
Chris Dalton27059d32018-01-23 14:06:50 -070053 static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*);
Chris Dalton5d2de082017-12-19 10:40:23 -070054
Chris Dalton13235d82018-05-23 22:51:22 +000055 GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType,
Chris Dalton1c548942018-05-22 13:09:48 -060056 const SkMatrix& viewMatrixIfUsingLocalCoords = SkMatrix::I());
Chris Dalton1a325d22017-07-14 15:17:41 -060057
Chris Dalton383a2ef2018-01-08 17:21:41 -050058 const char* name() const override { return "GrCCPathProcessor"; }
Robert Phillipse44ef102017-07-21 15:37:19 -040059 const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); }
Chris Dalton1a325d22017-07-14 15:17:41 -060060 const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); }
Chris Dalton1c548942018-05-22 13:09:48 -060061 const SkMatrix& localMatrix() const { return fLocalMatrix; }
Chris Dalton13235d82018-05-23 22:51:22 +000062 SkPath::FillType fillType() const { return fFillType; }
Chris Dalton1a325d22017-07-14 15:17:41 -060063 const Attribute& getInstanceAttrib(InstanceAttribs attribID) const {
64 const Attribute& attrib = this->getAttrib((int)attribID);
65 SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate);
66 return attrib;
67 }
68 const Attribute& getEdgeNormsAttrib() const {
69 SkASSERT(1 + kNumInstanceAttribs == this->numAttribs());
70 const Attribute& attrib = this->getAttrib(kNumInstanceAttribs);
71 SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate);
72 return attrib;
73 }
74
Chris Dalton13235d82018-05-23 22:51:22 +000075 void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
Chris Dalton1a325d22017-07-14 15:17:41 -060076 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
77
Chris Daltond925f2d2018-05-07 19:19:06 -060078 void drawPaths(GrOpFlushState*, const GrPipeline&, const GrBuffer* indexBuffer,
79 const GrBuffer* vertexBuffer, GrBuffer* instanceBuffer, int baseInstance,
80 int endInstance, const SkRect& bounds) const;
81
Chris Dalton1a325d22017-07-14 15:17:41 -060082private:
Chris Dalton13235d82018-05-23 22:51:22 +000083 const SkPath::FillType fFillType;
Chris Daltona3e92712017-12-04 11:45:51 -070084 const TextureSampler fAtlasAccess;
Chris Dalton1c548942018-05-22 13:09:48 -060085 SkMatrix fLocalMatrix;
Chris Dalton1a325d22017-07-14 15:17:41 -060086
87 typedef GrGeometryProcessor INHERITED;
88};
89
Chris Dalton1a325d22017-07-14 15:17:41 -060090#endif