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: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,7 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/ui.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/benchmarks.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/images.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/initialization.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart + ../../../flutter/LICENSE
Expand Down Expand Up @@ -4878,6 +4879,7 @@ FILE: ../../../flutter/lib/web_ui/lib/ui.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/asset_manager.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/benchmarks.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/images.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/initialization.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/platform_location.dart
FILE: ../../../flutter/lib/web_ui/lib/ui_web/src/ui_web/navigation/url_strategy.dart
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/lib/initialization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ part of ui;
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
Future<void> webOnlyInitializePlatform() async {
assert(() {
engine.printWarning(
'The webOnlyInitializePlatform API is deprecated and will be removed in a '
'future release. Please use `bootstrapEngine` from `dart:ui_web` instead.',
);
return true;
}());
await engine.initializeEngine();
}

Expand Down
19 changes: 16 additions & 3 deletions lib/web_ui/lib/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,22 @@ class TargetImageSize {
final int? height;
}

Future<Codec> webOnlyInstantiateImageCodecFromUrl(Uri uri,
{engine.WebOnlyImageCodecChunkCallback? chunkCallback}) =>
engine.renderer.instantiateImageCodecFromUrl(uri, chunkCallback: chunkCallback);
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
Future<Codec> webOnlyInstantiateImageCodecFromUrl(
Uri uri, {
ui_web.ImageCodecChunkCallback? chunkCallback,
}) {
assert(() {
engine.printWarning(
'The webOnlyInstantiateImageCodecFromUrl API is deprecated and will be '
'removed in a future release. Please use `createImageCodecFromUrl` from '
'`dart:ui_web` instead.',
);
return true;
}());
return ui_web.createImageCodecFromUrl(uri, chunkCallback: chunkCallback);
}

