forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[canvaskit] Fall back to
drawImage
for browsers that don't support …
…`createImageBitmap` (flutter#48336) Safari 14 doesn't have the `createImageBitmap` API available. This change allows us to render into `RenderCanvas` without using `createImageBitmap` in that case. Fixes flutter/flutter#138910 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
- Loading branch information
1 parent
fc2ab99
commit 96137d0
Showing
4 changed files
with
170 additions
and
19 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
65 changes: 65 additions & 0 deletions
65
lib/web_ui/test/canvaskit/no_create_image_bitmap_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,65 @@ | ||
// 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: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); | ||
} | ||
|
||
const ui.Rect region = ui.Rect.fromLTRB(0, 0, 500, 250); | ||
|
||
/// Test that we can render even if `createImageBitmap` is not supported. | ||
void testMain() { | ||
group('CanvasKit', () { | ||
setUpCanvasKitTest(); | ||
setUp(() async { | ||
EngineFlutterDisplay.instance.debugOverrideDevicePixelRatio(1.0); | ||
debugDisableCreateImageBitmapSupport = true; | ||
}); | ||
|
||
tearDown(() { | ||
debugDisableCreateImageBitmapSupport = false; | ||
}); | ||
|
||
test('can render without createImageBitmap', () async { | ||
final CkPictureRecorder recorder = CkPictureRecorder(); | ||
final CkCanvas canvas = recorder.beginRecording(region); | ||
|
||
final CkGradientLinear gradient = CkGradientLinear( | ||
ui.Offset(region.left + region.width / 4, region.height / 2), | ||
ui.Offset(region.right - region.width / 8, region.height / 2), | ||
const <ui.Color>[ | ||
ui.Color(0xFF4285F4), | ||
ui.Color(0xFF34A853), | ||
ui.Color(0xFFFBBC05), | ||
ui.Color(0xFFEA4335), | ||
ui.Color(0xFF4285F4), | ||
], | ||
const <double>[ | ||
0.0, | ||
0.25, | ||
0.5, | ||
0.75, | ||
1.0, | ||
], | ||
ui.TileMode.clamp, | ||
null); | ||
|
||
final CkPaint paint = CkPaint()..shader = gradient; | ||
|
||
canvas.drawRect(region, paint); | ||
|
||
await matchPictureGolden( | ||
'canvaskit_linear_gradient_no_create_image_bitmap.png', | ||
recorder.endRecording(), | ||
region: region, | ||
); | ||
}); | ||
}); | ||
} |