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
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GpuTimer.h"
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContext.h"
|
2017-07-13 19:07:54 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
namespace sk_gpu_test {
|
2016-10-05 15:42:03 +00:00
|
|
|
TestContext::TestContext()
|
|
|
|
: fFenceSync(nullptr)
|
|
|
|
, fGpuTimer(nullptr)
|
|
|
|
, fCurrentFenceIdx(0) {
|
2016-05-11 17:09:18 +00:00
|
|
|
memset(fFrameFences, 0, sizeof(fFrameFences));
|
|
|
|
}
|
|
|
|
|
|
|
|
TestContext::~TestContext() {
|
|
|
|
// Subclass should call teardown.
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
|
|
|
|
SkASSERT(0 == fFrameFences[i]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
SkASSERT(!fFenceSync);
|
2016-10-05 15:42:03 +00:00
|
|
|
SkASSERT(!fGpuTimer);
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
void TestContext::swapBuffers() { this->onPlatformSwapBuffers(); }
|
|
|
|
|
2017-11-17 14:25:23 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
void TestContext::waitOnSyncOrSwap() {
|
|
|
|
if (!fFenceSync) {
|
|
|
|
// Fallback on the platform SwapBuffers method for synchronization. This may have no effect.
|
|
|
|
this->swapBuffers();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-11 18:55:36 +00:00
|
|
|
this->submit();
|
2016-05-11 17:09:18 +00:00
|
|
|
if (fFrameFences[fCurrentFenceIdx]) {
|
2016-05-16 21:09:56 +00:00
|
|
|
if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx])) {
|
2016-05-11 17:09:18 +00:00
|
|
|
SkDebugf("WARNING: Wait failed for fence sync. Timings might not be accurate.\n");
|
|
|
|
}
|
|
|
|
fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence();
|
|
|
|
fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestContext::testAbandon() {
|
|
|
|
if (fFenceSync) {
|
|
|
|
memset(fFrameFences, 0, sizeof(fFrameFences));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestContext::teardown() {
|
|
|
|
if (fFenceSync) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
|
|
|
|
if (fFrameFences[i]) {
|
|
|
|
fFenceSync->deleteFence(fFrameFences[i]);
|
|
|
|
fFrameFences[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
fFenceSync.reset();
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
fGpuTimer.reset();
|
2016-05-11 17:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|