Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

ferhatb
Copy link
Contributor

@ferhatb ferhatb commented Oct 28, 2020

Description

  • This PR introduces density to PersistedPicture. After Scene preroll, the picture uses the absolute transform to compute best scalar to use to match physical pixels to canvas pixels and rescales recording canvas operations.
  • The scalar (density) is clamped to make sure we don't exceed webkit allocation limits.
  • Added code to free up canvas pool when canvas.getContext('2d') fails due to insufficient memory.

Related Issues

flutter/flutter#59775

Tests

Added SceneBuilder test that verifies when using a 0.5,0.5 scale transform, a smaller canvas is allocated instead of bounds.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [contributor guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [C++, Objective-C, Java style guides] for the engine.
  • I read the [tree hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Reviewer Checklist

  • I have submitted any presubmit flakes in this PR using the [engine presubmit flakes form] before re-triggering the failure.

Breaking Change

Did any tests fail when you ran them? Please read [handling breaking changes].

}
if (newChild.rootElement == null) {
print(newChild);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Removed.

});

group('SceneBuilder', () {
group('SceneBuilder', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

test('Canvas should allocate fewer pixels if scaled', () async {
final SurfaceSceneBuilder builder = SurfaceSceneBuilder();
final Picture picture1 = _drawPicture();
builder.pushClipRect(const Rect.fromLTRB(10, 10, 300, 300),);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary trailing comma

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

await testCase('', 'remove all', deletions: 2);
});

test('Canvas should allocate fewer pixels if scaled', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scaled as in "zoomed in" or "zoomed out"? (I know the answer now, but will need to think longer in a few months)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comment. thx.

// Force update to scene which will utilize reuse code path.
final SurfaceSceneBuilder builder2 = SurfaceSceneBuilder();
builder2.pushOffset(0, 0);
builder2.pushTransform(Matrix4.identity().scaled(0.5, 0.5).toFloat64());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need a test the zooms the picture in and makes sure that the growth in pixel count stops at screen size (i.e. that we're not allocating enormous canvases)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you zoom out, the big canvas becomes small ie scale factor < 1. I added another test case for zoom in.

if (scale < kEpsilon || scale == 1) {
// Handle local paint bounds scaled to 0, typical when using
// transform animations.
return 1.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be if ((scale - 1).abs() < kEpsilon)? Also scale 0 probably means "empty picture".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added and updated comment. It guards the code below from divide by zero.

//
// On a fullscreen high dpi device dpi*density*resolution will demand
// too much memory, so clamp at 4.
scale = math.min(4.0, ((scale / 2.0).ceil() * 2.0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we normalize before the previous if statement? This way if scale snaps to 1x we just return 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the early exit. For many apps most of the time scale is just 1.0 unless you use boxfit.

@ferhatb ferhatb added the platform-web Code specifically for the web engine label Oct 29, 2020
Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ferhatb ferhatb merged commit 1ad6765 into flutter:master Oct 30, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 3, 2020
cbracken pushed a commit to flutter/flutter that referenced this pull request Nov 3, 2020
* c597333 Roll Skia from f548a028ce70 to c21902c0d3cc (46 revisions) (flutter/engine#22224)

* 37d766c Fix includes to start with shell (flutter/engine#22227)

* 1ad6765 [web] Fixes canvas pixelation and overallocation due to transforms.  (flutter/engine#22160)

* 9f9fc1f Roll Skia from c21902c0d3cc to 9615bcf71f2a (1 revision) (flutter/engine#22226)

* 0faa72e Roll Dart SDK from fed66f60a3bc to 25ef5dc559cf (1 revision) (flutter/engine#22225)

* 172a393 Report image diff status for iOS scenario golden tests (flutter/engine#22230)

* fddabca updating integration tests version. (flutter/engine#22235)

* a36bcdc Roll Fuchsia Mac SDK from mhak7e_o6... to 8SkbMXJJ9... (flutter/engine#22231)

* 6a331d3 Roll Skia from 9615bcf71f2a to d5e6368fffd0 (8 revisions) (flutter/engine#22234)

* 9b34207 Fixing semantics borders on mobile web (flutter/engine#21856)

* 4e9459e Refactored the FlutterEngine to make it easier to implement spawn functionality (flutter/engine#21890)

* fa77e68 disable AppLifecycleTests (flutter/engine#22236)

* 153775b update golden (flutter/engine#22247)

* 50dbe85 [web] fix hot restart type error (flutter/engine#22248)

* c8cf09a Roll Skia from d5e6368fffd0 to 7585a65ac709 (7 revisions) (flutter/engine#22237)

* 68e2e46 Roll Fuchsia Mac SDK from 8SkbMXJJ9... to Pz4ZHZrUp... (flutter/engine#22246)

* d3182bc Roll Dart SDK from 25ef5dc559cf to 5acb5fcf84cb (4 revisions) (flutter/engine#22243)

* 9b4bb20 makes android semanticsnode to ignore hittest if it is not focusable (flutter/engine#22205)

* 3c7a54e Roll Fuchsia Linux SDK from sNx8qabBn... to QqGvMWaYk... (flutter/engine#22244)

* eea98b2 Roll Skia from 7585a65ac709 to dffd20efe95c (14 revisions) (flutter/engine#22250)

* 46e3bba Defer Windows arrow key and delete handling (flutter/engine#22207)

* 14437d6 fix _getArrayBuffer signature (flutter/engine#22251)

* 8defec6 Fix nullability issue with Image.network (flutter/engine#22252)

* 67d55ed Roll Dart SDK from 5acb5fcf84cb to a9d583383410 (4 revisions) (flutter/engine#22255)

* 7c8f57c Report error when instantiating CanvasKit network image (flutter/engine#22159)

* 9945db3 Remove the metrics task from cirrus. (flutter/engine#22240)

* bd19181 Add braces on if statements to match linter style (flutter/engine#22130)

* e9c62e7 do not print in _computePixelDensity (flutter/engine#22257)

* 2617101 Roll Dart SDK from a9d583383410 to d2577410a501 (1 revision) (flutter/engine#22258)

* 3d194fa Switch macOS embedding to proc table embedder API (flutter/engine#21811)

* 31b6f0b Roll Fuchsia Mac SDK from Pz4ZHZrUp... to 6yEx5GNGG... (flutter/engine#22262)

* 78a0181 Roll Fuchsia Linux SDK from QqGvMWaYk... to oLF1FW-gC... (flutter/engine#22264)

* ccdb681 WeakPersistentHandle migration (flutter/engine#19843)

* ce0a30c Roll Dart SDK from 52783837369d to b43baaaa477d (723 revisions) (flutter/engine#22265)

* 59b01e0 [web] Fix repaint logic for cullrect,transform changes (flutter/engine#22273)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes platform-web Code specifically for the web engine

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants