blob: a8ba0851082d938a77a234b726552c4c3b9bc4ee [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
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000011#include "SkMatrix.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000012#include "SkRect.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000013#include "SkRefCnt.h"
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000014#include "SkStrokeRec.h"
robertphillips@google.comf6747b02012-06-12 00:32:28 +000015
16class GrGpu;
joshualitt9853cce2014-11-17 14:22:48 -080017class GrDrawState;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000018class GrDrawTarget;
19class GrIndexBuffer;
20
21/*
22 * This class wraps helper functions that draw AA rects (filled & stroked)
23 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000024class GrAARectRenderer : public SkRefCnt {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000025public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000026 SK_DECLARE_INST_COUNT(GrAARectRenderer)
robertphillips@google.comf6747b02012-06-12 00:32:28 +000027
joshualittb44293e2014-10-28 08:12:18 -070028 GrAARectRenderer(GrGpu* gpu)
29 : fGpu(gpu)
30 , fAAFillRectIndexBuffer(NULL)
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000031 , fAAMiterStrokeRectIndexBuffer(NULL)
32 , fAABevelStrokeRectIndexBuffer(NULL) {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000033 }
34
35 void reset();
36
37 ~GrAARectRenderer() {
38 this->reset();
39 }
40
41 // TODO: potentialy fuse the fill & stroke methods and differentiate
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000042 // between them by passing in stroke (==NULL means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000043
joshualittb44293e2014-10-28 08:12:18 -070044 void fillAARect(GrDrawTarget* target,
joshualitt9853cce2014-11-17 14:22:48 -080045 GrDrawState* ds,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000046 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000047 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070048 const SkRect& devRect) {
joshualitt9853cce2014-11-17 14:22:48 -080049 this->geometryFillAARect(target, ds, rect, combinedMatrix, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000050 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000051
joshualitt9853cce2014-11-17 14:22:48 -080052 void strokeAARect(GrDrawTarget*,
53 GrDrawState*,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000054 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000055 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000056 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070057 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000058
robertphillips@google.com83d1a682013-05-17 12:50:27 +000059 // First rect is outer; second rect is inner
joshualitt9853cce2014-11-17 14:22:48 -080060 void fillAANestedRects(GrDrawTarget*,
61 GrDrawState*,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000062 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070063 const SkMatrix& combinedMatrix);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000064
robertphillips@google.comf6747b02012-06-12 00:32:28 +000065private:
joshualittb44293e2014-10-28 08:12:18 -070066 GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000067
joshualitt9853cce2014-11-17 14:22:48 -080068 void geometryFillAARect(GrDrawTarget*,
69 GrDrawState*,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000070 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000071 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070072 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000073
joshualitt9853cce2014-11-17 14:22:48 -080074 void geometryStrokeAARect(GrDrawTarget*,
75 GrDrawState*,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000076 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000077 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000078 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000079 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000080
joshualittb44293e2014-10-28 08:12:18 -070081 GrGpu* fGpu;
82 GrIndexBuffer* fAAFillRectIndexBuffer;
83 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
84 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
85
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000086 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000087};
88
89#endif // GrAARectRenderer_DEFINED