blob: 62df73130f5a52a5ee4b4a10e03e4111ca979745 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 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 */
reed@android.comed673312009-02-27 16:24:51 +00008#include "Test.h"
9
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000010#include "GrContext.h"
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000011#include "gl/SkNativeGLContext.h"
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000012#include "SkTLazy.h"
13
reed@android.comed673312009-02-27 16:24:51 +000014using namespace skiatest;
15
16Reporter::Reporter() {
17 this->resetReporting();
18}
19
20void Reporter::resetReporting() {
21 fCurrTest = NULL;
22 fTestCount = 0;
reed@android.com4516f472009-06-29 16:25:36 +000023 sk_bzero(fResultCount, sizeof(fResultCount));
reed@android.comed673312009-02-27 16:24:51 +000024}
25
26void Reporter::startTest(Test* test) {
27 SkASSERT(NULL == fCurrTest);
28 fCurrTest = test;
29 this->onStart(test);
30 fTestCount += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000031 fCurrTestSuccess = true; // we're optimistic
reed@android.comed673312009-02-27 16:24:51 +000032}
33
34void Reporter::report(const char desc[], Result result) {
35 if (NULL == desc) {
36 desc = "<no description>";
37 }
38 this->onReport(desc, result);
39 fResultCount[result] += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000040 if (kFailed == result) {
41 fCurrTestSuccess = false;
42 }
reed@android.comed673312009-02-27 16:24:51 +000043}
44
45void Reporter::endTest(Test* test) {
46 SkASSERT(test == fCurrTest);
47 this->onEnd(test);
48 fCurrTest = NULL;
49}
50
51///////////////////////////////////////////////////////////////////////////////
52
53Test::Test() : fReporter(NULL) {}
54
55Test::~Test() {
reed@google.com82065d62011-02-07 15:30:46 +000056 SkSafeUnref(fReporter);
reed@android.comed673312009-02-27 16:24:51 +000057}
58
59void Test::setReporter(Reporter* r) {
60 SkRefCnt_SafeAssign(fReporter, r);
61}
62
63const char* Test::getName() {
64 if (fName.size() == 0) {
65 this->onGetName(&fName);
66 }
67 return fName.c_str();
68}
69
reed@android.comeeb3b7f2009-04-09 04:06:54 +000070bool Test::run() {
reed@android.comed673312009-02-27 16:24:51 +000071 fReporter->startTest(this);
72 this->onRun(fReporter);
73 fReporter->endTest(this);
reed@android.comeeb3b7f2009-04-09 04:06:54 +000074 return fReporter->getCurrSuccess();
reed@android.comed673312009-02-27 16:24:51 +000075}
76
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000077///////////////////////////////////////////////////////////////////////////////
78
79
80GrContext* GpuTest::GetContext() {
81 // preserve this order, we want gGrContext destroyed after gEGLContext
bsalomon@google.com373a6632011-10-19 20:43:20 +000082 static SkTLazy<SkNativeGLContext> gGLContext;
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000083 static SkAutoTUnref<GrContext> gGrContext;
84
85 if (NULL == gGrContext.get()) {
bsalomon@google.come2953132011-10-13 13:33:08 +000086 gGLContext.init();
87 if (gGLContext.get()->init(800, 600)) {
bsalomon@google.com373a6632011-10-19 20:43:20 +000088 GrPlatform3DContext ctx = reinterpret_cast<GrPlatform3DContext>(gGLContext.get()->gl());
89 gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, ctx));
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000090 }
91 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +000092 if (gGLContext.get()) {
93 gGLContext.get()->makeCurrent();
94 }
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000095 return gGrContext.get();
96}
97