| 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 |
|
| 9 |
#include "tools/ganesh/TestContext.h" |
| 10 |
|
| 11 |
#include "include/gpu/ganesh/GrDirectContext.h" |
| 12 |
#include "src/core/SkTraceEvent.h" |
| 13 |
#include "tools/ganesh/GpuTimer.h" |
| 14 |
#include "tools/gpu/FlushFinishTracker.h" |
| 15 |
|
| 16 |
namespace sk_gpu_test { |
| 17 |
TestContext::TestContext() : fGpuTimer(nullptr) {} |
| 18 |
|
| 19 |
TestContext::~TestContext() { |
| 20 |
// Subclass should call teardown. |
| 21 |
SkASSERT(!fGpuTimer); |
| 22 |
} |
| 23 |
|
| 24 |
sk_sp<GrDirectContext> TestContext::makeContext(const GrContextOptions&) { |
| 25 |
return nullptr; |
| 26 |
} |
| 27 |
|
| 28 |
void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); } |
| 29 |
void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); } |
| 30 |
|
| 31 |
SkScopeExit TestContext::makeCurrentAndAutoRestore() const { |
| 32 |
auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore()); |
| 33 |
this->makeCurrent(); |
| 34 |
return asr; |
| 35 |
} |
| 36 |
|
| 37 |
void TestContext::flushAndWaitOnSync(GrDirectContext* context) { |
| 38 |
TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 39 |
SkASSERT(context); |
| 40 |
|
| 41 |
if (fFinishTrackers[fCurrentFlushIdx]) { |
| 42 |
fFinishTrackers[fCurrentFlushIdx]->waitTillFinished(); |
| 43 |
} |
| 44 |
|
| 45 |
fFinishTrackers[fCurrentFlushIdx].reset(new FlushFinishTracker(context)); |
| 46 |
|
| 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); |
| 56 |
context->submit(); |
| 57 |
|
| 58 |
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers); |
| 59 |
} |
| 60 |
|
| 61 |
void TestContext::flushAndSyncCpu(GrDirectContext* context) { |
| 62 |
SkASSERT(context); |
| 63 |
context->flush(); |
| 64 |
context->submit(GrSyncCpu::kYes); |
| 65 |
} |
| 66 |
|
| 67 |
void TestContext::testAbandon() { |
| 68 |
} |
| 69 |
|
| 70 |
void TestContext::teardown() { |
| 71 |
fGpuTimer.reset(); |
| 72 |
} |
| 73 |
|
| 74 |
} // namespace sk_gpu_test |