@@ -246,45 +246,59 @@ DlRect DisplayListMatrixClipState::GetLocalCullCoverage() const {
246246}
247247
248248bool DisplayListMatrixClipState::rect_covers_cull (const DlRect& content) const {
249- if (content.IsEmpty ()) {
249+ return TransformedRectCoversBounds (content, matrix_, cull_rect_);
250+ }
251+
252+ bool DisplayListMatrixClipState::TransformedRectCoversBounds (
253+ const DlRect& local_rect,
254+ const DlMatrix& matrix,
255+ const DlRect& cull_bounds) {
256+ if (local_rect.IsEmpty ()) {
250257 return false ;
251258 }
252- if (cull_rect_ .IsEmpty ()) {
259+ if (cull_bounds .IsEmpty ()) {
253260 return true ;
254261 }
255- if (matrix_ .IsAligned2D ()) {
262+ if (matrix .IsAligned2D ()) {
256263 // This transform-to-device calculation is faster and more accurate
257264 // for rect-to-rect aligned transformations, but not accurate under
258265 // (non-quadrant) rotations and skews.
259- return content .TransformAndClipBounds (matrix_ ).Contains (cull_rect_ );
266+ return local_rect .TransformAndClipBounds (matrix ).Contains (cull_bounds );
260267 }
261268 DlPoint corners[4 ];
262- if (!getLocalCullCorners (corners)) {
269+ if (!GetLocalCorners (corners, cull_bounds, matrix )) {
263270 return false ;
264271 }
265272 for (auto corner : corners) {
266- if (!content .ContainsInclusive (corner)) {
273+ if (!local_rect .ContainsInclusive (corner)) {
267274 return false ;
268275 }
269276 }
270277 return true ;
271278}
272279
273280bool DisplayListMatrixClipState::oval_covers_cull (const DlRect& bounds) const {
274- if (bounds.IsEmpty ()) {
281+ return TransformedOvalCoversBounds (bounds, matrix_, cull_rect_);
282+ }
283+
284+ bool DisplayListMatrixClipState::TransformedOvalCoversBounds (
285+ const DlRect& local_oval_bounds,
286+ const DlMatrix& matrix,
287+ const DlRect& cull_bounds) {
288+ if (local_oval_bounds.IsEmpty ()) {
275289 return false ;
276290 }
277- if (cull_rect_ .IsEmpty ()) {
291+ if (cull_bounds .IsEmpty ()) {
278292 return true ;
279293 }
280294 DlPoint corners[4 ];
281- if (!getLocalCullCorners (corners)) {
295+ if (!GetLocalCorners (corners, cull_bounds, matrix )) {
282296 return false ;
283297 }
284- DlPoint center = bounds .GetCenter ();
285- DlSize scale = 2.0 / bounds .GetSize ();
298+ DlPoint center = local_oval_bounds .GetCenter ();
299+ DlSize scale = 2.0 / local_oval_bounds .GetSize ();
286300 for (auto corner : corners) {
287- if (!bounds .Contains (corner)) {
301+ if (!local_oval_bounds .Contains (corner)) {
288302 return false ;
289303 }
290304 if (((corner - center) * scale).GetLengthSquared () >= 1.0 ) {
@@ -296,28 +310,37 @@ bool DisplayListMatrixClipState::oval_covers_cull(const DlRect& bounds) const {
296310
297311bool DisplayListMatrixClipState::rrect_covers_cull (
298312 const DlRoundRect& content) const {
299- if (content.IsEmpty ()) {
313+ return TransformedRRectCoversBounds (content, matrix_, cull_rect_);
314+ }
315+
316+ bool DisplayListMatrixClipState::TransformedRRectCoversBounds (
317+ const DlRoundRect& local_rrect,
318+ const DlMatrix& matrix,
319+ const DlRect& cull_bounds) {
320+ if (local_rrect.IsEmpty ()) {
300321 return false ;
301322 }
302- if (cull_rect_ .IsEmpty ()) {
323+ if (cull_bounds .IsEmpty ()) {
303324 return true ;
304325 }
305- if (content.IsRect ()) {
306- return rect_covers_cull (content.GetBounds ());
326+ if (local_rrect.IsRect ()) {
327+ return TransformedRectCoversBounds (local_rrect.GetBounds (), matrix,
328+ cull_bounds);
307329 }
308- if (content.IsOval ()) {
309- return oval_covers_cull (content.GetBounds ());
330+ if (local_rrect.IsOval ()) {
331+ return TransformedOvalCoversBounds (local_rrect.GetBounds (), matrix,
332+ cull_bounds);
310333 }
311- if (!content .GetRadii ().AreAllCornersSame ()) {
334+ if (!local_rrect .GetRadii ().AreAllCornersSame ()) {
312335 return false ;
313336 }
314337 DlPoint corners[4 ];
315- if (!getLocalCullCorners (corners)) {
338+ if (!GetLocalCorners (corners, cull_bounds, matrix )) {
316339 return false ;
317340 }
318- auto outer = content .GetBounds ();
341+ auto outer = local_rrect .GetBounds ();
319342 auto center = outer.GetCenter ();
320- auto radii = content .GetRadii ().top_left ;
343+ auto radii = local_rrect .GetRadii ().top_left ;
321344 auto inner = outer.GetSize () * 0.5 - radii;
322345 auto scale = 1.0 / radii;
323346 for (auto corner : corners) {
@@ -335,25 +358,34 @@ bool DisplayListMatrixClipState::rrect_covers_cull(
335358
336359bool DisplayListMatrixClipState::rsuperellipse_covers_cull (
337360 const DlRoundSuperellipse& content) const {
338- if (content.IsEmpty ()) {
361+ return TransformedRoundSuperellipseCoversBounds (content, matrix_, cull_rect_);
362+ }
363+
364+ bool DisplayListMatrixClipState::TransformedRoundSuperellipseCoversBounds (
365+ const DlRoundSuperellipse& local_rse,
366+ const DlMatrix& matrix,
367+ const DlRect& cull_bounds) {
368+ if (local_rse.IsEmpty ()) {
339369 return false ;
340370 }
341- if (cull_rect_ .IsEmpty ()) {
371+ if (cull_bounds .IsEmpty ()) {
342372 return true ;
343373 }
344- if (content.IsRect ()) {
345- return rect_covers_cull (content.GetBounds ());
374+ if (local_rse.IsRect ()) {
375+ return TransformedRectCoversBounds (local_rse.GetBounds (), matrix,
376+ cull_bounds);
346377 }
347- if (content.IsOval ()) {
348- return oval_covers_cull (content.GetBounds ());
378+ if (local_rse.IsOval ()) {
379+ return TransformedOvalCoversBounds (local_rse.GetBounds (), matrix,
380+ cull_bounds);
349381 }
350382 DlPoint corners[4 ];
351- if (!getLocalCullCorners (corners)) {
383+ if (!GetLocalCorners (corners, cull_bounds, matrix )) {
352384 return false ;
353385 }
354- auto outer = content .GetBounds ();
386+ auto outer = local_rse .GetBounds ();
355387 auto param = impeller::RoundSuperellipseParam::MakeBoundsRadii (
356- outer, content .GetRadii ());
388+ outer, local_rse .GetRadii ());
357389 for (auto corner : corners) {
358390 if (!outer.Contains (corner)) {
359391 return false ;
@@ -365,15 +397,17 @@ bool DisplayListMatrixClipState::rsuperellipse_covers_cull(
365397 return true ;
366398}
367399
368- bool DisplayListMatrixClipState::getLocalCullCorners (DlPoint corners[4 ]) const {
369- if (!is_matrix_invertable ()) {
400+ bool DisplayListMatrixClipState::GetLocalCorners (DlPoint corners[4 ],
401+ const DlRect& rect,
402+ const DlMatrix& matrix) {
403+ if (!matrix.IsInvertible ()) {
370404 return false ;
371405 }
372- DlMatrix inverse = matrix_ .Invert ();
373- corners[0 ] = inverse * cull_rect_ .GetLeftTop ();
374- corners[1 ] = inverse * cull_rect_ .GetRightTop ();
375- corners[2 ] = inverse * cull_rect_ .GetRightBottom ();
376- corners[3 ] = inverse * cull_rect_ .GetLeftBottom ();
406+ DlMatrix inverse = matrix .Invert ();
407+ corners[0 ] = inverse * rect .GetLeftTop ();
408+ corners[1 ] = inverse * rect .GetRightTop ();
409+ corners[2 ] = inverse * rect .GetRightBottom ();
410+ corners[3 ] = inverse * rect .GetLeftBottom ();
377411 return true ;
378412}
379413
0 commit comments