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
|
|
|
|
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
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
GrContext* GpuTest::GetContext() {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-08-16 15:45:58 +00:00
|
|
|
// preserve this order, we want gGrContext destroyed after gEGLContext
|
2011-10-19 20:43:20 +00:00
|
|
|
static SkTLazy<SkNativeGLContext> gGLContext;
|
2011-08-16 15:45:58 +00:00
|
|
|
static SkAutoTUnref<GrContext> gGrContext;
|
|
|
|
|
|
|
|
if (NULL == gGrContext.get()) {
|
2011-10-13 13:33:08 +00:00
|
|
|
gGLContext.init();
|
|
|
|
if (gGLContext.get()->init(800, 600)) {
|
2011-10-19 20:43:20 +00:00
|
|
|
GrPlatform3DContext ctx = reinterpret_cast<GrPlatform3DContext>(gGLContext.get()->gl());
|
|
|
|
gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, 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
|
|
|
}
|
|
|
|
|