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