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/gpu/TestContext.h" 10 11#include "include/gpu/GrDirectContext.h" 12#include "src/core/SkTraceEvent.h" 13#include "tools/gpu/FlushFinishTracker.h" 14#include "tools/gpu/GpuTimer.h" 15 16namespace sk_gpu_test { 17TestContext::TestContext() : fGpuTimer(nullptr) {} 18 19TestContext::~TestContext() { 20 // Subclass should call teardown. 21 SkASSERT(!fGpuTimer); 22} 23 24sk_sp<GrDirectContext> TestContext::makeContext(const GrContextOptions&) { 25 return nullptr; 26} 27 28void TestContext::makeNotCurrent() const { this->onPlatformMakeNotCurrent(); } 29void TestContext::makeCurrent() const { this->onPlatformMakeCurrent(); } 30 31SkScopeExit TestContext::makeCurrentAndAutoRestore() const { 32 auto asr = SkScopeExit(this->onPlatformGetAutoContextRestore()); 33 this->makeCurrent(); 34 return asr; 35} 36 37void 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) % SK_ARRAY_COUNT(fFinishTrackers); 59} 60 61void TestContext::testAbandon() { 62} 63 64void TestContext::teardown() { 65 fGpuTimer.reset(); 66} 67 68} // namespace sk_gpu_test 69