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

Conversation

angjieli
Copy link
Contributor

@angjieli angjieli commented Oct 14, 2020

Description

Support auto detect mode to determine which rendering backend to use.

If auto detect is enabled (set by environment variable FLUTTER_WEB_AUTO_DETECT), developers will be allowed to set window.flutterWebRenderer to either canvaskit or html to select the rendering backend.
If window.flutterWebRenderer is not set, flutter engine will use canvaskit for desktop device while using html for mobile device.
If window.flutterWebRenderer is set to an invalid value (not canvaskit nor html), it will default to html.

If auto detect is disabled, it will check the value of environment variable FLUTTER_WEB_USE_SKIA. If true, use canvaksit. Otherwise, use html.

Tests

Updated some test to reflect this change.

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

Breaking Change

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

@angjieli angjieli requested a review from yjbanov October 15, 2020 15:41
@chinmaygarde chinmaygarde added the platform-web Code specifically for the web engine label Oct 15, 2020
/// EXPERIMENTAL: Enable the Skia-based rendering backend.
const bool experimentalUseSkia =
@JS('window.flutterWebRenderer')
external String? get customRenderer;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "custom renderer" sounds like this is the renderer itself. I'd call this requestedRendererType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, let's leave dartdocs explaining what it's for.

@yjbanov yjbanov requested a review from jonahwilliams October 16, 2020 23:36
@yjbanov
Copy link
Contributor

yjbanov commented Oct 16, 2020

Added @jonahwilliams to reviewer list to have a look at the gn changes.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

gn changes LGTM

Copy link
Contributor

@nturgut nturgut left a comment

Choose a reason for hiding this comment

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

The failing test on Cirrus is fixed yesterday, we should sync to head though.

_autoDetect ? _detectRenderer() : _useSkia;

/// Returns true if CanvasKit is used.
/// Otherwise, returns false.
Copy link
Contributor

Choose a reason for hiding this comment

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

if (requestedRendererType != null) {
return requestedRendererType! == 'canvaskit';
}
// If requestedRendererType is not specified, use CanvasKit for desktop and
Copy link
Contributor

Choose a reason for hiding this comment

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

@yjbanov @ferhatb if I'm not mistaken we are setting Canvaskit as default for desktop. I am personally not sure if we are ready for this step as testing goes:

  • Majority of our unit tests are build with canvaskit.
  • We have coverage in many critical areas with integration tests on Desktop browsers (text editing, font loading, keyboard, platform selection, image loading, semantics (in draft), scroll (in pr), pointer events (in pr), tree shaking, platform messages). None of them runs with Canvaskit though.

Shall we prioritize running them with Canvaskit then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. We should definitely ramp up testing in CanvasKit mode. This PR is not changing the default yet (--web-renderer=auto will default to CanvasKit on desktop, but --web-renderer itself defaults to html so overall the defaults are not changing), so tests can proceed on their own schedule.

In terms of test prioritization, testing things in CanvasKit mode where the choice of renderer has known effects is a good place to start from. From your list the affected areas are: font loading, image loading. Text editing is also affected but I'm not sure our existing tests will catch the distinction, so we may need new tests. Tree shaking is affected; we use devicelab for that, so it would be best to reuse the existing tests. Other things affected by renderer choice: rendering quality, platform views. There's also performance, but our benchmarks already cover both HTML and CanvasKit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@angjieli tl;dr there's no action items for this PR w.r.t. running existing tests in CanvasKit mode

///
/// Using flutter tools option "--web-render=cavanskit" would set the value to
/// true.
/// Using flutter tools option "--web-render=html" would set the value to false.
Copy link
Contributor

Choose a reason for hiding this comment

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

very nit: typo for canvaskit

@nturgut
Copy link
Contributor

nturgut commented Oct 20, 2020

@ferhatb @yjbanov I have an idea for increasing test coverage. When we are running framework tests with local engine, we can run them both with canvaskit and html backend. I'll do that by setting FLUTTER_WEB_AUTO_DETECT in a new luci builder. It will be a very easy change in flutter/infra code. Please let me know if this sound good to you?

@angjieli angjieli requested a review from yjbanov October 22, 2020 15:46
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

if (requestedRendererType != null) {
return requestedRendererType! == 'canvaskit';
}
// If requestedRendererType is not specified, use CanvasKit for desktop and
Copy link
Contributor

Choose a reason for hiding this comment

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

@angjieli tl;dr there's no action items for this PR w.r.t. running existing tests in CanvasKit mode

