Flutter Engine
 
Loading...
Searching...
No Matches
helpers.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_LIB_WEB_UI_SKWASM_HELPERS_H_
6#define FLUTTER_LIB_WEB_UI_SKWASM_HELPERS_H_
7
10
11#include "third_party/skia/include/core/SkMatrix.h"
12#include "third_party/skia/include/core/SkRRect.h"
13#include "third_party/skia/include/core/SkSamplingOptions.h"
14
15namespace Skwasm {
16
17template <typename T>
19 public:
20 sp_wrapper(std::shared_ptr<T> ptr) : _ptr(std::move(ptr)) {}
21
22 const std::shared_ptr<T>& shared() { return _ptr; }
23
24 T* raw() { return _ptr.get(); }
25
26 private:
27 std::shared_ptr<T> _ptr;
28};
29
31 // clang-format off
32 return flutter::DlMatrix(
33 f[0], f[3], 0, f[6],
34 f[1], f[4], 0, f[7],
35 0, 0, 1, 0,
36 f[2], f[5], 0, f[8]
37 );
38 // clang-format on
39}
40
41inline SkMatrix createSkMatrix(const SkScalar* f) {
42 return SkMatrix::MakeAll(f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7],
43 f[8]);
44}
45
46inline flutter::DlRect createDlRect(const float* f) {
47 return flutter::DlRect::MakeLTRB(f[0], f[1], f[2], f[3]);
48}
49
51 // Flutter has radii in TL,TR,BR,BL (clockwise) order,
52 // but Impeller uses TL,TR,BL,BR (zig-zag) order
54 .top_left = flutter::DlSize(f[0], f[1]),
55 .top_right = flutter::DlSize(f[2], f[3]),
56 .bottom_left = flutter::DlSize(f[6], f[7]),
57 .bottom_right = flutter::DlSize(f[4], f[5]),
58 };
59 return radii;
60}
61
66
67inline SkRRect createSkRRect(const SkScalar* f) {
68 const SkRect* rect = reinterpret_cast<const SkRect*>(f);
69 const SkVector* radiiValues = reinterpret_cast<const SkVector*>(f + 4);
70 SkRRect rr;
71 rr.setRectRadii(*rect, radiiValues);
72 return rr;
73}
74
75// This needs to be kept in sync with the "FilterQuality" enum in dart:ui
76enum class FilterQuality {
77 none,
78 low,
79 medium,
80 high,
81};
82
93
107} // namespace Skwasm
108
109#endif // FLUTTER_LIB_WEB_UI_SKWASM_HELPERS_H_
const std::shared_ptr< T > & shared()
Definition helpers.h:22
sp_wrapper(std::shared_ptr< T > ptr)
Definition helpers.h:20
flutter::DlFilterMode filterModeForQuality(FilterQuality quality)
Definition helpers.h:83
flutter::DlRoundingRadii createDlRadii(const float *f)
Definition helpers.h:50
SkRRect createSkRRect(const SkScalar *f)
Definition helpers.h:67
flutter::DlMatrix createDlMatrixFrom3x3(const flutter::DlScalar *f)
Definition helpers.h:30
flutter::DlRect createDlRect(const float *f)
Definition helpers.h:46
flutter::DlRoundRect createDlRRect(const float *f)
Definition helpers.h:62
FilterQuality
Definition helpers.h:76
SkMatrix createSkMatrix(const SkScalar *f)
Definition helpers.h:41
flutter::DlImageSampling samplingOptionsForQuality(FilterQuality quality)
Definition helpers.h:94
impeller::Scalar DlScalar
impeller::Matrix DlMatrix
impeller::Size DlSize
Definition ref_ptr.h:261
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition round_rect.cc:9
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129