• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
8 #include "Test.h"
9 
10 #include "GrContext.h"
11 #include "gl/SkNativeGLContext.h"
12 #include "SkTLazy.h"
13 
14 using namespace skiatest;
15 
Reporter()16 Reporter::Reporter() {
17     this->resetReporting();
18 }
19 
resetReporting()20 void Reporter::resetReporting() {
21     fCurrTest = NULL;
22     fTestCount = 0;
23     sk_bzero(fResultCount, sizeof(fResultCount));
24 }
25 
startTest(Test * test)26 void Reporter::startTest(Test* test) {
27     SkASSERT(NULL == fCurrTest);
28     fCurrTest = test;
29     this->onStart(test);
30     fTestCount += 1;
31     fCurrTestSuccess = true;    // we're optimistic
32 }
33 
report(const char desc[],Result result)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;
40     if (kFailed == result) {
41         fCurrTestSuccess = false;
42     }
43 }
44 
endTest(Test * test)45 void Reporter::endTest(Test* test) {
46     SkASSERT(test == fCurrTest);
47     this->onEnd(test);
48     fCurrTest = NULL;
49 }
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 
Test()53 Test::Test() : fReporter(NULL) {}
54 
~Test()55 Test::~Test() {
56     SkSafeUnref(fReporter);
57 }
58 
setReporter(Reporter * r)59 void Test::setReporter(Reporter* r) {
60     SkRefCnt_SafeAssign(fReporter, r);
61 }
62 
getName()63 const char* Test::getName() {
64     if (fName.size() == 0) {
65         this->onGetName(&fName);
66     }
67     return fName.c_str();
68 }
69 
run()70 bool Test::run() {
71     fReporter->startTest(this);
72     this->onRun(fReporter);
73     fReporter->endTest(this);
74     return fReporter->getCurrSuccess();
75 }
76 
77 ///////////////////////////////////////////////////////////////////////////////
78 
79 
GetContext()80 GrContext* GpuTest::GetContext() {
81     // preserve this order, we want gGrContext destroyed after gEGLContext
82     static SkTLazy<SkNativeGLContext> gGLContext;
83     static SkAutoTUnref<GrContext> gGrContext;
84 
85     if (NULL == gGrContext.get()) {
86         gGLContext.init();
87         if (gGLContext.get()->init(800, 600)) {
88             GrPlatform3DContext ctx = reinterpret_cast<GrPlatform3DContext>(gGLContext.get()->gl());
89             gGrContext.reset(GrContext::Create(kOpenGL_Shaders_GrEngine, ctx));
90         }
91     }
92     if (gGLContext.get()) {
93         gGLContext.get()->makeCurrent();
94     }
95     return gGrContext.get();
96 }
97 
98