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; |
| 17 | class GrDrawTarget; |
| 18 | class GrIndexBuffer; |
| 19 | |
| 20 | /* |
| 21 | * This class wraps helper functions that draw AA rects (filled & stroked) |
| 22 | */ |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 23 | class GrAARectRenderer : public SkRefCnt { |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 24 | public: |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 25 | SK_DECLARE_INST_COUNT(GrAARectRenderer) |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 26 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 27 | GrAARectRenderer() |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 28 | : fAAFillRectIndexBuffer(NULL) |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 29 | , fAAMiterStrokeRectIndexBuffer(NULL) |
| 30 | , fAABevelStrokeRectIndexBuffer(NULL) { |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void reset(); |
| 34 | |
| 35 | ~GrAARectRenderer() { |
| 36 | this->reset(); |
| 37 | } |
| 38 | |
| 39 | // TODO: potentialy fuse the fill & stroke methods and differentiate |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 40 | // between them by passing in stroke (==NULL means fill). |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 41 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 42 | void fillAARect(GrGpu* gpu, |
| 43 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 44 | const SkRect& rect, |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 45 | const SkMatrix& combinedMatrix, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame^] | 46 | const SkRect& devRect) { |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 47 | #ifdef SHADER_AA_FILL_RECT |
| 48 | if (combinedMatrix.rectStaysRect()) { |
| 49 | this->shaderFillAlignedAARect(gpu, target, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 50 | rect, combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 51 | } else { |
| 52 | this->shaderFillAARect(gpu, target, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 53 | rect, combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 54 | } |
| 55 | #else |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame^] | 56 | this->geometryFillAARect(gpu, target, rect, combinedMatrix, devRect); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 57 | #endif |
| 58 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 59 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 60 | void strokeAARect(GrGpu* gpu, |
| 61 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 62 | const SkRect& rect, |
robertphillips@google.com | 18136d1 | 2013-05-10 11:05:58 +0000 | [diff] [blame] | 63 | const SkMatrix& combinedMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 64 | const SkRect& devRect, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame^] | 65 | const SkStrokeRec& stroke); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 66 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 67 | // First rect is outer; second rect is inner |
| 68 | void fillAANestedRects(GrGpu* gpu, |
| 69 | GrDrawTarget* target, |
| 70 | const SkRect rects[2], |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame^] | 71 | const SkMatrix& combinedMatrix); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 72 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 73 | private: |
| 74 | GrIndexBuffer* fAAFillRectIndexBuffer; |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 75 | GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; |
| 76 | GrIndexBuffer* fAABevelStrokeRectIndexBuffer; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 77 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 78 | GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); |
| 79 | |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 80 | static int aaStrokeRectIndexCount(bool miterStroke); |
| 81 | GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 82 | |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 83 | void geometryFillAARect(GrGpu* gpu, |
| 84 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 85 | const SkRect& rect, |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 86 | const SkMatrix& combinedMatrix, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame^] | 87 | const SkRect& devRect); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 88 | |
| 89 | void shaderFillAARect(GrGpu* gpu, |
| 90 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 91 | const SkRect& rect, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 92 | const SkMatrix& combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 93 | |
| 94 | void shaderFillAlignedAARect(GrGpu* gpu, |
| 95 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 96 | const SkRect& rect, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 97 | const SkMatrix& combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 98 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 99 | void geometryStrokeAARect(GrGpu* gpu, |
| 100 | GrDrawTarget* target, |
| 101 | const SkRect& devOutside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 102 | const SkRect& devOutsideAssist, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 103 | const SkRect& devInside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 104 | bool miterStroke); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 105 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 106 | typedef SkRefCnt INHERITED; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif // GrAARectRenderer_DEFINED |