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" |
| 14 | |
| 15 | class GrGpu; |
| 16 | class GrDrawTarget; |
| 17 | class GrIndexBuffer; |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 18 | class SkMatrix; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 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 | f6747b0 | 2012-06-12 00:32:28 +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, |
| 50 | combinedMatrix, devRect); |
| 51 | } else { |
| 52 | this->shaderFillAARect(gpu, target, |
| 53 | rect, combinedMatrix, devRect); |
| 54 | } |
| 55 | #else |
| 56 | this->geometryFillAARect(gpu, target, |
| 57 | devRect, useVertexCoverage); |
| 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, |
| 63 | const GrRect& devRect, |
| 64 | const GrVec& devStrokeSize, |
| 65 | bool useVertexCoverage); |
| 66 | |
| 67 | private: |
| 68 | GrIndexBuffer* fAAFillRectIndexBuffer; |
| 69 | GrIndexBuffer* fAAStrokeRectIndexBuffer; |
| 70 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 71 | GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); |
| 72 | |
| 73 | static int aaStrokeRectIndexCount(); |
| 74 | GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu); |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 75 | |
robertphillips@google.com | b19cb7f | 2013-05-02 15:37:20 +0000 | [diff] [blame^] | 76 | // TODO: Remove the useVertexCoverage boolean. Just use it all the time |
| 77 | // since we now have a coverage vertex attribute |
| 78 | void geometryFillAARect(GrGpu* gpu, |
| 79 | GrDrawTarget* target, |
| 80 | const GrRect& devRect, |
| 81 | bool useVertexCoverage); |
| 82 | |
| 83 | void shaderFillAARect(GrGpu* gpu, |
| 84 | GrDrawTarget* target, |
| 85 | const GrRect& rect, |
| 86 | const SkMatrix& combinedMatrix, |
| 87 | const GrRect& devRect); |
| 88 | |
| 89 | void shaderFillAlignedAARect(GrGpu* gpu, |
| 90 | GrDrawTarget* target, |
| 91 | const GrRect& rect, |
| 92 | const SkMatrix& combinedMatrix, |
| 93 | const GrRect& devRect); |
| 94 | |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 95 | typedef GrRefCnt INHERITED; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | #endif // GrAARectRenderer_DEFINED |