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 GrFinishCallbacks_DEFINED 9 #define GrFinishCallbacks_DEFINED 10 11 #include "include/gpu/GrTypes.h" 12 #include "include/private/GrTypesPriv.h" 13 14 #include <list> 15 16 class GrGpu; 17 18 /** 19 * Maintains a list of callbacks to be called when work on the GPU is complete. 20 */ 21 22 class GrFinishCallbacks { 23 public: 24 GrFinishCallbacks(GrGpu* gpu); 25 ~GrFinishCallbacks(); 26 27 /** 28 * Call all the callbacks in the list. This will block until all work is done. 29 * 30 * @param doDelete delete the contained fence object. 31 */ 32 void callAll(bool doDelete); 33 34 /** 35 * Add a new callback to the list. 36 * 37 * @param finishedProc The function to call when GPU work is complete. 38 * @param finishedContext The context object to pass back to the callback. 39 */ 40 void add(GrGpuFinishedProc finishedProc, GrGpuFinishedContext finishedContext); 41 42 /** 43 * Check if any GPU work is complete, and call the associated callbacks. 44 * This call is non-blocking. 45 */ 46 void check(); 47 48 /** 49 * Returns true if the callback list is empty. 50 */ empty()51 bool empty() const { return fCallbacks.empty(); } 52 53 private: 54 struct FinishCallback { 55 GrGpuFinishedProc fCallback; 56 GrGpuFinishedContext fContext; 57 GrFence fFence; 58 }; 59 60 GrGpu* fGpu; 61 std::list<FinishCallback> fCallbacks; 62 }; 63 64 #endif 65