1cb93a386Sopenharmony_ci
2cb93a386Sopenharmony_ci/*
3cb93a386Sopenharmony_ci * Copyright 2016 Google Inc.
4cb93a386Sopenharmony_ci *
5cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
6cb93a386Sopenharmony_ci * found in the LICENSE file.
7cb93a386Sopenharmony_ci */
8cb93a386Sopenharmony_ci
9cb93a386Sopenharmony_ci#include "tools/gpu/TestContext.h"
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/gpu/GrDirectContext.h"
12cb93a386Sopenharmony_ci#include "src/core/SkTraceEvent.h"
13cb93a386Sopenharmony_ci#include "tools/gpu/FlushFinishTracker.h"
14cb93a386Sopenharmony_ci#include "tools/gpu/GpuTimer.h"
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_cinamespace sk_gpu_test {
17cb93a386Sopenharmony_ciTestContext::TestContext() : fGpuTimer(nullptr) {}
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ciTestContext::~TestContext() {
20cb93a386Sopenharmony_ci    // Subclass should call teardown.
21cb93a386Sopenharmony_ci    SkASSERT(!fGpuTimer);
22cb93a386Sopenharmony_ci}
23cb93a386Sopenharmony_ci
24cb93a386Sopenharmony_cisk_sp<GrDirectContext> TestContext::makeContext(const GrContextOptions&) {
25cb93a386Sopenharmony_ci    return nullptr;
26cb93a386Sopenharmony_ci}
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_civoid TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); }
29cb93a386Sopenharmony_civoid TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); }
30cb93a386Sopenharmony_ci
31cb93a386Sopenharmony_ciSkScopeExit TestContext::makeCurrentAndAutoRestore() const {
32cb93a386Sopenharmony_ci    auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore());
33cb93a386Sopenharmony_ci    this->makeCurrent();
34cb93a386Sopenharmony_ci    return asr;
35cb93a386Sopenharmony_ci}
36cb93a386Sopenharmony_ci
37cb93a386Sopenharmony_civoid TestContext::flushAndWaitOnSync(GrDirectContext* context) {
38cb93a386Sopenharmony_ci    TRACE_EVENT0("skia.gpu", TRACE_FUNC);
39cb93a386Sopenharmony_ci    SkASSERT(context);
40cb93a386Sopenharmony_ci
41cb93a386Sopenharmony_ci    if (fFinishTrackers[fCurrentFlushIdx]) {
42cb93a386Sopenharmony_ci        fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
43cb93a386Sopenharmony_ci    }
44cb93a386Sopenharmony_ci
45cb93a386Sopenharmony_ci    fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context));
46cb93a386Sopenharmony_ci
47cb93a386Sopenharmony_ci    // We add an additional ref to the current flush tracker here. This ref is owned by the finish
48cb93a386Sopenharmony_ci    // callback on the flush call. The finish callback will unref the tracker when called.
49cb93a386Sopenharmony_ci    fFinishTrackers[fCurrentFlushIdx]->ref();
50cb93a386Sopenharmony_ci
51cb93a386Sopenharmony_ci    GrFlushInfo flushInfo;
52cb93a386Sopenharmony_ci    flushInfo.fFinishedProc = FlushFinishTracker::FlushFinished;
53cb93a386Sopenharmony_ci    flushInfo.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get();
54cb93a386Sopenharmony_ci
55cb93a386Sopenharmony_ci    context->flush(flushInfo);
56cb93a386Sopenharmony_ci    context->submit();
57cb93a386Sopenharmony_ci
58cb93a386Sopenharmony_ci    fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
59cb93a386Sopenharmony_ci}
60cb93a386Sopenharmony_ci
61cb93a386Sopenharmony_civoid TestContext::testAbandon() {
62cb93a386Sopenharmony_ci}
63cb93a386Sopenharmony_ci
64cb93a386Sopenharmony_civoid TestContext::teardown() {
65cb93a386Sopenharmony_ci    fGpuTimer.reset();
66cb93a386Sopenharmony_ci}
67cb93a386Sopenharmony_ci
68cb93a386Sopenharmony_ci}  // namespace sk_gpu_test
69