Flutter Engine
The Flutter Engine
pathmaskcache.cpp
Go to the documentation of this file.
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/gm.h"
12#include "include/core/SkPath.h"
13#include "include/core/SkRect.h"
15#include "include/core/SkSize.h"
20
21using namespace skia_private;
22
23/** This tests the GPU backend's caching of path coverage masks */
24class PathMaskCache : public skiagm::GM {
25public:
27
28protected:
29 SkString getName() const override { return SkString("path_mask_cache"); }
30
31 SkISize getISize() override { return SkISize::Make(650, 950); }
32
33 void onDraw(SkCanvas* canvas) override {
34 static constexpr SkScalar kPad = 5.f;
35
37 paint.setAntiAlias(true);
38 auto drawPathSet = [canvas] (const SkPath& path, const SkMatrix& m) {
40 paint.setAntiAlias(true);
41 SkRect bounds = path.getBounds();
42 m.mapRect(&bounds);
43 bounds.roundOut();
44 canvas->save();
45 canvas->translate(-bounds.fLeft, -bounds.fTop);
46
47 canvas->save();
48 canvas->concat(m);
49 canvas->drawPath(path, paint);
50 canvas->restore();
51
52 // translate by integer
53 canvas->translate(bounds.width() + kPad, 0.f);
54 canvas->save();
55 canvas->concat(m);
56 canvas->drawPath(path, paint);
57 canvas->restore();
58
59 // translate by non-integer
60 canvas->translate(bounds.width() + kPad + 0.15f, 0.f);
61 canvas->save();
62 canvas->concat(m);
63 canvas->drawPath(path, paint);
64 canvas->restore();
65
66 // translate again so total translate fraction is almost identical to previous.
67 canvas->translate(bounds.width() + kPad + 0.002f, 0.f);
68 canvas->save();
69 canvas->concat(m);
70 canvas->drawPath(path, paint);
71 canvas->restore();
72 canvas->restore();
73 return bounds.fBottom + kPad;
74 };
75
76
77 TArray<SkPath> paths;
78 paths.push_back();
79 paths.back().moveTo(0.f, 0.f);
80 paths.back().lineTo(98.f, 100.f);
81 paths.back().lineTo(100.f, 100.f);
82 paths.back().conicTo(150.f, 50.f, 100.f, 0.f, 0.6f);
83 paths.back().conicTo(148.f, 50.f, 100.f, 100.f, 0.6f);
84 paths.back().conicTo(50.f, 30.f, 0.f, 100.f, 0.9f);
85
86 paths.push_back();
87 paths.back().addCircle(30.f, 30.f, 30.f);
88 paths.back().addRect(SkRect::MakeXYWH(45.f, 45.f, 50.f, 60.f));
90
91 canvas->translate(kPad, kPad);
92
93 for (const SkPath& path : paths) {
94 SkScalar ty = drawPathSet(path, SkMatrix::I());
95 canvas->translate(0, ty);
96
97 // Non-uniform scale.
98 SkMatrix s;
99 s.setScale(0.5f, 2.f);
100 ty = drawPathSet(path, s);
101 canvas->translate(0.f, ty);
102
103 // Rotation
104 SkMatrix r;
105 r.setRotate(60.f, path.getBounds().centerX(), path.getBounds().centerY());
106 ty = drawPathSet(path, r);
107 canvas->translate(0.f, ty);
108 }
109 }
110
112 options->fGpuPathRenderers = GpuPathRenderers::kNone;
113 options->fAllowPathMaskCaching = true;
114 }
115
116private:
117 using INHERITED = GM;
118};
119
120DEF_GM( return new PathMaskCache(); )
const char * options
constexpr int kPad
void modifyGrContextOptions(GrContextOptions *options) override
SkISize getISize() override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
Definition: SkPath.h:59
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.cpp:1213
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
void setFillType(SkPathFillType ft)
Definition: SkPath.h:235
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
SkPath & conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
Definition: SkPath.cpp:766
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Definition: SkPath.cpp:864
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
#define DEF_GM(CODE)
Definition: gm.h:40
Optional< SkRect > bounds
Definition: SkRecords.h:189
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659