@angjieli angjieli added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Oct 22, 2020
@fluttergithubbot fluttergithubbot merged commit cde1e3f into flutter:master Oct 22, 2020
zanderso pushed a commit to flutter/flutter that referenced this pull request Oct 23, 2020
* 000bf4b Roll Skia from 2d2f82c00aeb to 5c7bb326a7b3 (33 revisions) (flutter/engine#22059)

* ae92dbf Roll Fuchsia Linux SDK from lPMs_KwnU... to gqS_DIjN4... (flutter/engine#22057)

* 92cd74e Roll Fuchsia Mac SDK from pZ9FgVZTK... to WLxBkBnZa... (flutter/engine#22055)

* e51c710 Roll Dart SDK from a3d902d8598e to 9f907e198970 (2 revisions) (flutter/engine#22058)

* 326b202 Reland fuchsia external view embedder will be shared with platform view (flutter/engine#22008)

* a9a9a2f Roll Skia from 5c7bb326a7b3 to 65674e4c2e56 (3 revisions) (flutter/engine#22060)

* 1233fe4 Revert "Revert "Explicitly make the X connection for EGL. (#21831)" (#21851)" (flutter/engine#21871)

* aed8e01 Fixes Edge trigger route change announcement (flutter/engine#21975)

* 6bc70e4 Reland: Migration to PlatformDispatcher and multi-window (flutter/engine#21932)

* 5ca5e26 Add FlEventChannel (flutter/engine#21316)

* 77b0052 Roll Skia from 65674e4c2e56 to 01b05e5b830b (3 revisions) (flutter/engine#22062)

* 3d27fd5 Support loading assets from Android dynamic feature modules (flutter/engine#21504)

* 742dfbe support uri intent launcher in android (flutter/engine#21275)

* cde1e3f Auto detect mode to determine which rendering backend to use. (flutter/engine#21852)

* 329ccf7 Roll Skia from 01b05e5b830b to 53281c712159 (1 revision) (flutter/engine#22065)

* cde78c1 Add a golden scenario test for fallback font rendering on iOS take 2 (flutter/engine#22033)

* 4f4599b Roll Dart SDK from 9f907e198970 to 37ccceacad41 (3 revisions) (flutter/engine#22069)

* f0b10c5 [web] Prevent using DOM nodes for canvas with large number of draws (flutter/engine#22064)

* a86ba57 Roll Fuchsia Mac SDK from WLxBkBnZa... to zDfaxkqlv... (flutter/engine#22073)

* 645198a Roll Fuchsia Linux SDK from gqS_DIjN4... to vuKxZmSVj... (flutter/engine#22074)

* 0b26570 Revert dart rolls (flutter/engine#22078)
@happyharis
Copy link

Is there a way to check whether the HTML is being rendered only, or canvas kit is being rendered only?

@angjieli
Copy link
Contributor Author

angjieli commented Nov 5, 2020

Is there a way to check whether the HTML is being rendered only, or canvas kit is being rendered only?

IIRC, you should be able to tell the difference by examining the compiled javascript code. @yjbanov feel free to correct me if I am wrong

@slavap
Copy link

slavap commented Jan 5, 2021

@yjbanov @angjieli
How can I get access to engine.useCanvasKit from regular Flutter application?
Right now I cannot figure out from the code which renderer is used to adjust my code accordingly, so I have to explicitly specify --web-renderer html

@angjieli
Copy link
Contributor Author

angjieli commented Jan 5, 2021

@yjbanov @angjieli
How can I get access to engine.useCanvasKit from regular Flutter application?
Right now I cannot figure out from the code which renderer is used to adjust my code accordingly, so I have to explicitly specify --web-renderer html

Once you have launched the application in auto mode, you can enter window.flutterWebRenderer=html in your browser's console before the application is launched. By doing so, your application will be rendered using html.

@slavap
Copy link

slavap commented Jan 5, 2021

@angjieli No, my question was - how to detect which mode was set by auto setting, I don't want to explicitly force anything.

@angjieli
Copy link
Contributor Author

angjieli commented Jan 5, 2021

@angjieli No, my question was - how to detect which mode was set by auto setting, I don't want to explicitly force anything.

Oh, misread the question. There is no good way to check the rendering backend at this point. IIRC, the info is not exposed to flutter application.

@slavap
Copy link

slavap commented Jan 5, 2021

@angjieli
That's bad, it has to be exposed to Flutter app, preferable as constant. We have kIsWeb, probably adding kIsWebHtml and kIsWebCanvasKit will cover all cases.

@angjieli
Copy link
Contributor Author

angjieli commented Jan 5, 2021

@angjieli
That's bad, it has to be exposed to Flutter app, preferable as constant. We have kIsWeb, probably adding kIsWebHtml and kIsWebCanvasKit will cover all cases.

Yeah. Feel free to file an issue and we can fix it.

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 waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants