michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef GrAARectRenderer_DEFINED michael@0: #define GrAARectRenderer_DEFINED michael@0: michael@0: #include "SkMatrix.h" michael@0: #include "SkRect.h" michael@0: #include "SkRefCnt.h" michael@0: #include "SkStrokeRec.h" michael@0: michael@0: class GrGpu; michael@0: class GrDrawTarget; michael@0: class GrIndexBuffer; michael@0: michael@0: /* michael@0: * This class wraps helper functions that draw AA rects (filled & stroked) michael@0: */ michael@0: class GrAARectRenderer : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(GrAARectRenderer) michael@0: michael@0: GrAARectRenderer() michael@0: : fAAFillRectIndexBuffer(NULL) michael@0: , fAAMiterStrokeRectIndexBuffer(NULL) michael@0: , fAABevelStrokeRectIndexBuffer(NULL) { michael@0: } michael@0: michael@0: void reset(); michael@0: michael@0: ~GrAARectRenderer() { michael@0: this->reset(); michael@0: } michael@0: michael@0: // TODO: potentialy fuse the fill & stroke methods and differentiate michael@0: // between them by passing in stroke (==NULL means fill). michael@0: michael@0: void fillAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& rect, michael@0: const SkMatrix& combinedMatrix, michael@0: const SkRect& devRect, michael@0: bool useVertexCoverage) { michael@0: #ifdef SHADER_AA_FILL_RECT michael@0: if (combinedMatrix.rectStaysRect()) { michael@0: this->shaderFillAlignedAARect(gpu, target, michael@0: rect, combinedMatrix); michael@0: } else { michael@0: this->shaderFillAARect(gpu, target, michael@0: rect, combinedMatrix); michael@0: } michael@0: #else michael@0: this->geometryFillAARect(gpu, target, michael@0: rect, combinedMatrix, michael@0: devRect, useVertexCoverage); michael@0: #endif michael@0: } michael@0: michael@0: void strokeAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& rect, michael@0: const SkMatrix& combinedMatrix, michael@0: const SkRect& devRect, michael@0: const SkStrokeRec* stroke, michael@0: bool useVertexCoverage); michael@0: michael@0: // First rect is outer; second rect is inner michael@0: void fillAANestedRects(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect rects[2], michael@0: const SkMatrix& combinedMatrix, michael@0: bool useVertexCoverage); michael@0: michael@0: private: michael@0: GrIndexBuffer* fAAFillRectIndexBuffer; michael@0: GrIndexBuffer* fAAMiterStrokeRectIndexBuffer; michael@0: GrIndexBuffer* fAABevelStrokeRectIndexBuffer; michael@0: michael@0: GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu); michael@0: michael@0: static int aaStrokeRectIndexCount(bool miterStroke); michael@0: GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke); michael@0: michael@0: // TODO: Remove the useVertexCoverage boolean. Just use it all the time michael@0: // since we now have a coverage vertex attribute michael@0: void geometryFillAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& rect, michael@0: const SkMatrix& combinedMatrix, michael@0: const SkRect& devRect, michael@0: bool useVertexCoverage); michael@0: michael@0: void shaderFillAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& rect, michael@0: const SkMatrix& combinedMatrix); michael@0: michael@0: void shaderFillAlignedAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& rect, michael@0: const SkMatrix& combinedMatrix); michael@0: michael@0: void geometryStrokeAARect(GrGpu* gpu, michael@0: GrDrawTarget* target, michael@0: const SkRect& devOutside, michael@0: const SkRect& devOutsideAssist, michael@0: const SkRect& devInside, michael@0: bool useVertexCoverage, michael@0: bool miterStroke); michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif // GrAARectRenderer_DEFINED