This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Use H5vcc CanvasKit implementation if it is detected. #31191
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
66ddb42
Use H5vcc CanvasKit implementation if it is detected.
b-luk fc0ab52
Use `??=` over testing for null.
b-luk 4b3fdd8
Add tests exercising a monkey-patched h5vcc implementation.
b-luk 503f21c
Remove debugging print statement.
b-luk 0343783
Move h5vcc tests to new file.
b-luk b0ec882
Move patchH5vccCanvasKit from common.dart to h5vcc_test.dart since it…
b-luk 41416c1
Move h5vcc monkey patching out of its separate function.
b-luk ec9c424
Update test to add a check for <canvas> element, and fix a typo.
b-luk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
// 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 'dart:html' as html; | ||
import 'dart:js' as js; | ||
|
||
import 'package:test/bootstrap/browser.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:ui/src/engine.dart'; | ||
import 'package:ui/ui.dart' as ui; | ||
|
||
import 'common.dart'; | ||
|
||
void main() { | ||
internalBootstrapBrowserTest(() => testMain); | ||
} | ||
|
||
void testMain() { | ||
group('H5vcc patched CanvasKit', () { | ||
int getH5vccSkSurfaceCalledCount = 0; | ||
|
||
setUpAll(() async { | ||
// Set `window.h5vcc` to PatchedH5vcc which uses a downloaded CanvasKit. | ||
final CanvasKit downloadedCanvasKit = await downloadCanvasKit(); | ||
debugH5vccSetter = PatchedH5vcc(downloadedCanvasKit); | ||
|
||
// Monkey-patch the getH5vccSkSurface function of | ||
// `window.h5vcc.canvasKit`. | ||
js.context['h5vcc']['canvasKit']['getH5vccSkSurface'] = () { | ||
getH5vccSkSurfaceCalledCount++; | ||
|
||
// Returns a fake [SkSurface] object with a minimal implementation. | ||
return js.JsObject.jsify(<String, dynamic>{ | ||
'dispose': () {} | ||
}); | ||
}; | ||
}); | ||
|
||
setUpCanvasKitTest(); | ||
|
||
setUp(() { | ||
getH5vccSkSurfaceCalledCount = 0; | ||
}); | ||
|
||
test('sets useH5vccCanvasKit', () { | ||
expect(useH5vccCanvasKit, true); | ||
}); | ||
|
||
test('API includes patched getH5vccSkSurface', () { | ||
expect(canvasKit.getH5vccSkSurface, isNotNull); | ||
}); | ||
|
||
test('Surface acquireFrame uses getH5vccSkSurface', () { | ||
final Surface surface = SurfaceFactory.instance.getSurface(); | ||
surface.acquireFrame(ui.Size.zero); | ||
expect(getH5vccSkSurfaceCalledCount, 1); | ||
b-luk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// No <canvas> element should be created. | ||
expect( | ||
flutterViewEmbedder.glassPaneElement!.querySelectorAll<html.Element>('canvas'), | ||
isEmpty, | ||
); | ||
}); | ||
}, testOn: 'chrome'); | ||
} | ||
|
||
class PatchedH5vcc implements H5vcc { | ||
@override | ||
final CanvasKit canvasKit; | ||
|
||
PatchedH5vcc(this.canvasKit); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.