blob: d6d07dde12cdee404b947cafe039dd50407a9e81 [file] [log] [blame]
robertphillips@google.comf6747b02012-06-12 00:32:28 +00001/*
2 * Copyright 2012 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
robertphillips@google.comf6747b02012-06-12 00:32:28 +00008#ifndef GrAARectRenderer_DEFINED
9#define GrAARectRenderer_DEFINED
10
joshualitt2e3b3e32014-12-09 13:31:14 -080011#include "GrColor.h"
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000012#include "SkMatrix.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000013#include "SkRect.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000014#include "SkRefCnt.h"
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000015#include "SkStrokeRec.h"
robertphillips@google.comf6747b02012-06-12 00:32:28 +000016
17class GrGpu;
joshualitt9853cce2014-11-17 14:22:48 -080018class GrDrawState;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000019class GrDrawTarget;
20class GrIndexBuffer;
21
22/*
23 * This class wraps helper functions that draw AA rects (filled & stroked)
24 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000025class GrAARectRenderer : public SkRefCnt {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000026public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000027 SK_DECLARE_INST_COUNT(GrAARectRenderer)
robertphillips@google.comf6747b02012-06-12 00:32:28 +000028
joshualittb44293e2014-10-28 08:12:18 -070029 GrAARectRenderer(GrGpu* gpu)
30 : fGpu(gpu)
31 , fAAFillRectIndexBuffer(NULL)
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000032 , fAAMiterStrokeRectIndexBuffer(NULL)
33 , fAABevelStrokeRectIndexBuffer(NULL) {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000034 }
35
36 void reset();
37
38 ~GrAARectRenderer() {
39 this->reset();
40 }
41
42 // TODO: potentialy fuse the fill & stroke methods and differentiate
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000043 // between them by passing in stroke (==NULL means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000044
joshualittb44293e2014-10-28 08:12:18 -070045 void fillAARect(GrDrawTarget* target,
joshualitt9853cce2014-11-17 14:22:48 -080046 GrDrawState* ds,
joshualitt2e3b3e32014-12-09 13:31:14 -080047 GrColor color,
joshualitt8059eb92014-12-29 15:10:07 -080048 const SkMatrix& viewMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000049 const SkRect& rect,
bsalomon9c0822a2014-08-11 11:07:48 -070050 const SkRect& devRect) {
joshualitt8059eb92014-12-29 15:10:07 -080051 this->geometryFillAARect(target, ds, color, viewMatrix, rect, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000052 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000053
joshualitt9853cce2014-11-17 14:22:48 -080054 void strokeAARect(GrDrawTarget*,
55 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080056 GrColor,
joshualitt8059eb92014-12-29 15:10:07 -080057 const SkMatrix& viewMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000058 const SkRect& rect,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000059 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070060 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000061
robertphillips@google.com83d1a682013-05-17 12:50:27 +000062 // First rect is outer; second rect is inner
joshualitt9853cce2014-11-17 14:22:48 -080063 void fillAANestedRects(GrDrawTarget*,
64 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080065 GrColor,
joshualitt8059eb92014-12-29 15:10:07 -080066 const SkMatrix& viewMatrix,
67 const SkRect rects[2]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000068
robertphillips@google.comf6747b02012-06-12 00:32:28 +000069private:
joshualittb44293e2014-10-28 08:12:18 -070070 GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000071
joshualitt9853cce2014-11-17 14:22:48 -080072 void geometryFillAARect(GrDrawTarget*,
73 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080074 GrColor,
joshualitt8059eb92014-12-29 15:10:07 -080075 const SkMatrix& viewMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000076 const SkRect& rect,
bsalomon9c0822a2014-08-11 11:07:48 -070077 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000078
joshualitt9853cce2014-11-17 14:22:48 -080079 void geometryStrokeAARect(GrDrawTarget*,
80 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080081 GrColor,
joshualitt8059eb92014-12-29 15:10:07 -080082 const SkMatrix& viewMatrix,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000083 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000084 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000085 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000086 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000087
joshualittb44293e2014-10-28 08:12:18 -070088 GrGpu* fGpu;
89 GrIndexBuffer* fAAFillRectIndexBuffer;
90 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
91 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
92
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000093 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000094};
95
96#endif // GrAARectRenderer_DEFINED