Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: src/gpu/GrAARectRenderer.cpp

Issue 1279303002: Expand functionality of GrRectBatchFactory with AARects (Closed) Base URL: https://skia.googlesource.com/skia.git@batchfactory3
Patch Set: tweaks Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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 #include "GrAARectRenderer.h"
9 #include "GrBatchTarget.h"
10 #include "GrBatchTest.h"
11 #include "GrContext.h"
12 #include "GrDrawTarget.h"
13 #include "GrGeometryProcessor.h"
14 #include "GrInvariantOutput.h"
15 #include "GrTestUtils.h"
16 #include "GrVertexBuffer.h"
17 #include "SkColorPriv.h"
18 #include "batches/GrAAFillRectBatch.h"
19 #include "batches/GrAAStrokeRectBatch.h"
20 #include "gl/GrGLProcessor.h"
21 #include "gl/GrGLGeometryProcessor.h"
22 #include "gl/builders/GrGLProgramBuilder.h"
23
24 ///////////////////////////////////////////////////////////////////////////////
25
26 void GrAARectRenderer::GeometryFillAARect(GrDrawTarget* target,
27 const GrPipelineBuilder& pipelineBuild er,
28 GrColor color,
29 const SkMatrix& viewMatrix,
30 const SkRect& rect,
31 const SkRect& devRect) {
32 GrAAFillRectBatch::Geometry geometry;
33 geometry.fRect = rect;
34 geometry.fViewMatrix = viewMatrix;
35 geometry.fDevRect = devRect;
36 geometry.fColor = color;
37
38
39 SkAutoTUnref<GrBatch> batch(GrAAFillRectBatch::Create(geometry));
40 target->drawBatch(pipelineBuilder, batch);
41 }
42
43 void GrAARectRenderer::StrokeAARect(GrDrawTarget* target,
44 const GrPipelineBuilder& pipelineBuilder,
45 GrColor color,
46 const SkMatrix& viewMatrix,
47 const SkRect& rect,
48 const SkRect& devRect,
49 const SkStrokeRec& stroke) {
50 SkVector devStrokeSize;
51 SkScalar width = stroke.getWidth();
52 if (width > 0) {
53 devStrokeSize.set(width, width);
54 viewMatrix.mapVectors(&devStrokeSize, 1);
55 devStrokeSize.setAbs(devStrokeSize);
56 } else {
57 devStrokeSize.set(SK_Scalar1, SK_Scalar1);
58 }
59
60 const SkScalar dx = devStrokeSize.fX;
61 const SkScalar dy = devStrokeSize.fY;
62 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf);
63 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf);
64
65 SkScalar spare;
66 {
67 SkScalar w = devRect.width() - dx;
68 SkScalar h = devRect.height() - dy;
69 spare = SkTMin(w, h);
70 }
71
72 SkRect devOutside(devRect);
73 devOutside.outset(rx, ry);
74
75 bool miterStroke = true;
76 // For hairlines, make bevel and round joins appear the same as mitered ones .
77 // small miter limit means right angles show bevel...
78 if ((width > 0) && (stroke.getJoin() != SkPaint::kMiter_Join ||
79 stroke.getMiter() < SK_ScalarSqrt2)) {
80 miterStroke = false;
81 }
82
83 if (spare <= 0 && miterStroke) {
84 FillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, devOu tside);
85 return;
86 }
87
88 SkRect devInside(devRect);
89 devInside.inset(rx, ry);
90
91 SkRect devOutsideAssist(devRect);
92
93 // For bevel-stroke, use 2 SkRect instances(devOutside and devOutsideAssist)
94 // to draw the outer of the rect. Because there are 8 vertices on the outer
95 // edge, while vertex number of inner edge is 4, the same as miter-stroke.
96 if (!miterStroke) {
97 devOutside.inset(0, ry);
98 devOutsideAssist.outset(0, ry);
99 }
100
101 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
102 devOutsideAssist, devInside, miterStroke);
103 }
104
105 void GrAARectRenderer::GeometryStrokeAARect(GrDrawTarget* target,
106 const GrPipelineBuilder& pipelineBui lder,
107 GrColor color,
108 const SkMatrix& viewMatrix,
109 const SkRect& devOutside,
110 const SkRect& devOutsideAssist,
111 const SkRect& devInside,
112 bool miterStroke) {
113 GrAAStrokeRectBatch::Geometry geometry;
114 geometry.fColor = color;
115 geometry.fDevOutside = devOutside;
116 geometry.fDevOutsideAssist = devOutsideAssist;
117 geometry.fDevInside = devInside;
118 geometry.fMiterStroke = miterStroke;
119
120 SkAutoTUnref<GrBatch> batch(GrAAStrokeRectBatch::Create(geometry, viewMatrix ));
121 target->drawBatch(pipelineBuilder, batch);
122 }
123
124 void GrAARectRenderer::FillAANestedRects(GrDrawTarget* target,
125 const GrPipelineBuilder& pipelineBuilde r,
126 GrColor color,
127 const SkMatrix& viewMatrix,
128 const SkRect rects[2]) {
129 SkASSERT(viewMatrix.rectStaysRect());
130 SkASSERT(!rects[0].isEmpty() && !rects[1].isEmpty());
131
132 SkRect devOutside, devInside;
133 viewMatrix.mapRect(&devOutside, rects[0]);
134 viewMatrix.mapRect(&devInside, rects[1]);
135
136 if (devInside.isEmpty()) {
137 FillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, devOu tside);
138 return;
139 }
140
141 GeometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
142 devOutside, devInside, true);
143 }
OLDNEW
« no previous file with comments | « src/gpu/GrAARectRenderer.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698