blob: 3e7e980e59371c6e3fa2043f6ee0ae33e79cb5c5 [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
robertphillips@google.comf6747b02012-06-12 00:32:28 +00008#ifndef GrAARectRenderer_DEFINED
9#define GrAARectRenderer_DEFINED
10
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000011#include "SkMatrix.h"
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000012#include "SkRect.h"
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000013#include "SkRefCnt.h"
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000014#include "SkStrokeRec.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 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000023class GrAARectRenderer : public SkRefCnt {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000024public:
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)
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000029 , fAAMiterStrokeRectIndexBuffer(NULL)
30 , fAABevelStrokeRectIndexBuffer(NULL) {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000031 }
32
33 void reset();
34
35 ~GrAARectRenderer() {
36 this->reset();
37 }
38
39 // TODO: potentialy fuse the fill & stroke methods and differentiate
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000040 // between them by passing in stroke (==NULL means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000041
robertphillips@google.comf6747b02012-06-12 00:32:28 +000042 void fillAARect(GrGpu* gpu,
43 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000044 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000045 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000046 const SkRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000047 bool useVertexCoverage) {
48#ifdef SHADER_AA_FILL_RECT
49 if (combinedMatrix.rectStaysRect()) {
50 this->shaderFillAlignedAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000051 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000052 } else {
53 this->shaderFillAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000054 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000055 }
56#else
57 this->geometryFillAARect(gpu, target,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000058 rect, combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000059 devRect, useVertexCoverage);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000060#endif
61 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000062
robertphillips@google.comf6747b02012-06-12 00:32:28 +000063 void strokeAARect(GrGpu* gpu,
64 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000065 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000066 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000067 const SkRect& devRect,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000068 const SkStrokeRec* stroke,
robertphillips@google.comf6747b02012-06-12 00:32:28 +000069 bool useVertexCoverage);
70
robertphillips@google.com83d1a682013-05-17 12:50:27 +000071 // 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
robertphillips@google.comf6747b02012-06-12 00:32:28 +000078private:
79 GrIndexBuffer* fAAFillRectIndexBuffer;
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000080 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
81 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000082
robertphillips@google.comf6747b02012-06-12 00:32:28 +000083 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
84
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000085 static int aaStrokeRectIndexCount(bool miterStroke);
86 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke);
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000087
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000088 // 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,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000092 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000093 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000094 const SkRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000095 bool useVertexCoverage);
96
97 void shaderFillAARect(GrGpu* gpu,
98 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000099 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +0000100 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +0000101
102 void shaderFillAlignedAARect(GrGpu* gpu,
103 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000104 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +0000105 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +0000106
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000107 void geometryStrokeAARect(GrGpu* gpu,
108 GrDrawTarget* target,
109 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000110 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000111 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000112 bool useVertexCoverage,
113 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000114
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000115 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +0000116};
117
118#endif // GrAARectRenderer_DEFINED