blob: 22478cc6b691b8f8a8fac8b9ec714524dcacf688 [file] [log] [blame]
Greg Daniel02497d42020-02-21 15:46:27 -05001/*
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"
Greg Daniel02497d42020-02-21 15:46:27 -050012
Robert Phillips00f78de2020-07-01 16:09:43 -040013class GrDirectContext;
Greg Daniel02497d42020-02-21 15:46:27 -050014
15namespace sk_gpu_test {
16
17class FlushFinishTracker : public SkRefCnt {
18public:
19 static void FlushFinished(void* finishedContext) {
20 auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
21 tracker->setFinished();
22 tracker->unref();
23 }
24
Robert Phillips00f78de2020-07-01 16:09:43 -040025 FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
Greg Daniel02497d42020-02-21 15:46:27 -050026
27 void setFinished() { fIsFinished = true; }
28
Robert Phillips00f78de2020-07-01 16:09:43 -040029 void waitTillFinished();
Greg Daniel02497d42020-02-21 15:46:27 -050030
31private:
Robert Phillips00f78de2020-07-01 16:09:43 -040032 GrDirectContext* fContext;
Greg Daniel02497d42020-02-21 15:46:27 -050033
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