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