blob: 860b771ba72e6b1c91593bef05808e8187fcec70 [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
Robert Phillips00f78de2020-07-01 16:09:43 -040011#include "include/gpu/GrDirectContext.h"
Greg Daniel02497d42020-02-21 15:46:27 -050012#include "src/core/SkTraceEvent.h"
Greg Daniel02497d42020-02-21 15:46:27 -050013#include "tools/gpu/FlushFinishTracker.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "tools/gpu/GpuTimer.h"
csmartdaltonc6618dd2016-10-05 08:42:03 -070015
bsalomon18a2f9d2016-05-11 10:09:18 -070016namespace sk_gpu_test {
Greg Daniel02497d42020-02-21 15:46:27 -050017TestContext::TestContext() : fGpuTimer(nullptr) {}
bsalomon18a2f9d2016-05-11 10:09:18 -070018
19TestContext::~TestContext() {
20 // Subclass should call teardown.
csmartdaltonc6618dd2016-10-05 08:42:03 -070021 SkASSERT(!fGpuTimer);
bsalomon18a2f9d2016-05-11 10:09:18 -070022}
23
Greg Danielb76a72a2017-07-13 15:07:54 -040024sk_sp<GrContext> TestContext::makeGrContext(const GrContextOptions&) {
25 return nullptr;
26}
27
Robert Phillipsedf3f382020-02-13 12:59:19 -050028void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); }
bsalomon18a2f9d2016-05-11 10:09:18 -070029void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
30
Brian Salomon55ad7742017-11-17 09:25:23 -050031SkScopeExit TestContext::makeCurrentAndAutoRestore() const {
32 auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
33 this->makeCurrent();
34 return asr;
35}
36
Robert Phillips00f78de2020-07-01 16:09:43 -040037void TestContext::flushAndWaitOnSync(GrDirectContext* context) {
Greg Daniel02497d42020-02-21 15:46:27 -050038 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
39 SkASSERT(context);
bsalomon18a2f9d2016-05-11 10:09:18 -070040
Greg Daniel02497d42020-02-21 15:46:27 -050041 if (fFinishTrackers[fCurrentFlushIdx]) {
42 fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
bsalomon18a2f9d2016-05-11 10:09:18 -070043 }
44
Greg Daniel02497d42020-02-21 15:46:27 -050045 fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context));
bsalomon18a2f9d2016-05-11 10:09:18 -070046
Greg Daniel02497d42020-02-21 15:46:27 -050047 // 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 Daniel0a2464f2020-05-14 15:45:44 -040056 context->submit();
Greg Daniel02497d42020-02-21 15:46:27 -050057
58 fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
bsalomon18a2f9d2016-05-11 10:09:18 -070059}
60
61void TestContext::testAbandon() {
bsalomon18a2f9d2016-05-11 10:09:18 -070062}
63
64void TestContext::teardown() {
csmartdaltonc6618dd2016-10-05 08:42:03 -070065 fGpuTimer.reset();
bsalomon18a2f9d2016-05-11 10:09:18 -070066}
67
68}