aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/gpu/TestContext.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-05-11 10:09:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-11 10:09:18 -0700
commit18a2f9dff839a3f60850c25e1a701b682a497afb (patch)
tree0113e4f746b09221f6ccce88beadb60432347682 /tools/gpu/TestContext.cpp
parent393c2ff0d2db9c5d84e6ed660ea9f546f438cb47 (diff)
Add base class for GLTestContext and add new subclass VkTestContext.
Diffstat (limited to 'tools/gpu/TestContext.cpp')
-rw-r--r--tools/gpu/TestContext.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/gpu/TestContext.cpp b/tools/gpu/TestContext.cpp
new file mode 100644
index 0000000000..09174cd984
--- /dev/null
+++ b/tools/gpu/TestContext.cpp
@@ -0,0 +1,67 @@
+
+/*
+ * 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 "TestContext.h"
+
+namespace sk_gpu_test {
+TestContext::TestContext() : fFenceSync(nullptr), fCurrentFenceIdx(0) {
+ 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);
+}
+
+void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
+
+void TestContext::swapBuffers() { this->onPlatformSwapBuffers(); }
+
+void TestContext::waitOnSyncOrSwap() {
+ if (!fFenceSync) {
+ // Fallback on the platform SwapBuffers method for synchronization. This may have no effect.
+ this->swapBuffers();
+ return;
+ }
+
+ if (fFrameFences[fCurrentFenceIdx]) {
+ if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx], true)) {
+ 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;
+ }
+ }
+ delete fFenceSync;
+ fFenceSync = nullptr;
+ }
+}
+
+}