blob: b1780ad46a477feb1be3b21a843f18bb0c5660b8 [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,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000048 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000049 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070050 const SkRect& devRect) {
joshualitt2e3b3e32014-12-09 13:31:14 -080051 this->geometryFillAARect(target, ds, color, rect, combinedMatrix, 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,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000057 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000058 const SkMatrix& combinedMatrix,
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,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000066 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070067 const SkMatrix& combinedMatrix);
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,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000075 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000076 const SkMatrix& combinedMatrix,
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,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000082 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000083 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000084 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000085 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000086
joshualittb44293e2014-10-28 08:12:18 -070087 GrGpu* fGpu;
88 GrIndexBuffer* fAAFillRectIndexBuffer;
89 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
90 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
91
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000092 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000093};
94
95#endif // GrAARectRenderer_DEFINED