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" |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 10 | #if SK_ANGLE |
| 11 | #include "gl/SkANGLEGLContext.h" |
| 12 | #endif |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 13 | #include "gl/SkNativeGLContext.h" |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 14 | #if SK_MESA |
tomhudson@google.com | 6bf38b5 | 2012-02-14 15:11:59 +0000 | [diff] [blame] | 15 | #include "gl/SkMesaGLContext.h" |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 16 | #endif |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 17 | |
| 18 | static void GLInterfaceValidationTest(skiatest::Reporter* reporter) { |
| 19 | typedef const GrGLInterface* (*interfaceFactory)(); |
| 20 | struct { |
| 21 | interfaceFactory fFactory; |
| 22 | const char* fName; |
| 23 | } interfaceFactories[] = { |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 24 | #if SK_ANGLE |
| 25 | {GrGLCreateANGLEInterface, "ANGLE"}, |
| 26 | #endif |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 27 | {GrGLCreateNativeInterface, "Native"}, |
| 28 | #if SK_MESA |
| 29 | {GrGLCreateMesaInterface, "Mesa"}, |
| 30 | #endif |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 31 | {GrGLCreateDebugInterface, "Debug"}, |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 32 | {GrGLCreateNullInterface, "Null"}, |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL |
| 36 | // context has been created. Also, preserve the current context that may |
| 37 | // be in use by outer test harness. |
| 38 | SkNativeGLContext::AutoContextRestore nglacr; |
| 39 | SkNativeGLContext nglctx; |
| 40 | static const int gBOGUS_SIZE = 16; |
| 41 | bool nativeContextInit = nglctx.init(gBOGUS_SIZE, gBOGUS_SIZE); |
| 42 | REPORTER_ASSERT(reporter, nativeContextInit); |
| 43 | if (!nativeContextInit) { |
| 44 | return; |
| 45 | } |
| 46 | #if SK_MESA |
| 47 | // We must have a current OSMesa context to initialize an OSMesa |
| 48 | // GrGLInterface |
| 49 | SkMesaGLContext::AutoContextRestore mglacr; |
| 50 | SkMesaGLContext mglctx; |
| 51 | bool mesaContextInit = mglctx.init(gBOGUS_SIZE, gBOGUS_SIZE); |
| 52 | REPORTER_ASSERT(reporter, mesaContextInit); |
| 53 | if(!mesaContextInit) { |
| 54 | return; |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | SkAutoTUnref<const GrGLInterface> iface; |
| 59 | for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) { |
| 60 | iface.reset(interfaceFactories[i].fFactory()); |
| 61 | REPORTER_ASSERT(reporter, NULL != iface.get()); |
| 62 | if (iface.get()) { |
bsalomon@google.com | b447d21 | 2012-02-10 20:25:36 +0000 | [diff] [blame] | 63 | for (GrGLBinding binding = kFirstGrGLBinding; |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 64 | binding <= kLastGrGLBinding; |
| 65 | binding = static_cast<GrGLBinding>(binding << 1)) { |
| 66 | if (iface.get()->fBindingsExported & binding) { |
| 67 | REPORTER_ASSERT(reporter, iface.get()->validate(binding)); |
| 68 | } |
| 69 | } |
bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | #include "TestClassDef.h" |
| 76 | DEFINE_TESTCLASS("GLInterfaceValidation", |
| 77 | GLInterfaceValidationTestClass, |
| 78 | GLInterfaceValidationTest) |
| 79 | |