1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "include/gpu/gl/GrGLAssembleInterface.h"
9 #include "include/gpu/gl/GrGLInterface.h"
10 #include "src/gpu/gl/GrGLUtil.h"
11 
12 // Define this to get a prototype for glXGetProcAddress on some systems
13 #define GLX_GLXEXT_PROTOTYPES 1
14 #include <GL/glx.h>
15 
glx_get(void* ctx, const char name[])16 static GrGLFuncPtr glx_get(void* ctx, const char name[]) {
17     // Avoid calling glXGetProcAddress() for EGL procs.
18     // We don't expect it to ever succeed, but somtimes it returns non-null anyway.
19     if (0 == strncmp(name, "egl", 3)) {
20         return nullptr;
21     }
22 
23     SkASSERT(nullptr == ctx);
24     SkASSERT(glXGetCurrentContext());
25     return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name));
26 }
27 
GrGLMakeGLXInterface()28 sk_sp<const GrGLInterface> GrGLMakeGLXInterface() {
29     if (nullptr == glXGetCurrentContext()) {
30         return nullptr;
31     }
32 
33     return GrGLMakeAssembledInterface(nullptr, glx_get);
34 }
35