|
|
|
|
@@ -605,7 +605,7 @@ void Shell::OnPlatformViewCreated(std::unique_ptr<Surface> surface) {
|
|
|
|
|
// setup/suspension of all activities that may be interacting with the GPU in
|
|
|
|
|
// a synchronous fashion.
|
|
|
|
|
fml::AutoResetWaitableEvent latch;
|
|
|
|
|
auto gpu_task =
|
|
|
|
|
auto raster_task =
|
|
|
|
|
fml::MakeCopyable([& waiting_for_first_frame = waiting_for_first_frame_,
|
|
|
|
|
rasterizer = rasterizer_->GetWeakPtr(), //
|
|
|
|
|
surface = std::move(surface), //
|
|
|
|
|
@@ -623,19 +623,20 @@ void Shell::OnPlatformViewCreated(std::unique_ptr<Surface> surface) {
|
|
|
|
|
|
|
|
|
|
// The normal flow executed by this method is that the platform thread is
|
|
|
|
|
// starting the sequence and waiting on the latch. Later the UI thread posts
|
|
|
|
|
// gpu_task to the raster thread which signals the latch. If the GPU the and
|
|
|
|
|
// platform threads are the same this results in a deadlock as the gpu_task
|
|
|
|
|
// will never be posted to the plaform/raster thread that is blocked on a
|
|
|
|
|
// latch. To avoid the described deadlock, if the raster and the platform
|
|
|
|
|
// threads are the same, should_post_gpu_task will be false, and then instead
|
|
|
|
|
// of posting a task to the raster thread, the ui thread just signals the
|
|
|
|
|
// latch and the platform/raster thread follows with executing gpu_task.
|
|
|
|
|
bool should_post_gpu_task = task_runners_.GetRasterTaskRunner() !=
|
|
|
|
|
task_runners_.GetPlatformTaskRunner();
|
|
|
|
|
// raster_task to the raster thread which signals the latch. If the raster and
|
|
|
|
|
// the platform threads are the same this results in a deadlock as the
|
|
|
|
|
// raster_task will never be posted to the plaform/raster thread that is
|
|
|
|
|
// blocked on a latch. To avoid the described deadlock, if the raster and the
|
|
|
|
|
// platform threads are the same, should_post_raster_task will be false, and
|
|
|
|
|
// then instead of posting a task to the raster thread, the ui thread just
|
|
|
|
|
// signals the latch and the platform/raster thread follows with executing
|
|
|
|
|
// raster_task.
|
|
|
|
|
bool should_post_raster_task = task_runners_.GetRasterTaskRunner() !=
|
|
|
|
|
task_runners_.GetPlatformTaskRunner();
|
|
|
|
|
|
|
|
|
|
auto ui_task = [engine = engine_->GetWeakPtr(), //
|
|
|
|
|
raster_task_runner = task_runners_.GetRasterTaskRunner(), //
|
|
|
|
|
gpu_task, should_post_gpu_task,
|
|
|
|
|
raster_task, should_post_raster_task,
|
|
|
|
|
&latch //
|
|
|
|
|
] {
|
|
|
|
|
if (engine) {
|
|
|
|
|
@@ -643,10 +644,10 @@ void Shell::OnPlatformViewCreated(std::unique_ptr<Surface> surface) {
|
|
|
|
|
}
|
|
|
|
|
// Step 2: Next, tell the raster thread that it should create a surface for
|
|
|
|
|
// its rasterizer.
|
|
|
|
|
if (should_post_gpu_task) {
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(raster_task_runner, gpu_task);
|
|
|
|
|
if (should_post_raster_task) {
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(raster_task_runner, raster_task);
|
|
|
|
|
} else {
|
|
|
|
|
// See comment on should_post_gpu_task, in this case we just unblock
|
|
|
|
|
// See comment on should_post_raster_task, in this case we just unblock
|
|
|
|
|
// the platform thread.
|
|
|
|
|
latch.Signal();
|
|
|
|
|
}
|
|
|
|
|
@@ -674,11 +675,11 @@ void Shell::OnPlatformViewCreated(std::unique_ptr<Surface> surface) {
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(task_runners_.GetIOTaskRunner(), io_task);
|
|
|
|
|
|
|
|
|
|
latch.Wait();
|
|
|
|
|
if (!should_post_gpu_task) {
|
|
|
|
|
// See comment on should_post_gpu_task, in this case the gpu_task
|
|
|
|
|
if (!should_post_raster_task) {
|
|
|
|
|
// See comment on should_post_raster_task, in this case the raster_task
|
|
|
|
|
// wasn't executed, and we just run it here as the platform thread
|
|
|
|
|
// is the raster thread.
|
|
|
|
|
gpu_task();
|
|
|
|
|
raster_task();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -706,9 +707,9 @@ void Shell::OnPlatformViewDestroyed() {
|
|
|
|
|
latch.Signal();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto gpu_task = [rasterizer = rasterizer_->GetWeakPtr(),
|
|
|
|
|
io_task_runner = task_runners_.GetIOTaskRunner(),
|
|
|
|
|
io_task]() {
|
|
|
|
|
auto raster_task = [rasterizer = rasterizer_->GetWeakPtr(),
|
|
|
|
|
io_task_runner = task_runners_.GetIOTaskRunner(),
|
|
|
|
|
io_task]() {
|
|
|
|
|
if (rasterizer) {
|
|
|
|
|
rasterizer->Teardown();
|
|
|
|
|
}
|
|
|
|
|
@@ -718,29 +719,29 @@ void Shell::OnPlatformViewDestroyed() {
|
|
|
|
|
|
|
|
|
|
// The normal flow executed by this method is that the platform thread is
|
|
|
|
|
// starting the sequence and waiting on the latch. Later the UI thread posts
|
|
|
|
|
// gpu_task to the raster thread triggers signaling the latch(on the IO
|
|
|
|
|
// thread). If the GPU the and platform threads are the same this results in a
|
|
|
|
|
// deadlock as the gpu_task will never be posted to the plaform/raster thread
|
|
|
|
|
// that is blocked on a latch. To avoid the described deadlock, if the raster
|
|
|
|
|
// and the platform threads are the same, should_post_gpu_task will be false,
|
|
|
|
|
// and then instead of posting a task to the raster thread, the ui thread just
|
|
|
|
|
// signals the latch and the platform/raster thread follows with executing
|
|
|
|
|
// gpu_task.
|
|
|
|
|
bool should_post_gpu_task = task_runners_.GetRasterTaskRunner() !=
|
|
|
|
|
task_runners_.GetPlatformTaskRunner();
|
|
|
|
|
// raster_task to the raster thread triggers signaling the latch(on the IO
|
|
|
|
|
// thread). If the raster and the platform threads are the same this results
|
|
|
|
|
// in a deadlock as the raster_task will never be posted to the plaform/raster
|
|
|
|
|
// thread that is blocked on a latch. To avoid the described deadlock, if the
|
|
|
|
|
// raster and the platform threads are the same, should_post_raster_task will
|
|
|
|
|
// be false, and then instead of posting a task to the raster thread, the ui
|
|
|
|
|
// thread just signals the latch and the platform/raster thread follows with
|
|
|
|
|
// executing raster_task.
|
|
|
|
|
bool should_post_raster_task = task_runners_.GetRasterTaskRunner() !=
|
|
|
|
|
task_runners_.GetPlatformTaskRunner();
|
|
|
|
|
|
|
|
|
|
auto ui_task = [engine = engine_->GetWeakPtr(),
|
|
|
|
|
raster_task_runner = task_runners_.GetRasterTaskRunner(),
|
|
|
|
|
gpu_task, should_post_gpu_task, &latch]() {
|
|
|
|
|
raster_task, should_post_raster_task, &latch]() {
|
|
|
|
|
if (engine) {
|
|
|
|
|
engine->OnOutputSurfaceDestroyed();
|
|
|
|
|
}
|
|
|
|
|
// Step 1: Next, tell the raster thread that its rasterizer should suspend
|
|
|
|
|
// access to the underlying surface.
|
|
|
|
|
if (should_post_gpu_task) {
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(raster_task_runner, gpu_task);
|
|
|
|
|
if (should_post_raster_task) {
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(raster_task_runner, raster_task);
|
|
|
|
|
} else {
|
|
|
|
|
// See comment on should_post_gpu_task, in this case we just unblock
|
|
|
|
|
// See comment on should_post_raster_task, in this case we just unblock
|
|
|
|
|
// the platform thread.
|
|
|
|
|
latch.Signal();
|
|
|
|
|
}
|
|
|
|
|
@@ -750,11 +751,11 @@ void Shell::OnPlatformViewDestroyed() {
|
|
|
|
|
// surface is about to go away.
|
|
|
|
|
fml::TaskRunner::RunNowOrPostTask(task_runners_.GetUITaskRunner(), ui_task);
|
|
|
|
|
latch.Wait();
|
|
|
|
|
if (!should_post_gpu_task) {
|
|
|
|
|
// See comment on should_post_gpu_task, in this case the gpu_task
|
|
|
|
|
if (!should_post_raster_task) {
|
|
|
|
|
// See comment on should_post_raster_task, in this case the raster_task
|
|
|
|
|
// wasn't executed, and we just run it here as the platform thread
|
|
|
|
|
// is the raster thread.
|
|
|
|
|
gpu_task();
|
|
|
|
|
raster_task();
|
|
|
|
|
latch.Wait();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|