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: 25 SK_DECLARE_INST_COUNT(GrAARectRenderer) 26 27 GrAARectRenderer() 28 : fAAFillRectIndexBuffer(NULL) 29 , fAAMiterStrokeRectIndexBuffer(NULL) 30 , fAABevelStrokeRectIndexBuffer(NULL) { 31 } 32 33 void reset(); 34 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 42 void fillAARect(GrGpu* gpu, 43 GrDrawTarget* target, 44 const SkRect& rect, 45 const SkMatrix& combinedMatrix, 46 const SkRect& devRect) { 47 #ifdef SHADER_AA_FILL_RECT 48 if (combinedMatrix.rectStaysRect()) { 49 this->shaderFillAlignedAARect(gpu, target, 50 rect, combinedMatrix); 51 } else { 52 this->shaderFillAARect(gpu, target, 53 rect, combinedMatrix); 54 } 55 #else 56 this->geometryFillAARect(gpu, target, rect, combinedMatrix, devRect); 57 #endif 58 } 59 60 void strokeAARect(GrGpu* gpu, 61 GrDrawTarget* target, 62 const SkRect& rect, 63 const SkMatrix& combinedMatrix, 64 const SkRect& devRect, 65 const SkStrokeRec& stroke); 66 67 // First rect is outer; second rect is inner 68 void fillAANestedRects(GrGpu* gpu, 69 GrDrawTarget* target, 70 const SkRect rects[2], 71 const SkMatrix& combinedMatrix); 72 73 private: 74 GrIndexBuffer* fAAFillRectIndexBuffer; 75 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; 76 GrIndexBuffer* fAABevelStrokeRectIndexBuffer; 77 78 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); 79 80 static int aaStrokeRectIndexCount(bool miterStroke); 81 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); 82 83 void geometryFillAARect(GrGpu* gpu, 84 GrDrawTarget* target, 85 const SkRect& rect, 86 const SkMatrix& combinedMatrix, 87 const SkRect& devRect); 88 89 void shaderFillAARect(GrGpu* gpu, 90 GrDrawTarget* target, 91 const SkRect& rect, 92 const SkMatrix& combinedMatrix); 93 94 void shaderFillAlignedAARect(GrGpu* gpu, 95 GrDrawTarget* target, 96 const SkRect& rect, 97 const SkMatrix& combinedMatrix); 98 99 void geometryStrokeAARect(GrGpu* gpu, 100 GrDrawTarget* target, 101 const SkRect& devOutside, 102 const SkRect& devOutsideAssist, 103 const SkRect& devInside, 104 bool miterStroke); 105 106 typedef SkRefCnt INHERITED; 107 }; 108 109 #endif // GrAARectRenderer_DEFINED 110