Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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));
89 paths.back().setFillType(SkPathFillType::kEvenOdd);
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:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
void concat(const SkMatrix &matrix)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:452
static const SkMatrix & I()
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition gm.cpp:81
const Paint & paint
float SkScalar
Definition extension.cpp:12
struct MyStruct s
#define DEF_GM(CODE)
Definition gm.h:40
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