bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "tools/gpu/TestContext.h" |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 10 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 11 | #include "include/gpu/GrContext.h" |
| 12 | #include "src/core/SkTraceEvent.h" |
| 13 | #include "src/gpu/GrContextPriv.h" |
| 14 | #include "tools/gpu/FlushFinishTracker.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "tools/gpu/GpuTimer.h" |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 16 | |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 17 | namespace sk_gpu_test { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 18 | TestContext::TestContext() : fGpuTimer(nullptr) {} |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 19 | |
| 20 | TestContext::~TestContext() { |
| 21 | // Subclass should call teardown. |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 22 | SkASSERT(!fGpuTimer); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Greg Daniel | b76a72a | 2017-07-13 15:07:54 -0400 | [diff] [blame] | 25 | sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) { |
| 26 | return nullptr; |
| 27 | } |
| 28 | |
Robert Phillips | edf3f38 | 2020-02-13 12:59:19 -0500 | [diff] [blame] | 29 | void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); } |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 30 | void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); } |
| 31 | |
Brian Salomon | 55ad774 | 2017-11-17 09:25:23 -0500 | [diff] [blame] | 32 | SkScopeExit TestContext::makeCurrentAndAutoRestore() const { |
| 33 | auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore()); |
| 34 | this->makeCurrent(); |
| 35 | return asr; |
| 36 | } |
| 37 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 38 | void TestContext::flushAndWaitOnSync(GrContext* context) { |
| 39 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 40 | SkASSERT(context); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 41 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 42 | if (fFinishTrackers[fCurrentFlushIdx]) { |
| 43 | fFinishTrackers[fCurrentFlushIdx]->waitTillFinished(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 46 | fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context)); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 47 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 48 | // We add an additional ref to the current flush tracker here. This ref is owned by the finish |
| 49 | // callback on the flush call. The finish callback will unref the tracker when called. |
| 50 | fFinishTrackers[fCurrentFlushIdx]->ref(); |
| 51 | |
| 52 | GrFlushInfo flushInfo; |
| 53 | flushInfo.fFinishedProc = FlushFinishTracker::FlushFinished; |
| 54 | flushInfo.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get(); |
| 55 | |
| 56 | context->flush(flushInfo); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 57 | context->submit(); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 58 | |
| 59 | fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | void TestContext::testAbandon() { |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void TestContext::teardown() { |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 66 | fGpuTimer.reset(); |
bsalomon | 18a2f9d | 2016-05-11 10:09:18 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } |