| 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 | |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 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 | |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 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. |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 55 | SkNativeGLContext::AutoContextRestore nglACR; |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 56 | SkNativeGLContext nglctx; |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 57 | bool nativeContextInit = nglctx.init(kBogusSize, kBogusSize); |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 58 | REPORTER_ASSERT(reporter, nativeContextInit); |
| 59 | if (!nativeContextInit) { |
| 60 | return; |
| 61 | } |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 62 | |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 63 | #if SK_MESA |
| 64 | // We must have a current OSMesa context to initialize an OSMesa |
| 65 | // GrGLInterface |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 66 | SkMesaGLContext::AutoContextRestore mglACR; |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 67 | SkMesaGLContext mglctx; |
| bsalomon@google.com | a1d27cd | 2013-03-08 19:01:01 +0000 | [diff] [blame] | 68 | bool mesaContextInit = mglctx.init(kBogusSize, kBogusSize); |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 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()) { |
| bsalomon@google.com | b447d21 | 2012-02-10 20:25:36 +0000 | [diff] [blame] | 80 | for (GrGLBinding binding = kFirstGrGLBinding; |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 81 | binding <= kLastGrGLBinding; |
| 82 | binding = static_cast<GrGLBinding>(binding << 1)) { |
| 83 | if (iface.get()->fBindingsExported & binding) { |
| 84 | REPORTER_ASSERT(reporter, iface.get()->validate(binding)); |
| 85 | } |
| 86 | } |
| bsalomon@google.com | 57f5d98 | 2011-10-24 21:17:53 +0000 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | |
| 92 | #include "TestClassDef.h" |
| 93 | DEFINE_TESTCLASS("GLInterfaceValidation", |
| 94 | GLInterfaceValidationTestClass, |
| 95 | GLInterfaceValidationTest) |
| 96 | |
| bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 97 | #endif |