blob: 9ca2cc27ba7bd79adbbf70926b0c6ae983a9cefe [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"
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000010#if SK_ANGLE
11#include "gl/SkANGLEGLContext.h"
12#endif
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000013#include "gl/SkNativeGLContext.h"
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000014#if SK_MESA
tomhudson@google.com6bf38b52012-02-14 15:11:59 +000015#include "gl/SkMesaGLContext.h"
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000016#endif
bsalomon@google.com57f5d982011-10-24 21:17:53 +000017
18static void GLInterfaceValidationTest(skiatest::Reporter* reporter) {
19 typedef const GrGLInterface* (*interfaceFactory)();
20 struct {
21 interfaceFactory fFactory;
22 const char* fName;
23 } interfaceFactories[] = {
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000024#if SK_ANGLE
25 {GrGLCreateANGLEInterface, "ANGLE"},
26#endif
bsalomon@google.com57f5d982011-10-24 21:17:53 +000027 {GrGLCreateNativeInterface, "Native"},
28#if SK_MESA
29 {GrGLCreateMesaInterface, "Mesa"},
30#endif
robertphillips@google.comd3b9fbb2012-03-28 16:19:11 +000031 {GrGLCreateDebugInterface, "Debug"},
bsalomon@google.com74913722011-10-27 20:44:19 +000032 {GrGLCreateNullInterface, "Null"},
bsalomon@google.com57f5d982011-10-24 21:17:53 +000033 };
34
35 // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL
36 // context has been created. Also, preserve the current context that may
37 // be in use by outer test harness.
38 SkNativeGLContext::AutoContextRestore nglacr;
39 SkNativeGLContext nglctx;
40 static const int gBOGUS_SIZE = 16;
41 bool nativeContextInit = nglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
42 REPORTER_ASSERT(reporter, nativeContextInit);
43 if (!nativeContextInit) {
44 return;
45 }
46#if SK_MESA
47 // We must have a current OSMesa context to initialize an OSMesa
48 // GrGLInterface
49 SkMesaGLContext::AutoContextRestore mglacr;
50 SkMesaGLContext mglctx;
51 bool mesaContextInit = mglctx.init(gBOGUS_SIZE, gBOGUS_SIZE);
52 REPORTER_ASSERT(reporter, mesaContextInit);
53 if(!mesaContextInit) {
54 return;
55 }
56#endif
57
58 SkAutoTUnref<const GrGLInterface> iface;
59 for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) {
60 iface.reset(interfaceFactories[i].fFactory());
61 REPORTER_ASSERT(reporter, NULL != iface.get());
62 if (iface.get()) {
bsalomon@google.comb447d212012-02-10 20:25:36 +000063 for (GrGLBinding binding = kFirstGrGLBinding;
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000064 binding <= kLastGrGLBinding;
65 binding = static_cast<GrGLBinding>(binding << 1)) {
66 if (iface.get()->fBindingsExported & binding) {
67 REPORTER_ASSERT(reporter, iface.get()->validate(binding));
68 }
69 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +000070 }
71 }
72}
73
74
75#include "TestClassDef.h"
76DEFINE_TESTCLASS("GLInterfaceValidation",
77 GLInterfaceValidationTestClass,
78 GLInterfaceValidationTest)
79