blob: 966383f2a6e46fa80d99d835e67fe49774cb913b [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
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000040 static const int kBogusSize = 16;
41
42#if SK_ANGLE
43 SkANGLEGLContext::AutoContextRestore angleACR;
44 SkANGLEGLContext angleContext;
45 bool angleContextInit = angleContext.init(kBogusSize, kBogusSize);
46 REPORTER_ASSERT(reporter, angleContextInit);
47 if (!angleContextInit) {
48 return;
49 }
50#endif
51
bsalomon@google.com57f5d982011-10-24 21:17:53 +000052 // On some platforms GrGLCreateNativeInterface will fail unless an OpenGL
53 // context has been created. Also, preserve the current context that may
54 // be in use by outer test harness.
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000055 SkNativeGLContext::AutoContextRestore nglACR;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000056 SkNativeGLContext nglctx;
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000057 bool nativeContextInit = nglctx.init(kBogusSize, kBogusSize);
bsalomon@google.com57f5d982011-10-24 21:17:53 +000058 REPORTER_ASSERT(reporter, nativeContextInit);
59 if (!nativeContextInit) {
60 return;
61 }
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000062
bsalomon@google.com57f5d982011-10-24 21:17:53 +000063#if SK_MESA
64 // We must have a current OSMesa context to initialize an OSMesa
65 // GrGLInterface
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000066 SkMesaGLContext::AutoContextRestore mglACR;
bsalomon@google.com57f5d982011-10-24 21:17:53 +000067 SkMesaGLContext mglctx;
bsalomon@google.coma1d27cd2013-03-08 19:01:01 +000068 bool mesaContextInit = mglctx.init(kBogusSize, kBogusSize);
bsalomon@google.com57f5d982011-10-24 21:17:53 +000069 REPORTER_ASSERT(reporter, mesaContextInit);
70 if(!mesaContextInit) {
71 return;
72 }
73#endif
74
75 SkAutoTUnref<const GrGLInterface> iface;
76 for (size_t i = 0; i < SK_ARRAY_COUNT(interfaceFactories); ++i) {
77 iface.reset(interfaceFactories[i].fFactory());
78 REPORTER_ASSERT(reporter, NULL != iface.get());
79 if (iface.get()) {
bsalomon@google.comb447d212012-02-10 20:25:36 +000080 for (GrGLBinding binding = kFirstGrGLBinding;
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000081 binding <= kLastGrGLBinding;
82 binding = static_cast<GrGLBinding>(binding << 1)) {
83 if (iface.get()->fBindingsExported & binding) {
84 REPORTER_ASSERT(reporter, iface.get()->validate(binding));
85 }
86 }
bsalomon@google.com57f5d982011-10-24 21:17:53 +000087 }
88 }
89}
90
91
92#include "TestClassDef.h"
93DEFINE_TESTCLASS("GLInterfaceValidation",
94 GLInterfaceValidationTestClass,
95 GLInterfaceValidationTest)
96
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +000097#endif