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