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