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

Commit 83dfdbd

Browse files
committed
Post at a later time from the same task runner
1 parent 2db5060 commit 83dfdbd

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

shell/common/vsync_waiter.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
9898
fml::TimePoint frame_target_time,
9999
bool pause_secondary_tasks) {
100100
FML_DCHECK(fml::TimePoint::Now() >= frame_start_time);
101-
FML_DCHECK(task_runners_.GetPlatformTaskRunner()->RunsTasksOnCurrentThread());
102101

103102
Callback callback;
104103
std::vector<fml::closure> secondary_callbacks;

shell/common/vsync_waiter_fallback.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#define FML_USED_ON_EMBEDDER
6+
57
#include "flutter/shell/common/vsync_waiter_fallback.h"
68

9+
#include <memory>
10+
711
#include "flutter/fml/logging.h"
12+
#include "flutter/fml/message_loop.h"
813
#include "flutter/fml/trace_event.h"
914

1015
namespace flutter {
@@ -38,10 +43,16 @@ void VsyncWaiterFallback::AwaitVSync() {
3843
auto frame_start_time =
3944
SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
4045
auto frame_target_time = frame_start_time + kSingleFrameInterval;
41-
42-
task_runners_.GetPlatformTaskRunner()->PostTaskForTime(
43-
[frame_start_time, frame_target_time, this]() {
44-
FireCallback(frame_start_time, frame_target_time, !for_testing_);
46+
std::weak_ptr<VsyncWaiterFallback> weak_this =
47+
std::static_pointer_cast<VsyncWaiterFallback>(shared_from_this());
48+
49+
auto current_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
50+
current_task_runner->PostTaskForTime(
51+
[frame_start_time, frame_target_time, weak_this]() {
52+
if (auto vsync_waiter = weak_this.lock()) {
53+
vsync_waiter->FireCallback(frame_start_time, frame_target_time,
54+
!vsync_waiter->for_testing_);
55+
}
4556
},
4657
frame_start_time);
4758
}

0 commit comments

Comments
 (0)