2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/TestContext.h"
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-02-21 20:46:27 +00:00
|
|
|
#include "src/core/SkTraceEvent.h"
|
|
|
|
#include "tools/gpu/FlushFinishTracker.h"
|
|
|
|
#include "tools/gpu/GpuTimer.h"
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
namespace sk_gpu_test {
|
2020-02-21 20:46:27 +00:00
|
|
|
TestContext::TestContext() : fGpuTimer(nullptr) {}
|
2016-05-11 17:09:18 +00:00
|
|
|
|
|
|
|
TestContext::~TestContext() {
|
|
|
|
// Subclass should call teardown.
|
2016-10-05 15:42:03 +00:00
|
|
|
SkASSERT(!fGpuTimer);
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> TestContext::makeContext(const GrContextOptions&) {
|
2017-07-13 19:07:54 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-13 17:59:19 +00:00
|
|
|
void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); }
|
2016-05-11 17:09:18 +00:00
|
|
|
void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
|
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
SkScopeExit TestContext::makeCurrentAndAutoRestore() const {
|
|
|
|
auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
|
|
|
|
this->makeCurrent();
|
|
|
|
return asr;
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
void TestContext::flushAndWaitOnSync(GrDirectContext* context) {
|
2020-02-21 20:46:27 +00:00
|
|
|
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
|
|
|
SkASSERT(context);
|
2017-11-17 14:25:23 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
if (fFinishTrackers[fCurrentFlushIdx]) {
|
|
|
|
fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
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();
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
context->flush(flushInfo);
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit();
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestContext::testAbandon() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestContext::teardown() {
|
2016-10-05 15:42:03 +00:00
|
|
|
fGpuTimer.reset();
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|