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