Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay metal drawable acquisition till frame submission. #13367

Merged
merged 2 commits into from
Oct 28, 2019

Conversation

chinmaygarde
Copy link
Member

Uses the new SkSurface::MakeFromCAMetalLayer Skia API. Fixes flutter/flutter#41829

Uses the new `SkSurface::MakeFromCAMetalLayer` Skia API.
@chinmaygarde chinmaygarde added this to In Progress in Metal Renderer via automation Oct 26, 2019
bounds.height * scale, // height
1, // sample count
metal_texture_info // metal texture info
auto surface = SkSurface::MakeFromCAMetalLayer(context_.get(), // context
Copy link
Contributor

Choose a reason for hiding this comment

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

Does next_drawable_ get set synchronously here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. This will defer the next drawable acquisition till much later. In fact, it is almost guaranteed to not be set after this call. I would have captured it in one of the scoped wrappers otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the next_drawable_ isn't set until after we check if it's null in the callback?

Copy link
Member Author

Choose a reason for hiding this comment

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

The next GPUSurfaceMetal::AcquireFrame will collect it if there is a next frame. GPUSurfaceMetal::~GPUSurfaceMetal will collect it via ReleaseUnusedDrawableIfNecessary if there isn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

I should mention that either case is extremely unlikely because the surface frame itself is collected immediately after submission.

canvas->flush();
if (!hasExternalViewEmbedder) {

if (next_drawable_ == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that this callback gets invoked between lines 101 and 104 above?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. These are on the same thread and tasks are posted serially.

Comment on lines 119 to 125
// External views need to present with transaction. When presenting with
// transaction, we have to block, otherwise we risk presenting the drawable
// after the CATransaction has completed.
// See:
// https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction
// TODO(dnfield): only do this if transactions are actually being used.
// https://github.com/flutter/flutter/issues/24133
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe we should move this comment down to line 143 now, since we're no longer getting whether it's an external view embedder here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Do the platform view tests pass on the metal backend with this? We only run them on OpenGL on CI AFAIK.

Copy link
Member Author

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Addressed all comments. I also missed a release of the drawable when the surface itself is collected without pending surface frame submission.

Do the platform view tests pass on the metal backend with this?

Yes, but this needs to be automated. Tracking in flutter/flutter#43649

bounds.height * scale, // height
1, // sample count
metal_texture_info // metal texture info
auto surface = SkSurface::MakeFromCAMetalLayer(context_.get(), // context
Copy link
Member Author

Choose a reason for hiding this comment

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

No. This will defer the next drawable acquisition till much later. In fact, it is almost guaranteed to not be set after this call. I would have captured it in one of the scoped wrappers otherwise.

Comment on lines 119 to 125
// External views need to present with transaction. When presenting with
// transaction, we have to block, otherwise we risk presenting the drawable
// after the CATransaction has completed.
// See:
// https://developer.apple.com/documentation/quartzcore/cametallayer/1478157-presentswithtransaction
// TODO(dnfield): only do this if transactions are actually being used.
// https://github.com/flutter/flutter/issues/24133
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

canvas->flush();
if (!hasExternalViewEmbedder) {

if (next_drawable_ == nullptr) {
Copy link
Member Author

Choose a reason for hiding this comment

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

No. These are on the same thread and tasks are posted serially.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@chinmaygarde chinmaygarde merged commit 4044876 into flutter:master Oct 28, 2019
Metal Renderer automation moved this from In Progress to Done Oct 28, 2019
@chinmaygarde chinmaygarde deleted the metal_surface branch October 28, 2019 20:24
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 29, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Oct 29, 2019
git@github.com:flutter/engine.git/compare/49971e21402e...25563a1

git log 49971e2..25563a1 --no-merges --oneline
2019-10-29 iska.kaushik@gmail.com Update recipe_changelog to account for dart_aot runner and clobbering
2019-10-28 iska.kaushik@gmail.com Revert "[flutter_runner] Don't build far files twice (#13397)" (flutter/engine#13400)
2019-10-28 matthew-carroll@users.noreply.github.com Remove multiplexed Flutter Android Lifecycle. (#43663) (flutter/engine#13394)
2019-10-28 iska.kaushik@gmail.com [flutter_runner] Don't build far files twice (flutter/engine#13397)
2019-10-28 chinmaygarde@google.com Delay metal drawable acquisition till frame submission. (flutter/engine#13367)
2019-10-28 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/mac-amd64 from 9MM-e... to mc3jR... (flutter/engine#13390)
2019-10-28 bkonyi@google.com Roll src/third_party/dart 5e39817ec7..e1fce75301 (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC aaclarke@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
git@github.com:flutter/engine.git/compare/49971e21402e...25563a1

git log 49971e2..25563a1 --no-merges --oneline
2019-10-29 iska.kaushik@gmail.com Update recipe_changelog to account for dart_aot runner and clobbering
2019-10-28 iska.kaushik@gmail.com Revert "[flutter_runner] Don't build far files twice (flutter#13397)" (flutter/engine#13400)
2019-10-28 matthew-carroll@users.noreply.github.com Remove multiplexed Flutter Android Lifecycle. (flutter#43663) (flutter/engine#13394)
2019-10-28 iska.kaushik@gmail.com [flutter_runner] Don't build far files twice (flutter/engine#13397)
2019-10-28 chinmaygarde@google.com Delay metal drawable acquisition till frame submission. (flutter/engine#13367)
2019-10-28 skia-flutter-autoroll@skia.org Roll fuchsia/sdk/core/mac-amd64 from 9MM-e... to mc3jR... (flutter/engine#13390)
2019-10-28 bkonyi@google.com Roll src/third_party/dart 5e39817ec7..e1fce75301 (2 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC aaclarke@google.com on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
3 participants