2020-02-21 20:46:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google LLC
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FlushFinishTracker_DEFINED
|
|
|
|
#define FlushFinishTracker_DEFINED
|
|
|
|
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2022-03-30 20:55:09 +00:00
|
|
|
#include "include/gpu/GpuTypes.h"
|
2020-02-21 20:46:27 +00:00
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
class GrDirectContext;
|
2020-02-21 20:46:27 +00:00
|
|
|
|
2022-03-28 19:27:44 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
2022-04-07 20:08:04 +00:00
|
|
|
namespace skgpu::graphite { class Context; }
|
2022-03-28 19:27:44 +00:00
|
|
|
#endif
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
|
|
|
class FlushFinishTracker : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
static void FlushFinished(void* finishedContext) {
|
|
|
|
auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
|
|
|
|
tracker->setFinished();
|
|
|
|
tracker->unref();
|
|
|
|
}
|
|
|
|
|
2022-03-30 20:55:09 +00:00
|
|
|
static void FlushFinishedResult(void* finishedContext, skgpu::CallbackResult) {
|
|
|
|
FlushFinished(finishedContext);
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
|
2022-03-28 19:27:44 +00:00
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
2022-04-07 20:08:04 +00:00
|
|
|
FlushFinishTracker(skgpu::graphite::Context* context) : fGraphiteContext(context) {}
|
2022-03-28 19:27:44 +00:00
|
|
|
#endif
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
void setFinished() { fIsFinished = true; }
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
void waitTillFinished();
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-28 19:27:44 +00:00
|
|
|
GrDirectContext* fContext = nullptr;
|
|
|
|
#ifdef SK_GRAPHITE_ENABLED
|
2022-04-07 20:08:04 +00:00
|
|
|
skgpu::graphite::Context* fGraphiteContext = nullptr;
|
2022-03-28 19:27:44 +00:00
|
|
|
#endif
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
// Currently we don't have the this bool be atomic cause all current uses of this class happen
|
|
|
|
// on a single thread. In other words we call flush, checkAsyncWorkCompletion, and
|
|
|
|
// waitTillFinished all on the same thread. If we ever want to support the flushing and waiting
|
|
|
|
// to happen on different threads then we should make this atomic.
|
|
|
|
bool fIsFinished = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
} //namespace sk_gpu_test
|
|
|
|
|
|
|
|
#endif
|