blob: 549c2ca96e2cf76ff60940adfc059efc8476e59f [file] [log] [blame]
robertphillips@google.comf6747b02012-06-12 00:32:28 +00001/*
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"
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000014#include "SkMatrix.h"
robertphillips@google.comf6747b02012-06-12 00:32:28 +000015
16class GrGpu;
17class GrDrawTarget;
18class GrIndexBuffer;
19
20/*
21 * This class wraps helper functions that draw AA rects (filled & stroked)
22 */
23class GrAARectRenderer : public GrRefCnt {
24public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000025 SK_DECLARE_INST_COUNT(GrAARectRenderer)
robertphillips@google.comf6747b02012-06-12 00:32:28 +000026
rmistry@google.comfbfcd562012-08-23 18:09:54 +000027 GrAARectRenderer()
robertphillips@google.comf6747b02012-06-12 00:32:28 +000028 : 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.comdf3695e2013-04-09 14:01:44 +000039 // between them by passing in strokeWidth (<0 means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000040
robertphillips@google.comf6747b02012-06-12 00:32:28 +000041 void fillAARect(GrGpu* gpu,
42 GrDrawTarget* target,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000043 const GrRect& rect,
44 const SkMatrix& combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000045 const GrRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000046 bool useVertexCoverage) {
47#ifdef SHADER_AA_FILL_RECT
48 if (combinedMatrix.rectStaysRect()) {
49 this->shaderFillAlignedAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000050 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000051 } else {
52 this->shaderFillAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000053 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000054 }
55#else
56 this->geometryFillAARect(gpu, target,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000057 rect, combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000058 devRect, useVertexCoverage);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000059#endif
60 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000061
robertphillips@google.comf6747b02012-06-12 00:32:28 +000062 void strokeAARect(GrGpu* gpu,
63 GrDrawTarget* target,
robertphillips@google.com18136d12013-05-10 11:05:58 +000064 const GrRect& rect,
65 const SkMatrix& combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000066 const GrRect& devRect,
robertphillips@google.comf6747b02012-06-12 00:32:28 +000067 const GrVec& devStrokeSize,
68 bool useVertexCoverage);
69
70private:
71 GrIndexBuffer* fAAFillRectIndexBuffer;
72 GrIndexBuffer* fAAStrokeRectIndexBuffer;
73
robertphillips@google.comf6747b02012-06-12 00:32:28 +000074 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
75
76 static int aaStrokeRectIndexCount();
77 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000078
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000079 // TODO: Remove the useVertexCoverage boolean. Just use it all the time
80 // since we now have a coverage vertex attribute
81 void geometryFillAARect(GrGpu* gpu,
82 GrDrawTarget* target,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000083 const GrRect& rect,
84 const SkMatrix& combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000085 const GrRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000086 bool useVertexCoverage);
87
88 void shaderFillAARect(GrGpu* gpu,
89 GrDrawTarget* target,
90 const GrRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000091 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000092
93 void shaderFillAlignedAARect(GrGpu* gpu,
94 GrDrawTarget* target,
95 const GrRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000096 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000097
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000098 typedef GrRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000099};
100
101#endif // GrAARectRenderer_DEFINED