blob: 9b9e5dcbb9dbd63e1ee48e4bbb8fab41445beec9 [file] [log] [blame]
bsalomon18a2f9d2016-05-11 10:09:18 -07001
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 Kleinc0bd9f92019-04-23 12:05:21 -05009#include "tools/gpu/TestContext.h"
bsalomon18a2f9d2016-05-11 10:09:18 -070010
Greg Daniel02497d42020-02-21 15:46:27 -050011#include "include/gpu/GrContext.h"
12#include "src/core/SkTraceEvent.h"
13#include "src/gpu/GrContextPriv.h"
14#include "tools/gpu/FlushFinishTracker.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "tools/gpu/GpuTimer.h"
csmartdaltonc6618dd2016-10-05 08:42:03 -070016
bsalomon18a2f9d2016-05-11 10:09:18 -070017namespace sk_gpu_test {
Greg Daniel02497d42020-02-21 15:46:27 -050018TestContext::TestContext() : fGpuTimer(nullptr) {}
bsalomon18a2f9d2016-05-11 10:09:18 -070019
20TestContext::~TestContext() {
21 // Subclass should call teardown.
csmartdaltonc6618dd2016-10-05 08:42:03 -070022 SkASSERT(!fGpuTimer);
bsalomon18a2f9d2016-05-11 10:09:18 -070023}
24
Greg Danielb76a72a2017-07-13 15:07:54 -040025sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) {
26 return nullptr;
27}
28
Robert Phillipsedf3f382020-02-13 12:59:19 -050029void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); }
bsalomon18a2f9d2016-05-11 10:09:18 -070030void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
31
Brian Salomon55ad7742017-11-17 09:25:23 -050032SkScopeExit TestContext::makeCurrentAndAutoRestore() const {
33 auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
34 this->makeCurrent();
35 return asr;
36}
37
Greg Daniel02497d42020-02-21 15:46:27 -050038void TestContext::flushAndWaitOnSync(GrContext* context) {
39 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
40 SkASSERT(context);
bsalomon18a2f9d2016-05-11 10:09:18 -070041
Greg Daniel02497d42020-02-21 15:46:27 -050042 if (fFinishTrackers[fCurrentFlushIdx]) {
43 fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
bsalomon18a2f9d2016-05-11 10:09:18 -070044 }
45
Greg Daniel02497d42020-02-21 15:46:27 -050046 fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context));
bsalomon18a2f9d2016-05-11 10:09:18 -070047
Greg Daniel02497d42020-02-21 15:46:27 -050048 // 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 Daniel0a2464f2020-05-14 15:45:44 -040057 context->submit();
Greg Daniel02497d42020-02-21 15:46:27 -050058
59 fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
bsalomon18a2f9d2016-05-11 10:09:18 -070060}
61
62void TestContext::testAbandon() {
bsalomon18a2f9d2016-05-11 10:09:18 -070063}
64
65void TestContext::teardown() {
csmartdaltonc6618dd2016-10-05 08:42:03 -070066 fGpuTimer.reset();
bsalomon18a2f9d2016-05-11 10:09:18 -070067}
68
69}