blob: dbc1e5847e596524b6d42616f6f2bc567ecc2727 [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
8#ifndef GrCCPRPathProcessor_DEFINED
9#define GrCCPRPathProcessor_DEFINED
10
11#include "GrGeometryProcessor.h"
12#include "SkPath.h"
13#include <array>
14
15class GrOnFlushResourceProvider;
16class GrShaderCaps;
17
18/**
19 * This class draws AA paths using the coverage count masks produced by GrCCPRCoverageProcessor.
20 *
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 */
27class GrCCPRPathProcessor : public GrGeometryProcessor {
28public:
29 static constexpr int kPerInstanceIndexCount = 6 * 3;
30 static sk_sp<GrBuffer> FindOrMakeIndexBuffer(GrOnFlushResourceProvider*);
31 static sk_sp<GrBuffer> FindOrMakeVertexBuffer(GrOnFlushResourceProvider*);
32
33 enum class InstanceAttribs {
34 kDevBounds,
35 kDevBounds45,
36 kViewMatrix, // FIXME: This causes a lot of duplication. It could move to a texel buffer.
37 kViewTranslate,
38 kAtlasOffset,
39 kColor
40 };
41 static constexpr int kNumInstanceAttribs = 1 + (int)InstanceAttribs::kColor;
42
43 struct Instance {
44 SkRect fDevBounds;
45 SkRect fDevBounds45; // Bounding box in "| 1 -1 | * devCoords" space.
46 // | 1 1 |
47 std::array<float, 4> fViewMatrix; // {kScaleX, kSkewy, kSkewX, kScaleY}
48 std::array<float, 2> fViewTranslate;
49 std::array<int32_t, 2> fAtlasOffset;
50 uint32_t fColor;
51
52 GR_STATIC_ASSERT(SK_SCALAR_IS_FLOAT);
53 };
54
55 GR_STATIC_ASSERT(4 * 17 == sizeof(Instance)); // FIXME: 4 * 16 by making fAtlasOffset int16_t's.
56
57 GrCCPRPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType,
58 const GrShaderCaps&);
59
60 const char* name() const override { return "GrCCPRPathProcessor"; }
Robert Phillipse44ef102017-07-21 15:37:19 -040061 const GrSurfaceProxy* atlasProxy() const { return fAtlasAccess.proxy(); }
Chris Dalton1a325d22017-07-14 15:17:41 -060062 const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); }
63 SkPath::FillType fillType() const { return fFillType; }
64 const Attribute& getInstanceAttrib(InstanceAttribs attribID) const {
65 const Attribute& attrib = this->getAttrib((int)attribID);
66 SkASSERT(Attribute::InputRate::kPerInstance == attrib.fInputRate);
67 return attrib;
68 }
69 const Attribute& getEdgeNormsAttrib() const {
70 SkASSERT(1 + kNumInstanceAttribs == this->numAttribs());
71 const Attribute& attrib = this->getAttrib(kNumInstanceAttribs);
72 SkASSERT(Attribute::InputRate::kPerVertex == attrib.fInputRate);
73 return attrib;
74 }
75
76 void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
77 GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
78
79private:
80 const SkPath::FillType fFillType;
81 TextureSampler fAtlasAccess;
82
83 typedef GrGeometryProcessor INHERITED;
84};
85
86#endif