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

Conversation

@jason-simmons
Copy link
Member

UI thread APIs that need to access the IO thread's resource context should
obtain a weak pointer to the IO manager and pass that to the IO thread.

Copy link
Contributor

@gw280 gw280 left a comment

Choose a reason for hiding this comment

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

LGTM apart from some questions. Needs a unit test, though.

}

fml::WeakPtr<IOManager> UIDartState::GetIOManager() const {
return io_manager_;
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 be vending a new WeakPtr here by calling io_manager_->GetWeakIOManager()?

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 UI thread can safely copy io_manager_, but it can't safely dereference and call io_manager_->GetWeakIOManager

image = canvas_image->image(), //
context = std::move(context), //
fml::MakeCopyable([callback = std::move(callback), //
image = canvas_image->image(), //
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: // alignment

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the empty comments

std::move(image), //
context.get(), //
EncodeImageAndInvokeDataCallback(std::move(callback), //
std::move(image), //
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: // alignment

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed the empty comments

fml::WeakPtr<IOManager> GetIOManager() const;

fml::WeakPtr<GrContext> GetResourceContext() const;
fml::RefPtr<flutter::SkiaUnrefQueue> GetSkiaUnrefQueue() const;
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 also delete this method and expect callees to go through the IOManager as well? It seems like that should be the direction we go down - but I'm happy to defer this to another issue (and file one to track that) instead of overloading this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we should never dereference io_manager_ on the UI thread.

Fixing this for SkiaUnrefQueue will require a different approach because it is used widely in UI thread APIs that do not run tasks on the IO thread. One option would be keeping a strong RefPtr to the SkiaUnrefQueue in UIDartState.

UI thread APIs that need to access the IO thread's resource context should
obtain a weak pointer to the IO manager and pass that to the IO thread.
@jason-simmons
Copy link
Member Author

Not sure how to test this effectively with our current infrastructure.

This issue involves Dart APIs invoked on the UI thread using an object that is owned by the IO thread. Ideally a Dart test like https://github.com/flutter/engine/blob/master/testing/dart/canvas_test.dart should catch this. But the flutter_tester environment that runs the Dart tests uses the same thread for platform/UI/IO/GPU. So the assertions can't differentiate beween the UI thread and the IO thread.

Copy link
Contributor

@gw280 gw280 left a comment

Choose a reason for hiding this comment

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

LGTM with the caveat that we file an issue for this unit test and GetSkiaUnrefQueue() change. I can start looking at the unit test now.

image_format //
);

task_runners.GetIOTaskRunner()->PostTask(fml::MakeCopyable(
Copy link
Member

Choose a reason for hiding this comment

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

Noooo. The slashes.

@jason-simmons jason-simmons merged commit 8882bf3 into flutter:master Oct 18, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Oct 21, 2019
…flutter/engine#13232) (#43045)

git@github.com:flutter/engine.git/compare/8aefcd857508...8882bf3

git log 8aefcd8..8882bf3 --no-merges --oneline
2019-10-18 jason-simmons@users.noreply.github.com Avoid dereferencing IO manager weak pointers on the UI thread (flutter/engine#13232)


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 franciscojma@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
…flutter/engine#13232) (flutter#43045)

git@github.com:flutter/engine.git/compare/8aefcd857508...8882bf3

git log 8aefcd8..8882bf3 --no-merges --oneline
2019-10-18 jason-simmons@users.noreply.github.com Avoid dereferencing IO manager weak pointers on the UI thread (flutter/engine#13232)


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 franciscojma@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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants