robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 1 | /* |
| 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.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 8 | #ifndef GrAARectRenderer_DEFINED |
| 9 | #define GrAARectRenderer_DEFINED |
| 10 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 11 | #include "GrColor.h" |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 12 | #include "SkMatrix.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 13 | #include "SkRect.h" |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 14 | #include "SkRefCnt.h" |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 15 | #include "SkStrokeRec.h" |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 16 | |
| 17 | class GrGpu; |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 18 | class GrDrawState; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 19 | class GrDrawTarget; |
| 20 | class GrIndexBuffer; |
| 21 | |
| 22 | /* |
| 23 | * This class wraps helper functions that draw AA rects (filled & stroked) |
| 24 | */ |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 25 | class GrAARectRenderer : public SkRefCnt { |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 26 | public: |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 27 | SK_DECLARE_INST_COUNT(GrAARectRenderer) |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 28 | |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 29 | GrAARectRenderer(GrGpu* gpu) |
| 30 | : fGpu(gpu) |
| 31 | , fAAFillRectIndexBuffer(NULL) |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 32 | , fAAMiterStrokeRectIndexBuffer(NULL) |
| 33 | , fAABevelStrokeRectIndexBuffer(NULL) { |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 34 | } |
| 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.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 43 | // between them by passing in stroke (==NULL means fill). |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 44 | |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 45 | void fillAARect(GrDrawTarget* target, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 46 | GrDrawState* ds, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 47 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 48 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 49 | const SkRect& rect, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 50 | const SkRect& devRect) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 51 | this->geometryFillAARect(target, ds, color, viewMatrix, rect, devRect); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 52 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 53 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 54 | void strokeAARect(GrDrawTarget*, |
| 55 | GrDrawState*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 56 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 57 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 58 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 59 | const SkRect& devRect, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 60 | const SkStrokeRec& stroke); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 61 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 62 | // First rect is outer; second rect is inner |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 63 | void fillAANestedRects(GrDrawTarget*, |
| 64 | GrDrawState*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 65 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 66 | const SkMatrix& viewMatrix, |
| 67 | const SkRect rects[2]); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 68 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 69 | private: |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 70 | GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 71 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 72 | void geometryFillAARect(GrDrawTarget*, |
| 73 | GrDrawState*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 74 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 75 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 76 | const SkRect& rect, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 77 | const SkRect& devRect); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 78 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 79 | void geometryStrokeAARect(GrDrawTarget*, |
| 80 | GrDrawState*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 81 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 82 | const SkMatrix& viewMatrix, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 83 | const SkRect& devOutside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 84 | const SkRect& devOutsideAssist, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 85 | const SkRect& devInside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 86 | bool miterStroke); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 87 | |
joshualitt | b44293e | 2014-10-28 08:12:18 -0700 | [diff] [blame] | 88 | GrGpu* fGpu; |
| 89 | GrIndexBuffer* fAAFillRectIndexBuffer; |
| 90 | GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; |
| 91 | GrIndexBuffer* fAABevelStrokeRectIndexBuffer; |
| 92 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 93 | typedef SkRefCnt INHERITED; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | #endif // GrAARectRenderer_DEFINED |