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