From e162fed3362a29aefd4c66fa8bbed6137f9511ce Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 8 Jul 2022 12:41:05 -0700 Subject: [PATCH] Rename toGpuImage to toImageSync (flutter/engine#34504) --- engine/src/flutter/lib/ui/compositing.dart | 10 +-- .../src/flutter/lib/ui/compositing/scene.cc | 12 +-- engine/src/flutter/lib/ui/compositing/scene.h | 6 +- engine/src/flutter/lib/ui/painting.dart | 21 +++-- engine/src/flutter/lib/ui/painting/picture.cc | 20 ++--- engine/src/flutter/lib/ui/painting/picture.h | 14 +-- engine/src/flutter/lib/web_ui/lib/canvas.dart | 2 +- .../flutter/lib/web_ui/lib/compositing.dart | 2 +- .../engine/canvaskit/layer_scene_builder.dart | 4 +- .../lib/src/engine/canvaskit/picture.dart | 4 +- .../lib/web_ui/lib/src/engine/html/scene.dart | 4 +- .../lib/web_ui/lib/src/engine/picture.dart | 4 +- .../web_ui/test/canvaskit/picture_test.dart | 4 +- .../shell/common/fixtures/shell_test.dart | 4 +- engine/src/flutter/shell/common/rasterizer.cc | 89 ++++++++++--------- .../flutter/shell/common/shell_unittests.cc | 4 +- .../src/flutter/testing/dart/canvas_test.dart | 32 +++---- .../testing/dart/compositing_test.dart | 25 ++---- .../testing/dart/image_shader_test.dart | 2 +- 19 files changed, 127 insertions(+), 136 deletions(-) diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index dbfc6918ce..d98275d34f 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -21,22 +21,22 @@ class Scene extends NativeFieldWrapperClass1 { @pragma('vm:entry-point') Scene._(); - /// Creates a GPU resident image from this scene. + /// Synchronously creates a handle to an image from this scene. /// - /// {@macro dart.ui.painting.Picture.toGpuImage} - Image toGpuImage(int width, int height) { + /// {@macro dart.ui.painting.Picture.toImageSync} + Image toImageSync(int width, int height) { if (width <= 0 || height <= 0) { throw Exception('Invalid image dimensions.'); } final _Image image = _Image._(); - final String? result = _toGpuImage(width, height, image); + final String? result = _toImageSync(width, height, image); if (result != null) { throw PictureRasterizationException._(result); } return Image._(image, image.width, image.height); } - String? _toGpuImage(int width, int height, _Image outImage) native 'Scene_toGpuImage'; + String? _toImageSync(int width, int height, _Image outImage) native 'Scene_toImageSync'; /// Creates a raster image representation of the current state of the scene. /// This is a slow operation that is performed on a background thread. diff --git a/engine/src/flutter/lib/ui/compositing/scene.cc b/engine/src/flutter/lib/ui/compositing/scene.cc index e42ec7c8d6..48def9ddc2 100644 --- a/engine/src/flutter/lib/ui/compositing/scene.cc +++ b/engine/src/flutter/lib/ui/compositing/scene.cc @@ -22,7 +22,7 @@ namespace flutter { IMPLEMENT_WRAPPERTYPEINFO(ui, Scene); #define FOR_EACH_BINDING(V) \ - V(Scene, toGpuImage) \ + V(Scene, toImageSync) \ V(Scene, toImage) \ V(Scene, dispose) @@ -67,10 +67,10 @@ void Scene::dispose() { ClearDartWrapper(); } -Dart_Handle Scene::toGpuImage(uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle) { - TRACE_EVENT0("flutter", "Scene::toGpuImage"); +Dart_Handle Scene::toImageSync(uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle) { + TRACE_EVENT0("flutter", "Scene::toImageSync"); if (!layer_tree_) { return tonic::ToDart("Scene did not contain a layer tree."); @@ -81,7 +81,7 @@ Dart_Handle Scene::toGpuImage(uint32_t width, return tonic::ToDart("Could not flatten scene into a layer tree."); } - Picture::RasterizeToGpuImage(picture, width, height, raw_image_handle); + Picture::RasterizeToImageSync(picture, width, height, raw_image_handle); return Dart_Null(); } diff --git a/engine/src/flutter/lib/ui/compositing/scene.h b/engine/src/flutter/lib/ui/compositing/scene.h index 29b66d150f..d550eac484 100644 --- a/engine/src/flutter/lib/ui/compositing/scene.h +++ b/engine/src/flutter/lib/ui/compositing/scene.h @@ -32,9 +32,9 @@ class Scene : public RefCountedDartWrappable { std::unique_ptr takeLayerTree(); - Dart_Handle toGpuImage(uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle); + Dart_Handle toImageSync(uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle); Dart_Handle toImage(uint32_t width, uint32_t height, diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index 91803c6112..92fa4967a1 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -5375,9 +5375,9 @@ class Picture extends NativeFieldWrapperClass1 { } String? _toImage(int width, int height, _Callback<_Image?> callback) native 'Picture_toImage'; - /// Creates a GPU resident image from this picture. + /// Synchronously creates a handle to an image of this picture. /// - /// {@template dart.ui.painting.Picture.toGpuImage} + /// {@template dart.ui.painting.Picture.toImageSync} /// The returned image will be `width` pixels wide and `height` pixels high. /// The picture is rasterized within the 0 (left), 0 (top), `width` (right), /// `height` (bottom) bounds. Content outside these bounds is clipped. @@ -5386,20 +5386,23 @@ class Picture extends NativeFieldWrapperClass1 { /// asynchronously. If the rasterization fails, an exception will be thrown /// when the image is drawn to a [Canvas]. /// - /// In the flutter_tester, this will always created a light gray and white - /// checkerboard bitmap with the requested dimensions. + /// If a GPU context is available, this image will be created as GPU resident + /// and not copied back to the host. This means the image will be more + /// efficient to draw. + /// + /// If no GPU context is availalbe, the image will be rasterized on the CPU. /// {@endtemplate} - Image toGpuImage(int width, int height) { + Image toImageSync(int width, int height) { assert(!_disposed); if (width <= 0 || height <= 0) { throw Exception('Invalid image dimensions.'); } final _Image image = _Image._(); - _toGpuImage(width, height, image); + _toImageSync(width, height, image); return Image._(image, image.width, image.height); } - void _toGpuImage(int width, int height, _Image outImage) native 'Picture_toGpuImage'; + void _toImageSync(int width, int height, _Image outImage) native 'Picture_toImageSync'; /// Release the resources used by this object. The object is no longer usable /// after this method is called. @@ -5909,7 +5912,7 @@ Future _futurize(_Callbacker callbacker) { } /// An exception thrown by [Canvas.drawImage] and related methods when drawing -/// an [Image] created via [Picture.toGpuImage] that is in an invalid state. +/// an [Image] created via [Picture.toImageSync] that is in an invalid state. /// /// This exception may be thrown if the requested image dimensions exceeded the /// maximum 2D texture size allowed by the GPU, or if no GPU surface or context @@ -5920,7 +5923,7 @@ class PictureRasterizationException implements Exception { /// A string containing details about the failure. final String message; - /// If available, the stack trace at the time [Picture.toGpuImage] was called. + /// If available, the stack trace at the time [Picture.toImageSync] was called. final StackTrace? stack; @override diff --git a/engine/src/flutter/lib/ui/painting/picture.cc b/engine/src/flutter/lib/ui/painting/picture.cc index 816c555da3..4ec907e093 100644 --- a/engine/src/flutter/lib/ui/painting/picture.cc +++ b/engine/src/flutter/lib/ui/painting/picture.cc @@ -23,7 +23,7 @@ IMPLEMENT_WRAPPERTYPEINFO(ui, Picture); #define FOR_EACH_BINDING(V) \ V(Picture, toImage) \ - V(Picture, toGpuImage) \ + V(Picture, toImageSync) \ V(Picture, dispose) \ V(Picture, GetAllocationSize) @@ -53,19 +53,19 @@ Dart_Handle Picture::toImage(uint32_t width, raw_image_callback); } -void Picture::toGpuImage(uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle) { +void Picture::toImageSync(uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle) { FML_DCHECK(display_list_.skia_object()); - RasterizeToGpuImage(display_list_.skia_object(), width, height, - raw_image_handle); + RasterizeToImageSync(display_list_.skia_object(), width, height, + raw_image_handle); } // static -void Picture::RasterizeToGpuImage(sk_sp display_list, - uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle) { +void Picture::RasterizeToImageSync(sk_sp display_list, + uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle) { auto* dart_state = UIDartState::Current(); auto unref_queue = dart_state->GetSkiaUnrefQueue(); auto snapshot_delegate = dart_state->GetSnapshotDelegate(); diff --git a/engine/src/flutter/lib/ui/painting/picture.h b/engine/src/flutter/lib/ui/painting/picture.h index e7f4f02e2c..92653e9123 100644 --- a/engine/src/flutter/lib/ui/painting/picture.h +++ b/engine/src/flutter/lib/ui/painting/picture.h @@ -37,9 +37,9 @@ class Picture : public RefCountedDartWrappable { uint32_t height, Dart_Handle raw_image_callback); - void toGpuImage(uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle); + void toImageSync(uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle); void dispose(); @@ -47,10 +47,10 @@ class Picture : public RefCountedDartWrappable { static void RegisterNatives(tonic::DartLibraryNatives* natives); - static void RasterizeToGpuImage(sk_sp display_list, - uint32_t width, - uint32_t height, - Dart_Handle raw_image_handle); + static void RasterizeToImageSync(sk_sp display_list, + uint32_t width, + uint32_t height, + Dart_Handle raw_image_handle); static Dart_Handle RasterizeToImage(sk_sp display_list, uint32_t width, diff --git a/engine/src/flutter/lib/web_ui/lib/canvas.dart b/engine/src/flutter/lib/web_ui/lib/canvas.dart index b78e19e415..c9359b6930 100644 --- a/engine/src/flutter/lib/web_ui/lib/canvas.dart +++ b/engine/src/flutter/lib/web_ui/lib/canvas.dart @@ -155,7 +155,7 @@ abstract class Canvas { abstract class Picture { Future toImage(int width, int height); - Image toGpuImage(int width, int height); + Image toImageSync(int width, int height); void dispose(); bool get debugDisposed; int get approximateBytesUsed; diff --git a/engine/src/flutter/lib/web_ui/lib/compositing.dart b/engine/src/flutter/lib/web_ui/lib/compositing.dart index c18280559b..96c51cbeee 100644 --- a/engine/src/flutter/lib/web_ui/lib/compositing.dart +++ b/engine/src/flutter/lib/web_ui/lib/compositing.dart @@ -6,7 +6,7 @@ part of ui; abstract class Scene { Future toImage(int width, int height); - Image toGpuImage(int width, int height); + Image toImageSync(int width, int height); void dispose(); } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart index eff0fa26d9..eb6d860a0e 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/layer_scene_builder.dart @@ -27,9 +27,9 @@ class LayerScene implements ui.Scene { } @override - ui.Image toGpuImage(int width, int height) { + ui.Image toImageSync(int width, int height) { final ui.Picture picture = layerTree.flatten(); - return picture.toGpuImage(width, height); + return picture.toImageSync(width, height); } } diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart index a02a9a2cf5..c2af7eb844 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/canvaskit/picture.dart @@ -92,11 +92,11 @@ class CkPicture extends ManagedSkiaObject implements ui.Picture { @override Future toImage(int width, int height) async { - return toGpuImage(width, height); + return toImageSync(width, height); } @override - ui.Image toGpuImage(int width, int height) { + ui.Image toImageSync(int width, int height) { assert(debugCheckNotDisposed('Cannot convert picture to image.')); final SkSurface skSurface = canvasKit.MakeSurface(width, height); final SkCanvas skCanvas = skSurface.getCanvas(); diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/html/scene.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/html/scene.dart index 50cee45690..645390e28e 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/html/scene.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/html/scene.dart @@ -25,8 +25,8 @@ class SurfaceScene implements ui.Scene { } @override - ui.Image toGpuImage(int width, int height) { - throw UnsupportedError('toGpuImage is not supported on the Web'); + ui.Image toImageSync(int width, int height) { + throw UnsupportedError('toImageSync is not supported on the Web'); } /// Releases the resources used by this scene. diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/picture.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/picture.dart index 1734c414cc..dc432b2b9f 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/picture.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/picture.dart @@ -89,8 +89,8 @@ class EnginePicture implements ui.Picture { } @override - ui.Image toGpuImage(int width, int height) { - throw UnsupportedError('toGpuImage is not supported on the HTML backend. Use drawPicture instead, or toImage.'); + ui.Image toImageSync(int width, int height) { + throw UnsupportedError('toImageSync is not supported on the HTML backend. Use drawPicture instead, or toImage.'); } bool _disposed = false; diff --git a/engine/src/flutter/lib/web_ui/test/canvaskit/picture_test.dart b/engine/src/flutter/lib/web_ui/test/canvaskit/picture_test.dart index 1c437293a7..b082d13d6e 100644 --- a/engine/src/flutter/lib/web_ui/test/canvaskit/picture_test.dart +++ b/engine/src/flutter/lib/web_ui/test/canvaskit/picture_test.dart @@ -86,13 +86,13 @@ void testMain() { }); }); - test('toGpuImage', () async { + test('toImageSync', () async { const ui.Color color = ui.Color(0xFFAAAAAA); final ui.PictureRecorder recorder = ui.PictureRecorder(); final ui.Canvas canvas = ui.Canvas(recorder); canvas.drawPaint(ui.Paint()..color = color); final ui.Picture picture = recorder.endRecording(); - final ui.Image image = picture.toGpuImage(10, 15); + final ui.Image image = picture.toImageSync(10, 15); expect(image.width, 10); expect(image.height, 15); diff --git a/engine/src/flutter/shell/common/fixtures/shell_test.dart b/engine/src/flutter/shell/common/fixtures/shell_test.dart index 4aded8ad83..b8908bdd24 100644 --- a/engine/src/flutter/shell/common/fixtures/shell_test.dart +++ b/engine/src/flutter/shell/common/fixtures/shell_test.dart @@ -324,13 +324,13 @@ void scene_with_red_box() { @pragma('vm:entry-point') -Future toGpuImage() async { +Future toImageSync() async { final PictureRecorder recorder = PictureRecorder(); final Canvas canvas = Canvas(recorder); canvas.drawPaint(Paint()..color = const Color(0xFFAAAAAA)); final Picture picture = recorder.endRecording(); - final Image image = picture.toGpuImage(20, 25); + final Image image = picture.toImageSync(20, 25); void expect(Object? a, Object? b) { if (a != b) { throw 'Expected $a to == $b'; diff --git a/engine/src/flutter/shell/common/rasterizer.cc b/engine/src/flutter/shell/common/rasterizer.cc index f246d1cead..8587d253d1 100644 --- a/engine/src/flutter/shell/common/rasterizer.cc +++ b/engine/src/flutter/shell/common/rasterizer.cc @@ -248,28 +248,26 @@ bool Rasterizer::ShouldResubmitFrame(const RasterStatus& raster_status) { } namespace { -std::pair, std::string> MakeBitmapImage(SkISize picture_size) { +std::pair, std::string> MakeBitmapImage( + sk_sp display_list, + const SkImageInfo& image_info) { + FML_DCHECK(display_list); // Use 16384 as a proxy for the maximum texture size for a GPU image. // This is meant to be large enough to avoid false positives in test contexts, // but not so artificially large to be completely unrealistic on any platform. // This limit is taken from the Metal specification. D3D, Vulkan, and GL // generally have lower limits. - if (picture_size.width() > 16384 || picture_size.height() > 16384) { + if (image_info.width() > 16384 || image_info.height() > 16384) { return {nullptr, "unable to create render target at specified size"}; } - SkBitmap bitmap; - if (!bitmap.tryAllocN32Pixels(picture_size.width(), picture_size.height())) { - return {nullptr, "unable to create render target at specified size"}; - } - bitmap.eraseColor(SK_ColorLTGRAY); - uint32_t half_width = std::floor(picture_size.width() / 2); - uint32_t half_height = std::floor(picture_size.height() / 2); - bitmap.erase(SK_ColorWHITE, SkIRect::MakeLTRB(0, 0, half_width, half_height)); - bitmap.erase(SK_ColorWHITE, - SkIRect::MakeLTRB(half_width, half_height, picture_size.width(), - picture_size.height())); - bitmap.setImmutable(); - return {bitmap.asImage(), ""}; + + sk_sp surface = SkSurface::MakeRaster(image_info); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorTRANSPARENT); + display_list->RenderTo(canvas); + + sk_sp image = surface->makeImageSnapshot(); + return {image, image ? "" : "Unable to create image"}; } } // namespace @@ -279,35 +277,44 @@ std::pair, std::string> Rasterizer::MakeGpuImage( TRACE_EVENT0("flutter", "Rasterizer::MakeGpuImage"); FML_DCHECK(display_list); - switch (gpu_image_behavior_) { - case MakeGpuImageBehavior::kGpu: - break; - case MakeGpuImageBehavior::kBitmap: - return MakeBitmapImage(picture_size); - } - - if (!surface_) { - return {nullptr, "GPU surface unavilable"}; - } - - auto* context = surface_->GetContext(); - if (!context) { - return {nullptr, "GPU context unavailable"}; - } - const SkImageInfo image_info = SkImageInfo::MakeN32Premul(picture_size); - sk_sp surface = - SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, image_info); - if (!surface) { - return {nullptr, "unable to create render target at specified size"}; - } + std::pair, std::string> result; + delegate_.GetIsGpuDisabledSyncSwitch()->Execute( + fml::SyncSwitch::Handlers() + .SetIfTrue([&result, &image_info, &display_list] { + result = MakeBitmapImage(std::move(display_list), image_info); + }) + .SetIfFalse([&result, &image_info, &display_list, + surface = surface_.get(), + gpu_image_behavior = gpu_image_behavior_] { + if (!surface || + gpu_image_behavior == MakeGpuImageBehavior::kBitmap) { + result = MakeBitmapImage(std::move(display_list), image_info); + return; + } - SkCanvas* canvas = surface->getCanvas(); - canvas->clear(SK_ColorTRANSPARENT); - display_list->RenderTo(canvas); + auto* context = surface->GetContext(); + if (!context) { + result = MakeBitmapImage(std::move(display_list), image_info); + return; + } - sk_sp image = surface->makeImageSnapshot(); - return {image, image ? "" : "Unable to create image"}; + sk_sp sk_surface = SkSurface::MakeRenderTarget( + context, SkBudgeted::kYes, image_info); + if (!sk_surface) { + result = {nullptr, + "unable to create render target at specified size"}; + return; + } + + SkCanvas* canvas = sk_surface->getCanvas(); + canvas->clear(SK_ColorTRANSPARENT); + display_list->RenderTo(canvas); + + sk_sp image = sk_surface->makeImageSnapshot(); + result = {image, image ? "" : "Unable to create image"}; + })); + return result; } namespace { diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index 9c7de893b4..23f91cdbda 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -3754,7 +3754,7 @@ TEST_F(ShellTest, SpawnWorksWithOnError) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); } -TEST_F(ShellTest, PictureToGpuImage) { +TEST_F(ShellTest, PictureToImageSync) { #if !SHELL_ENABLE_GL // GL emulation does not exist on Fuchsia. GTEST_SKIP(); @@ -3778,7 +3778,7 @@ TEST_F(ShellTest, PictureToGpuImage) { ASSERT_TRUE(shell->IsSetup()); auto configuration = RunConfiguration::InferFromSettings(settings); PlatformViewNotifyCreated(shell.get()); - configuration.SetEntrypoint("toGpuImage"); + configuration.SetEntrypoint("toImageSync"); RunEngine(shell.get(), std::move(configuration)); PumpOneFrame(shell.get()); diff --git a/engine/src/flutter/testing/dart/canvas_test.dart b/engine/src/flutter/testing/dart/canvas_test.dart index 1bf1fb6cc4..4de620f975 100644 --- a/engine/src/flutter/testing/dart/canvas_test.dart +++ b/engine/src/flutter/testing/dart/canvas_test.dart @@ -410,12 +410,12 @@ void main() { expect(areEqual, true); }, skip: !Platform.isLinux); // https://github.com/flutter/flutter/issues/53784 - test('toGpuImage - too big', () async { + test('toImageSync - too big', () async { PictureRecorder recorder = PictureRecorder(); Canvas canvas = Canvas(recorder); canvas.drawPaint(Paint()..color = const Color(0xFF123456)); final Picture picture = recorder.endRecording(); - final Image image = picture.toGpuImage(300000, 4000000); + final Image image = picture.toImageSync(300000, 4000000); picture.dispose(); expect(image.width, 300000); @@ -454,12 +454,12 @@ void main() { ); }); - test('toGpuImage - succeeds', () async { + test('toImageSync - succeeds', () async { PictureRecorder recorder = PictureRecorder(); Canvas canvas = Canvas(recorder); canvas.drawPaint(Paint()..color = const Color(0xFF123456)); final Picture picture = recorder.endRecording(); - final Image image = picture.toGpuImage(30, 40); + final Image image = picture.toImageSync(30, 40); picture.dispose(); expect(image.width, 30); @@ -485,36 +485,26 @@ void main() { ); }); - test('toGpuImage - toByteData', () async { + test('toImageSync - toByteData', () async { const Color color = Color(0xFF123456); final PictureRecorder recorder = PictureRecorder(); final Canvas canvas = Canvas(recorder); canvas.drawPaint(Paint()..color = color); final Picture picture = recorder.endRecording(); - final Image image = picture.toGpuImage(6, 8); + final Image image = picture.toImageSync(6, 8); picture.dispose(); expect(image.width, 6); expect(image.height, 8); - final ByteData? data = await image.toByteData(); + final ByteData? data = await image.toByteData(format: ImageByteFormat.rawRgba); expect(data, isNotNull); expect(data!.lengthInBytes, 6 * 8 * 4); - final Uint32List bytes = data.buffer.asUint32List(); - // Draws a checkerboard due to flutter_tester not having a GPU context. - const int white = 0xFFFFFFFF; - const int grey = 0xFFCCCCCC; - expect(bytes, const [ - white, white, white, grey, grey, grey, // - white, white, white, grey, grey, grey, - white, white, white, grey, grey, grey, - white, white, white, grey, grey, grey, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - ]); + expect(data.buffer.asUint8List()[0], 0x12); + expect(data.buffer.asUint8List()[1], 0x34); + expect(data.buffer.asUint8List()[2], 0x56); + expect(data.buffer.asUint8List()[3], 0xFF); }); test('Canvas.drawParagraph throws when Paragraph.layout was not called', () async { diff --git a/engine/src/flutter/testing/dart/compositing_test.dart b/engine/src/flutter/testing/dart/compositing_test.dart index c55f18899e..30f644fbf6 100644 --- a/engine/src/flutter/testing/dart/compositing_test.dart +++ b/engine/src/flutter/testing/dart/compositing_test.dart @@ -8,17 +8,18 @@ import 'dart:ui'; import 'package:litetest/litetest.dart'; void main() { - test('Scene.toGpuImage succeeds', () async { + test('Scene.toImageSync succeeds', () async { final PictureRecorder recorder = PictureRecorder(); final Canvas canvas = Canvas(recorder); - canvas.drawPaint(Paint()..color = const Color(0xFF123456)); + const Color color = Color(0xFF123456); + canvas.drawPaint(Paint()..color = color); final Picture picture = recorder.endRecording(); final SceneBuilder builder = SceneBuilder(); builder.pushOffset(10, 10); builder.addPicture(const Offset(5, 5), picture); final Scene scene = builder.build(); - final Image image = scene.toGpuImage(6, 8); + final Image image = scene.toImageSync(6, 8); picture.dispose(); scene.dispose(); @@ -29,20 +30,10 @@ void main() { expect(data, isNotNull); expect(data!.lengthInBytes, 6 * 8 * 4); - final Uint32List bytes = data.buffer.asUint32List(); - // Draws a checkerboard due to flutter_tester not having a GPU context. - const int white = 0xFFFFFFFF; - const int grey = 0xFFCCCCCC; - expect(bytes, const [ - white, white, white, grey, grey, grey, // - white, white, white, grey, grey, grey, - white, white, white, grey, grey, grey, - white, white, white, grey, grey, grey, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - grey, grey, grey, white, white, white, - ]); + expect(data.buffer.asUint8List()[0], 0x12); + expect(data.buffer.asUint8List()[1], 0x34); + expect(data.buffer.asUint8List()[2], 0x56); + expect(data.buffer.asUint8List()[3], 0xFF); }); test('addPicture with disposed picture does not crash', () { diff --git a/engine/src/flutter/testing/dart/image_shader_test.dart b/engine/src/flutter/testing/dart/image_shader_test.dart index 5aab759536..64aa7ccc90 100644 --- a/engine/src/flutter/testing/dart/image_shader_test.dart +++ b/engine/src/flutter/testing/dart/image_shader_test.dart @@ -23,7 +23,7 @@ void main() { final Canvas canvas = Canvas(recorder); canvas.drawPaint(Paint()..color = const Color(0xFFABCDEF)); final Picture picture = recorder.endRecording(); - final Image image = picture.toGpuImage(50, 50); + final Image image = picture.toImageSync(50, 50); picture.dispose(); // TODO(dnfield): this should not throw once