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