Skip to content

Commit b34ad4a

Browse files
[skwasm] Fix clip rect occlusion rect calculation. (#165446)
The clip region is always expressed in the global coordinates. Hence, we should do the intersection with the clip *after* transforming the rectangle to global coordinates. This fixes dart-lang/sdk#59993 --------- Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
1 parent 096c4ac commit b34ad4a

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

engine/src/flutter/lib/web_ui/lib/src/engine/layers.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class PlatformViewStyling {
777777
final PlatformViewClip clip;
778778

779779
ui.Rect mapLocalToGlobal(ui.Rect rect) {
780-
return position.mapLocalToGlobal(rect.intersect(clip.outerRect));
780+
return position.mapLocalToGlobal(rect).intersect(clip.outerRect);
781781
}
782782

783783
static PlatformViewStyling combine(PlatformViewStyling outer, PlatformViewStyling inner) {
@@ -886,7 +886,7 @@ class PlatformViewNoClip implements PlatformViewClip {
886886
}
887887

888888
class PlatformViewRectClip implements PlatformViewClip {
889-
PlatformViewRectClip(this.rect);
889+
const PlatformViewRectClip(this.rect);
890890

891891
final ui.Rect rect;
892892

engine/src/flutter/lib/web_ui/lib/src/engine/scene_builder.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ class EngineSceneBuilder implements ui.SceneBuilder {
264264
}
265265
sliceIndex--;
266266
}
267-
sliceIndex = 0;
268267
final SceneSlice slice = sceneSlices[sliceIndex];
269268
slice.platformViewOcclusionMap.addRect(globalPlatformViewRect);
270269
return sliceIndex;

engine/src/flutter/lib/web_ui/test/engine/scene_builder_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,49 @@ void testMain() {
207207
expect(slices[1], layerSlice(withPictureRect: const ui.Rect.fromLTRB(200, 200, 300, 300)));
208208
});
209209

210+
test('nested offset and clip', () {
211+
final EngineSceneBuilder builder = EngineSceneBuilder();
212+
{
213+
builder.pushOffset(16, 43);
214+
{
215+
builder.pushClipRect(
216+
const ui.Rect.fromLTRB(0, 0, 1007, 1122),
217+
clipBehavior: ui.Clip.hardEdge,
218+
);
219+
{
220+
builder.pushOffset(1, 214);
221+
builder.addPlatformView(1, width: 1005, height: 907);
222+
builder.pop();
223+
}
224+
builder.pop();
225+
}
226+
builder.pop();
227+
}
228+
229+
const ui.Rect pictureRect = ui.Rect.fromLTRB(16, 198, 310, 280);
230+
builder.addPicture(ui.Offset.zero, StubPicture(pictureRect));
231+
232+
final EngineScene scene = builder.build() as EngineScene;
233+
final List<LayerSlice?> slices = scene.rootLayer.slices;
234+
expect(slices.length, 2);
235+
expect(
236+
slices[0],
237+
layerSlice(
238+
withPlatformViews: <PlatformView>[
239+
PlatformView(
240+
1,
241+
const ui.Rect.fromLTRB(0, 0, 1005, 907),
242+
const PlatformViewStyling(
243+
position: PlatformViewPosition.offset(ui.Offset(17, 257)),
244+
clip: PlatformViewRectClip(ui.Rect.fromLTRB(16.0, 43.0, 1023.0, 1165.0)),
245+
),
246+
),
247+
],
248+
),
249+
);
250+
expect(slices[1], layerSlice(withPictureRect: pictureRect));
251+
});
252+
210253
test('grid view test', () {
211254
// This test case covers a grid of elements, where each element is a platform
212255
// view that has flutter content underneath it and on top of it.

0 commit comments

Comments
 (0)