skia2/tools/gpu/TestContext.cpp
Greg Daniel 02497d4016 Update nanobench and skpbench to use flush API for gpu syncing.
This also allows us to remove all the one off Fence code that we
implemented in all the backend TestContexts

Change-Id: I9ff7ba4690cf3f19a180f51fc510991a112bb62c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272456
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
2020-02-24 17:21:35 +00:00

69 lines
1.8 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "tools/gpu/TestContext.h"
#include "include/gpu/GrContext.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/GrContextPriv.h"
#include "tools/gpu/FlushFinishTracker.h"
#include "tools/gpu/GpuTimer.h"
namespace sk_gpu_test {
TestContext::TestContext() : fGpuTimer(nullptr) {}
TestContext::~TestContext() {
// Subclass should call teardown.
SkASSERT(!fGpuTimer);
}
sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) {
return nullptr;
}
void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); }
void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
SkScopeExit TestContext::makeCurrentAndAutoRestore() const {
auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
this->makeCurrent();
return asr;
}
void TestContext::flushAndWaitOnSync(GrContext* context) {
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
SkASSERT(context);
if (fFinishTrackers[fCurrentFlushIdx]) {
fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
}
fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context));
// We add an additional ref to the current flush tracker here. This ref is owned by the finish
// callback on the flush call. The finish callback will unref the tracker when called.
fFinishTrackers[fCurrentFlushIdx]->ref();
GrFlushInfo flushInfo;
flushInfo.fFinishedProc = FlushFinishTracker::FlushFinished;
flushInfo.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get();
context->flush(flushInfo);
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
}
void TestContext::testAbandon() {
}
void TestContext::teardown() {
fGpuTimer.reset();
}
}