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

Side by Side Diff: gm/pathmaskcache.cpp

Issue 2335343008: Add optional sw generated path coverage mask caching (Closed)
Patch Set: comments Created 4 years, 3 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 | « no previous file | include/gpu/GrContextOptions.h » ('j') | include/gpu/GrContextOptions.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "gm.h"
9
10 #if SK_SUPPORT_GPU
11
12 #include "GrContext.h"
13 #include "GrContextOptions.h"
14 #include "SkPath.h"
15
16 /** This tests the GPU backend's caching of path coverage masks */
17 class PathMaskCache : public skiagm::GM {
18 public:
19 PathMaskCache() {}
20
21 protected:
22 SkString onShortName() override { return SkString("path_mask_cache"); }
23
24 SkISize onISize() override {
25 return SkISize::Make(650, 950);
26 }
27
robertphillips 2016/09/21 15:42:39 rm ?
bsalomon 2016/09/21 16:01:09 Done.
28 void onOnceBeforeDraw() override {}
29
30 void onDraw(SkCanvas* canvas) override {
31 static constexpr SkScalar kPad = 5;
32
33 SkPaint paint;
34 paint.setAntiAlias(true);
35 auto drawPathSet = [canvas] (const SkPath& path, const SkMatrix& m) {
36 SkPaint paint;
37 paint.setAntiAlias(true);
38 SkRect bounds = path.getBounds();
39 m.mapRect(&bounds);
40 bounds.roundOut();
41 canvas->save();
42 canvas->translate(-bounds.fLeft, -bounds.fTop);
43
44 canvas->save();
45 canvas->concat(m);
46 canvas->drawPath(path, paint);
47 canvas->restore();
48
49 // translate by integer
50 canvas->translate(bounds.width() + kPad, 0.f);
51 canvas->save();
52 canvas->concat(m);
53 canvas->drawPath(path, paint);
54 canvas->restore();
55
56 // translate by non-integer
57 canvas->translate(bounds.width() + kPad + 0.15f, 0.f);
58 canvas->save();
59 canvas->concat(m);
60 canvas->drawPath(path, paint);
61 canvas->restore();
62
63 // translate again so total translate fraction is almost identic al to previous.
64 canvas->translate(bounds.width() + kPad + 0.002f, 0.f);
65 canvas->save();
66 canvas->concat(m);
67 canvas->drawPath(path, paint);
68 canvas->restore();
69 canvas->restore();
70 return bounds.fBottom + kPad;
71 };
72
73
74 SkTArray<SkPath> paths;
75 paths.push_back();
76 paths.back().moveTo(0, 0);
77 paths.back().lineTo(98, 100);
78 paths.back().lineTo(100, 100);
79 paths.back().conicTo(150, 50, 100, 0, 0.6f);
80 paths.back().conicTo(148, 50, 100, 100, 0.6f);
81 paths.back().conicTo(50, 30, 0, 100, 0.9f);
82
83 paths.push_back();
84 paths.back().addCircle(30.f, 30.f, 30.f);
85 paths.back().addRect(SkRect::MakeXYWH(45, 45, 50, 60));
86 paths.back().setFillType(SkPath::kEvenOdd_FillType);
87
88 canvas->translate(kPad, kPad);
89
robertphillips 2016/09/21 15:42:39 I'm a bit surprised we're not checking in to see w
bsalomon 2016/09/21 16:01:09 I couldn't think of a good way to expose that here
90 for (const SkPath& path : paths) {
91 SkScalar ty = drawPathSet(path, SkMatrix::I());
92 canvas->translate(0, ty);
93
94 // Non-uniform scale.
95 SkMatrix s;
96 s.setScale(0.5f, 2.f);
97 ty = drawPathSet(path, s);
98 canvas->translate(0, ty);
99
100 // Rotation
101 SkMatrix r;
102 r.setRotate(60.f, path.getBounds().centerX(), path.getBounds().cente rY());
103 ty = drawPathSet(path, r);
104 canvas->translate(0, ty);
105 }
106 }
107
108 void modifyGrContextOptions(GrContextOptions* options) override {
109 options->fForceSWPathMasks = true;
110 options->fAllowPathMaskCaching = true;
111 }
112
113 private:
114 typedef GM INHERITED;
115 };
116
117 DEF_GM( return new PathMaskCache(); )
118
119 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/GrContextOptions.h » ('j') | include/gpu/GrContextOptions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698