forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[canvaskit] reuse canvases when window resizes (flutter#22966)
- Loading branch information
Showing
2 changed files
with
74 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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.12 | ||
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('CanvasKit', () { | ||
setUpCanvasKitTest(); | ||
|
||
test('Surface allocates canvases efficiently', () { | ||
final Surface surface = Surface(HtmlViewEmbedder()); | ||
final CkSurface original = surface.acquireRenderSurface(ui.Size(9, 19)); | ||
|
||
// Expect exact requested dimensions. | ||
expect(original.width(), 9); | ||
expect(original.height(), 19); | ||
|
||
// Shrinking reuses the existing surface straight-up. | ||
final CkSurface shrunk = surface.acquireRenderSurface(ui.Size(5, 15)); | ||
expect(shrunk, same(original)); | ||
|
||
// The first increase will allocate a new surface, but will overallocate | ||
// by 40% to accommodate future increases. | ||
final CkSurface firstIncrease = surface.acquireRenderSurface(ui.Size(10, 20)); | ||
expect(firstIncrease, isNot(same(original))); | ||
|
||
// Expect overallocated dimensions | ||
expect(firstIncrease.width(), 14); | ||
expect(firstIncrease.height(), 28); | ||
|
||
// Subsequent increases within 40% reuse the old surface. | ||
final CkSurface secondIncrease = surface.acquireRenderSurface(ui.Size(11, 22)); | ||
expect(secondIncrease, same(firstIncrease)); | ||
|
||
// Increases beyond the 40% limit will cause a new allocation. | ||
final CkSurface huge = surface.acquireRenderSurface(ui.Size(20, 40)); | ||
expect(huge, isNot(same(firstIncrease))); | ||
|
||
// Also over-allocated | ||
expect(huge.width(), 28); | ||
expect(huge.height(), 56); | ||
|
||
// Shrink again. Reuse the last allocated surface. | ||
final CkSurface shrunk2 = surface.acquireRenderSurface(ui.Size(5, 15)); | ||
expect(shrunk2, same(huge)); | ||
}); | ||
}, skip: isIosSafari); | ||
} |