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