Debian Codegraph @

tools/gpu/FlushFinishTracker.h

raw
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
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/GpuTypes.h"
13
14 #include <functional>
15
16 #if defined(SK_GANESH)
17 class GrDirectContext;
18 #endif
19
20 #if defined(SK_GRAPHITE)
21 namespace skgpu::graphite { class Context; }
22 #endif
23
24 namespace sk_gpu_test {
25
26 class FlushFinishTracker : public SkRefCnt {
27 public:
28 static void FlushFinished(void* finishedContext) {
29 auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
30 tracker->setFinished();
31 tracker->unref();
32 }
33
34 static void FlushFinishedResult(void* finishedContext, skgpu::CallbackResult) {
35 FlushFinished(finishedContext);
36 }
37
38 #if defined(SK_GANESH)
39 explicit FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
40 #endif
41 #if defined(SK_GRAPHITE)
42 explicit FlushFinishTracker(skgpu::graphite::Context* context) : fGraphiteContext(context) {}
43 #endif
44
45 void setFinished() { fIsFinished = true; }
46
47 void waitTillFinished(std::function<void()> tick = {});
48
49 private:
50 #if defined(SK_GANESH)
51 GrDirectContext* fContext = nullptr;
52 #endif
53 #if defined(SK_GRAPHITE)
54 skgpu::graphite::Context* fGraphiteContext = nullptr;
55 #endif
56
57 // Currently we don't have the this bool be atomic cause all current uses of this class happen
58 // on a single thread. In other words we call flush, checkAsyncWorkCompletion, and
59 // waitTillFinished all on the same thread. If we ever want to support the flushing and waiting
60 // to happen on different threads then we should make this atomic.
61 bool fIsFinished = false;
62 };
63
64 } //namespace sk_gpu_test
65
66 #endif