Home | History | Annotate | Download | only in tests
      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 
     10 
     11 #include "Test.h"
     12 // This is a GPU-backend specific test
     13 #if SK_SUPPORT_GPU
     14 
     15 #if SK_ANGLE
     16 #include "gl/SkANGLEGLContext.h"
     17 #endif
     18 #include "gl/SkNativeGLContext.h"
     19 #if SK_MESA
     20 #include "gl/SkMesaGLContext.h"
     21 #endif
     22 
     23 static void GLInterfaceValidationTest(skiatest::Reporter* reporter) {
     24     typedef const GrGLInterface* (*interfaceFactory)();
     25     struct {
     26        interfaceFactory fFactory;
     27        const char* fName;
     28     } interfaceFactories[] = {
     29 #if SK_ANGLE
     30         {GrGLCreateANGLEInterface, "ANGLE"},
     31 #endif
     32         {GrGLCreateNativeInterface, "Native"},
     33 #if SK_MESA
     34         {GrGLCreateMesaInterface, "Mesa"},
     35 #endif
     36         {GrGLCreateDebugInterface, "Debug"},
     37         {GrGLCreateNullInterface, "Null"},
     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()) {
     68             for (GrGLBinding binding = kFirstGrGLBinding;
     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             }
     75         }
     76     }
     77 }
     78 
     79 
     80 #include "TestClassDef.h"
     81 DEFINE_TESTCLASS("GLInterfaceValidation",
     82                  GLInterfaceValidationTestClass,
     83                  GLInterfaceValidationTest)
     84 
     85 #endif
     86