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

Side by Side Diff: gm/convex_all_line_paths.cpp

Issue 1120023003: Refugee from Dead Machine 13: New version of the convex AA tessellator Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 7 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 | « dm/DMSrcSink.cpp ('k') | gm/rects.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "GrAAConvexTessellator.h"
9 10
10 static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) { 11 static void create_ngon(int n, SkPoint* pts, SkScalar width, SkScalar height) {
11 float angleStep = 360.0f / n, angle = 0.0f, sin, cos; 12 float angleStep = 360.0f / n, angle = 0.0f, sin, cos;
12 if ((n % 2) == 1) { 13 if ((n % 2) == 1) {
13 angle = angleStep/2.0f; 14 angle = angleStep/2.0f;
14 } 15 }
15 16
16 for (int i = 0; i < n; ++i) { 17 for (int i = 0; i < n; ++i) {
17 sin = SkScalarSinCos(SkDegreesToRadians(angle), &cos); 18 sin = SkScalarSinCos(SkDegreesToRadians(angle), &cos);
18 pts[i].fX = -sin * width; 19 pts[i].fX = -sin * width;
19 pts[i].fY = cos * height; 20 pts[i].fY = cos * height;
20 angle += angleStep; 21 angle += angleStep;
21 } 22 }
22 } 23 }
23 24
24 namespace skiagm { 25 namespace skiagm {
25 26
26 // This GM is intended to exercise Ganesh's handling of convex line-only 27 // This GM is intended to exercise Ganesh's handling of convex line-only
27 // paths 28 // paths
28 class ConvexLineOnlyPathsGM : public GM { 29 class ConvexLineOnlyPathsGM : public GM {
29 public: 30 public:
30 ConvexLineOnlyPathsGM() { 31 ConvexLineOnlyPathsGM() {
31 fOffset.set(0, SkScalarHalf(kMaxPathHeight)); 32 fOffset.set(0, SkScalarHalf(kMaxPathHeight));
32 this->setBGColor(0xFFFFFFFF); 33 this->setBGColor(0xFF404040);
33 } 34 }
34 35
35 protected: 36 protected:
36 SkString onShortName() override { return SkString("convex-lineonly-paths"); } 37 SkString onShortName() override { return SkString("convex-lineonly-paths"); }
37 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); } 38 SkISize onISize() override { return SkISize::Make(kGMWidth, kGMHeight); }
38 bool runAsBench() const override { return true; } 39 bool runAsBench() const override { return true; }
39 40
40 static SkPath GetPath(int index, int offset, SkPath::Direction dir) { 41 static SkPath GetPath(int index, int offset, SkPath::Direction dir) {
41 // narrow rect 42 // narrow rect
42 const SkPoint gPoints0[] = { 43 const SkPoint gPoints0[] = {
43 { -1.5f, -50.0f }, 44 { -1.5f, -50.0f },
44 { 1.5f, -50.0f }, 45 { 1.5f, -50.0f },
45 { 1.5f, 50.0f }, 46 { 1.5f, 50.0f },
46 { -1.5f, 50.0f } 47 { -1.5f, 50.0f }
47 }; 48 };
48 // narrow rect on an angle 49 // narrow rect on an angle
49 const SkPoint gPoints1[] = { 50 const SkPoint gPoints1[] = {
50 { -50.0f, -49.0f }, 51 { -50.0f, -49.0f },
51 { -49.0f, -50.0f }, 52 { -49.0f, -50.0f },
52 { 50.0f, 49.0f }, 53 { 50.0f, 49.0f },
53 { 49.0f, 50.0f } 54 { 49.0f, 50.0f }
54 }; 55 };
55 // trap - narrow on top - wide on bottom 56 // trap - narrow on top - wide on bottom
56 const SkPoint gPoints2[] = { 57 const SkPoint gPoints2[] = {
57 { -10.0f, -50.0f }, 58 { -2.0f, -50.0f },
58 { 10.0f, -50.0f }, 59 { 2.0f, -50.0f },
59 { 50.0f, 50.0f }, 60 { 50.0f, 50.0f },
60 { -50.0f, 50.0f } 61 { -50.0f, 50.0f }
61 }; 62 };
62 // wide skewed rect 63 // wide skewed rect
63 const SkPoint gPoints3[] = { 64 const SkPoint gPoints3[] = {
64 { -50.0f, -50.0f }, 65 { -50.0f, -50.0f },
65 { 0.0f, -50.0f }, 66 { 0.0f, -50.0f },
66 { 50.0f, 50.0f }, 67 { 50.0f, 50.0f },
67 { 0.0f, 50.0f } 68 { 0.0f, 50.0f }
68 }; 69 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 { -25.00f, 50.00f }, 124 { -25.00f, 50.00f },
124 { -40.45f, 47.55f }, 125 { -40.45f, 47.55f },
125 { -54.39f, 40.45f }, 126 { -54.39f, 40.45f },
126 { -65.45f, 29.39f }, 127 { -65.45f, 29.39f },
127 { -72.55f, 15.45f }, 128 { -72.55f, 15.45f },
128 { -75.00f, 0.00f }, 129 { -75.00f, 0.00f },
129 { -72.55f, -15.45f }, 130 { -72.55f, -15.45f },
130 { -65.45f, -29.39f }, 131 { -65.45f, -29.39f },
131 { -54.39f, -40.45f }, 132 { -54.39f, -40.45f },
132 { -40.45f, -47.55f }, 133 { -40.45f, -47.55f },
133 { -25.0f, -50.0f }, 134 { -25.0f, -50.0f },
134 { -9.55f, -47.55f }, 135 { -9.55f, -47.55f },
135 { 4.39f, -40.45f }, 136 { 4.39f, -40.45f },
136 { 75.00f, 0.00f } 137 { 75.00f, 0.00f }
137 }; 138 };
138 // clipped triangle 139 // clipped triangle
139 const SkPoint gPoints10[] = { 140 const SkPoint gPoints10[] = {
140 { -10.0f, -50.0f }, 141 { -10.0f, -50.0f },
141 { 10.0f, -50.0f }, 142 { 10.0f, -50.0f },
142 { 50.0f, 31.0f }, 143 { 50.0f, 31.0f },
143 { 40.0f, 50.0f }, 144 { 40.0f, 50.0f },
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 canvas->save(); 277 canvas->save();
277 canvas->translate(center.fX, center.fY); 278 canvas->translate(center.fX, center.fY);
278 canvas->scale(scales[i], scales[i]); 279 canvas->scale(scales[i], scales[i]);
279 paint.setColor(colors[i%2]); 280 paint.setColor(colors[i%2]);
280 canvas->drawPath(path, paint); 281 canvas->drawPath(path, paint);
281 canvas->restore(); 282 canvas->restore();
282 } 283 }
283 } 284 }
284 285
285 void onDraw(SkCanvas* canvas) override { 286 void onDraw(SkCanvas* canvas) override {
287 #if 0
288 SkPath path = GetPath(8, 0, SkPath::kCCW_Direction);
289
290 SkMatrix m2;
291 m2.setScale(0.01f, 0.01f);
292 // m2.postTranslate(kGMWidth/2, kGMHeight/2);
293
294 path.transform(m2);
295
296 GrAAConvexTessellator result;
297 result.setTargetDepth(40.0f);
298
299 result.tessellate(SkMatrix::I(), path);
300
301 canvas->translate(kGMWidth/2, kGMHeight/2);
302 canvas->scale(400, 400);
303 #if GR_AA_CONVEX_TESSELLATOR_VIZ
304 result.draw(canvas);
305 #endif
306
307 #else
286 for (int i = 0; i < kNumPaths; ++i) { 308 for (int i = 0; i < kNumPaths; ++i) {
287 this->drawPath(canvas, i); 309 this->drawPath(canvas, i);
288 } 310 }
289 311
290 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP U rasterization) 312 // Repro for crbug.com/472723 (Missing AA on portions of graphic with GP U rasterization)
291 { 313 {
292 canvas->translate(356.0f, 50.0f); 314 canvas->translate(356.0f, 50.0f);
293 315
294 SkPaint p; 316 SkPaint p;
295 p.setAntiAlias(true); 317 p.setAntiAlias(true);
296 318
297 SkPath p1; 319 SkPath p1;
298 p1.moveTo(60.8522949f, 364.671021f); 320 p1.moveTo(60.8522949f, 364.671021f);
299 p1.lineTo(59.4380493f, 364.671021f); 321 p1.lineTo(59.4380493f, 364.671021f);
300 p1.lineTo(385.414276f, 690.647217f); 322 p1.lineTo(385.414276f, 690.647217f);
301 p1.lineTo(386.121399f, 689.940125f); 323 p1.lineTo(386.121399f, 689.940125f);
302 canvas->drawPath(p1, p); 324 canvas->drawPath(p1, p);
303 } 325 }
326 #endif
304 } 327 }
305 328
306 private: 329 private:
307 static const int kNumPaths = 20; 330 static const int kNumPaths = 20;
308 static const int kMaxPathHeight = 100; 331 static const int kMaxPathHeight = 100;
309 static const int kGMWidth = 512; 332 static const int kGMWidth = 1024;
310 static const int kGMHeight = 512; 333 static const int kGMHeight = 1024;
311 334
312 SkPoint fOffset; // the right edge of the last drawn path 335 SkPoint fOffset; // the right edge of the last drawn path
313 336
314 typedef GM INHERITED; 337 typedef GM INHERITED;
315 }; 338 };
316 339
317 ////////////////////////////////////////////////////////////////////////////// 340 //////////////////////////////////////////////////////////////////////////////
318 341
319 DEF_GM( return SkNEW(ConvexLineOnlyPathsGM); ) 342 DEF_GM( return SkNEW(ConvexLineOnlyPathsGM); )
320 343
321 } 344 }
OLDNEW
« no previous file with comments | « dm/DMSrcSink.cpp ('k') | gm/rects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698