1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/GrAARectRenderer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef GrAARectRenderer_DEFINED 1.12 +#define GrAARectRenderer_DEFINED 1.13 + 1.14 +#include "SkMatrix.h" 1.15 +#include "SkRect.h" 1.16 +#include "SkRefCnt.h" 1.17 +#include "SkStrokeRec.h" 1.18 + 1.19 +class GrGpu; 1.20 +class GrDrawTarget; 1.21 +class GrIndexBuffer; 1.22 + 1.23 +/* 1.24 + * This class wraps helper functions that draw AA rects (filled & stroked) 1.25 + */ 1.26 +class GrAARectRenderer : public SkRefCnt { 1.27 +public: 1.28 + SK_DECLARE_INST_COUNT(GrAARectRenderer) 1.29 + 1.30 + GrAARectRenderer() 1.31 + : fAAFillRectIndexBuffer(NULL) 1.32 + , fAAMiterStrokeRectIndexBuffer(NULL) 1.33 + , fAABevelStrokeRectIndexBuffer(NULL) { 1.34 + } 1.35 + 1.36 + void reset(); 1.37 + 1.38 + ~GrAARectRenderer() { 1.39 + this->reset(); 1.40 + } 1.41 + 1.42 + // TODO: potentialy fuse the fill & stroke methods and differentiate 1.43 + // between them by passing in stroke (==NULL means fill). 1.44 + 1.45 + void fillAARect(GrGpu* gpu, 1.46 + GrDrawTarget* target, 1.47 + const SkRect& rect, 1.48 + const SkMatrix& combinedMatrix, 1.49 + const SkRect& devRect, 1.50 + bool useVertexCoverage) { 1.51 +#ifdef SHADER_AA_FILL_RECT 1.52 + if (combinedMatrix.rectStaysRect()) { 1.53 + this->shaderFillAlignedAARect(gpu, target, 1.54 + rect, combinedMatrix); 1.55 + } else { 1.56 + this->shaderFillAARect(gpu, target, 1.57 + rect, combinedMatrix); 1.58 + } 1.59 +#else 1.60 + this->geometryFillAARect(gpu, target, 1.61 + rect, combinedMatrix, 1.62 + devRect, useVertexCoverage); 1.63 +#endif 1.64 + } 1.65 + 1.66 + void strokeAARect(GrGpu* gpu, 1.67 + GrDrawTarget* target, 1.68 + const SkRect& rect, 1.69 + const SkMatrix& combinedMatrix, 1.70 + const SkRect& devRect, 1.71 + const SkStrokeRec* stroke, 1.72 + bool useVertexCoverage); 1.73 + 1.74 + // First rect is outer; second rect is inner 1.75 + void fillAANestedRects(GrGpu* gpu, 1.76 + GrDrawTarget* target, 1.77 + const SkRect rects[2], 1.78 + const SkMatrix& combinedMatrix, 1.79 + bool useVertexCoverage); 1.80 + 1.81 +private: 1.82 + GrIndexBuffer* fAAFillRectIndexBuffer; 1.83 + GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; 1.84 + GrIndexBuffer* fAABevelStrokeRectIndexBuffer; 1.85 + 1.86 + GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); 1.87 + 1.88 + static int aaStrokeRectIndexCount(bool miterStroke); 1.89 + GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); 1.90 + 1.91 + // TODO: Remove the useVertexCoverage boolean. Just use it all the time 1.92 + // since we now have a coverage vertex attribute 1.93 + void geometryFillAARect(GrGpu* gpu, 1.94 + GrDrawTarget* target, 1.95 + const SkRect& rect, 1.96 + const SkMatrix& combinedMatrix, 1.97 + const SkRect& devRect, 1.98 + bool useVertexCoverage); 1.99 + 1.100 + void shaderFillAARect(GrGpu* gpu, 1.101 + GrDrawTarget* target, 1.102 + const SkRect& rect, 1.103 + const SkMatrix& combinedMatrix); 1.104 + 1.105 + void shaderFillAlignedAARect(GrGpu* gpu, 1.106 + GrDrawTarget* target, 1.107 + const SkRect& rect, 1.108 + const SkMatrix& combinedMatrix); 1.109 + 1.110 + void geometryStrokeAARect(GrGpu* gpu, 1.111 + GrDrawTarget* target, 1.112 + const SkRect& devOutside, 1.113 + const SkRect& devOutsideAssist, 1.114 + const SkRect& devInside, 1.115 + bool useVertexCoverage, 1.116 + bool miterStroke); 1.117 + 1.118 + typedef SkRefCnt INHERITED; 1.119 +}; 1.120 + 1.121 +#endif // GrAARectRenderer_DEFINED