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, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 46 | const SkRect& devRect, |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 47 | bool useVertexCoverage) { |
| 48 | #ifdef SHADER_AA_FILL_RECT |
| 49 | if (combinedMatrix.rectStaysRect()) { |
| 50 | this->shaderFillAlignedAARect(gpu, target, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 51 | rect, combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 52 | } else { |
| 53 | this->shaderFillAARect(gpu, target, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 54 | rect, combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 55 | } |
| 56 | #else |
| 57 | this->geometryFillAARect(gpu, target, |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 58 | rect, combinedMatrix, |
robertphillips@google.com | afd1cba | 2013-05-14 19:47:47 +0000 | [diff] [blame] | 59 | devRect, useVertexCoverage); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 60 | #endif |
| 61 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 62 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 63 | void strokeAARect(GrGpu* gpu, |
| 64 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 65 | const SkRect& rect, |
robertphillips@google.com | 18136d1 | 2013-05-10 11:05:58 +0000 | [diff] [blame] | 66 | const SkMatrix& combinedMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 67 | const SkRect& devRect, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 68 | const SkStrokeRec* stroke, |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 69 | bool useVertexCoverage); |
| 70 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 71 | // First rect is outer; second rect is inner |
| 72 | void fillAANestedRects(GrGpu* gpu, |
| 73 | GrDrawTarget* target, |
| 74 | const SkRect rects[2], |
| 75 | const SkMatrix& combinedMatrix, |
| 76 | bool useVertexCoverage); |
| 77 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 78 | private: |
| 79 | GrIndexBuffer* fAAFillRectIndexBuffer; |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 80 | GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; |
| 81 | GrIndexBuffer* fAABevelStrokeRectIndexBuffer; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 82 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 83 | GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); |
| 84 | |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 85 | static int aaStrokeRectIndexCount(bool miterStroke); |
| 86 | GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 87 | |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 88 | // TODO: Remove the useVertexCoverage boolean. Just use it all the time |
| 89 | // since we now have a coverage vertex attribute |
| 90 | void geometryFillAARect(GrGpu* gpu, |
| 91 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 92 | const SkRect& rect, |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 93 | const SkMatrix& combinedMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 94 | const SkRect& devRect, |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 95 | bool useVertexCoverage); |
| 96 | |
| 97 | void shaderFillAARect(GrGpu* gpu, |
| 98 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 99 | const SkRect& rect, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 100 | const SkMatrix& combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 101 | |
| 102 | void shaderFillAlignedAARect(GrGpu* gpu, |
| 103 | GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 104 | const SkRect& rect, |
robertphillips@google.com | 114eb9e | 2013-05-10 13:16:13 +0000 | [diff] [blame] | 105 | const SkMatrix& combinedMatrix); |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame] | 106 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 107 | void geometryStrokeAARect(GrGpu* gpu, |
| 108 | GrDrawTarget* target, |
| 109 | const SkRect& devOutside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 110 | const SkRect& devOutsideAssist, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 111 | const SkRect& devInside, |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 112 | bool useVertexCoverage, |
| 113 | bool miterStroke); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 114 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 115 | typedef SkRefCnt INHERITED; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | #endif // GrAARectRenderer_DEFINED |