Flutter Engine
The Flutter Engine
dl_matrix_clip_tracker.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_DISPLAY_LIST_UTILS_DL_MATRIX_CLIP_TRACKER_H_
6#define FLUTTER_DISPLAY_LIST_UTILS_DL_MATRIX_CLIP_TRACKER_H_
7
8#include <vector>
9
10#include "flutter/display_list/dl_canvas.h"
11#include "flutter/display_list/geometry/dl_geometry_types.h"
12#include "flutter/fml/logging.h"
13
20
21namespace flutter {
22
24 private:
26
27 public:
28 explicit DisplayListMatrixClipState(const DlRect& cull_rect,
29 const DlMatrix& matrix = DlMatrix());
30 explicit DisplayListMatrixClipState(const SkRect& cull_rect);
31 DisplayListMatrixClipState(const SkRect& cull_rect, const SkMatrix& matrix);
32 DisplayListMatrixClipState(const SkRect& cull_rect, const SkM44& matrix);
34
35 static bool is_3x3(const SkM44& m44);
36
37 // This method should almost never be used as it breaks the encapsulation
38 // of the enclosing clips. However it is needed for practical purposes in
39 // some rare cases - such as when a saveLayer is collecting rendering
40 // operations prior to applying a filter on the entire layer bounds and
41 // some of those operations fall outside the enclosing clip, but their
42 // filtered content will spread out from where they were rendered on the
43 // layer into the enclosing clipped area.
44 // Omitting the |cull_rect| argument, or passing nullptr, will restore the
45 // cull rect to the initial value it had when the tracker was constructed.
46 void resetDeviceCullRect(const DlRect& cull_rect);
47 void resetDeviceCullRect(const SkRect& cull_rect) {
48 resetDeviceCullRect(ToDlRect(cull_rect));
49 }
50 void resetLocalCullRect(const DlRect& cull_rect);
51 void resetLocalCullRect(const SkRect& cull_rect) {
52 resetLocalCullRect(ToDlRect(cull_rect));
53 }
54
55 bool using_4x4_matrix() const { return !matrix_.IsAffine(); }
56 bool is_matrix_invertable() const { return matrix_.GetDeterminant() != 0.0f; }
57 bool has_perspective() const { return matrix_.HasPerspective(); }
58
59 const DlMatrix& matrix() const { return matrix_; }
60 SkM44 matrix_4x4() const { return SkM44::ColMajor(matrix_.m); }
61 SkMatrix matrix_3x3() const { return ToSkMatrix(matrix_); }
62
63 SkRect local_cull_rect() const;
64 SkRect device_cull_rect() const { return ToSkRect(cull_rect_); }
65
66 bool rect_covers_cull(const DlRect& content) const;
67 bool rect_covers_cull(const SkRect& content) const {
69 }
70 bool oval_covers_cull(const DlRect& content_bounds) const;
71 bool oval_covers_cull(const SkRect& content_bounds) const {
72 return oval_covers_cull(ToDlRect(content_bounds));
73 }
74 bool rrect_covers_cull(const SkRRect& content) const;
75
76 bool content_culled(const DlRect& content_bounds) const;
77 bool content_culled(const SkRect& content_bounds) const {
78 return content_culled(ToDlRect(content_bounds));
79 }
80 bool is_cull_rect_empty() const { return cull_rect_.IsEmpty(); }
81
83 matrix_ = matrix_.Translate({tx, ty});
84 }
85 void scale(SkScalar sx, SkScalar sy) {
86 matrix_ = matrix_.Scale({sx, sy, 1.0f});
87 }
88 void skew(SkScalar skx, SkScalar sky) {
89 matrix_ = matrix_ * DlMatrix::MakeSkew(skx, sky);
90 }
91 void rotate(SkScalar degrees) {
92 matrix_ = matrix_ * DlMatrix::MakeRotationZ(DlDegrees(degrees));
93 }
94 void transform(const DlMatrix& matrix) { matrix_ = matrix_ * matrix; }
95 void transform(const SkM44& m44) { transform(ToDlMatrix(m44)); }
97 // clang-format off
99 SkScalar mxx, SkScalar mxy, SkScalar mxt,
100 SkScalar myx, SkScalar myy, SkScalar myt) {
101 matrix_ = matrix_ * DlMatrix::MakeColumn(
102 mxx, myx, 0.0f, 0.0f,
103 mxy, myy, 0.0f, 0.0f,
104 0.0f, 0.0f, 1.0f, 0.0f,
105 mxt, myt, 0.0f, 1.0f
106 );
107 }
109 SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt,
110 SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt,
111 SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt,
112 SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt) {
113 matrix_ = matrix_ * DlMatrix::MakeColumn(
114 mxx, myx, mzx, mwx,
115 mxy, myy, mzy, mwy,
116 mxz, myz, mzz, mwz,
117 mxt, myt, mzt, mwt
118 );
119 }
120 // clang-format on
121 void setTransform(const DlMatrix& matrix) { matrix_ = matrix; }
122 void setTransform(const SkMatrix& matrix) { matrix_ = ToDlMatrix(matrix); }
123 void setTransform(const SkM44& m44) { matrix_ = ToDlMatrix(m44); }
124 void setIdentity() { matrix_ = DlMatrix(); }
125 // If the matrix in |other_tracker| is invertible then transform this
126 // tracker by the inverse of its matrix and return true. Otherwise,
127 // return false and leave this tracker unmodified.
128 bool inverseTransform(const DisplayListMatrixClipState& other_tracker);
129
130 bool mapRect(DlRect* rect) const { return mapRect(*rect, rect); }
131 bool mapRect(const DlRect& src, DlRect* mapped) const {
132 *mapped = src.TransformAndClipBounds(matrix_);
133 return matrix_.IsAligned2D();
134 }
135 bool mapRect(SkRect* rect) const { return mapRect(*rect, rect); }
136 bool mapRect(const SkRect& src, SkRect* mapped) const {
137 *mapped = ToSkRect(ToDlRect(src).TransformAndClipBounds(matrix_));
138 return matrix_.IsAligned2D();
139 }
140
141 /// @brief Maps the rect by the current matrix and then clips it against
142 /// the current cull rect, returning true if the result is non-empty.
144 return mapAndClipRect(*rect, rect);
145 }
146 bool mapAndClipRect(const SkRect& src, SkRect* mapped) const;
147
148 void clipRect(const DlRect& rect, ClipOp op, bool is_aa);
149 void clipRect(const SkRect& rect, ClipOp op, bool is_aa) {
150 clipRect(ToDlRect(rect), op, is_aa);
151 }
152 void clipRRect(const SkRRect& rrect, ClipOp op, bool is_aa);
153 void clipPath(const SkPath& path, ClipOp op, bool is_aa);
154
155 private:
156 DlRect cull_rect_;
157 DlMatrix matrix_;
158
159 bool getLocalCullCorners(DlPoint corners[4]) const;
160 void adjustCullRect(const DlRect& clip, ClipOp op, bool is_aa);
161};
162
163} // namespace flutter
164
165#endif // FLUTTER_DISPLAY_LIST_UTILS_DL_MATRIX_CLIP_TRACKER_H_
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition: SkPath.cpp:3892
Definition: SkM44.h:150
static SkM44 ColMajor(const SkScalar c[16])
Definition: SkM44.h:218
Definition: SkPath.h:59
bool mapAndClipRect(SkRect *rect) const
Maps the rect by the current matrix and then clips it against the current cull rect,...
bool inverseTransform(const DisplayListMatrixClipState &other_tracker)
void resetLocalCullRect(const SkRect &cull_rect)
bool mapRect(const DlRect &src, DlRect *mapped) const
void scale(SkScalar sx, SkScalar sy)
void clipRRect(const SkRRect &rrect, ClipOp op, bool is_aa)
void clipRect(const DlRect &rect, ClipOp op, bool is_aa)
DisplayListMatrixClipState(const DisplayListMatrixClipState &other)=default
bool content_culled(const SkRect &content_bounds) const
void transform2DAffine(SkScalar mxx, SkScalar mxy, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myt)
bool mapRect(const SkRect &src, SkRect *mapped) const
bool rect_covers_cull(const SkRect &content) const
void setTransform(const DlMatrix &matrix)
void clipPath(const SkPath &path, ClipOp op, bool is_aa)
void resetLocalCullRect(const DlRect &cull_rect)
void transformFullPerspective(SkScalar mxx, SkScalar mxy, SkScalar mxz, SkScalar mxt, SkScalar myx, SkScalar myy, SkScalar myz, SkScalar myt, SkScalar mzx, SkScalar mzy, SkScalar mzz, SkScalar mzt, SkScalar mwx, SkScalar mwy, SkScalar mwz, SkScalar mwt)
void transform(const SkMatrix &matrix)
void clipRect(const SkRect &rect, ClipOp op, bool is_aa)
void skew(SkScalar skx, SkScalar sky)
bool content_culled(const DlRect &content_bounds) const
void transform(const DlMatrix &matrix)
void resetDeviceCullRect(const DlRect &cull_rect)
void setTransform(const SkMatrix &matrix)
bool oval_covers_cull(const DlRect &content_bounds) const
bool oval_covers_cull(const SkRect &content_bounds) const
void resetDeviceCullRect(const SkRect &cull_rect)
static bool is_3x3(const SkM44 &m44)
DisplayListMatrixClipState(const DlRect &cull_rect, const DlMatrix &matrix=DlMatrix())
bool rect_covers_cull(const DlRect &content) const
void translate(SkScalar tx, SkScalar ty)
bool rrect_covers_cull(const SkRRect &content) const
float SkScalar
Definition: extension.cpp:12
union flutter::testing::@2836::KeyboardChange::@76 content
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
constexpr DlMatrix ToDlMatrix(const SkMatrix &matrix)
impeller::Matrix DlMatrix
impeller::Degrees DlDegrees
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
const DlRect & ToDlRect(const SkRect &rect)
constexpr SkMatrix ToSkMatrix(const DlMatrix &matrix)
const SkRect & ToSkRect(const DlRect &rect)
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
constexpr bool IsAffine() const
Definition: matrix.h:321
Scalar m[16]
Definition: matrix.h:39
constexpr Matrix Translate(const Vector3 &t) const
Definition: matrix.h:240
static constexpr Matrix MakeColumn(Scalar m0, Scalar m1, Scalar m2, Scalar m3, Scalar m4, Scalar m5, Scalar m6, Scalar m7, Scalar m8, Scalar m9, Scalar m10, Scalar m11, Scalar m12, Scalar m13, Scalar m14, Scalar m15)
Definition: matrix.h:69
static constexpr Matrix MakeSkew(Scalar sx, Scalar sy)
Definition: matrix.h:117
constexpr Matrix Scale(const Vector3 &s) const
Definition: matrix.h:252
static Matrix MakeRotationZ(Radians r)
Definition: matrix.h:213
Scalar GetDeterminant() const
Definition: matrix.cc:162
constexpr bool HasPerspective() const
Definition: matrix.h:330
constexpr bool IsAligned2D(Scalar tolerance=0) const
Definition: matrix.h:336
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:287