bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +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 | */ |
| 8 | |
| 9 | #include "Test.h" |
| 10 | #include "SkNativeGLContext.h" |
| 11 | #include "SkMesaGLContext.h" |
| 12 | |
| 13 | static void GLInterfaceValidationTest(skiatest::Reporter* reporter) { |
| 14 | typedef const GrGLInterface* (*interfaceFactory)(); |
| 15 | struct { |
| 16 | interfaceFactory fFactory; |
| 17 | const char* fName; |
| 18 | } interfaceFactories[] = { |
| 19 | {GrGLCreateNativeInterface, "Native"}, |
| 20 | #if SK_MESA |
| 21 | {GrGLCreateMesaInterface, "Mesa"}, |
| 22 | #endif |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 23 | {GrGLCreateNullInterface, "Null"}, |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL |
| 27 | // context has been created. Also, preserve the current context that may |
| 28 | // be in use by outer test harness. |
| 29 | SkNativeGLContext::AutoContextRestore nglacr; |
| 30 | SkNativeGLContext nglctx; |
| 31 | static const int gBOGUS_SIZE = 16; |
| 32 | bool nativeContextInit = nglctx.init(gBOGUS_SIZE, gBOGUS_SIZE); |
| 33 | REPORTER_ASSERT(reporter, nativeContextInit); |
| 34 | if (!nativeContextInit) { |
| 35 | return; |
| 36 | } |
| 37 | #if SK_MESA |
| 38 | // We must have a current OSMesa context to initialize an OSMesa |
| 39 | // GrGLInterface |
| 40 | SkMesaGLContext::AutoContextRestore mglacr; |
| 41 | SkMesaGLContext mglctx; |
| 42 | bool mesaContextInit = mglctx.init(gBOGUS_SIZE, gBOGUS_SIZE); |
| 43 | REPORTER_ASSERT(reporter, mesaContextInit); |
| 44 | if(!mesaContextInit) { |
| 45 | return; |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | SkAutoTUnref<const GrGLInterface> iface; |
| 50 | for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) { |
| 51 | iface.reset(interfaceFactories[i].fFactory()); |
| 52 | REPORTER_ASSERT(reporter, NULL != iface.get()); |
| 53 | if (iface.get()) { |
bsalomon@google.com | 1dcf506 | 2011-11-14 19:29:53 +0000 | [diff] [blame] | 54 | REPORTER_ASSERT(reporter, iface.get()->validate()); |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | |
| 60 | #include "TestClassDef.h" |
| 61 | DEFINE_TESTCLASS("GLInterfaceValidation", |
| 62 | GLInterfaceValidationTestClass, |
| 63 | GLInterfaceValidationTest) |
| 64 | |