blob: d97a1118240b4ebfa0b3eea8aebad6ddddff9170 [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,
joshualittd27f73e2014-12-29 07:43:36 -080048 const SkMatrix& localMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000049 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000050 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070051 const SkRect& devRect) {
joshualittd27f73e2014-12-29 07:43:36 -080052 this->geometryFillAARect(target, ds, color, localMatrix, rect, combinedMatrix, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000053 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000054
joshualitt9853cce2014-11-17 14:22:48 -080055 void strokeAARect(GrDrawTarget*,
56 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080057 GrColor,
joshualittd27f73e2014-12-29 07:43:36 -080058 const SkMatrix& localMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000059 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000060 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000061 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070062 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000063
robertphillips@google.com83d1a682013-05-17 12:50:27 +000064 // First rect is outer; second rect is inner
joshualitt9853cce2014-11-17 14:22:48 -080065 void fillAANestedRects(GrDrawTarget*,
66 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080067 GrColor,
joshualittd27f73e2014-12-29 07:43:36 -080068 const SkMatrix& localMatrix,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000069 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070070 const SkMatrix& combinedMatrix);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000071
robertphillips@google.comf6747b02012-06-12 00:32:28 +000072private:
joshualittb44293e2014-10-28 08:12:18 -070073 GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000074
joshualitt9853cce2014-11-17 14:22:48 -080075 void geometryFillAARect(GrDrawTarget*,
76 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080077 GrColor,
joshualittd27f73e2014-12-29 07:43:36 -080078 const SkMatrix& localMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000079 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000080 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070081 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000082
joshualitt9853cce2014-11-17 14:22:48 -080083 void geometryStrokeAARect(GrDrawTarget*,
84 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080085 GrColor,
joshualittd27f73e2014-12-29 07:43:36 -080086 const SkMatrix& localMatrix,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000087 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000088 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000089 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000090 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000091
joshualittb44293e2014-10-28 08:12:18 -070092 GrGpu* fGpu;
93 GrIndexBuffer* fAAFillRectIndexBuffer;
94 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
95 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
96
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000097 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000098};
99
100#endif // GrAARectRenderer_DEFINED