forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image.toByteData and Picture.toImage implementations (#3) (flutter#20750
) * `Image.toByteData()` was not implemented in either DomCanvas or CanvasKit. This PR covers **both.** * `Picture.toImage()` was not implemented in either DomCanvas or CanvasKit. This PR covers **CanvasKit**
- Loading branch information
Showing
6 changed files
with
210 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
lib/web_ui/test/golden_tests/engine/canvas_to_picture_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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. | ||
|
||
// @dart = 2.6 | ||
import 'dart:html' as html; | ||
|
||
import 'package:ui/ui.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
|
||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
void testMain() async { | ||
final Rect region = Rect.fromLTWH(0, 0, 500, 500); | ||
|
||
setUp(() async { | ||
debugShowClipLayers = true; | ||
SurfaceSceneBuilder.debugForgetFrameScene(); | ||
for (html.Node scene in html.document.querySelectorAll('flt-scene')) { | ||
scene.remove(); | ||
} | ||
|
||
await webOnlyInitializePlatform(); | ||
webOnlyFontCollection.debugRegisterTestFonts(); | ||
await webOnlyFontCollection.ensureFontsLoaded(); | ||
}); | ||
|
||
test('Convert Canvas to Picture', () async { | ||
final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); | ||
final Picture testPicture = await _drawTestPictureWithCircle(region); | ||
builder.addPicture(Offset.zero, testPicture); | ||
|
||
html.document.body.append(builder | ||
.build() | ||
.webOnlyRootElement); | ||
|
||
//await matchGoldenFile('canvas_to_picture.png', region: region, write: true); | ||
}); | ||
} | ||
|
||
Picture _drawTestPictureWithCircle(Rect region) { | ||
final EnginePictureRecorder recorder = PictureRecorder(); | ||
final RecordingCanvas canvas = recorder.beginRecording(region); | ||
canvas.drawOval( | ||
region, | ||
Paint() | ||
..style = PaintingStyle.fill | ||
..color = Color(0xFF00FF00)); | ||
return recorder.endRecording(); | ||
} |