1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef FlushFinishTracker_DEFINED 9cb93a386Sopenharmony_ci#define FlushFinishTracker_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciclass GrDirectContext; 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_cinamespace sk_gpu_test { 16cb93a386Sopenharmony_ci 17cb93a386Sopenharmony_ciclass FlushFinishTracker : public SkRefCnt { 18cb93a386Sopenharmony_cipublic: 19cb93a386Sopenharmony_ci static void FlushFinished(void* finishedContext) { 20cb93a386Sopenharmony_ci auto tracker = static_cast<FlushFinishTracker*>(finishedContext); 21cb93a386Sopenharmony_ci tracker->setFinished(); 22cb93a386Sopenharmony_ci tracker->unref(); 23cb93a386Sopenharmony_ci } 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ci FlushFinishTracker(GrDirectContext* context) : fContext(context) {} 26cb93a386Sopenharmony_ci 27cb93a386Sopenharmony_ci void setFinished() { fIsFinished = true; } 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ci void waitTillFinished(); 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ciprivate: 32cb93a386Sopenharmony_ci GrDirectContext* fContext; 33cb93a386Sopenharmony_ci 34cb93a386Sopenharmony_ci // Currently we don't have the this bool be atomic cause all current uses of this class happen 35cb93a386Sopenharmony_ci // on a single thread. In other words we call flush, checkAsyncWorkCompletion, and 36cb93a386Sopenharmony_ci // waitTillFinished all on the same thread. If we ever want to support the flushing and waiting 37cb93a386Sopenharmony_ci // to happen on different threads then we should make this atomic. 38cb93a386Sopenharmony_ci bool fIsFinished = false; 39cb93a386Sopenharmony_ci}; 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci} //namespace sk_gpu_test 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci#endif 44