blob: 2557c4c71c26af8e899e232dafe81459a81bd13d [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.comb447d212012-02-10 20:25:36 +000054 for (GrGLBinding binding = kFirstGrGLBinding;
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000055 binding <= kLastGrGLBinding;
56 binding = static_cast<GrGLBinding>(binding << 1)) {
57 if (iface.get()->fBindingsExported & binding) {
58 REPORTER_ASSERT(reporter, iface.get()->validate(binding));
59 }
60 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +000061 }
62 }
63}
64
65
66#include "TestClassDef.h"
67DEFINE_TESTCLASS("GLInterfaceValidation",
68 GLInterfaceValidationTestClass,
69 GLInterfaceValidationTest)
70