Revert "[skwasm] Clip pictures if they go beyond the bounds of the window. (#50887)" (flutter/engine#51067)
This reverts commit 3af9b7b3ba.
The change is causing skwasm benchmarks to flake. See https://ci.chromium.org/ui/p/flutter/builders/luci.flutter.prod/Linux%20web_benchmarks_skwasm
This commit is contained in:
@@ -20,7 +20,6 @@ typedef RenderResult = ({
|
||||
// composite pictures into the canvases in the DOM tree it builds.
|
||||
abstract class PictureRenderer {
|
||||
FutureOr<RenderResult> renderPictures(List<ScenePicture> picture);
|
||||
ScenePicture clipPicture(ScenePicture picture, ui.Rect clip);
|
||||
}
|
||||
|
||||
class _SceneRender {
|
||||
@@ -87,41 +86,12 @@ class EngineSceneView {
|
||||
}
|
||||
}
|
||||
|
||||
ScenePicture _clipPictureIfNeeded(ScenePicture picture, ui.Rect clip) {
|
||||
final ui.Rect pictureRect = picture.cullRect;
|
||||
if (pictureRect.left >= clip.left &&
|
||||
pictureRect.top >= clip.top &&
|
||||
pictureRect.right <= clip.right &&
|
||||
pictureRect.bottom <= clip.bottom) {
|
||||
// The picture is already within the clip bounds.
|
||||
return picture;
|
||||
}
|
||||
|
||||
return pictureRenderer.clipPicture(picture, clip);
|
||||
}
|
||||
|
||||
ui.Rect? _getScreenBounds() {
|
||||
final DomScreen? screen = domWindow.screen;
|
||||
if (screen == null) {
|
||||
return null;
|
||||
}
|
||||
return ui.Rect.fromLTWH(0, 0, screen.width, screen.height);
|
||||
}
|
||||
|
||||
Future<void> _renderScene(EngineScene scene, FrameTimingRecorder? recorder) async {
|
||||
final ui.Rect? screenBounds = _getScreenBounds();
|
||||
if (screenBounds == null) {
|
||||
// The browser isn't displaying the document. Skip rendering.
|
||||
return;
|
||||
}
|
||||
final List<LayerSlice> slices = scene.rootLayer.slices;
|
||||
final List<ScenePicture> picturesToRender = <ScenePicture>[];
|
||||
final List<ScenePicture> originalPicturesToRender = <ScenePicture>[];
|
||||
for (final LayerSlice slice in slices) {
|
||||
if (slice is PictureSlice && !slice.picture.cullRect.isEmpty) {
|
||||
originalPicturesToRender.add(slice.picture);
|
||||
final ScenePicture clippedPicture = _clipPictureIfNeeded(slice.picture, screenBounds);
|
||||
picturesToRender.add(clippedPicture);
|
||||
if (slice is PictureSlice) {
|
||||
picturesToRender.add(slice.picture);
|
||||
}
|
||||
}
|
||||
final Map<ScenePicture, DomImageBitmap> renderMap;
|
||||
@@ -129,7 +99,7 @@ class EngineSceneView {
|
||||
final RenderResult renderResult = await pictureRenderer.renderPictures(picturesToRender);
|
||||
renderMap = <ScenePicture, DomImageBitmap>{
|
||||
for (int i = 0; i < picturesToRender.length; i++)
|
||||
originalPicturesToRender[i]: renderResult.imageBitmaps[i],
|
||||
picturesToRender[i]: renderResult.imageBitmaps[i],
|
||||
};
|
||||
recorder?.recordRasterStart(renderResult.rasterStartMicros);
|
||||
recorder?.recordRasterFinish(renderResult.rasterEndMicros);
|
||||
@@ -155,11 +125,10 @@ class EngineSceneView {
|
||||
}
|
||||
}
|
||||
|
||||
final ui.Rect clippedBounds = slice.picture.cullRect.intersect(screenBounds);
|
||||
if (container != null) {
|
||||
container.bounds = clippedBounds;
|
||||
container.bounds = slice.picture.cullRect;
|
||||
} else {
|
||||
container = PictureSliceContainer(clippedBounds);
|
||||
container = PictureSliceContainer(slice.picture.cullRect);
|
||||
}
|
||||
container.updateContents();
|
||||
container.renderBitmap(renderMap[slice.picture]!);
|
||||
|
||||
@@ -482,14 +482,4 @@ class SkwasmPictureRenderer implements PictureRenderer {
|
||||
@override
|
||||
FutureOr<RenderResult> renderPictures(List<ScenePicture> pictures) =>
|
||||
surface.renderPictures(pictures.cast<SkwasmPicture>());
|
||||
|
||||
@override
|
||||
ScenePicture clipPicture(ScenePicture picture, ui.Rect clip) {
|
||||
final ui.PictureRecorder recorder = ui.PictureRecorder();
|
||||
final ui.Canvas canvas = ui.Canvas(recorder, clip);
|
||||
canvas.clipRect(clip);
|
||||
canvas.drawPicture(picture);
|
||||
|
||||
return recorder.endRecording() as ScenePicture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,14 +43,7 @@ class StubPictureRenderer implements PictureRenderer {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
ScenePicture clipPicture(ScenePicture picture, ui.Rect clip) {
|
||||
clipRequests[picture] = clip;
|
||||
return picture;
|
||||
}
|
||||
|
||||
List<ScenePicture> renderedPictures = <ScenePicture>[];
|
||||
Map<ScenePicture, ui.Rect> clipRequests = <ScenePicture, ui.Rect>{};
|
||||
}
|
||||
|
||||
void testMain() {
|
||||
@@ -156,21 +149,4 @@ void testMain() {
|
||||
expect(stubPictureRenderer.renderedPictures.first, pictures.first);
|
||||
expect(stubPictureRenderer.renderedPictures.last, pictures.last);
|
||||
});
|
||||
|
||||
test('SceneView clips pictures that are outside the window screen', () async {
|
||||
final StubPicture picture = StubPicture(const ui.Rect.fromLTWH(
|
||||
-50,
|
||||
-50,
|
||||
100,
|
||||
120,
|
||||
));
|
||||
|
||||
final EngineRootLayer rootLayer = EngineRootLayer();
|
||||
rootLayer.slices.add(PictureSlice(picture));
|
||||
final EngineScene scene = EngineScene(rootLayer);
|
||||
await sceneView.renderScene(scene, null);
|
||||
|
||||
expect(stubPictureRenderer.renderedPictures.length, 1);
|
||||
expect(stubPictureRenderer.clipRequests.containsKey(picture), true);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user