void decodeImageFromList(Uint8List list, ImageDecoderCallback callback) {
_decodeImageFromListAsync(list, callback);
Expand Down
7 changes: 4 additions & 3 deletions lib/web_ui/lib/src/engine/canvaskit/image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:typed_data';

import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia.
FutureOr<ui.Codec> skiaInstantiateImageCodec(Uint8List list,
Expand Down Expand Up @@ -159,7 +160,7 @@ const String _kNetworkImageMessage = 'Failed to load network image.';
/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia after
/// requesting from URI.
Future<ui.Codec> skiaInstantiateWebImageCodec(
String url, WebOnlyImageCodecChunkCallback? chunkCallback) async {
String url, ui_web.ImageCodecChunkCallback? chunkCallback) async {
final Uint8List list = await fetchImage(url, chunkCallback);
if (browserSupportsImageDecoder) {
return CkBrowserImageDecoder.create(data: list, debugSource: url);
Expand All @@ -169,7 +170,7 @@ Future<ui.Codec> skiaInstantiateWebImageCodec(
}

/// Sends a request to fetch image data.
Future<Uint8List> fetchImage(String url, WebOnlyImageCodecChunkCallback? chunkCallback) async {
Future<Uint8List> fetchImage(String url, ui_web.ImageCodecChunkCallback? chunkCallback) async {
try {
final HttpFetchResponse response = await httpFetch(url);
final int? contentLength = response.contentLength;
Expand Down Expand Up @@ -200,7 +201,7 @@ Future<Uint8List> fetchImage(String url, WebOnlyImageCodecChunkCallback? chunkCa
/// Reads the [payload] in chunks using the browser's Streams API
///
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API
Future<Uint8List> readChunked(HttpFetchPayload payload, int contentLength, WebOnlyImageCodecChunkCallback chunkCallback) async {
Future<Uint8List> readChunked(HttpFetchPayload payload, int contentLength, ui_web.ImageCodecChunkCallback chunkCallback) async {
final JSUint8Array result = createUint8ArrayFromLength(contentLength);
int position = 0;
int cumulativeBytesLoaded = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ class LayerSceneBuilder implements ui.SceneBuilder {
ui.Offset offset = ui.Offset.zero,
double width = 0.0,
double height = 0.0,
Object? webOnlyPaintedBy,
}) {
currentLayer.add(PlatformViewLayer(viewId, offset, width, height));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class CanvasKitRenderer implements Renderer {
@override
Future<ui.Codec> instantiateImageCodecFromUrl(
Uri uri, {
WebOnlyImageCodecChunkCallback? chunkCallback
ui_web.ImageCodecChunkCallback? chunkCallback
}) => skiaInstantiateWebImageCodec(uri.toString(), chunkCallback);

@override
Expand Down
9 changes: 4 additions & 5 deletions lib/web_ui/lib/src/engine/html/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:typed_data';

import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

class HtmlRenderer implements Renderer {
static HtmlRenderer get instance => _instance;
Expand Down Expand Up @@ -176,11 +177,9 @@ class HtmlRenderer implements Renderer {
@override
Future<ui.Codec> instantiateImageCodecFromUrl(
Uri uri, {
WebOnlyImageCodecChunkCallback? chunkCallback}) {
return futurize<ui.Codec>((Callback<ui.Codec> callback) {
callback(HtmlCodec(uri.toString(), chunkCallback: chunkCallback));
return null;
});
ui_web.ImageCodecChunkCallback? chunkCallback,
}) async {
return HtmlCodec(uri.toString(), chunkCallback: chunkCallback);
}

@override
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/lib/src/engine/html/scene_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
/// overlay or not.
///
/// We use this to avoid spamming the console with redundant warning messages.
static bool _webOnlyDidWarnAboutPerformanceOverlay = false;
static bool _didWarnAboutPerformanceOverlay = false;

void _addPerformanceOverlay(
int enabledOptions,
Expand All @@ -338,8 +338,8 @@ class SurfaceSceneBuilder implements ui.SceneBuilder {
double top,
double bottom,
) {
if (!_webOnlyDidWarnAboutPerformanceOverlay) {
_webOnlyDidWarnAboutPerformanceOverlay = true;
if (!_didWarnAboutPerformanceOverlay) {
_didWarnAboutPerformanceOverlay = true;
printWarning("The performance overlay isn't supported on the web");
}
}
Expand Down
8 changes: 5 additions & 3 deletions lib/web_ui/lib/src/engine/html_image_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:typed_data';

import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

import 'browser_detection.dart';
import 'dom.dart';
Expand All @@ -20,14 +21,15 @@ Object? get _jsImageDecodeFunction => getJsProperty<Object?>(
);
final bool _supportsDecode = _jsImageDecodeFunction != null;

typedef WebOnlyImageCodecChunkCallback = void Function(
int cumulativeBytesLoaded, int expectedTotalBytes);
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
typedef WebOnlyImageCodecChunkCallback = ui_web.ImageCodecChunkCallback;

class HtmlCodec implements ui.Codec {
HtmlCodec(this.src, {this.chunkCallback});

final String src;
final WebOnlyImageCodecChunkCallback? chunkCallback;
final ui_web.ImageCodecChunkCallback? chunkCallback;

@override
int get frameCount => 1;
Expand Down
4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import 'dart:typed_data';

import 'package:ui/src/engine/skwasm/skwasm_stub.dart' if (dart.library.ffi) 'package:ui/src/engine/skwasm/skwasm_impl.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

import 'browser_detection.dart';
import 'canvaskit/renderer.dart';
import 'configuration.dart';
import 'embedder.dart';
import 'fonts.dart';
import 'html/renderer.dart';
import 'html_image_codec.dart';

final Renderer _renderer = Renderer._internal();
Renderer get renderer => _renderer;
Expand Down Expand Up @@ -131,7 +131,7 @@ abstract class Renderer {

Future<ui.Codec> instantiateImageCodecFromUrl(
Uri uri, {
WebOnlyImageCodecChunkCallback? chunkCallback,
ui_web.ImageCodecChunkCallback? chunkCallback,
});

void decodeImageFromPixels(
Expand Down
2 changes: 1 addition & 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 @@ -389,7 +389,7 @@ class SkwasmRenderer implements Renderer {
@override
Future<ui.Codec> instantiateImageCodecFromUrl(
Uri uri, {
WebOnlyImageCodecChunkCallback? chunkCallback
ui_web.ImageCodecChunkCallback? chunkCallback
}) async {
final DomResponse response = await rawHttpGet(uri.toString());
final String? contentType = response.headers.get('Content-Type');
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 @@ -145,7 +145,7 @@ class SkwasmRenderer implements Renderer {
}

@override
Future<ui.Codec> instantiateImageCodecFromUrl(Uri uri, {WebOnlyImageCodecChunkCallback? chunkCallback}) {
Future<ui.Codec> instantiateImageCodecFromUrl(Uri uri, {ui_web.ImageCodecChunkCallback? chunkCallback}) {
throw UnimplementedError('Skwasm not implemented on this platform.');
}

Expand Down
39 changes: 34 additions & 5 deletions lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
bool override = false;

assert(() {
if (webOnlyDebugPhysicalSizeOverride != null) {
_physicalSize = webOnlyDebugPhysicalSizeOverride;
if (debugPhysicalSizeOverride != null) {
_physicalSize = debugPhysicalSizeOverride;
override = true;
}
return true;
Expand Down Expand Up @@ -319,8 +319,37 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
/// Lazily populated and cleared at the end of the frame.
ui.Size? _physicalSize;

/// Overrides the value of [physicalSize] in tests.
ui.Size? webOnlyDebugPhysicalSizeOverride;
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
ui.Size? get webOnlyDebugPhysicalSizeOverride {
assert(() {
printWarning(
'The webOnlyDebugPhysicalSizeOverride API is deprecated and will be '
'removed in a future release. Please use '
'`SingletonFlutterWindow.debugPhysicalSizeOverride` from `dart:ui_web` '
'instead.',
);
return true;
}());
return debugPhysicalSizeOverride;
}

// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
set webOnlyDebugPhysicalSizeOverride(ui.Size? value) {
assert(() {
printWarning(
'The webOnlyDebugPhysicalSizeOverride API is deprecated and will be '
'removed in a future release. Please use '
'`SingletonFlutterWindow.debugPhysicalSizeOverride` from `dart:ui_web` '
'instead.',
);
return true;
}());
debugPhysicalSizeOverride = value;
}

ui.Size? debugPhysicalSizeOverride;
}

/// The Web implementation of [ui.SingletonFlutterWindow].
Expand All @@ -336,7 +365,7 @@ class EngineSingletonFlutterWindow extends EngineFlutterWindow {
/// Overrides the default device pixel ratio.
///
/// This is useful in tests to emulate screens of different dimensions.
void debugOverrideDevicePixelRatio(double value) {
void debugOverrideDevicePixelRatio(double? value) {
_debugDevicePixelRatio = value;
}

Expand Down
1 change: 1 addition & 0 deletions lib/web_ui/lib/ui_web/src/ui_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ library ui_web;

export 'ui_web/asset_manager.dart';
export 'ui_web/benchmarks.dart';
export 'ui_web/images.dart';
export 'ui_web/initialization.dart';
export 'ui_web/navigation/platform_location.dart';
export 'ui_web/navigation/url_strategy.dart';
Expand Down
27 changes: 27 additions & 0 deletions lib/web_ui/lib/ui_web/src/ui_web/images.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;

/// Signature of the callback that receives progress updates as image chunks are
/// loaded.
typedef ImageCodecChunkCallback = void Function(
int cumulativeBytesLoaded,
int expectedTotalBytes,
);

/// Creates a [ui.Codec] for the image located at [uri].
///
/// The [chunkCallback] is called with progress updates as image chunks are
/// loaded.
Future<ui.Codec> createImageCodecFromUrl(
Uri uri, {
ImageCodecChunkCallback? chunkCallback,
}) {
return renderer.instantiateImageCodecFromUrl(
uri,
chunkCallback: chunkCallback,
);
}
15 changes: 13 additions & 2 deletions lib/web_ui/lib/ui_web/src/ui_web/testing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;

extension SingletonFlutterWindowExtension on ui.SingletonFlutterWindow {
/// Overrides the value of [physicalSize] in tests.
set debugPhysicalSizeOverride(ui.Size? value) {
(this as EngineFlutterWindow).debugPhysicalSizeOverride = value;
}
}

/// Overrides the value of [ui.FlutterView.devicePixelRatio] in tests.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify here... the framework uses this for testing? If not, and this is only used in the engine, I think we can just remove the API completely. If it is used in the framework... blech. I wish we could just actually control this with the test harness rather than having a special magic debug API.

That being said, if the framework is using this, I'm fine with just moving forward this way.

(Ditto for debugPhysicalSizeOverride above)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went and looked it up and answered my own question... yes the framework uses it for testing in its test bootstrap. 😞

void debugOverrideDevicePixelRatio(double? value) {
(ui.window as EngineSingletonFlutterWindow).debugOverrideDevicePixelRatio(value);
}

/// Whether the Flutter engine is running in `flutter test` emulation mode.
///
/// When true, the engine will emulate a specific screen size, and always
Expand All @@ -18,8 +30,7 @@ set debugEmulateFlutterTesterEnvironment(bool value) {
_debugEmulateFlutterTesterEnvironment = value;
if (_debugEmulateFlutterTesterEnvironment) {
const ui.Size logicalSize = ui.Size(800.0, 600.0);
window.webOnlyDebugPhysicalSizeOverride =
logicalSize * window.devicePixelRatio;
window.debugPhysicalSizeOverride = logicalSize * window.devicePixelRatio;
}
debugDisableFontFallbacks = value;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ void testMain() {
sb.addPicture(ui.Offset.zero, picture);
sb.addPlatformView(0, width: 10, height: 10);

window.webOnlyDebugPhysicalSizeOverride = const ui.Size(100, 100);
window.debugPhysicalSizeOverride = const ui.Size(100, 100);
window.debugForceResize();
CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree);
_expectSceneMatches(<_EmbeddedViewMarker>[
Expand All @@ -653,7 +653,7 @@ void testMain() {
_overlay,
]);

window.webOnlyDebugPhysicalSizeOverride = const ui.Size(200, 200);
window.debugPhysicalSizeOverride = const ui.Size(200, 200);
window.debugForceResize();
CanvasKitRenderer.instance.rasterizer.draw(sb.build().layerTree);
_expectSceneMatches(<_EmbeddedViewMarker>[
Expand All @@ -662,7 +662,7 @@ void testMain() {
_overlay,
]);

window.webOnlyDebugPhysicalSizeOverride = null;
window.debugPhysicalSizeOverride = null;
window.debugForceResize();
// ImageDecoder is not supported in Safari or Firefox.
}, skip: isSafari || isFirefox);
Expand Down
3 changes: 2 additions & 1 deletion lib/web_ui/test/canvaskit/fragment_program_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:test/test.dart';

import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;

void main() {
internalBootstrapBrowserTest(() => testMain);
Expand Down Expand Up @@ -182,7 +183,7 @@ const String kJsonIPLR = r'''

void testMain() {
setUpAll(() async {
await ui.webOnlyInitializePlatform();
await ui_web.bootstrapEngine();
});

test('FragmentProgram can be created from JSON IPLR bundle', () {
Expand Down
Loading