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