Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 9778c2c

Browse files
Fix scene view canvas/platform view placement. (#45199)
I wasn't adjusting the `left` and `top` css styles based on the device pixel ratio. This fixes that and also sets up unit tests for `SceneView`.
1 parent ffda7e3 commit 9778c2c

File tree

4 files changed

+312
-184
lines changed

4 files changed

+312
-184
lines changed

lib/web_ui/lib/src/engine/scene_view.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,13 @@ final class PictureSliceContainer extends SliceContainer {
163163
final DomCSSStyleDeclaration style = canvas.style;
164164
final double logicalWidth = roundedOutBounds.width / window.devicePixelRatio;
165165
final double logicalHeight = roundedOutBounds.height / window.devicePixelRatio;
166+
final double logicalLeft = roundedOutBounds.left / window.devicePixelRatio;
167+
final double logicalTop = roundedOutBounds.top / window.devicePixelRatio;
166168
style.width = '${logicalWidth}px';
167169
style.height = '${logicalHeight}px';
168170
style.position = 'absolute';
169-
style.left = '${roundedOutBounds.left}px';
170-
style.top = '${roundedOutBounds.top}px';
171+
style.left = '${logicalLeft}px';
172+
style.top = '${logicalTop}px';
171173
canvas.width = roundedOutBounds.width.ceilToDouble();
172174
canvas.height = roundedOutBounds.height.ceilToDouble();
173175
}
@@ -221,8 +223,10 @@ final class PlatformViewContainer extends SliceContainer {
221223
style.position = 'absolute';
222224

223225
final ui.Offset? offset = _styling!.position.offset;
224-
style.left = '${offset?.dx ?? 0}px';
225-
style.top = '${offset?.dy ?? 0}px';
226+
final double logicalLeft = (offset?.dx ?? 0) / window.devicePixelRatio;
227+
final double logicalTop = (offset?.dy ?? 0) / window.devicePixelRatio;
228+
style.left = '${logicalLeft}px';
229+
style.top = '${logicalTop}px';
226230

227231
final Matrix4? transform = _styling!.position.transform;
228232
style.transform = transform != null ? float64ListToCssTransform3d(transform.storage) : '';

lib/web_ui/test/engine/scene_builder_test.dart

Lines changed: 2 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:typed_data';
6-
75
import 'package:test/bootstrap/browser.dart';
86
import 'package:test/test.dart';
97
import 'package:ui/src/engine.dart';
108

119
import 'package:ui/ui.dart' as ui;
1210

11+
import 'scene_builder_utils.dart';
12+
1313
void main() {
1414
internalBootstrapBrowserTest(() => testMain);
1515
}
@@ -229,181 +229,3 @@ class PlatformViewSliceMatcher extends Matcher {
229229
return true;
230230
}
231231
}
232-
233-
class StubPicture implements ScenePicture {
234-
StubPicture(this.cullRect);
235-
236-
@override
237-
final ui.Rect cullRect;
238-
239-
@override
240-
int get approximateBytesUsed => throw UnimplementedError();
241-
242-
@override
243-
bool get debugDisposed => throw UnimplementedError();
244-
245-
@override
246-
void dispose() {}
247-
248-
@override
249-
Future<ui.Image> toImage(int width, int height) {
250-
throw UnimplementedError();
251-
}
252-
253-
@override
254-
ui.Image toImageSync(int width, int height) {
255-
throw UnimplementedError();
256-
}
257-
}
258-
259-
class StubCompositePicture extends StubPicture {
260-
StubCompositePicture(this.children) : super(
261-
children.fold(null, (ui.Rect? previousValue, StubPicture child) {
262-
return previousValue?.expandToInclude(child.cullRect) ?? child.cullRect;
263-
})!
264-
);
265-
266-
final List<StubPicture> children;
267-
}
268-
269-
class StubPictureRecorder implements ui.PictureRecorder {
270-
StubPictureRecorder(this.canvas);
271-
272-
final StubSceneCanvas canvas;
273-
274-
@override
275-
ui.Picture endRecording() {
276-
return StubCompositePicture(canvas.pictures);
277-
}
278-
279-
@override
280-
bool get isRecording => throw UnimplementedError();
281-
}
282-
283-
class StubSceneCanvas implements SceneCanvas {
284-
List<StubPicture> pictures = <StubPicture>[];
285-
286-
@override
287-
void drawPicture(ui.Picture picture) {
288-
pictures.add(picture as StubPicture);
289-
}
290-
291-
@override
292-
void clipPath(ui.Path path, {bool doAntiAlias = true}) {}
293-
294-
@override
295-
void clipRRect(ui.RRect rrect, {bool doAntiAlias = true}) {}
296-
297-
@override
298-
void clipRect(ui.Rect rect, {ui.ClipOp clipOp = ui.ClipOp.intersect, bool doAntiAlias = true}) {}
299-
300-
@override
301-
void drawArc(ui.Rect rect, double startAngle, double sweepAngle, bool useCenter, ui.Paint paint) {}
302-
303-
@override
304-
void drawAtlas(ui.Image atlas, List<ui.RSTransform> transforms, List<ui.Rect> rects, List<ui.Color>? colors, ui.BlendMode? blendMode, ui.Rect? cullRect, ui.Paint paint) {}
305-
306-
@override
307-
void drawCircle(ui.Offset c, double radius, ui.Paint paint) {}
308-
309-
@override
310-
void drawColor(ui.Color color, ui.BlendMode blendMode) {}
311-
312-
@override
313-
void drawDRRect(ui.RRect outer, ui.RRect inner, ui.Paint paint) {}
314-
315-
@override
316-
void drawImage(ui.Image image, ui.Offset offset, ui.Paint paint) {}
317-
318-
@override
319-
void drawImageNine(ui.Image image, ui.Rect center, ui.Rect dst, ui.Paint paint) {}
320-
321-
@override
322-
void drawImageRect(ui.Image image, ui.Rect src, ui.Rect dst, ui.Paint paint) {}
323-
324-
@override
325-
void drawLine(ui.Offset p1, ui.Offset p2, ui.Paint paint) {}
326-
327-
@override
328-
void drawOval(ui.Rect rect, ui.Paint paint) {}
329-
330-
@override
331-
void drawPaint(ui.Paint paint) {}
332-
333-
@override
334-
void drawParagraph(ui.Paragraph paragraph, ui.Offset offset) {}
335-
336-
@override
337-
void drawPath(ui.Path path, ui.Paint paint) {}
338-
339-
@override
340-
void drawPoints(ui.PointMode pointMode, List<ui.Offset> points, ui.Paint paint) {}
341-
342-
@override
343-
void drawRRect(ui.RRect rrect, ui.Paint paint) {}
344-
345-
@override
346-
void drawRawAtlas(ui.Image atlas, Float32List rstTransforms, Float32List rects, Int32List? colors, ui.BlendMode? blendMode, ui.Rect? cullRect, ui.Paint paint) {}
347-
348-
@override
349-
void drawRawPoints(ui.PointMode pointMode, Float32List points, ui.Paint paint) {}
350-
351-
@override
352-
void drawRect(ui.Rect rect, ui.Paint paint) {}
353-
354-
@override
355-
void drawShadow(ui.Path path, ui.Color color, double elevation, bool transparentOccluder) {}
356-
357-
@override
358-
void drawVertices(ui.Vertices vertices, ui.BlendMode blendMode, ui.Paint paint) {}
359-
360-
@override
361-
ui.Rect getDestinationClipBounds() {
362-
throw UnimplementedError();
363-
}
364-
365-
@override
366-
ui.Rect getLocalClipBounds() {
367-
throw UnimplementedError();
368-
}
369-
370-
@override
371-
int getSaveCount() {
372-
throw UnimplementedError();
373-
}
374-
375-
@override
376-
Float64List getTransform() {
377-
throw UnimplementedError();
378-
}
379-
380-
@override
381-
void restore() {}
382-
383-
@override
384-
void restoreToCount(int count) {}
385-
386-
@override
387-
void rotate(double radians) {}
388-
389-
@override
390-
void save() {}
391-
392-
@override
393-
void saveLayer(ui.Rect? bounds, ui.Paint paint) {}
394-
395-
@override
396-
void saveLayerWithFilter(ui.Rect? bounds, ui.Paint paint, ui.ImageFilter backdropFilter) {}
397-
398-
@override
399-
void scale(double sx, [double? sy]) {}
400-
401-
@override
402-
void skew(double sx, double sy) {}
403-
404-
@override
405-
void transform(Float64List matrix4) {}
406-
407-
@override
408-
void translate(double dx, double dy) {}
409-
}

0 commit comments

Comments
 (0)