blob: c6e3976b7f741e785a2131ebc8263802c2fdec30 [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
joshualittb44293e2014-10-28 08:12:18 -070027 GrAARectRenderer(GrGpu* gpu)
28 : fGpu(gpu)
29 , fAAFillRectIndexBuffer(NULL)
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000030 , fAAMiterStrokeRectIndexBuffer(NULL)
31 , fAABevelStrokeRectIndexBuffer(NULL) {
robertphillips@google.comf6747b02012-06-12 00:32:28 +000032 }
33
34 void reset();
35
36 ~GrAARectRenderer() {
37 this->reset();
38 }
39
40 // TODO: potentialy fuse the fill & stroke methods and differentiate
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000041 // between them by passing in stroke (==NULL means fill).
robertphillips@google.comf6747b02012-06-12 00:32:28 +000042
joshualittb44293e2014-10-28 08:12:18 -070043 void fillAARect(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
joshualittb44293e2014-10-28 08:12:18 -070056 this->geometryFillAARect(target, rect, combinedMatrix, devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000057#endif
58 }
robertphillips@google.comdf3695e2013-04-09 14:01:44 +000059
joshualittb44293e2014-10-28 08:12:18 -070060 void strokeAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000061 const SkRect& rect,
robertphillips@google.com18136d12013-05-10 11:05:58 +000062 const SkMatrix& combinedMatrix,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000063 const SkRect& devRect,
bsalomon9c0822a2014-08-11 11:07:48 -070064 const SkStrokeRec& stroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000065
robertphillips@google.com83d1a682013-05-17 12:50:27 +000066 // First rect is outer; second rect is inner
joshualittb44293e2014-10-28 08:12:18 -070067 void fillAANestedRects(GrDrawTarget* target,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000068 const SkRect rects[2],
bsalomon9c0822a2014-08-11 11:07:48 -070069 const SkMatrix& combinedMatrix);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000070
robertphillips@google.comf6747b02012-06-12 00:32:28 +000071private:
joshualittb44293e2014-10-28 08:12:18 -070072 GrIndexBuffer* aaStrokeRectIndexBuffer(bool miterStroke);
robertphillips@google.comf6747b02012-06-12 00:32:28 +000073
joshualittb44293e2014-10-28 08:12:18 -070074 void geometryFillAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000075 const SkRect& rect,
robertphillips@google.com4b140b52013-05-02 17:13:13 +000076 const SkMatrix& combinedMatrix,
bsalomon9c0822a2014-08-11 11:07:48 -070077 const SkRect& devRect);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000078
joshualittb44293e2014-10-28 08:12:18 -070079 void shaderFillAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000080 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000081 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000082
joshualittb44293e2014-10-28 08:12:18 -070083 void shaderFillAlignedAARect(GrDrawTarget* target,
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000084 const SkRect& rect,
robertphillips@google.com114eb9e2013-05-10 13:16:13 +000085 const SkMatrix& combinedMatrix);
robertphillips@google.comb19cb7f2013-05-02 15:37:20 +000086
joshualittb44293e2014-10-28 08:12:18 -070087 void geometryStrokeAARect(GrDrawTarget* target,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000088 const SkRect& devOutside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000089 const SkRect& devOutsideAssist,
robertphillips@google.com83d1a682013-05-17 12:50:27 +000090 const SkRect& devInside,
commit-bot@chromium.org6006d0f2013-11-06 10:08:21 +000091 bool miterStroke);
robertphillips@google.com83d1a682013-05-17 12:50:27 +000092
joshualittb44293e2014-10-28 08:12:18 -070093 GrGpu* fGpu;
94 GrIndexBuffer* fAAFillRectIndexBuffer;
95 GrIndexBuffer* fAAMiterStrokeRectIndexBuffer;
96 GrIndexBuffer* fAABevelStrokeRectIndexBuffer;
97
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +000098 typedef SkRefCnt INHERITED;
robertphillips@google.comf6747b02012-06-12 00:32:28 +000099};
100
101#endif // GrAARectRenderer_DEFINED