blob: 758f303c0c3c44257a337c10b2eca7a943ed017b [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
23 };
24
25 // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL
26 // context has been created. Also, preserve the current context that may
27 // be in use by outer test harness.
28 SkNativeGLContext::AutoContextRestore nglacr;
29 SkNativeGLContext nglctx;
30 static const int gBOGUS_SIZE = 16;
31 bool nativeContextInit = nglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
32 REPORTER_ASSERT(reporter, nativeContextInit);
33 if (!nativeContextInit) {
34 return;
35 }
36#if SK_MESA
37 // We must have a current OSMesa context to initialize an OSMesa
38 // GrGLInterface
39 SkMesaGLContext::AutoContextRestore mglacr;
40 SkMesaGLContext mglctx;
41 bool mesaContextInit = mglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
42 REPORTER_ASSERT(reporter, mesaContextInit);
43 if(!mesaContextInit) {
44 return;
45 }
46#endif
47
48 SkAutoTUnref<const GrGLInterface> iface;
49 for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) {
50 iface.reset(interfaceFactories[i].fFactory());
51 REPORTER_ASSERT(reporter, NULL != iface.get());
52 if (iface.get()) {
53 REPORTER_ASSERT(reporter, iface.get()->validate(kOpenGL_Shaders_GrEngine));
54 }
55 }
56}
57
58
59#include "TestClassDef.h"
60DEFINE_TESTCLASS("GLInterfaceValidation",
61 GLInterfaceValidationTestClass,
62 GLInterfaceValidationTest)
63