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