Flutter Engine
The Flutter Engine
ChromeMDRefreshTabs.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(ChromeMDRefreshTabs, 256, 256, false, 0) {
5SkPath GetInteriorPath(
6 float scale, const SkISize& size, float endcap_width, float horizontal_inset = 0) {
7 const float right = size.fWidth * scale;
8 // The bottom of the tab needs to be pixel-aligned or else when we call
9 // ClipPath with anti-aliasing enabled it can cause artifacts.
10 const float bottom = std::ceil(size.fHeight * scale);
11
12 // const float scaled_horizontal_inset = horizontal_inset * scale;
13
14 const float endcap_radius = endcap_width / 2;
15
16 // Construct the interior path by intersecting paths representing the left
17 // and right halves of the tab. Compared to computing the full path at once,
18 // this makes it easier to avoid overdraw in the top center near minimum
19 // width, and to implement cases where |horizontal_inset| != 0.
20 SkPath right_path;
21
22 right_path.moveTo(right, bottom);
23 // right_path.moveTo(right - 1 - scaled_horizontal_inset, bottom);
24
25 right_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
26 SkPathDirection::kCW, right - endcap_radius, bottom - endcap_radius);
27 // right_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, -0.5 * scale,
28 // -2 * scale, -1.5 * scale);
29
30 right_path.lineTo(right - endcap_radius, endcap_radius);
31 // right_path.lineTo(
32 // right - 1 - scaled_horizontal_inset - (endcap_width - 2) * scale,
33 // 2.5 * scale);
34
35 right_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
36 SkPathDirection::kCCW, right - endcap_width, 0);
37 // right_path.rCubicTo(-0.375 * scale, -1 * scale, -1.25 * scale, -1.5 * scale,
38 // -2 * scale, -1.5 * scale);
39
40 right_path.lineTo(0, 0);
41 right_path.lineTo(0, bottom);
42 right_path.close();
43
44 SkPath left_path;
45 // const float scaled_endcap_width = 1 + endcap_width * scale;
46 left_path.moveTo(endcap_width, 0);
47 // left_path.moveTo(scaled_endcap_width + scaled_horizontal_inset, scale);
48
49 left_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
50 SkPathDirection::kCCW, endcap_radius, endcap_radius);
51 // left_path.rCubicTo(-0.75 * scale, 0, -1.625 * scale, 0.5 * scale, -2 * scale,
52 // 1.5 * scale);
53
54 left_path.lineTo(endcap_radius, bottom - endcap_radius);
55 // left_path.lineTo(1 + scaled_horizontal_inset + 2 * scale,
56 // bottom - 1.5 * scale);
57
58 left_path.arcTo(endcap_radius, endcap_radius, 90, SkPath::kSmall_ArcSize,
59 SkPathDirection::kCW, 0, bottom);
60 // left_path.rCubicTo(-0.375 * scale, scale, -1.25 * scale, 1.5 * scale,
61 // -2 * scale, 1.5 * scale);
62
63 left_path.lineTo(right, bottom);
64 left_path.lineTo(right, 0);
65 left_path.close();
66
67 SkPath complete_path;
68 Op(left_path, right_path, SkPathOp::kIntersect_SkPathOp, &complete_path);
69 return complete_path;
70}
71
72void draw(SkCanvas* canvas) {
73 SkPaint p;
74 p.setColor(SK_ColorRED);
75 p.setAntiAlias(true);
76 p.setStyle(SkPaint::kStroke_Style);
77 p.setStrokeWidth(1);
78 SkPath path = GetInteriorPath(1.f, SkISize::Make(250, 36), 16);
79 canvas->drawPath(path, p);
80
81 // canvas->drawLine(20, 20, 100, 100, p);
82}
83} // END FIDDLE
REG_FIDDLE(ChromeMDRefreshTabs, 256, 256, false, 0)
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
@ kIntersect_SkPathOp
intersect the two paths
Definition: SkPathOps.h:24
static bool right(const SkPoint &p0, const SkPoint &p1)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
SkPath & arcTo(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
Definition: SkPath.cpp:1220
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728
@ kSmall_ArcSize
smaller of arc pair
Definition: SkPath.h:924
SkPath & close()
Definition: SkPath.cpp:823
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
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SIN Vec< N, float > ceil(const Vec< N, float > &x)
Definition: SkVx.h:702
const Scalar scale
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20