Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: tools/gpu/TestContext.cpp

Issue 1964243003: Add base class for GLTestContext and add new subclass VkTestContext. (Closed) Base URL: https://chromium.googlesource.com/skia.git@ContextInfo
Patch Set: update Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/gpu/TestContext.cpp
diff --git a/tools/gpu/TestContext.cpp b/tools/gpu/TestContext.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..87d79acdd3c4efe420e1d33fb87c83e57f915036
--- /dev/null
+++ b/tools/gpu/TestContext.cpp
@@ -0,0 +1,65 @@
+
+/*
+ * Copyright 2013 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() : 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(nullptr == fFenceSync.get());
+}
+
+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;
+ }
+ }
+ fFenceSync.reset(nullptr);
+ }
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698