GrAARectRenderer.h revision fd03d4a829efe2d77a712fd991927c55f59a2ffe
1f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com/*
2f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * Copyright 2012 Google Inc.
3f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com *
4f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
5f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * found in the LICENSE file.
6f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com */
7f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
8f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
9f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#ifndef GrAARectRenderer_DEFINED
10f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#define GrAARectRenderer_DEFINED
11f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
12f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#include "GrRefCnt.h"
13114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com#include "SkMatrix.h"
14fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org#include "SkRect.h"
15f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
16f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrGpu;
17f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrDrawTarget;
18f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrIndexBuffer;
19f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
20f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com/*
21f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com * This class wraps helper functions that draw AA rects (filled & stroked)
22f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com */
23f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comclass GrAARectRenderer : public GrRefCnt {
24f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.compublic:
254d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    SK_DECLARE_INST_COUNT(GrAARectRenderer)
26f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
27fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com    GrAARectRenderer()
28f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    : fAAFillRectIndexBuffer(NULL)
29f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    , fAAStrokeRectIndexBuffer(NULL) {
30f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    }
31f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
32f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    void reset();
33f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
34f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    ~GrAARectRenderer() {
35f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com        this->reset();
36f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    }
37f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
38f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    // TODO: potentialy fuse the fill & stroke methods and differentiate
39df3695e5c72b3b4401e71ff259827d87bfe8a06frobertphillips@google.com    // between them by passing in strokeWidth (<0 means fill).
40f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
41f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    void fillAARect(GrGpu* gpu,
42f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com                    GrDrawTarget* target,
43fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                    const SkRect& rect,
44b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                    const SkMatrix& combinedMatrix,
45fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                    const SkRect& devRect,
46b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                    bool useVertexCoverage) {
47b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#ifdef SHADER_AA_FILL_RECT
48b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com        if (combinedMatrix.rectStaysRect()) {
49b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com            this->shaderFillAlignedAARect(gpu, target,
50114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com                                          rect, combinedMatrix);
51b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com        } else {
52b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com            this->shaderFillAARect(gpu, target,
53114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com                                   rect, combinedMatrix);
54b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com        }
55b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#else
56b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com        this->geometryFillAARect(gpu, target,
574b140b5fbedcb75d0b9587fa9d232ce54d9c7eb5robertphillips@google.com                                 rect, combinedMatrix,
58afd1cba5237eba5394ee011106eede9f6c8074c8robertphillips@google.com                                 devRect, useVertexCoverage);
59b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com#endif
60b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    }
61df3695e5c72b3b4401e71ff259827d87bfe8a06frobertphillips@google.com
62f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    void strokeAARect(GrGpu* gpu,
63f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com                      GrDrawTarget* target,
64fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                      const SkRect& rect,
6518136d1cf284bea42ae574e491fa8032aef4e7ddrobertphillips@google.com                      const SkMatrix& combinedMatrix,
66fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                      const SkRect& devRect,
6783d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                      SkScalar width,
68f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com                      bool useVertexCoverage);
69f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
7083d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com    // First rect is outer; second rect is inner
7183d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com    void fillAANestedRects(GrGpu* gpu,
7283d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                           GrDrawTarget* target,
7383d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                           const SkRect rects[2],
7483d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                           const SkMatrix& combinedMatrix,
7583d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                           bool useVertexCoverage);
7683d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com
77f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.comprivate:
78f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    GrIndexBuffer*              fAAFillRectIndexBuffer;
79f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    GrIndexBuffer*              fAAStrokeRectIndexBuffer;
80f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
81f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
82f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
83f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    static int aaStrokeRectIndexCount();
84f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com    GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
854d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com
86b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    // TODO: Remove the useVertexCoverage boolean. Just use it all the time
87b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    // since we now have a coverage vertex attribute
88b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    void geometryFillAARect(GrGpu* gpu,
89b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                            GrDrawTarget* target,
90fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                            const SkRect& rect,
914b140b5fbedcb75d0b9587fa9d232ce54d9c7eb5robertphillips@google.com                            const SkMatrix& combinedMatrix,
92fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                            const SkRect& devRect,
93b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                            bool useVertexCoverage);
94b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com
95b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    void shaderFillAARect(GrGpu* gpu,
96b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                          GrDrawTarget* target,
97fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                          const SkRect& rect,
98114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com                          const SkMatrix& combinedMatrix);
99b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com
100b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com    void shaderFillAlignedAARect(GrGpu* gpu,
101b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com                                 GrDrawTarget* target,
102fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org                                 const SkRect& rect,
103114eb9e69942c11635380284deb9cc91eaab3632robertphillips@google.com                                 const SkMatrix& combinedMatrix);
104b19cb7f36785f3ad3b1512c342fc662ab79e3fcarobertphillips@google.com
10583d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com    void geometryStrokeAARect(GrGpu* gpu,
10683d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                              GrDrawTarget* target,
10783d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                              const SkRect& devOutside,
10883d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                              const SkRect& devInside,
10983d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com                              bool useVertexCoverage);
11083d1a68141830cbfa0d5fca6f9c9bccf9c978ad2robertphillips@google.com
1114d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com    typedef GrRefCnt INHERITED;
112f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com};
113f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com
114f6747b0b90b3a270ec7b7bdfdc211cf5c19f28c2robertphillips@google.com#endif // GrAARectRenderer_DEFINED
115