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 
9 #include "gl/GrGLInterface.h"
10 #include "gl/GrGLAssembleInterface.h"
11 #include "gl/GrGLUtil.h"
12 
13 // Define this to get a prototype for glXGetProcAddress on some systems
14 #define GLX_GLXEXT_PROTOTYPES 1
15 #include <GL/glx.h>
16 
glx_get(void * ctx,const char name[])17 static GrGLFuncPtr glx_get(void* ctx, const char name[]) {
18     // Avoid calling glXGetProcAddress() for EGL procs.
19     // We don't expect it to ever succeed, but somtimes it returns non-null anyway.
20     if (0 == strncmp(name, "egl", 3)) {
21         return nullptr;
22     }
23 
24     SkASSERT(nullptr == ctx);
25     SkASSERT(glXGetCurrentContext());
26     return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name));
27 }
28 
GrGLMakeNativeInterface()29 sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
30     if (nullptr == glXGetCurrentContext()) {
31         return nullptr;
32     }
33 
34     return GrGLMakeAssembledInterface(nullptr, glx_get);
35 }
36 
GrGLCreateNativeInterface()37 const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
38