blob: 0b89358f25dc1c0abdef5278e7ef57df4bfa5a1b [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
11#include "GrGeometryProcessor.h"
12#include "SkPath.h"
13#include <array>
14
15class GrOnFlushResourceProvider;
16class GrShaderCaps;
17
18/**
Chris Dalton383a2ef2018-01-08 17:21:41 -050019 * This class draws AA paths using the coverage count masks produced by GrCCCoverageProcessor.
Chris Dalton1a325d22017-07-14 15:17:41 -060020 *
21 * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and
22 * fill rule.
23 *
24 * The caller must set up an instance buffer as detailed below, then draw indexed-instanced
25 * triangles using the index and vertex buffers provided by this class.
26 */
Chris Dalton383a2ef2018-01-08 17:21:41 -050027class GrCCPathProcessor : public GrGeometryProcessor {
Chris Dalton1a325d22017-07-14 15:17:41 -060028public:
29 static constexpr int kPerInstanceIndexCount = 6 * 3;
Chris Dalton1a325d22017-07-14 15:17:41 -060030
31 enum class InstanceAttribs {
32 kDevBounds,
33 kDevBounds45,
34 kViewMatrix, // FIXME: This causes a lot of duplication. It could move to a texel buffer.
35 kViewTranslate,
36 kAtlasOffset,
37 kColor
38 };
39 static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor;
40
41 struct Instance {
Chris Daltona3e92712017-12-04 11:45:51 -070042 SkRect fDevBounds;
43 SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space.
44 // | 1 1 |
45 std::array<float, 4> fViewMatrix; // {kScaleX, kSkewy, kSkewX, kScaleY}
46 std::array<float, 2> fViewTranslate;
47 std::array<int16_t, 2> fAtlasOffset;
48 uint32_t fColor;
Chris Dalton1a325d22017-07-14 15:17:41 -060049
50 GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
51 };
52
Chris Daltona045eea2017-10-24 13:22:10 -060053 GR_STATIC_ASSERT(4 * 16 == sizeof(Instance));
Chris Dalton1a325d22017-07-14 15:17:41 -060054
Chris Dalton5d2de082017-12-19 10:40:23 -070055 static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*);
56 static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*);
57
Chris Dalton383a2ef2018-01-08 17:21:41 -050058 GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType,
59 const GrShaderCaps&);
Chris Dalton1a325d22017-07-14 15:17:41 -060060
Chris Dalton383a2ef2018-01-08 17:21:41 -050061 const char* name() const override { return "GrCCPathProcessor"; }
Robert Phillipse44ef102017-07-21 15:37:19 -040062 const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); }
Chris Dalton1a325d22017-07-14 15:17:41 -060063 const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); }
64 SkPath::FillType fillType() const { return fFillType; }
65 const Attribute& getInstanceAttrib(InstanceAttribs attribID) const {
66 const Attribute& attrib = this->getAttrib((int)attribID);
67 SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate);
68 return attrib;
69 }
70 const Attribute& getEdgeNormsAttrib() const {
71 SkASSERT(1 + kNumInstanceAttribs == this->numAttribs());
72 const Attribute& attrib = this->getAttrib(kNumInstanceAttribs);
73 SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate);
74 return attrib;
75 }
76
77 void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
78 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
79
80private:
Chris Daltona3e92712017-12-04 11:45:51 -070081 const SkPath::FillType fFillType;
82 const TextureSampler fAtlasAccess;
Chris Dalton1a325d22017-07-14 15:17:41 -060083
84 typedef GrGeometryProcessor INHERITED;
85};
86
87#endif