Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 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" |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 12 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 13 | class GrDirectContext; |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 14 | |
| 15 | namespace sk_gpu_test { |
| 16 | |
| 17 | class FlushFinishTracker : public SkRefCnt { |
| 18 | public: |
| 19 | static void FlushFinished(void* finishedContext) { |
| 20 | auto tracker = static_cast<FlushFinishTracker*>(finishedContext); |
| 21 | tracker->setFinished(); |
| 22 | tracker->unref(); |
| 23 | } |
| 24 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 25 | FlushFinishTracker(GrDirectContext* context) : fContext(context) {} |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 26 | |
| 27 | void setFinished() { fIsFinished = true; } |
| 28 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 29 | void waitTillFinished(); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 30 | |
| 31 | private: |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 32 | GrDirectContext* fContext; |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 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 |