blob: 2be13f026cd2b2f47758647b4e8900f564d11260 [file] [log] [blame]
bsalomon@google.com57f5d982011-10-24 21:17:53 +00001
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
13static 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.com74913722011-10-27 20:44:19 +000023 {GrGLCreateNullInterface, "Null"},
bsalomon@google.com57f5d982011-10-24 21:17:53 +000024 };
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.com1dcf5062011-11-14 19:29:53 +000054 REPORTER_ASSERT(reporter, iface.get()->validate());
bsalomon@google.com57f5d982011-10-24 21:17:53 +000055 }
56 }
57}
58
59
60#include "TestClassDef.h"
61DEFINE_TESTCLASS("GLInterfaceValidation",
62 GLInterfaceValidationTestClass,
63 GLInterfaceValidationTest)
64