mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Now that tonic doesn't depend on anything in //sky/engine anymore, we can move the code to a location where its dependencies are clearer.
45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/tonic/dart_microtask_queue.h"
|
|
|
|
#include "base/trace_event/trace_event.h"
|
|
#include "flutter/tonic/dart_invoke.h"
|
|
#include "flutter/tonic/dart_state.h"
|
|
|
|
namespace blink {
|
|
namespace {
|
|
|
|
typedef std::vector<DartPersistentValue> MicrotaskQueue;
|
|
|
|
static MicrotaskQueue& GetQueue() {
|
|
static MicrotaskQueue* queue = new MicrotaskQueue();
|
|
return *queue;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void DartMicrotaskQueue::ScheduleMicrotask(Dart_Handle callback) {
|
|
GetQueue().emplace_back(DartState::Current(), callback);
|
|
}
|
|
|
|
void DartMicrotaskQueue::RunMicrotasks() {
|
|
MicrotaskQueue& queue = GetQueue();
|
|
while(!queue.empty()) {
|
|
TRACE_EVENT0("flutter", "DartMicrotaskQueue::RunMicrotasks");
|
|
|
|
MicrotaskQueue local;
|
|
std::swap(queue, local);
|
|
for (const auto& callback : local) {
|
|
base::WeakPtr<DartState> dart_state = callback.dart_state();
|
|
if (!dart_state.get())
|
|
continue;
|
|
DartState::Scope dart_scope(dart_state.get());
|
|
DartInvokeVoid(callback.value());
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|