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