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