blob: 0441ab0fa7b4d7b41e3064714165e0829cd31299 [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.comcf8fb1f2012-08-02 14:03:32 +000010#include "SkTLazy.h"
11
12#if SK_SUPPORT_GPU
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000013#include "GrContext.h"
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000014#include "gl/SkNativeGLContext.h"
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000015#else
16class GrContext;
17#endif
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000018
reed@android.comed673312009-02-27 16:24:51 +000019using namespace skiatest;
20
21Reporter::Reporter() {
22 this->resetReporting();
23}
24
25void Reporter::resetReporting() {
26 fCurrTest = NULL;
27 fTestCount = 0;
reed@android.com4516f472009-06-29 16:25:36 +000028 sk_bzero(fResultCount, sizeof(fResultCount));
reed@android.comed673312009-02-27 16:24:51 +000029}
30
31void Reporter::startTest(Test* test) {
32 SkASSERT(NULL == fCurrTest);
33 fCurrTest = test;
34 this->onStart(test);
35 fTestCount += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000036 fCurrTestSuccess = true; // we're optimistic
reed@android.comed673312009-02-27 16:24:51 +000037}
38
39void Reporter::report(const char desc[], Result result) {
40 if (NULL == desc) {
41 desc = "<no description>";
42 }
43 this->onReport(desc, result);
44 fResultCount[result] += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000045 if (kFailed == result) {
46 fCurrTestSuccess = false;
47 }
reed@android.comed673312009-02-27 16:24:51 +000048}
49
50void Reporter::endTest(Test* test) {
51 SkASSERT(test == fCurrTest);
52 this->onEnd(test);
53 fCurrTest = NULL;
54}
55
56///////////////////////////////////////////////////////////////////////////////
57
58Test::Test() : fReporter(NULL) {}
59
60Test::~Test() {
reed@google.com82065d62011-02-07 15:30:46 +000061 SkSafeUnref(fReporter);
reed@android.comed673312009-02-27 16:24:51 +000062}
63
64void Test::setReporter(Reporter* r) {
65 SkRefCnt_SafeAssign(fReporter, r);
66}
67
68const char* Test::getName() {
69 if (fName.size() == 0) {
70 this->onGetName(&fName);
71 }
72 return fName.c_str();
73}
74
reed@android.comeeb3b7f2009-04-09 04:06:54 +000075bool Test::run() {
reed@android.comed673312009-02-27 16:24:51 +000076 fReporter->startTest(this);
77 this->onRun(fReporter);
78 fReporter->endTest(this);
reed@android.comeeb3b7f2009-04-09 04:06:54 +000079 return fReporter->getCurrSuccess();
reed@android.comed673312009-02-27 16:24:51 +000080}
81
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000082///////////////////////////////////////////////////////////////////////////////
83
84
85GrContext* GpuTest::GetContext() {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000086#if SK_SUPPORT_GPU
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000087 // preserve this order, we want gGrContext destroyed after gEGLContext
bsalomon@google.com373a6632011-10-19 20:43:20 +000088 static SkTLazy<SkNativeGLContext> gGLContext;
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000089 static SkAutoTUnref<GrContext> gGrContext;
90
91 if (NULL == gGrContext.get()) {
bsalomon@google.come2953132011-10-13 13:33:08 +000092 gGLContext.init();
93 if (gGLContext.get()->init(800, 600)) {
bsalomon@google.com373a6632011-10-19 20:43:20 +000094 GrPlatform3DContext ctx = reinterpret_cast<GrPlatform3DContext>(gGLContext.get()->gl());
95 gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, ctx));
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000096 }
97 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +000098 if (gGLContext.get()) {
99 gGLContext.get()->makeCurrent();
100 }
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000101 return gGrContext.get();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000102#else
103 return NULL;
104#endif
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000105}
106