blob: bfa295bb13ab33f4a99a225035bdf0bf07d670e5 [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,
bsalomon9c0822a2014-08-11 11:07:48 -070046 const SkRect& devRect) {
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000047#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
bsalomon9c0822a2014-08-11 11:07:48 -070056 this->geometryFillAARect(gpu, target, rect, combinedMatrix, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000057#endif
58 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000059
robertphillips@google.comf6747b02012-06-12 00:32:28 +000060 void strokeAARect(GrGpu* gpu,
61 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000062 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000063 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000064 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070065 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000066
robertphillips@google.com83d1a682013-05-17 12:50:27 +000067 // First rect is outer; second rect is inner
68 void fillAANestedRects(GrGpu* gpu,
69 GrDrawTarget* target,
70 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070071 const SkMatrix& combinedMatrix);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000072
robertphillips@google.comf6747b02012-06-12 00:32:28 +000073private:
74 GrIndexBuffer* fAAFillRectIndexBuffer;
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000075 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
76 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000077
robertphillips@google.comf6747b02012-06-12 00:32:28 +000078 GrIndexBuffer* aaFillRectIndexBuffer(GrGpu* gpu);
79
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000080 static int aaStrokeRectIndexCount(bool miterStroke);
81 GrIndexBuffer* aaStrokeRectIndexBuffer(GrGpu* gpu, bool miterStroke);
robertphillips@google.com4d73ac22012-06-13 18:54:08 +000082
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000083 void geometryFillAARect(GrGpu* gpu,
84 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000085 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000086 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070087 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000088
89 void shaderFillAARect(GrGpu* gpu,
90 GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000091 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000092 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000093
94 void shaderFillAlignedAARect(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
robertphillips@google.com83d1a682013-05-17 12:50:27 +000099 void geometryStrokeAARect(GrGpu* gpu,
100 GrDrawTarget* target,
101 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000102 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000103 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +0000104 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +0000105
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000106 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +0000107};
108
109#endif // GrAARectRenderer_DEFINED