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 | |
djsollen@google.com | 0945bde | 2012-11-29 15:28:45 +0000 | [diff] [blame] | 86 | #if SK_SUPPORT_GPU |
| 87 | static SkAutoTUnref<SkNativeGLContext> gGLContext; |
| 88 | static SkAutoTUnref<GrContext> gGrContext; |
| 89 | #endif |
| 90 | |
| 91 | void GpuTest::DestroyContext() { |
| 92 | #if SK_SUPPORT_GPU |
bsalomon@google.com | 83a853a | 2012-11-29 17:27:37 +0000 | [diff] [blame] | 93 | // preserve this order, we want gGrContext destroyed before gGLContext |
djsollen@google.com | 0945bde | 2012-11-29 15:28:45 +0000 | [diff] [blame] | 94 | gGrContext.reset(NULL); |
bsalomon@google.com | 83a853a | 2012-11-29 17:27:37 +0000 | [diff] [blame] | 95 | gGLContext.reset(NULL); |
djsollen@google.com | 0945bde | 2012-11-29 15:28:45 +0000 | [diff] [blame] | 96 | #endif |
| 97 | } |
| 98 | |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 99 | |
| 100 | GrContext* GpuTest::GetContext() { |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 101 | #if SK_SUPPORT_GPU |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 102 | if (NULL == gGrContext.get()) { |
djsollen@google.com | 0945bde | 2012-11-29 15:28:45 +0000 | [diff] [blame] | 103 | gGLContext.reset(new SkNativeGLContext()); |
bsalomon@google.com | e295313 | 2011-10-13 13:33:08 +0000 | [diff] [blame] | 104 | if (gGLContext.get()->init(800, 600)) { |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 105 | GrBackendContext ctx = reinterpret_cast<GrBackendContext>(gGLContext.get()->gl()); |
| 106 | gGrContext.reset(GrContext::Create(kOpenGL_GrBackend, ctx)); |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 107 | } |
| 108 | } |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 109 | if (gGLContext.get()) { |
| 110 | gGLContext.get()->makeCurrent(); |
| 111 | } |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 112 | return gGrContext.get(); |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 113 | #else |
| 114 | return NULL; |
| 115 | #endif |
bsalomon@google.com | a8e686e | 2011-08-16 15:45:58 +0000 | [diff] [blame] | 116 | } |
| 117 | |