blob: e39b87a5fd3305103497ba83a346373b881f530f [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;
17class GrDrawTarget;
18class GrIndexBuffer;
19
20/*
21 * This class wraps helper functions that draw AA rects (filled & stroked)
22 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000023class GrAARectRenderer : public SkRefCnt {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000024public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000025 SK_DECLARE_INST_COUNT(GrAARectRenderer)
robertphillips@google.comf6747b02012-06-12 00:32:28 +000026
joshualittb44293e2014-10-28 08:12:18 -070027 GrAARectRenderer(GrGpu* gpu)
28 : fGpu(gpu)
29 , fAAFillRectIndexBuffer(NULL)
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000030 , fAAMiterStrokeRectIndexBuffer(NULL)
31 , fAABevelStrokeRectIndexBuffer(NULL) {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000032 }
33
34 void reset();
35
36 ~GrAARectRenderer() {
37 this->reset();
38 }
39
40 // TODO: potentialy fuse the fill & stroke methods and differentiate
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000041 // between them by passing in stroke (==NULL means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000042
joshualittb44293e2014-10-28 08:12:18 -070043 void fillAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000044 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000045 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070046 const SkRect& devRect) {
joshualittb44293e2014-10-28 08:12:18 -070047 this->geometryFillAARect(target, rect, combinedMatrix, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000048 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000049
joshualittb44293e2014-10-28 08:12:18 -070050 void strokeAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000051 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000052 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000053 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070054 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000055
robertphillips@google.com83d1a682013-05-17 12:50:27 +000056 // First rect is outer; second rect is inner
joshualittb44293e2014-10-28 08:12:18 -070057 void fillAANestedRects(GrDrawTarget* target,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000058 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070059 const SkMatrix& combinedMatrix);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000060
robertphillips@google.comf6747b02012-06-12 00:32:28 +000061private:
joshualittb44293e2014-10-28 08:12:18 -070062 GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000063
joshualittb44293e2014-10-28 08:12:18 -070064 void geometryFillAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000065 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000066 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070067 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000068
joshualittb44293e2014-10-28 08:12:18 -070069 void geometryStrokeAARect(GrDrawTarget* target,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000070 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000071 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000072 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000073 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000074
joshualittb44293e2014-10-28 08:12:18 -070075 GrGpu* fGpu;
76 GrIndexBuffer* fAAFillRectIndexBuffer;
77 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
78 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
79
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000080 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000081};
82
83#endif // GrAARectRenderer_DEFINED