blob: deb83483c215fabbc2156167ef4408adf9556663 [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
robertphillips@google.coma22e2112012-08-16 14:58:06 +000019SK_DEFINE_INST_COUNT(skiatest::Reporter)
20
reed@android.comed673312009-02-27 16:24:51 +000021using namespace skiatest;
22
23Reporter::Reporter() {
24 this->resetReporting();
25}
26
27void Reporter::resetReporting() {
28 fCurrTest = NULL;
29 fTestCount = 0;
reed@android.com4516f472009-06-29 16:25:36 +000030 sk_bzero(fResultCount, sizeof(fResultCount));
reed@android.comed673312009-02-27 16:24:51 +000031}
32
33void Reporter::startTest(Test* test) {
34 SkASSERT(NULL == fCurrTest);
35 fCurrTest = test;
36 this->onStart(test);
37 fTestCount += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000038 fCurrTestSuccess = true; // we're optimistic
reed@android.comed673312009-02-27 16:24:51 +000039}
40
41void Reporter::report(const char desc[], Result result) {
42 if (NULL == desc) {
43 desc = "<no description>";
44 }
45 this->onReport(desc, result);
46 fResultCount[result] += 1;
reed@android.comeeb3b7f2009-04-09 04:06:54 +000047 if (kFailed == result) {
48 fCurrTestSuccess = false;
49 }
reed@android.comed673312009-02-27 16:24:51 +000050}
51
52void Reporter::endTest(Test* test) {
53 SkASSERT(test == fCurrTest);
54 this->onEnd(test);
55 fCurrTest = NULL;
56}
57
58///////////////////////////////////////////////////////////////////////////////
59
60Test::Test() : fReporter(NULL) {}
61
62Test::~Test() {
reed@google.com82065d62011-02-07 15:30:46 +000063 SkSafeUnref(fReporter);
reed@android.comed673312009-02-27 16:24:51 +000064}
65
66void Test::setReporter(Reporter* r) {
67 SkRefCnt_SafeAssign(fReporter, r);
68}
69
70const char* Test::getName() {
71 if (fName.size() == 0) {
72 this->onGetName(&fName);
73 }
74 return fName.c_str();
75}
76
reed@android.comeeb3b7f2009-04-09 04:06:54 +000077bool Test::run() {
reed@android.comed673312009-02-27 16:24:51 +000078 fReporter->startTest(this);
79 this->onRun(fReporter);
80 fReporter->endTest(this);
reed@android.comeeb3b7f2009-04-09 04:06:54 +000081 return fReporter->getCurrSuccess();
reed@android.comed673312009-02-27 16:24:51 +000082}
83
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000084///////////////////////////////////////////////////////////////////////////////
85
86
87GrContext* GpuTest::GetContext() {
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000088#if SK_SUPPORT_GPU
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000089 // preserve this order, we want gGrContext destroyed after gEGLContext
bsalomon@google.com373a6632011-10-19 20:43:20 +000090 static SkTLazy<SkNativeGLContext> gGLContext;
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000091 static SkAutoTUnref<GrContext> gGrContext;
92
93 if (NULL == gGrContext.get()) {
bsalomon@google.come2953132011-10-13 13:33:08 +000094 gGLContext.init();
95 if (gGLContext.get()->init(800, 600)) {
bsalomon@google.com373a6632011-10-19 20:43:20 +000096 GrPlatform3DContext ctx = reinterpret_cast<GrPlatform3DContext>(gGLContext.get()->gl());
97 gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, ctx));
bsalomon@google.coma8e686e2011-08-16 15:45:58 +000098 }
99 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +0000100 if (gGLContext.get()) {
101 gGLContext.get()->makeCurrent();
102 }
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000103 return gGrContext.get();
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000104#else
105 return NULL;
106#endif
bsalomon@google.coma8e686e2011-08-16 15:45:58 +0000107}
108