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