Flutter Engine
The Flutter Engine
FlushFinishTracker.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef FlushFinishTracker_DEFINED
9#define FlushFinishTracker_DEFINED
10
13
14#include <functional>
15
16class GrDirectContext;
17
18#if defined(SK_GRAPHITE)
19namespace skgpu::graphite { class Context; }
20#endif
21
22namespace sk_gpu_test {
23
25public:
26 static void FlushFinished(void* finishedContext) {
27 auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
28 tracker->setFinished();
29 tracker->unref();
30 }
31
32 static void FlushFinishedResult(void* finishedContext, skgpu::CallbackResult) {
33 FlushFinished(finishedContext);
34 }
35
36 FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
37#if defined(SK_GRAPHITE)
38 FlushFinishTracker(skgpu::graphite::Context* context) : fGraphiteContext(context) {}
39#endif
40
41 void setFinished() { fIsFinished = true; }
42
43 void waitTillFinished(std::function<void()> tick = {});
44
45private:
46 GrDirectContext* fContext = nullptr;
47#if defined(SK_GRAPHITE)
48 skgpu::graphite::Context* fGraphiteContext = nullptr;
49#endif
50
51 // Currently we don't have the this bool be atomic cause all current uses of this class happen
52 // on a single thread. In other words we call flush, checkAsyncWorkCompletion, and
53 // waitTillFinished all on the same thread. If we ever want to support the flushing and waiting
54 // to happen on different threads then we should make this atomic.
55 bool fIsFinished = false;
56};
57
58} //namespace sk_gpu_test
59
60#endif
static void FlushFinishedResult(void *finishedContext, skgpu::CallbackResult)
FlushFinishTracker(GrDirectContext *context)
static void FlushFinished(void *finishedContext)
void waitTillFinished(std::function< void()> tick={})
Dart_NativeFunction function
Definition: fuchsia.cc:51
CallbackResult
Definition: GpuTypes.h:45