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 #ifndef GrAARectRenderer_DEFINED 9 #define GrAARectRenderer_DEFINED 10 11 #include "SkMatrix.h" 12 #include "SkRect.h" 13 #include "SkRefCnt.h" 14 #include "SkStrokeRec.h" 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 SkRefCnt { 24 public: SK_DECLARE_INST_COUNT(GrAARectRenderer)25 SK_DECLARE_INST_COUNT(GrAARectRenderer) 26 27 GrAARectRenderer() 28 : fAAFillRectIndexBuffer(NULL) 29 , fAAMiterStrokeRectIndexBuffer(NULL) 30 , fAABevelStrokeRectIndexBuffer(NULL) { 31 } 32 33 void reset(); 34 ~GrAARectRenderer()35 ~GrAARectRenderer() { 36 this->reset(); 37 } 38 39 // TODO: potentialy fuse the fill & stroke methods and differentiate 40 // between them by passing in stroke (==NULL means fill). 41 fillAARect(GrGpu * gpu,GrDrawTarget * target,const SkRect & rect,const SkMatrix & combinedMatrix,const SkRect & devRect,bool useVertexCoverage)42 void fillAARect(GrGpu* gpu, 43 GrDrawTarget* target, 44 const SkRect& rect, 45 const SkMatrix& combinedMatrix, 46 const SkRect& devRect, 47 bool useVertexCoverage) { 48 #ifdef SHADER_AA_FILL_RECT 49 if (combinedMatrix.rectStaysRect()) { 50 this->shaderFillAlignedAARect(gpu, target, 51 rect, combinedMatrix); 52 } else { 53 this->shaderFillAARect(gpu, target, 54 rect, combinedMatrix); 55 } 56 #else 57 this->geometryFillAARect(gpu, target, 58 rect, combinedMatrix, 59 devRect, useVertexCoverage); 60 #endif 61 } 62 63 void strokeAARect(GrGpu* gpu, 64 GrDrawTarget* target, 65 const SkRect& rect, 66 const SkMatrix& combinedMatrix, 67 const SkRect& devRect, 68 const SkStrokeRec& stroke, 69 bool useVertexCoverage); 70 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 78 private: 79 GrIndexBuffer* fAAFillRectIndexBuffer; 80 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; 81 GrIndexBuffer* fAABevelStrokeRectIndexBuffer; 82 83 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); 84 85 static int aaStrokeRectIndexCount(bool miterStroke); 86 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); 87 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, 92 const SkRect& rect, 93 const SkMatrix& combinedMatrix, 94 const SkRect& devRect, 95 bool useVertexCoverage); 96 97 void shaderFillAARect(GrGpu* gpu, 98 GrDrawTarget* target, 99 const SkRect& rect, 100 const SkMatrix& combinedMatrix); 101 102 void shaderFillAlignedAARect(GrGpu* gpu, 103 GrDrawTarget* target, 104 const SkRect& rect, 105 const SkMatrix& combinedMatrix); 106 107 void geometryStrokeAARect(GrGpu* gpu, 108 GrDrawTarget* target, 109 const SkRect& devOutside, 110 const SkRect& devOutsideAssist, 111 const SkRect& devInside, 112 bool useVertexCoverage, 113 bool miterStroke); 114 115 typedef SkRefCnt INHERITED; 116 }; 117 118 #endif // GrAARectRenderer_DEFINED 119