2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2009-02-27 16:24:51 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#include "SkTLazy.h"
|
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2011-08-16 15:45:58 +00:00
|
|
|
#include "GrContext.h"
|
2012-02-14 15:11:59 +00:00
|
|
|
#include "gl/SkNativeGLContext.h"
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
|
|
|
class GrContext;
|
|
|
|
#endif
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2012-08-16 14:58:06 +00:00
|
|
|
SK_DEFINE_INST_COUNT(skiatest::Reporter)
|
|
|
|
|
2009-02-27 16:24:51 +00:00
|
|
|
using namespace skiatest;
|
|
|
|
|
|
|
|
Reporter::Reporter() {
|
|
|
|
this->resetReporting();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::resetReporting() {
|
|
|
|
fCurrTest = NULL;
|
|
|
|
fTestCount = 0;
|
2009-06-29 16:25:36 +00:00
|
|
|
sk_bzero(fResultCount, sizeof(fResultCount));
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::startTest(Test* test) {
|
|
|
|
SkASSERT(NULL == fCurrTest);
|
|
|
|
fCurrTest = test;
|
|
|
|
this->onStart(test);
|
|
|
|
fTestCount += 1;
|
2009-04-09 04:06:54 +00:00
|
|
|
fCurrTestSuccess = true; // we're optimistic
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::report(const char desc[], Result result) {
|
|
|
|
if (NULL == desc) {
|
|
|
|
desc = "<no description>";
|
|
|
|
}
|
|
|
|
this->onReport(desc, result);
|
|
|
|
fResultCount[result] += 1;
|
2009-04-09 04:06:54 +00:00
|
|
|
if (kFailed == result) {
|
|
|
|
fCurrTestSuccess = false;
|
|
|
|
}
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Reporter::endTest(Test* test) {
|
|
|
|
SkASSERT(test == fCurrTest);
|
|
|
|
this->onEnd(test);
|
|
|
|
fCurrTest = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Test::Test() : fReporter(NULL) {}
|
|
|
|
|
|
|
|
Test::~Test() {
|
2011-02-07 15:30:46 +00:00
|
|
|
SkSafeUnref(fReporter);
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test::setReporter(Reporter* r) {
|
|
|
|
SkRefCnt_SafeAssign(fReporter, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Test::getName() {
|
|
|
|
if (fName.size() == 0) {
|
|
|
|
this->onGetName(&fName);
|
|
|
|
}
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2009-04-09 04:06:54 +00:00
|
|
|
bool Test::run() {
|
2009-02-27 16:24:51 +00:00
|
|
|
fReporter->startTest(this);
|
|
|
|
this->onRun(fReporter);
|
|
|
|
fReporter->endTest(this);
|
2009-04-09 04:06:54 +00:00
|
|
|
return fReporter->getCurrSuccess();
|
2009-02-27 16:24:51 +00:00
|
|
|
}
|
|
|
|
|
2011-08-16 15:45:58 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-29 15:28:45 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
static SkAutoTUnref<SkNativeGLContext> gGLContext;
|
|
|
|
static SkAutoTUnref<GrContext> gGrContext;
|
|
|
|
#endif
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2012-11-29 15:28:45 +00:00
|
|
|
void GpuTest::DestroyContext() {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-11-29 17:27:37 +00:00
|
|
|
// preserve this order, we want gGrContext destroyed before gGLContext
|
2012-11-29 15:28:45 +00:00
|
|
|
gGrContext.reset(NULL);
|
2012-11-29 17:27:37 +00:00
|
|
|
gGLContext.reset(NULL);
|
2012-11-29 15:28:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-08-16 15:45:58 +00:00
|
|
|
|
2012-11-29 15:28:45 +00:00
|
|
|
GrContext* GpuTest::GetContext() {
|
|
|
|
#if SK_SUPPORT_GPU
|
2011-08-16 15:45:58 +00:00
|
|
|
if (NULL == gGrContext.get()) {
|
2012-11-29 15:28:45 +00:00
|
|
|
gGLContext.reset(new SkNativeGLContext());
|
2011-10-13 13:33:08 +00:00
|
|
|
if (gGLContext.get()->init(800, 600)) {
|
2012-10-25 18:43:28 +00:00
|
|
|
GrBackendContext ctx = reinterpret_cast<GrBackendContext>(gGLContext.get()->gl());
|
|
|
|
gGrContext.reset(GrContext::Create(kOpenGL_GrBackend, ctx));
|
2011-08-16 15:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-24 21:17:53 +00:00
|
|
|
if (gGLContext.get()) {
|
|
|
|
gGLContext.get()->makeCurrent();
|
|
|
|
}
|
2011-08-16 15:45:58 +00:00
|
|
|
return gGrContext.get();
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2011-08-16 15:45:58 +00:00
|
|
|
}
|