Flutter Engine
 
Loading...
Searching...
No Matches
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
13#include "flutter/fml/logging.h"
14
15namespace flutter {
16
18 public:
19 explicit DisplayListMatrixClipState(const DlRect& cull_rect,
20 const DlMatrix& matrix = DlMatrix());
22
23 // This method should almost never be used as it breaks the encapsulation
24 // of the enclosing clips. However it is needed for practical purposes in
25 // some rare cases - such as when a saveLayer is collecting rendering
26 // operations prior to applying a filter on the entire layer bounds and
27 // some of those operations fall outside the enclosing clip, but their
28 // filtered content will spread out from where they were rendered on the
29 // layer into the enclosing clipped area.
30 // Omitting the |cull_rect| argument, or passing nullptr, will restore the
31 // cull rect to the initial value it had when the tracker was constructed.
32 void resetDeviceCullRect(const DlRect& cull_rect);
33 void resetLocalCullRect(const DlRect& cull_rect);
34
35 bool using_4x4_matrix() const { return !matrix_.IsAffine(); }
36 bool is_matrix_invertable() const { return matrix_.IsInvertible(); }
37 bool has_perspective() const { return matrix_.HasPerspective(); }
38
39 const DlMatrix& matrix() const { return matrix_; }
40
42 DlRect GetDeviceCullCoverage() const { return cull_rect_; }
43
44 bool rect_covers_cull(const DlRect& content) const;
45 bool oval_covers_cull(const DlRect& content_bounds) const;
46 bool rrect_covers_cull(const DlRoundRect& content) const;
48
49 bool content_culled(const DlRect& content_bounds) const;
50 bool is_cull_rect_empty() const { return cull_rect_.IsEmpty(); }
51
53 matrix_ = matrix_.Translate({tx, ty});
54 }
55 void scale(DlScalar sx, DlScalar sy) {
56 matrix_ = matrix_.Scale({sx, sy, 1.0f});
57 }
58 void skew(DlScalar skx, DlScalar sky) {
59 matrix_ = matrix_ * DlMatrix::MakeSkew(skx, sky);
60 }
61 void rotate(DlRadians angle) {
62 matrix_ = matrix_ * DlMatrix::MakeRotationZ(angle);
63 }
64 void transform(const DlMatrix& matrix) { matrix_ = matrix_ * matrix; }
65 // clang-format off
67 DlScalar mxx, DlScalar mxy, DlScalar mxt,
68 DlScalar myx, DlScalar myy, DlScalar myt) {
69 matrix_ = matrix_ * DlMatrix::MakeColumn(
70 mxx, myx, 0.0f, 0.0f,
71 mxy, myy, 0.0f, 0.0f,
72 0.0f, 0.0f, 1.0f, 0.0f,
73 mxt, myt, 0.0f, 1.0f
74 );
75 }
77 DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt,
78 DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt,
79 DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt,
80 DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt) {
81 matrix_ = matrix_ * DlMatrix::MakeColumn(
82 mxx, myx, mzx, mwx,
83 mxy, myy, mzy, mwy,
84 mxz, myz, mzz, mwz,
85 mxt, myt, mzt, mwt
86 );
87 }
88 // clang-format on
89 void setTransform(const DlMatrix& matrix) { matrix_ = matrix; }
90 void setIdentity() { matrix_ = DlMatrix(); }
91 // If the matrix in |other_tracker| is invertible then transform this
92 // tracker by the inverse of its matrix and return true. Otherwise,
93 // return false and leave this tracker unmodified.
94 bool inverseTransform(const DisplayListMatrixClipState& other_tracker);
95
96 bool mapRect(DlRect* rect) const { return mapRect(*rect, rect); }
97 bool mapRect(const DlRect& src, DlRect* mapped) const {
98 *mapped = src.TransformAndClipBounds(matrix_);
99 return matrix_.IsAligned2D();
100 }
101
102 /// @brief Maps the rect by the current matrix and then clips it against
103 /// the current cull rect, returning true if the result is non-empty.
104 bool mapAndClipRect(DlRect* rect) const {
105 return mapAndClipRect(*rect, rect);
106 }
107 bool mapAndClipRect(const DlRect& src, DlRect* mapped) const;
108
109 void clipRect(const DlRect& rect, DlClipOp op, bool is_aa);
110 void clipOval(const DlRect& bounds, DlClipOp op, bool is_aa);
111 void clipRRect(const DlRoundRect& rrect, DlClipOp op, bool is_aa);
113 DlClipOp op,
114 bool is_aa);
115 void clipPath(const DlPath& path, DlClipOp op, bool is_aa);
116
117 /// @brief Checks if the local rect, when transformed by the matrix,
118 /// completely covers the indicated culling bounds.
119 ///
120 /// This utility method helps answer the question of whether a clip
121 /// rectangle being intersected under a transform is essentially obsolete
122 /// because it will not reduce the already existing clip culling bounds.
123 [[nodiscard]]
124 static bool TransformedRectCoversBounds(const DlRect& local_rect,
125 const DlMatrix& matrix,
126 const DlRect& cull_bounds);
127
128 /// @brief Checks if an oval defined by the local bounds, when transformed
129 /// by the matrix, completely covers the indicated culling bounds.
130 ///
131 /// This utility method helps answer the question of whether a clip
132 /// oval being intersected under a transform is essentially obsolete
133 /// because it will not reduce the already existing clip culling bounds.
134 [[nodiscard]]
135 static bool TransformedOvalCoversBounds(const DlRect& local_oval_bounds,
136 const DlMatrix& matrix,
137 const DlRect& cull_bounds);
138
139 /// @brief Checks if the local round rect, when transformed by the matrix,
140 /// completely covers the indicated culling bounds.
141 ///
142 /// This utility method helps answer the question of whether a clip
143 /// rrect being intersected under a transform is essentially obsolete
144 /// because it will not reduce the already existing clip culling bounds.
145 [[nodiscard]]
146 static bool TransformedRRectCoversBounds(const DlRoundRect& local_rrect,
147 const DlMatrix& matrix,
148 const DlRect& cull_bounds);
149
150 /// @brief Checks if the local round superellipse, when transformed by the
151 /// matrix, completely covers the indicated culling bounds.
152 ///
153 /// This utility method helps answer the question of whether a clip round
154 /// superellipse being intersected under a transform is essentially obsolete
155 /// because it will not reduce the already existing clip culling bounds.
156 [[nodiscard]]
158 const DlRoundSuperellipse& local_rse,
159 const DlMatrix& matrix,
160 const DlRect& cull_bounds);
161
162 private:
163 DlRect cull_rect_;
164 DlMatrix matrix_;
165
166 void adjustCullRect(const DlRect& clip, DlClipOp op, bool is_aa);
167
168 static bool GetLocalCorners(DlPoint corners[4],
169 const DlRect& rect,
170 const DlMatrix& matrix);
171};
172
173} // namespace flutter
174
175#endif // FLUTTER_DISPLAY_LIST_UTILS_DL_MATRIX_CLIP_TRACKER_H_
void translate(DlScalar tx, DlScalar ty)
static bool TransformedRectCoversBounds(const DlRect &local_rect, const DlMatrix &matrix, const DlRect &cull_bounds)
Checks if the local rect, when transformed by the matrix, completely covers the indicated culling bou...
bool inverseTransform(const DisplayListMatrixClipState &other_tracker)
bool mapRect(const DlRect &src, DlRect *mapped) const
void transform2DAffine(DlScalar mxx, DlScalar mxy, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myt)
void scale(DlScalar sx, DlScalar sy)
static bool TransformedRoundSuperellipseCoversBounds(const DlRoundSuperellipse &local_rse, const DlMatrix &matrix, const DlRect &cull_bounds)
Checks if the local round superellipse, when transformed by the matrix, completely covers the indicat...
bool rsuperellipse_covers_cull(const DlRoundSuperellipse &content) const
void clipRect(const DlRect &rect, DlClipOp op, bool is_aa)
DisplayListMatrixClipState(const DisplayListMatrixClipState &other)=default
bool rrect_covers_cull(const DlRoundRect &content) const
void clipRRect(const DlRoundRect &rrect, DlClipOp op, bool is_aa)
void clipRSuperellipse(const DlRoundSuperellipse &rse, DlClipOp op, bool is_aa)
void transformFullPerspective(DlScalar mxx, DlScalar mxy, DlScalar mxz, DlScalar mxt, DlScalar myx, DlScalar myy, DlScalar myz, DlScalar myt, DlScalar mzx, DlScalar mzy, DlScalar mzz, DlScalar mzt, DlScalar mwx, DlScalar mwy, DlScalar mwz, DlScalar mwt)
void setTransform(const DlMatrix &matrix)
void resetLocalCullRect(const DlRect &cull_rect)
static bool TransformedRRectCoversBounds(const DlRoundRect &local_rrect, const DlMatrix &matrix, const DlRect &cull_bounds)
Checks if the local round rect, when transformed by the matrix, completely covers the indicated culli...
bool content_culled(const DlRect &content_bounds) const
void transform(const DlMatrix &matrix)
void clipPath(const DlPath &path, DlClipOp op, bool is_aa)
void resetDeviceCullRect(const DlRect &cull_rect)
bool mapAndClipRect(DlRect *rect) const
Maps the rect by the current matrix and then clips it against the current cull rect,...
bool oval_covers_cull(const DlRect &content_bounds) const
bool rect_covers_cull(const DlRect &content) const
void clipOval(const DlRect &bounds, DlClipOp op, bool is_aa)
void skew(DlScalar skx, DlScalar sky)
static bool TransformedOvalCoversBounds(const DlRect &local_oval_bounds, const DlMatrix &matrix, const DlRect &cull_bounds)
Checks if an oval defined by the local bounds, when transformed by the matrix, completely covers the ...
union flutter::testing::@2824::KeyboardChange::@78 content
impeller::Scalar DlScalar
impeller::Matrix DlMatrix
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 switch_defs.h:52
A 4x4 matrix using column-major storage.
Definition matrix.h:37
constexpr bool IsAffine() const
Definition matrix.h:409
constexpr Matrix Translate(const Vector3 &t) const
Definition matrix.h:263
bool IsInvertible() const
Definition matrix.h:321
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:127
constexpr Matrix Scale(const Vector3 &s) const
Definition matrix.h:275
static Matrix MakeRotationZ(Radians r)
Definition matrix.h:223
constexpr bool HasPerspective() const
Definition matrix.h:418
constexpr bool IsAligned2D(Scalar tolerance=0) const
Definition matrix.h:424
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition rect.h:297
constexpr TRect TransformAndClipBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle, clipped against the near clippin...
Definition rect.h:438