OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
11 #include "Test.h" | 11 #include "Test.h" |
12 // This is a GPU-backend specific test | 12 // This is a GPU-backend specific test |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 | 14 |
15 #if SK_ANGLE | 15 #include "GrContextFactory.h" |
16 #include "gl/SkANGLEGLContext.h" | |
17 #endif | |
18 #include "gl/SkNativeGLContext.h" | |
19 #if SK_MESA | |
20 #include "gl/SkMesaGLContext.h" | |
21 #endif | |
22 | 16 |
23 static void GLInterfaceValidationTest(skiatest::Reporter* reporter) { | 17 static void GLInterfaceValidationTest(skiatest::Reporter* reporter, GrContextFac
tory* factory) { |
24 typedef const GrGLInterface* (*interfaceFactory)(); | 18 for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) { |
25 struct { | 19 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type)i; |
26 interfaceFactory fFactory; | 20 // this forces the factory to make the context if it hasn't yet |
27 const char* fName; | 21 factory->get(glCtxType); |
28 } interfaceFactories[] = { | 22 SkGLContextHelper* glCtxHelper = factory->getGLContext(glCtxType); |
29 #if SK_ANGLE | 23 REPORTER_ASSERT(reporter, NULL != glCtxHelper); |
30 {GrGLCreateANGLEInterface, "ANGLE"}, | 24 if (NULL != glCtxHelper) { |
31 #endif | 25 const GrGLInterface* interface = glCtxHelper->gl(); |
32 {GrGLCreateNativeInterface, "Native"}, | |
33 #if SK_MESA | |
34 {GrGLCreateMesaInterface, "Mesa"}, | |
35 #endif | |
36 {GrGLCreateDebugInterface, "Debug"}, | |
37 {GrGLCreateNullInterface, "Null"}, | |
38 }; | |
39 | |
40 static const int kBogusSize = 16; | |
41 | |
42 #if SK_ANGLE | |
43 SkANGLEGLContext::AutoContextRestore angleACR; | |
44 SkANGLEGLContext angleContext; | |
45 bool angleContextInit = angleContext.init(kBogusSize, kBogusSize); | |
46 REPORTER_ASSERT(reporter, angleContextInit); | |
47 if (!angleContextInit) { | |
48 return; | |
49 } | |
50 #endif | |
51 | |
52 // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL | |
53 // context has been created. Also, preserve the current context that may | |
54 // be in use by outer test harness. | |
55 SkNativeGLContext::AutoContextRestore nglACR; | |
56 SkNativeGLContext nglctx; | |
57 bool nativeContextInit = nglctx.init(kBogusSize, kBogusSize); | |
58 REPORTER_ASSERT(reporter, nativeContextInit); | |
59 if (!nativeContextInit) { | |
60 return; | |
61 } | |
62 | |
63 #if SK_MESA | |
64 // We must have a current OSMesa context to initialize an OSMesa | |
65 // GrGLInterface | |
66 SkMesaGLContext::AutoContextRestore mglACR; | |
67 SkMesaGLContext mglctx; | |
68 bool mesaContextInit = mglctx.init(kBogusSize, kBogusSize); | |
69 REPORTER_ASSERT(reporter, mesaContextInit); | |
70 if(!mesaContextInit) { | |
71 return; | |
72 } | |
73 #endif | |
74 | |
75 SkAutoTUnref<const GrGLInterface> iface; | |
76 for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) { | |
77 iface.reset(interfaceFactories[i].fFactory()); | |
78 REPORTER_ASSERT(reporter, NULL != iface.get()); | |
79 if (iface.get()) { | |
80 for (GrGLBinding binding = kFirstGrGLBinding; | 26 for (GrGLBinding binding = kFirstGrGLBinding; |
81 binding <= kLastGrGLBinding; | 27 binding <= kLastGrGLBinding; |
82 binding = static_cast<GrGLBinding>(binding << 1)) { | 28 binding = static_cast<GrGLBinding>(binding << 1)) { |
83 if (iface.get()->fBindingsExported & binding) { | 29 if (interface->fBindingsExported & binding) { |
84 REPORTER_ASSERT(reporter, iface.get()->validate(binding)); | 30 REPORTER_ASSERT(reporter, interface->validate(binding)); |
85 } | 31 } |
86 } | 32 } |
87 } | 33 } |
88 } | 34 } |
89 } | 35 } |
90 | 36 |
91 | 37 |
92 #include "TestClassDef.h" | 38 #include "TestClassDef.h" |
93 DEFINE_TESTCLASS("GLInterfaceValidation", | 39 DEFINE_GPUTESTCLASS("GLInterfaceValidation", |
94 GLInterfaceValidationTestClass, | 40 GLInterfaceValidationTestClass, |
95 GLInterfaceValidationTest) | 41 GLInterfaceValidationTest) |
96 | 42 |
97 #endif | 43 #endif |
OLD | NEW |