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 
13 class GrDirectContext;
14 
15 namespace sk_gpu_test {
16 
17 class FlushFinishTracker : public SkRefCnt {
18 public:
FlushFinished(void * finishedContext)19     static void FlushFinished(void* finishedContext) {
20         auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
21         tracker->setFinished();
22         tracker->unref();
23     }
24 
FlushFinishTracker(GrDirectContext * context)25     FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
26 
setFinished()27     void setFinished() { fIsFinished = true; }
28 
29     void waitTillFinished();
30 
31 private:
32     GrDirectContext* fContext;
33 
34     // Currently we don't have the this bool be atomic cause all current uses of this class happen
35     // on a single thread. In other words we call flush, checkAsyncWorkCompletion, and
36     // waitTillFinished all on the same thread. If we ever want to support the flushing and waiting
37     // to happen on different threads then we should make this atomic.
38     bool fIsFinished = false;
39 };
40 
41 } //namespace sk_gpu_test
42 
43 #endif
44