Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web_ui/lib/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract class PlatformDispatcher {

void scheduleFrame();

Future<void> render(Scene scene, [FlutterView view]);
void render(Scene scene, [FlutterView view]);

AccessibilityFeatures get accessibilityFeatures;

Expand Down
9 changes: 4 additions & 5 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class HtmlViewEmbedder {
sceneHost.append(_svgPathDefs!);
}

Future<void> submitFrame() async {
void submitFrame() {
final ViewListDiffResult? diffResult =
(_activeCompositionOrder.isEmpty || _compositionOrder.isEmpty)
? null
Expand All @@ -388,7 +388,7 @@ class HtmlViewEmbedder {
_context.pictureRecorders[pictureRecorderIndex].endRecording());
pictureRecorderIndex++;
}
await rasterizer.rasterizeToCanvas(overlay, pictures);
rasterizer.rasterizeToCanvas(overlay, pictures);
}
for (final CkPictureRecorder recorder
in _context.pictureRecordersCreatedDuringPreroll) {
Expand Down Expand Up @@ -443,7 +443,8 @@ class HtmlViewEmbedder {
sceneHost.insertBefore(platformViewRoot, elementToInsertBefore);
final RenderCanvas? overlay = _overlays[viewId];
if (overlay != null) {
sceneHost.insertBefore(overlay.htmlElement, elementToInsertBefore);
sceneHost.insertBefore(
overlay.htmlElement, elementToInsertBefore);
}
} else {
final DomElement platformViewRoot = _viewClipChains[viewId]!.root;
Expand Down Expand Up @@ -653,8 +654,6 @@ class HtmlViewEmbedder {
}
}
_svgClipDefs.clear();
_svgPathDefs?.remove();
_svgPathDefs = null;
}

static void removeElement(DomElement element) {
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/canvaskit/rasterizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Rasterizer {

/// Creates a new frame from this rasterizer's surface, draws the given
/// [LayerTree] into it, and then submits the frame.
Future<void> draw(LayerTree layerTree) async {
void draw(LayerTree layerTree) {
final ui.Size frameSize = view.physicalSize;
if (frameSize.isEmpty) {
// Available drawing area is empty. Skip drawing.
Expand All @@ -49,10 +49,10 @@ class Rasterizer {
compositorFrame.raster(layerTree, ignoreRasterCache: true);

sceneHost.prepend(renderCanvasFactory.baseCanvas.htmlElement);
await rasterizeToCanvas(renderCanvasFactory.baseCanvas,
rasterizeToCanvas(renderCanvasFactory.baseCanvas,
<CkPicture>[pictureRecorder.endRecording()]);

await viewEmbedder.submitFrame();
viewEmbedder.submitFrame();
}

/// Disposes of this rasterizer.
Expand Down
6 changes: 2 additions & 4 deletions lib/web_ui/lib/src/engine/canvaskit/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class CanvasKitRenderer implements Renderer {
viewManager.onViewDisposed.listen(_onViewDisposed);
_instance = this;
}();
registerHotRestartListener(dispose);
return _initialized;
}

Expand Down Expand Up @@ -403,7 +402,7 @@ class CanvasKitRenderer implements Renderer {
CkParagraphBuilder(style);

@override
Future<void> renderScene(ui.Scene scene, ui.FlutterView view) async {
void renderScene(ui.Scene scene, ui.FlutterView view) {
// "Build finish" and "raster start" happen back-to-back because we
// render on the same thread, so there's no overhead from hopping to
// another thread.
Expand All @@ -418,7 +417,7 @@ class CanvasKitRenderer implements Renderer {
"Unable to render to a view which hasn't been registered");
final Rasterizer rasterizer = _rasterizers[view.viewId]!;

await rasterizer.draw((scene as LayerScene).layerTree);
rasterizer.draw((scene as LayerScene).layerTree);
frameTimingsOnRasterFinish();
}

Expand Down Expand Up @@ -452,7 +451,6 @@ class CanvasKitRenderer implements Renderer {
rasterizer.dispose();
}
_rasterizers.clear();
clearFragmentProgramCache();
}

@override
Expand Down
22 changes: 13 additions & 9 deletions lib/web_ui/lib/src/engine/canvaskit/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ class Surface {
_surface!.flush();

if (browserSupportsCreateImageBitmap) {
JSObject bitmapSource;
DomImageBitmap bitmap;
if (Surface.offscreenCanvasSupported) {
bitmapSource = _offscreenCanvas! as JSObject;
bitmap = (await createImageBitmap(_offscreenCanvas! as JSObject, (
x: 0,
y: _pixelHeight - frameSize.height.toInt(),
width: frameSize.width.toInt(),
height: frameSize.height.toInt(),
)).toDart)! as DomImageBitmap;
} else {
bitmapSource = _canvasElement! as JSObject;
bitmap = (await createImageBitmap(_canvasElement! as JSObject, (
x: 0,
y: _pixelHeight - frameSize.height.toInt(),
width: frameSize.width.toInt(),
height: frameSize.height.toInt()
)).toDart)! as DomImageBitmap;
}
final DomImageBitmap bitmap = await createImageBitmap(bitmapSource, (
x: 0,
y: _pixelHeight - frameSize.height.toInt(),
width: frameSize.width.toInt(),
height: frameSize.height.toInt(),
));
canvas.render(bitmap);
} else {
// If the browser doesn't support `createImageBitmap` (e.g. Safari 14)
Expand Down
8 changes: 3 additions & 5 deletions lib/web_ui/lib/src/engine/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,14 @@ external JSPromise<JSAny?> _createImageBitmap2(
JSNumber width,
JSNumber height,
);
Future<DomImageBitmap> createImageBitmap(JSAny source,
JSPromise<JSAny?> createImageBitmap(JSAny source,
[({int x, int y, int width, int height})? bounds]) {
JSPromise<JSAny?> jsPromise;
if (bounds != null) {
jsPromise = _createImageBitmap2(source, bounds.x.toJS, bounds.y.toJS,
return _createImageBitmap2(source, bounds.x.toJS, bounds.y.toJS,
bounds.width.toJS, bounds.height.toJS);
} else {
jsPromise = _createImageBitmap1(source);
return _createImageBitmap1(source);
}
return js_util.promiseToFuture<DomImageBitmap>(jsPromise);
}

@JS()
Expand Down
3 changes: 1 addition & 2 deletions lib/web_ui/lib/src/engine/html/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class HtmlRenderer implements Renderer {
// to make the unpacking happen while we are waiting for network requests.
lineLookup;
});
registerHotRestartListener(clearFragmentProgramCache);

_instance = this;
}
Expand Down Expand Up @@ -324,7 +323,7 @@ class HtmlRenderer implements Renderer {
CanvasParagraphBuilder(style as EngineParagraphStyle);

@override
Future<void> renderScene(ui.Scene scene, ui.FlutterView view) async {
void renderScene(ui.Scene scene, ui.FlutterView view) {
final EngineFlutterView implicitView = EnginePlatformDispatcher.instance.implicitView!;
implicitView.dom.setScene((scene as SurfaceScene).webOnlyRootElement!);
frameTimingsOnRasterFinish();
Expand Down
24 changes: 3 additions & 21 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
}
}

/// A set of views which have rendered in the current `onBeginFrame` or
/// `onDrawFrame` scope.
Set<ui.FlutterView>? _viewsRenderedInCurrentFrame;

/// A callback invoked when any window begins a frame.
///
/// A callback that is invoked to notify the application that it is an
Expand All @@ -239,9 +235,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
/// Engine code should use this method instead of the callback directly.
/// Otherwise zones won't work properly.
void invokeOnBeginFrame(Duration duration) {
_viewsRenderedInCurrentFrame = <ui.FlutterView>{};
invoke1<Duration>(_onBeginFrame, _onBeginFrameZone, duration);
_viewsRenderedInCurrentFrame = null;
}

/// A callback that is invoked for each frame after [onBeginFrame] has
Expand All @@ -262,9 +256,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
/// Engine code should use this method instead of the callback directly.
/// Otherwise zones won't work properly.
void invokeOnDrawFrame() {
_viewsRenderedInCurrentFrame = <ui.FlutterView>{};
invoke(_onDrawFrame, _onDrawFrameZone);
_viewsRenderedInCurrentFrame = null;
}

/// A callback that is invoked when pointer data is available.
Expand Down Expand Up @@ -761,23 +753,14 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
/// * [RendererBinding], the Flutter framework class which manages layout and
/// painting.
@override
Future<void> render(ui.Scene scene, [ui.FlutterView? view]) async {
void render(ui.Scene scene, [ui.FlutterView? view]) {
assert(view != null || implicitView != null,
'Calling render without a FlutterView');
if (view == null && implicitView == null) {
// If there is no view to render into, then this is a no-op.
return;
}
final ui.FlutterView viewToRender = view ?? implicitView!;

// Only render in an `onDrawFrame` or `onBeginFrame` scope. This is checked
// by checking if the `_viewsRenderedInCurrentFrame` is non-null and this
// view hasn't been rendered already in this scope.
final bool shouldRender =
_viewsRenderedInCurrentFrame?.add(viewToRender) ?? false;
if (shouldRender) {
await renderer.renderScene(scene, viewToRender);
}
renderer.renderScene(scene, view ?? implicitView!);
}

/// Additional accessibility features that may be enabled by the platform.
Expand Down Expand Up @@ -1292,8 +1275,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
String get defaultRouteName {
// TODO(mdebbar): What should we do in multi-view mode?
// https://github.com/flutter/flutter/issues/139174
return _defaultRouteName ??=
implicitView?.browserHistory.currentPath ?? '/';
return _defaultRouteName ??= implicitView?.browserHistory.currentPath ?? '/';
}

/// Lazily initialized when the `defaultRouteName` getter is invoked.
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,5 @@ abstract class Renderer {

ui.ParagraphBuilder createParagraphBuilder(ui.ParagraphStyle style);

Future<void> renderScene(ui.Scene scene, ui.FlutterView view);
FutureOr<void> renderScene(ui.Scene scene, ui.FlutterView view);
}
1 change: 0 additions & 1 deletion lib/web_ui/lib/src/engine/skwasm/skwasm_impl/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ class SkwasmRenderer implements Renderer {
FutureOr<void> initialize() {
surface = SkwasmSurface();
sceneView = EngineSceneView(SkwasmPictureRenderer(surface));
registerHotRestartListener(clearFragmentProgramCache);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/skwasm/skwasm_stub/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class SkwasmRenderer implements Renderer {
}

@override
Future<void> renderScene(ui.Scene scene, ui.FlutterView view) {
void renderScene(ui.Scene scene, ui.FlutterView view) {
throw UnimplementedError('Skwasm not implemented on this platform.');
}

Expand Down
Loading