epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| 9 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 10 | #include "SkTLazy.h" |
| 11 | |
| 12 | #if SK_SUPPORT_GPU |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 13 | #include "GrContext.h" |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 14 | #include "gl/SkNativeGLContext.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 15 | #else |
| 16 | class GrContext; |
| 17 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 18 | |
robertphillips@google.com | a22e211 | 2012-08-16 14:58:06 +0000 | [diff] [blame] | 19 | SK_DEFINE_INST_COUNT(skiatest::Reporter) |
| 20 | |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 21 | using namespace skiatest; |
| 22 | |
| 23 | Reporter::Reporter() { |
| 24 | this->resetReporting(); |
| 25 | } |
| 26 | |
| 27 | void Reporter::resetReporting() { |
| 28 | fCurrTest = NULL; |
| 29 | fTestCount = 0; |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 30 | sk_bzero(fResultCount, sizeof(fResultCount)); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | void Reporter::startTest(Test* test) { |
| 34 | SkASSERT(NULL == fCurrTest); |
| 35 | fCurrTest = test; |
| 36 | this->onStart(test); |
| 37 | fTestCount += 1; |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 38 | fCurrTestSuccess = true; // we're optimistic |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void 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.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 47 | if (kFailed == result) { |
| 48 | fCurrTestSuccess = false; |
| 49 | } |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void Reporter::endTest(Test* test) { |
| 53 | SkASSERT(test == fCurrTest); |
| 54 | this->onEnd(test); |
| 55 | fCurrTest = NULL; |
| 56 | } |
| 57 | |
| 58 | /////////////////////////////////////////////////////////////////////////////// |
| 59 | |
| 60 | Test::Test() : fReporter(NULL) {} |
| 61 | |
| 62 | Test::~Test() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 63 | SkSafeUnref(fReporter); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void Test::setReporter(Reporter* r) { |
| 67 | SkRefCnt_SafeAssign(fReporter, r); |
| 68 | } |
| 69 | |
| 70 | const char* Test::getName() { |
| 71 | if (fName.size() == 0) { |
| 72 | this->onGetName(&fName); |
| 73 | } |
| 74 | return fName.c_str(); |
| 75 | } |
| 76 | |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 77 | bool Test::run() { |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 78 | fReporter->startTest(this); |
| 79 | this->onRun(fReporter); |
| 80 | fReporter->endTest(this); |
reed@android.com | eeb3b7f | 2009-04-09 04:06:54 +0000 | [diff] [blame] | 81 | return fReporter->getCurrSuccess(); |
reed@android.com | ed67331 | 2009-02-27 16:24:51 +0000 | [diff] [blame] | 82 | } |
| 83 | |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 84 | /////////////////////////////////////////////////////////////////////////////// |
| 85 | |
| 86 | |
| 87 | GrContext* GpuTest::GetContext() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 88 | #if SK_SUPPORT_GPU |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 89 | // preserve this order, we want gGrContext destroyed after gEGLContext |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 90 | static SkTLazy<SkNativeGLContext> gGLContext; |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 91 | static SkAutoTUnref<GrContext> gGrContext; |
| 92 | |
| 93 | if (NULL == gGrContext.get()) { |
bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 94 | gGLContext.init(); |
| 95 | if (gGLContext.get()->init(800, 600)) { |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 96 | GrBackendContext ctx = reinterpret_cast<GrBackendContext>(gGLContext.get()->gl()); |
| 97 | gGrContext.reset(GrContext::Create(kOpenGL_GrBackend, ctx)); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 100 | if (gGLContext.get()) { |
| 101 | gGLContext.get()->makeCurrent(); |
| 102 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 103 | return gGrContext.get(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 104 | #else |
| 105 | return NULL; |
| 106 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 107 | } |
| 108 | |