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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2013 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include "TestContext.h"
9
10 namespace sk_gpu_test {
11 TestContext::TestContext() : fCurrentFenceIdx(0) {
12 memset(fFrameFences, 0, sizeof(fFrameFences));
13 }
14
15 TestContext::~TestContext() {
16 // Subclass should call teardown.
17 #ifdef SK_DEBUG
18 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
19 SkASSERT(0 == fFrameFences[i]);
20 }
21 #endif
22 SkASSERT(nullptr == fFenceSync.get());
23 }
24
25 void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
26
27 void TestContext::swapBuffers() { this->onPlatformSwapBuffers(); }
28
29 void TestContext::waitOnSyncOrSwap() {
30 if (!fFenceSync) {
31 // Fallback on the platform SwapBuffers method for synchronization. This may have no effect.
32 this->swapBuffers();
33 return;
34 }
35
36 if (fFrameFences[fCurrentFenceIdx]) {
37 if (!fFenceSync->waitFence(fFrameFences[fCurrentFenceIdx], true)) {
38 SkDebugf("WARNING: Wait failed for fence sync. Timings might not be accurate.\n");
39 }
40 fFenceSync->deleteFence(fFrameFences[fCurrentFenceIdx]);
41 }
42
43 fFrameFences[fCurrentFenceIdx] = fFenceSync->insertFence();
44 fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences);
45 }
46
47 void TestContext::testAbandon() {
48 if (fFenceSync) {
49 memset(fFrameFences, 0, sizeof(fFrameFences));
50 }
51 }
52
53 void TestContext::teardown() {
54 if (fFenceSync) {
55 for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
56 if (fFrameFences[i]) {
57 fFenceSync->deleteFence(fFrameFences[i]);
58 fFrameFences[i] = 0;
59 }
60 }
61 fFenceSync.reset(nullptr);
62 }
63 }
64
65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698