Skip to content

Commit

Permalink
Add comment to use of 3x3 mapRect in TransformLayer (flutter#43608)
Browse files Browse the repository at this point in the history
Addresses comment in flutter/flutter#130303 (comment)

No tests as this is just a comment.
  • Loading branch information
flar authored and kjlubick committed Jul 14, 2023
1 parent 68ef9f8 commit aac10ee
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions flow/layers/transform_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ void TransformLayer::Preroll(PrerollContext* context) {
SkRect child_paint_bounds = SkRect::MakeEmpty();
PrerollChildren(context, &child_paint_bounds);

// We convert to a 3x3 matrix here primarily because the SkM44 object
// does not support a mapRect operation.
// https://bugs.chromium.org/p/skia/issues/detail?id=11720&q=mapRect&can=2
//
// All geometry is X,Y only which means the 3rd row of the 4x4 matrix
// is ignored and the output of the 3rd column is also ignored.
// So we can transform the rectangle using just the 3x3 SkMatrix
// equivalent without any loss of information.
//
// Performance consideration:
// Skia has an internal mapRect for their SkM44 object that is faster
// than what SkMatrix does when it has perspective elements. But SkMatrix
// is otherwise optimal for non-perspective matrices. If SkM44 ever exposes
// a mapRect operation, or if SkMatrix ever optimizes its handling of
// the perspective elements, this issue will become moot.
transform_.asM33().mapRect(&child_paint_bounds);
set_paint_bounds(child_paint_bounds);
}
Expand Down

0 comments on commit aac10ee

Please sign in to comment.