|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
| 5 | +#define FML_USED_ON_EMBEDDER |
| 6 | + |
5 | 7 | #include "flutter/shell/common/vsync_waiter_fallback.h" |
6 | 8 |
|
| 9 | +#include <memory> |
| 10 | + |
7 | 11 | #include "flutter/fml/logging.h" |
| 12 | +#include "flutter/fml/message_loop.h" |
8 | 13 | #include "flutter/fml/trace_event.h" |
9 | 14 |
|
10 | 15 | namespace flutter { |
@@ -38,10 +43,16 @@ void VsyncWaiterFallback::AwaitVSync() { |
38 | 43 | auto frame_start_time = |
39 | 44 | SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval); |
40 | 45 | 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 | + } |
45 | 56 | }, |
46 | 57 | frame_start_time); |
47 | 58 | } |
|
0 commit comments