blob: 2e705ca80191e958c4fa139e8745aea7c35bdd9a [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"
robertphillips@google.comf6747b02012-06-12 00:32:28 +000014
15class GrGpu;
16class GrDrawTarget;
17class GrIndexBuffer;
18
19/*
20 * This class wraps helper functions that draw AA rects (filled & stroked)
21 */
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000022class GrAARectRenderer : public SkRefCnt {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000023public:
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000024 SK_DECLARE_INST_COUNT(GrAARectRenderer)
robertphillips@google.comf6747b02012-06-12 00:32:28 +000025
rmistry@google.comfbfcd562012-08-23 18:09:54 +000026 GrAARectRenderer()
robertphillips@google.comf6747b02012-06-12 00:32:28 +000027 : fAAFillRectIndexBuffer(NULL)
28 , fAAStrokeRectIndexBuffer(NULL) {
29 }
30
31 void reset();
32
33 ~GrAARectRenderer() {
34 this->reset();
35 }
36
37 // TODO: potentialy fuse the fill & stroke methods and differentiate
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000038 // between them by passing in strokeWidth (<0 means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000039
robertphillips@google.comf6747b02012-06-12 00:32:28 +000040 void fillAARect(GrGpu* gpu,
41 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000042 const SkRect& rect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000043 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000044 const SkRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000045 bool useVertexCoverage) {
46#ifdef SHADER_AA_FILL_RECT
47 if (combinedMatrix.rectStaysRect()) {
48 this->shaderFillAlignedAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000049 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000050 } else {
51 this->shaderFillAARect(gpu, target,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000052 rect, combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000053 }
54#else
55 this->geometryFillAARect(gpu, target,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000056 rect, combinedMatrix,
robertphillips@google.comafd1cba2013-05-14 19:47:47 +000057 devRect, useVertexCoverage);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000058#endif
59 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000060
robertphillips@google.comf6747b02012-06-12 00:32:28 +000061 void strokeAARect(GrGpu* gpu,
62 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000063 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000064 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000065 const SkRect& devRect,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000066 SkScalar width,
robertphillips@google.comf6747b02012-06-12 00:32:28 +000067 bool useVertexCoverage);
68
robertphillips@google.com83d1a682013-05-17 12:50:27 +000069 // First rect is outer; second rect is inner
70 void fillAANestedRects(GrGpu* gpu,
71 GrDrawTarget* target,
72 const SkRect rects[2],
73 const SkMatrix& combinedMatrix,
74 bool useVertexCoverage);
75
robertphillips@google.comf6747b02012-06-12 00:32:28 +000076private:
77 GrIndexBuffer* fAAFillRectIndexBuffer;
78 GrIndexBuffer* fAAStrokeRectIndexBuffer;
79
robertphillips@google.comf6747b02012-06-12 00:32:28 +000080 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
81
82 static int aaStrokeRectIndexCount();
83 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu);
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000084
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000085 // TODO: Remove the useVertexCoverage boolean. Just use it all the time
86 // since we now have a coverage vertex attribute
87 void geometryFillAARect(GrGpu* gpu,
88 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000089 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000090 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000091 const SkRect& devRect,
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000092 bool useVertexCoverage);
93
94 void shaderFillAARect(GrGpu* gpu,
95 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000096 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000097 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000098
99 void shaderFillAlignedAARect(GrGpu* gpu,
100 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +0000101 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +0000102 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +0000103
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000104 void geometryStrokeAARect(GrGpu* gpu,
105 GrDrawTarget* target,
106 const SkRect& devOutside,
107 const SkRect& devInside,
108 bool useVertexCoverage);
109
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000110 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +0000111};
112
113#endif // GrAARectRenderer_DEFINED