Merge pull request #1001 from jamesr/remove_glx

Remove GLX code from //ui/gl, simplify build a bit
This commit is contained in:
James Robinson 2015-09-02 10:32:31 -07:00
commit 3418bb480e
18 changed files with 47 additions and 7821 deletions

View File

@ -8,15 +8,7 @@ if (is_android) {
import("//build/config/android/rules.gni")
}
config("gl_config") {
if (use_x11) {
defines = [ "GL_GLEXT_PROTOTYPES" ]
}
}
component("gl") {
output_name = "gl_wrapper" # Avoid colliding with OS X"s libGL.dylib.
source_set("gl") {
sources = [
"android/gl_jni_registrar.cc",
"android/gl_jni_registrar.h",
@ -26,12 +18,8 @@ component("gl") {
"android/surface_texture.h",
"android/surface_texture_listener.cc",
"android/surface_texture_listener.h",
"egl_util.cc",
"egl_util.h",
"gl_bindings.cc",
"gl_bindings.h",
"gl_bindings_autogen_egl.cc",
"gl_bindings_autogen_egl.h",
"gl_bindings_autogen_gl.cc",
"gl_bindings_autogen_gl.h",
"gl_bindings_autogen_osmesa.cc",
@ -41,8 +29,6 @@ component("gl") {
"gl_context.cc",
"gl_context.h",
"gl_context_android.cc",
"gl_context_egl.cc",
"gl_context_egl.h",
"gl_context_mac.mm",
"gl_context_osmesa.cc",
"gl_context_osmesa.h",
@ -71,8 +57,6 @@ component("gl") {
"gl_surface.cc",
"gl_surface.h",
"gl_surface_android.cc",
"gl_surface_egl.cc",
"gl_surface_egl.h",
"gl_surface_mac.mm",
"gl_surface_osmesa.cc",
"gl_surface_osmesa.h",
@ -95,14 +79,10 @@ component("gl") {
"sync_control_vsync_provider.h",
]
defines = [ "GL_IMPLEMENTATION" ]
include_dirs = [
"//third_party/switfshader/include",
"//third_party/mesa/src/include",
]
all_dependent_configs = [ ":gl_config" ]
deps = [
"//base/third_party/dynamic_annotations",
"//skia",
@ -121,25 +101,14 @@ component("gl") {
"gl_implementation_osmesa.h",
]
configs += [
"//third_party/khronos:khronos_headers",
]
configs += [ "//third_party/khronos:khronos_headers" ]
}
if (is_linux) {
deps += [ "//third_party/libevent" ]
}
if (use_x11) {
sources += [
"gl_bindings_autogen_glx.cc",
"gl_bindings_autogen_glx.h",
"gl_context_osmesa_x11.cc",
"gl_egl_api_implementation.cc",
"gl_egl_api_implementation.h",
"gl_glx_api_implementation.cc",
"gl_glx_api_implementation.h",
"gl_implementation_x11.cc",
"gl_surface_glx.cc",
"gl_surface_glx.h",
"gl_surface_osmesa_x11.cc",
"gl_surface_osmesa_x11.h",
]
@ -154,11 +123,19 @@ component("gl") {
}
if (is_android) {
sources += [
"egl_util.cc",
"egl_util.h",
"gl_bindings_autogen_egl.cc",
"gl_bindings_autogen_egl.h",
"gl_context_egl.cc",
"gl_context_egl.h",
"gl_egl_api_implementation.cc",
"gl_egl_api_implementation.h",
"gl_surface_egl.cc",
"gl_surface_egl.h",
]
defines += [
defines = [
"GL_GLEXT_PROTOTYPES",
"EGL_EGLEXT_PROTOTYPES",
]
@ -222,24 +199,6 @@ component("gl") {
}
}
source_set("gl_unittest_utils") {
testonly = true
sources = [
"gl_bindings_autogen_mock.cc",
"gl_bindings_autogen_mock.h",
"gl_mock.cc",
"gl_mock.h",
"gl_mock_autogen_gl.h",
]
configs += [ "//third_party/khronos:khronos_headers" ]
deps = [
":gl",
"//testing/gmock",
]
}
if (is_android) {
generate_jar_jni("surface_jni_headers") {
jni_package = "ui/gl"

View File

@ -22,7 +22,7 @@ std::string DriverOSMESA::GetPlatformExtensions() {
return "";
}
#if defined(USE_X11) || defined(OS_ANDROID) || defined(USE_OZONE)
#if defined(OS_ANDROID)
std::string DriverEGL::GetPlatformExtensions() {
EGLDisplay display =
g_driver_egl.fn.eglGetDisplayFn(GetPlatformDefaultEGLNativeDisplay());
@ -35,13 +35,4 @@ std::string DriverEGL::GetPlatformExtensions() {
}
#endif
#if defined(USE_X11)
std::string DriverGLX::GetPlatformExtensions() {
DCHECK(g_driver_glx.fn.glXQueryExtensionsStringFn);
const char* str =
g_driver_glx.fn.glXQueryExtensionsStringFn(gfx::GetXDisplay(), 0);
return str ? std::string(str) : "";
}
#endif
} // namespace gfx

View File

@ -8,9 +8,7 @@
#include <string>
// Includes the platform independent and platform dependent GL headers.
// Only include this in cc files. It pulls in system headers, including
// the X11 headers on linux, which define all kinds of macros that are
// liable to cause conflicts.
// Only include this in cc files.
#include <GL/gl.h>
#include <GL/glext.h>
@ -27,19 +25,6 @@
#include "build/build_config.h"
#include "ui/gl/gl_export.h"
// The standard OpenGL native extension headers are also included.
#if defined(USE_X11)
#include <GL/glx.h>
#include <GL/glxext.h>
// Undefine some macros defined by X headers. This is why this file should only
// be included in .cc files.
#undef Bool
#undef None
#undef Status
#endif
// GLES2 defines not part of Desktop GL
// Shader Precision-Specified Types
#define GL_LOW_FLOAT 0x8DF0
@ -314,7 +299,6 @@ typedef void (*GLDEBUGPROCKHR)(GLenum source, GLenum type, GLuint id,
#if defined(USE_X11)
#include "gl_bindings_autogen_egl.h"
#include "gl_bindings_autogen_glx.h"
#elif defined(USE_OZONE)
#include "gl_bindings_autogen_egl.h"
#elif defined(OS_ANDROID)
@ -371,21 +355,6 @@ struct GL_EXPORT DriverEGL {
};
#endif
#if defined(USE_X11)
struct GL_EXPORT DriverGLX {
void InitializeStaticBindings();
void InitializeDebugBindings();
void ClearBindings();
ProcsGLX fn;
ProcsGLX debug_fn;
ExtensionsGLX ext;
private:
static std::string GetPlatformExtensions();
};
#endif
// This #define is here to support autogenerated code.
#define g_current_gl_context g_current_gl_context_tls->Get()
GL_EXPORT extern base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls;
@ -394,19 +363,7 @@ GL_EXPORT extern OSMESAApi* g_current_osmesa_context;
GL_EXPORT extern DriverGL g_driver_gl;
GL_EXPORT extern DriverOSMESA g_driver_osmesa;
#if defined(USE_X11)
GL_EXPORT extern EGLApi* g_current_egl_context;
GL_EXPORT extern GLXApi* g_current_glx_context;
GL_EXPORT extern DriverEGL g_driver_egl;
GL_EXPORT extern DriverGLX g_driver_glx;
#elif defined(USE_OZONE)
GL_EXPORT extern EGLApi* g_current_egl_context;
GL_EXPORT extern DriverEGL g_driver_egl;
#elif defined(OS_ANDROID)
#if defined(OS_ANDROID)
GL_EXPORT extern EGLApi* g_current_egl_context;
GL_EXPORT extern DriverEGL g_driver_egl;

View File

@ -1,133 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file is auto-generated from
// ui/gl/generate_bindings.py
// It's formatted by clang-format using chromium coding style:
// clang-format -i -style=chromium filename
// DO NOT EDIT!
void glXBindTexImageEXTFn(Display* dpy,
GLXDrawable drawable,
int buffer,
int* attribList) override;
GLXFBConfig* glXChooseFBConfigFn(Display* dpy,
int screen,
const int* attribList,
int* nitems) override;
XVisualInfo* glXChooseVisualFn(Display* dpy,
int screen,
int* attribList) override;
void glXCopyContextFn(Display* dpy,
GLXContext src,
GLXContext dst,
unsigned long mask) override;
void glXCopySubBufferMESAFn(Display* dpy,
GLXDrawable drawable,
int x,
int y,
int width,
int height) override;
GLXContext glXCreateContextFn(Display* dpy,
XVisualInfo* vis,
GLXContext shareList,
int direct) override;
GLXContext glXCreateContextAttribsARBFn(Display* dpy,
GLXFBConfig config,
GLXContext share_context,
int direct,
const int* attrib_list) override;
GLXPixmap glXCreateGLXPixmapFn(Display* dpy,
XVisualInfo* visual,
Pixmap pixmap) override;
GLXContext glXCreateNewContextFn(Display* dpy,
GLXFBConfig config,
int renderType,
GLXContext shareList,
int direct) override;
GLXPbuffer glXCreatePbufferFn(Display* dpy,
GLXFBConfig config,
const int* attribList) override;
GLXPixmap glXCreatePixmapFn(Display* dpy,
GLXFBConfig config,
Pixmap pixmap,
const int* attribList) override;
GLXWindow glXCreateWindowFn(Display* dpy,
GLXFBConfig config,
Window win,
const int* attribList) override;
void glXDestroyContextFn(Display* dpy, GLXContext ctx) override;
void glXDestroyGLXPixmapFn(Display* dpy, GLXPixmap pixmap) override;
void glXDestroyPbufferFn(Display* dpy, GLXPbuffer pbuf) override;
void glXDestroyPixmapFn(Display* dpy, GLXPixmap pixmap) override;
void glXDestroyWindowFn(Display* dpy, GLXWindow window) override;
const char* glXGetClientStringFn(Display* dpy, int name) override;
int glXGetConfigFn(Display* dpy,
XVisualInfo* visual,
int attrib,
int* value) override;
GLXContext glXGetCurrentContextFn(void) override;
Display* glXGetCurrentDisplayFn(void) override;
GLXDrawable glXGetCurrentDrawableFn(void) override;
GLXDrawable glXGetCurrentReadDrawableFn(void) override;
int glXGetFBConfigAttribFn(Display* dpy,
GLXFBConfig config,
int attribute,
int* value) override;
GLXFBConfig glXGetFBConfigFromVisualSGIXFn(Display* dpy,
XVisualInfo* visualInfo) override;
GLXFBConfig* glXGetFBConfigsFn(Display* dpy,
int screen,
int* nelements) override;
bool glXGetMscRateOMLFn(Display* dpy,
GLXDrawable drawable,
int32* numerator,
int32* denominator) override;
void glXGetSelectedEventFn(Display* dpy,
GLXDrawable drawable,
unsigned long* mask) override;
bool glXGetSyncValuesOMLFn(Display* dpy,
GLXDrawable drawable,
int64* ust,
int64* msc,
int64* sbc) override;
XVisualInfo* glXGetVisualFromFBConfigFn(Display* dpy,
GLXFBConfig config) override;
int glXIsDirectFn(Display* dpy, GLXContext ctx) override;
int glXMakeContextCurrentFn(Display* dpy,
GLXDrawable draw,
GLXDrawable read,
GLXContext ctx) override;
int glXMakeCurrentFn(Display* dpy,
GLXDrawable drawable,
GLXContext ctx) override;
int glXQueryContextFn(Display* dpy,
GLXContext ctx,
int attribute,
int* value) override;
void glXQueryDrawableFn(Display* dpy,
GLXDrawable draw,
int attribute,
unsigned int* value) override;
int glXQueryExtensionFn(Display* dpy, int* errorb, int* event) override;
const char* glXQueryExtensionsStringFn(Display* dpy, int screen) override;
const char* glXQueryServerStringFn(Display* dpy, int screen, int name) override;
int glXQueryVersionFn(Display* dpy, int* maj, int* min) override;
void glXReleaseTexImageEXTFn(Display* dpy,
GLXDrawable drawable,
int buffer) override;
void glXSelectEventFn(Display* dpy,
GLXDrawable drawable,
unsigned long mask) override;
void glXSwapBuffersFn(Display* dpy, GLXDrawable drawable) override;
void glXSwapIntervalEXTFn(Display* dpy,
GLXDrawable drawable,
int interval) override;
void glXSwapIntervalMESAFn(unsigned int interval) override;
void glXUseXFontFn(Font font, int first, int count, int list) override;
void glXWaitGLFn(void) override;
int glXWaitVideoSyncSGIFn(int divisor,
int remainder,
unsigned int* count) override;
void glXWaitXFn(void) override;

File diff suppressed because it is too large Load Diff

View File

@ -1,424 +0,0 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file is auto-generated from
// ui/gl/generate_bindings.py
// It's formatted by clang-format using chromium coding style:
// clang-format -i -style=chromium filename
// DO NOT EDIT!
#ifndef UI_GFX_GL_GL_BINDINGS_AUTOGEN_GLX_H_
#define UI_GFX_GL_GL_BINDINGS_AUTOGEN_GLX_H_
namespace gfx {
class GLContext;
typedef void(GL_BINDING_CALL* glXBindTexImageEXTProc)(Display* dpy,
GLXDrawable drawable,
int buffer,
int* attribList);
typedef GLXFBConfig*(GL_BINDING_CALL* glXChooseFBConfigProc)(
Display* dpy,
int screen,
const int* attribList,
int* nitems);
typedef XVisualInfo*(GL_BINDING_CALL* glXChooseVisualProc)(Display* dpy,
int screen,
int* attribList);
typedef void(GL_BINDING_CALL* glXCopyContextProc)(Display* dpy,
GLXContext src,
GLXContext dst,
unsigned long mask);
typedef void(GL_BINDING_CALL* glXCopySubBufferMESAProc)(Display* dpy,
GLXDrawable drawable,
int x,
int y,
int width,
int height);
typedef GLXContext(GL_BINDING_CALL* glXCreateContextProc)(Display* dpy,
XVisualInfo* vis,
GLXContext shareList,
int direct);
typedef GLXContext(GL_BINDING_CALL* glXCreateContextAttribsARBProc)(
Display* dpy,
GLXFBConfig config,
GLXContext share_context,
int direct,
const int* attrib_list);
typedef GLXPixmap(GL_BINDING_CALL* glXCreateGLXPixmapProc)(Display* dpy,
XVisualInfo* visual,
Pixmap pixmap);
typedef GLXContext(GL_BINDING_CALL* glXCreateNewContextProc)(
Display* dpy,
GLXFBConfig config,
int renderType,
GLXContext shareList,
int direct);
typedef GLXPbuffer(GL_BINDING_CALL* glXCreatePbufferProc)(
Display* dpy,
GLXFBConfig config,
const int* attribList);
typedef GLXPixmap(GL_BINDING_CALL* glXCreatePixmapProc)(Display* dpy,
GLXFBConfig config,
Pixmap pixmap,
const int* attribList);
typedef GLXWindow(GL_BINDING_CALL* glXCreateWindowProc)(Display* dpy,
GLXFBConfig config,
Window win,
const int* attribList);
typedef void(GL_BINDING_CALL* glXDestroyContextProc)(Display* dpy,
GLXContext ctx);
typedef void(GL_BINDING_CALL* glXDestroyGLXPixmapProc)(Display* dpy,
GLXPixmap pixmap);
typedef void(GL_BINDING_CALL* glXDestroyPbufferProc)(Display* dpy,
GLXPbuffer pbuf);
typedef void(GL_BINDING_CALL* glXDestroyPixmapProc)(Display* dpy,
GLXPixmap pixmap);
typedef void(GL_BINDING_CALL* glXDestroyWindowProc)(Display* dpy,
GLXWindow window);
typedef const char*(GL_BINDING_CALL* glXGetClientStringProc)(Display* dpy,
int name);
typedef int(GL_BINDING_CALL* glXGetConfigProc)(Display* dpy,
XVisualInfo* visual,
int attrib,
int* value);
typedef GLXContext(GL_BINDING_CALL* glXGetCurrentContextProc)(void);
typedef Display*(GL_BINDING_CALL* glXGetCurrentDisplayProc)(void);
typedef GLXDrawable(GL_BINDING_CALL* glXGetCurrentDrawableProc)(void);
typedef GLXDrawable(GL_BINDING_CALL* glXGetCurrentReadDrawableProc)(void);
typedef int(GL_BINDING_CALL* glXGetFBConfigAttribProc)(Display* dpy,
GLXFBConfig config,
int attribute,
int* value);
typedef GLXFBConfig(GL_BINDING_CALL* glXGetFBConfigFromVisualSGIXProc)(
Display* dpy,
XVisualInfo* visualInfo);
typedef GLXFBConfig*(GL_BINDING_CALL* glXGetFBConfigsProc)(Display* dpy,
int screen,
int* nelements);
typedef bool(GL_BINDING_CALL* glXGetMscRateOMLProc)(Display* dpy,
GLXDrawable drawable,
int32* numerator,
int32* denominator);
typedef void(GL_BINDING_CALL* glXGetSelectedEventProc)(Display* dpy,
GLXDrawable drawable,
unsigned long* mask);
typedef bool(GL_BINDING_CALL* glXGetSyncValuesOMLProc)(Display* dpy,
GLXDrawable drawable,
int64* ust,
int64* msc,
int64* sbc);
typedef XVisualInfo*(GL_BINDING_CALL* glXGetVisualFromFBConfigProc)(
Display* dpy,
GLXFBConfig config);
typedef int(GL_BINDING_CALL* glXIsDirectProc)(Display* dpy, GLXContext ctx);
typedef int(GL_BINDING_CALL* glXMakeContextCurrentProc)(Display* dpy,
GLXDrawable draw,
GLXDrawable read,
GLXContext ctx);
typedef int(GL_BINDING_CALL* glXMakeCurrentProc)(Display* dpy,
GLXDrawable drawable,
GLXContext ctx);
typedef int(GL_BINDING_CALL* glXQueryContextProc)(Display* dpy,
GLXContext ctx,
int attribute,
int* value);
typedef void(GL_BINDING_CALL* glXQueryDrawableProc)(Display* dpy,
GLXDrawable draw,
int attribute,
unsigned int* value);
typedef int(GL_BINDING_CALL* glXQueryExtensionProc)(Display* dpy,
int* errorb,
int* event);
typedef const char*(GL_BINDING_CALL* glXQueryExtensionsStringProc)(Display* dpy,
int screen);
typedef const char*(GL_BINDING_CALL* glXQueryServerStringProc)(Display* dpy,
int screen,
int name);
typedef int(GL_BINDING_CALL* glXQueryVersionProc)(Display* dpy,
int* maj,
int* min);
typedef void(GL_BINDING_CALL* glXReleaseTexImageEXTProc)(Display* dpy,
GLXDrawable drawable,
int buffer);
typedef void(GL_BINDING_CALL* glXSelectEventProc)(Display* dpy,
GLXDrawable drawable,
unsigned long mask);
typedef void(GL_BINDING_CALL* glXSwapBuffersProc)(Display* dpy,
GLXDrawable drawable);
typedef void(GL_BINDING_CALL* glXSwapIntervalEXTProc)(Display* dpy,
GLXDrawable drawable,
int interval);
typedef void(GL_BINDING_CALL* glXSwapIntervalMESAProc)(unsigned int interval);
typedef void(GL_BINDING_CALL* glXUseXFontProc)(Font font,
int first,
int count,
int list);
typedef void(GL_BINDING_CALL* glXWaitGLProc)(void);
typedef int(GL_BINDING_CALL* glXWaitVideoSyncSGIProc)(int divisor,
int remainder,
unsigned int* count);
typedef void(GL_BINDING_CALL* glXWaitXProc)(void);
struct ExtensionsGLX {
bool b_GLX_ARB_create_context;
bool b_GLX_EXT_swap_control;
bool b_GLX_EXT_texture_from_pixmap;
bool b_GLX_MESA_copy_sub_buffer;
bool b_GLX_MESA_swap_control;
bool b_GLX_OML_sync_control;
bool b_GLX_SGIX_fbconfig;
bool b_GLX_SGI_video_sync;
};
struct ProcsGLX {
glXBindTexImageEXTProc glXBindTexImageEXTFn;
glXChooseFBConfigProc glXChooseFBConfigFn;
glXChooseVisualProc glXChooseVisualFn;
glXCopyContextProc glXCopyContextFn;
glXCopySubBufferMESAProc glXCopySubBufferMESAFn;
glXCreateContextProc glXCreateContextFn;
glXCreateContextAttribsARBProc glXCreateContextAttribsARBFn;
glXCreateGLXPixmapProc glXCreateGLXPixmapFn;
glXCreateNewContextProc glXCreateNewContextFn;
glXCreatePbufferProc glXCreatePbufferFn;
glXCreatePixmapProc glXCreatePixmapFn;
glXCreateWindowProc glXCreateWindowFn;
glXDestroyContextProc glXDestroyContextFn;
glXDestroyGLXPixmapProc glXDestroyGLXPixmapFn;
glXDestroyPbufferProc glXDestroyPbufferFn;
glXDestroyPixmapProc glXDestroyPixmapFn;
glXDestroyWindowProc glXDestroyWindowFn;
glXGetClientStringProc glXGetClientStringFn;
glXGetConfigProc glXGetConfigFn;
glXGetCurrentContextProc glXGetCurrentContextFn;
glXGetCurrentDisplayProc glXGetCurrentDisplayFn;
glXGetCurrentDrawableProc glXGetCurrentDrawableFn;
glXGetCurrentReadDrawableProc glXGetCurrentReadDrawableFn;
glXGetFBConfigAttribProc glXGetFBConfigAttribFn;
glXGetFBConfigFromVisualSGIXProc glXGetFBConfigFromVisualSGIXFn;
glXGetFBConfigsProc glXGetFBConfigsFn;
glXGetMscRateOMLProc glXGetMscRateOMLFn;
glXGetSelectedEventProc glXGetSelectedEventFn;
glXGetSyncValuesOMLProc glXGetSyncValuesOMLFn;
glXGetVisualFromFBConfigProc glXGetVisualFromFBConfigFn;
glXIsDirectProc glXIsDirectFn;
glXMakeContextCurrentProc glXMakeContextCurrentFn;
glXMakeCurrentProc glXMakeCurrentFn;
glXQueryContextProc glXQueryContextFn;
glXQueryDrawableProc glXQueryDrawableFn;
glXQueryExtensionProc glXQueryExtensionFn;
glXQueryExtensionsStringProc glXQueryExtensionsStringFn;
glXQueryServerStringProc glXQueryServerStringFn;
glXQueryVersionProc glXQueryVersionFn;
glXReleaseTexImageEXTProc glXReleaseTexImageEXTFn;
glXSelectEventProc glXSelectEventFn;
glXSwapBuffersProc glXSwapBuffersFn;
glXSwapIntervalEXTProc glXSwapIntervalEXTFn;
glXSwapIntervalMESAProc glXSwapIntervalMESAFn;
glXUseXFontProc glXUseXFontFn;
glXWaitGLProc glXWaitGLFn;
glXWaitVideoSyncSGIProc glXWaitVideoSyncSGIFn;
glXWaitXProc glXWaitXFn;
};
class GL_EXPORT GLXApi {
public:
GLXApi();
virtual ~GLXApi();
virtual void glXBindTexImageEXTFn(Display* dpy,
GLXDrawable drawable,
int buffer,
int* attribList) = 0;
virtual GLXFBConfig* glXChooseFBConfigFn(Display* dpy,
int screen,
const int* attribList,
int* nitems) = 0;
virtual XVisualInfo* glXChooseVisualFn(Display* dpy,
int screen,
int* attribList) = 0;
virtual void glXCopyContextFn(Display* dpy,
GLXContext src,
GLXContext dst,
unsigned long mask) = 0;
virtual void glXCopySubBufferMESAFn(Display* dpy,
GLXDrawable drawable,
int x,
int y,
int width,
int height) = 0;
virtual GLXContext glXCreateContextFn(Display* dpy,
XVisualInfo* vis,
GLXContext shareList,
int direct) = 0;
virtual GLXContext glXCreateContextAttribsARBFn(Display* dpy,
GLXFBConfig config,
GLXContext share_context,
int direct,
const int* attrib_list) = 0;
virtual GLXPixmap glXCreateGLXPixmapFn(Display* dpy,
XVisualInfo* visual,
Pixmap pixmap) = 0;
virtual GLXContext glXCreateNewContextFn(Display* dpy,
GLXFBConfig config,
int renderType,
GLXContext shareList,
int direct) = 0;
virtual GLXPbuffer glXCreatePbufferFn(Display* dpy,
GLXFBConfig config,
const int* attribList) = 0;
virtual GLXPixmap glXCreatePixmapFn(Display* dpy,
GLXFBConfig config,
Pixmap pixmap,
const int* attribList) = 0;
virtual GLXWindow glXCreateWindowFn(Display* dpy,
GLXFBConfig config,
Window win,
const int* attribList) = 0;
virtual void glXDestroyContextFn(Display* dpy, GLXContext ctx) = 0;
virtual void glXDestroyGLXPixmapFn(Display* dpy, GLXPixmap pixmap) = 0;
virtual void glXDestroyPbufferFn(Display* dpy, GLXPbuffer pbuf) = 0;
virtual void glXDestroyPixmapFn(Display* dpy, GLXPixmap pixmap) = 0;
virtual void glXDestroyWindowFn(Display* dpy, GLXWindow window) = 0;
virtual const char* glXGetClientStringFn(Display* dpy, int name) = 0;
virtual int glXGetConfigFn(Display* dpy,
XVisualInfo* visual,
int attrib,
int* value) = 0;
virtual GLXContext glXGetCurrentContextFn(void) = 0;
virtual Display* glXGetCurrentDisplayFn(void) = 0;
virtual GLXDrawable glXGetCurrentDrawableFn(void) = 0;
virtual GLXDrawable glXGetCurrentReadDrawableFn(void) = 0;
virtual int glXGetFBConfigAttribFn(Display* dpy,
GLXFBConfig config,
int attribute,
int* value) = 0;
virtual GLXFBConfig glXGetFBConfigFromVisualSGIXFn(
Display* dpy,
XVisualInfo* visualInfo) = 0;
virtual GLXFBConfig* glXGetFBConfigsFn(Display* dpy,
int screen,
int* nelements) = 0;
virtual bool glXGetMscRateOMLFn(Display* dpy,
GLXDrawable drawable,
int32* numerator,
int32* denominator) = 0;
virtual void glXGetSelectedEventFn(Display* dpy,
GLXDrawable drawable,
unsigned long* mask) = 0;
virtual bool glXGetSyncValuesOMLFn(Display* dpy,
GLXDrawable drawable,
int64* ust,
int64* msc,
int64* sbc) = 0;
virtual XVisualInfo* glXGetVisualFromFBConfigFn(Display* dpy,
GLXFBConfig config) = 0;
virtual int glXIsDirectFn(Display* dpy, GLXContext ctx) = 0;
virtual int glXMakeContextCurrentFn(Display* dpy,
GLXDrawable draw,
GLXDrawable read,
GLXContext ctx) = 0;
virtual int glXMakeCurrentFn(Display* dpy,
GLXDrawable drawable,
GLXContext ctx) = 0;
virtual int glXQueryContextFn(Display* dpy,
GLXContext ctx,
int attribute,
int* value) = 0;
virtual void glXQueryDrawableFn(Display* dpy,
GLXDrawable draw,
int attribute,
unsigned int* value) = 0;
virtual int glXQueryExtensionFn(Display* dpy, int* errorb, int* event) = 0;
virtual const char* glXQueryExtensionsStringFn(Display* dpy, int screen) = 0;
virtual const char* glXQueryServerStringFn(Display* dpy,
int screen,
int name) = 0;
virtual int glXQueryVersionFn(Display* dpy, int* maj, int* min) = 0;
virtual void glXReleaseTexImageEXTFn(Display* dpy,
GLXDrawable drawable,
int buffer) = 0;
virtual void glXSelectEventFn(Display* dpy,
GLXDrawable drawable,
unsigned long mask) = 0;
virtual void glXSwapBuffersFn(Display* dpy, GLXDrawable drawable) = 0;
virtual void glXSwapIntervalEXTFn(Display* dpy,
GLXDrawable drawable,
int interval) = 0;
virtual void glXSwapIntervalMESAFn(unsigned int interval) = 0;
virtual void glXUseXFontFn(Font font, int first, int count, int list) = 0;
virtual void glXWaitGLFn(void) = 0;
virtual int glXWaitVideoSyncSGIFn(int divisor,
int remainder,
unsigned int* count) = 0;
virtual void glXWaitXFn(void) = 0;
};
} // namespace gfx
#define glXBindTexImageEXT ::gfx::g_current_glx_context->glXBindTexImageEXTFn
#define glXChooseFBConfig ::gfx::g_current_glx_context->glXChooseFBConfigFn
#define glXChooseVisual ::gfx::g_current_glx_context->glXChooseVisualFn
#define glXCopyContext ::gfx::g_current_glx_context->glXCopyContextFn
#define glXCopySubBufferMESA \
::gfx::g_current_glx_context->glXCopySubBufferMESAFn
#define glXCreateContext ::gfx::g_current_glx_context->glXCreateContextFn
#define glXCreateContextAttribsARB \
::gfx::g_current_glx_context->glXCreateContextAttribsARBFn
#define glXCreateGLXPixmap ::gfx::g_current_glx_context->glXCreateGLXPixmapFn
#define glXCreateNewContext ::gfx::g_current_glx_context->glXCreateNewContextFn
#define glXCreatePbuffer ::gfx::g_current_glx_context->glXCreatePbufferFn
#define glXCreatePixmap ::gfx::g_current_glx_context->glXCreatePixmapFn
#define glXCreateWindow ::gfx::g_current_glx_context->glXCreateWindowFn
#define glXDestroyContext ::gfx::g_current_glx_context->glXDestroyContextFn
#define glXDestroyGLXPixmap ::gfx::g_current_glx_context->glXDestroyGLXPixmapFn
#define glXDestroyPbuffer ::gfx::g_current_glx_context->glXDestroyPbufferFn
#define glXDestroyPixmap ::gfx::g_current_glx_context->glXDestroyPixmapFn
#define glXDestroyWindow ::gfx::g_current_glx_context->glXDestroyWindowFn
#define glXGetClientString ::gfx::g_current_glx_context->glXGetClientStringFn
#define glXGetConfig ::gfx::g_current_glx_context->glXGetConfigFn
#define glXGetCurrentContext \
::gfx::g_current_glx_context->glXGetCurrentContextFn
#define glXGetCurrentDisplay \
::gfx::g_current_glx_context->glXGetCurrentDisplayFn
#define glXGetCurrentDrawable \
::gfx::g_current_glx_context->glXGetCurrentDrawableFn
#define glXGetCurrentReadDrawable \
::gfx::g_current_glx_context->glXGetCurrentReadDrawableFn
#define glXGetFBConfigAttrib \
::gfx::g_current_glx_context->glXGetFBConfigAttribFn
#define glXGetFBConfigFromVisualSGIX \
::gfx::g_current_glx_context->glXGetFBConfigFromVisualSGIXFn
#define glXGetFBConfigs ::gfx::g_current_glx_context->glXGetFBConfigsFn
#define glXGetMscRateOML ::gfx::g_current_glx_context->glXGetMscRateOMLFn
#define glXGetSelectedEvent ::gfx::g_current_glx_context->glXGetSelectedEventFn
#define glXGetSyncValuesOML ::gfx::g_current_glx_context->glXGetSyncValuesOMLFn
#define glXGetVisualFromFBConfig \
::gfx::g_current_glx_context->glXGetVisualFromFBConfigFn
#define glXIsDirect ::gfx::g_current_glx_context->glXIsDirectFn
#define glXMakeContextCurrent \
::gfx::g_current_glx_context->glXMakeContextCurrentFn
#define glXMakeCurrent ::gfx::g_current_glx_context->glXMakeCurrentFn
#define glXQueryContext ::gfx::g_current_glx_context->glXQueryContextFn
#define glXQueryDrawable ::gfx::g_current_glx_context->glXQueryDrawableFn
#define glXQueryExtension ::gfx::g_current_glx_context->glXQueryExtensionFn
#define glXQueryExtensionsString \
::gfx::g_current_glx_context->glXQueryExtensionsStringFn
#define glXQueryServerString \
::gfx::g_current_glx_context->glXQueryServerStringFn
#define glXQueryVersion ::gfx::g_current_glx_context->glXQueryVersionFn
#define glXReleaseTexImageEXT \
::gfx::g_current_glx_context->glXReleaseTexImageEXTFn
#define glXSelectEvent ::gfx::g_current_glx_context->glXSelectEventFn
#define glXSwapBuffers ::gfx::g_current_glx_context->glXSwapBuffersFn
#define glXSwapIntervalEXT ::gfx::g_current_glx_context->glXSwapIntervalEXTFn
#define glXSwapIntervalMESA ::gfx::g_current_glx_context->glXSwapIntervalMESAFn
#define glXUseXFont ::gfx::g_current_glx_context->glXUseXFontFn
#define glXWaitGL ::gfx::g_current_glx_context->glXWaitGLFn
#define glXWaitVideoSyncSGI ::gfx::g_current_glx_context->glXWaitVideoSyncSGIFn
#define glXWaitX ::gfx::g_current_glx_context->glXWaitXFn
#endif // UI_GFX_GL_GL_BINDINGS_AUTOGEN_GLX_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,86 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_glx_api_implementation.h"
#include "ui/gl/gl_implementation.h"
namespace gfx {
RealGLXApi* g_real_glx;
void InitializeStaticGLBindingsGLX() {
g_driver_glx.InitializeStaticBindings();
if (!g_real_glx) {
g_real_glx = new RealGLXApi();
}
g_real_glx->Initialize(&g_driver_glx);
g_current_glx_context = g_real_glx;
}
void InitializeDebugGLBindingsGLX() {
g_driver_glx.InitializeDebugBindings();
}
void ClearGLBindingsGLX() {
if (g_real_glx) {
delete g_real_glx;
g_real_glx = NULL;
}
g_current_glx_context = NULL;
g_driver_glx.ClearBindings();
}
GLXApi::GLXApi() {
}
GLXApi::~GLXApi() {
}
GLXApiBase::GLXApiBase()
: driver_(NULL) {
}
GLXApiBase::~GLXApiBase() {
}
void GLXApiBase::InitializeBase(DriverGLX* driver) {
driver_ = driver;
}
RealGLXApi::RealGLXApi() {
}
RealGLXApi::~RealGLXApi() {
}
void RealGLXApi::Initialize(DriverGLX* driver) {
InitializeBase(driver);
}
TraceGLXApi::~TraceGLXApi() {
}
bool GetGLWindowSystemBindingInfoGLX(GLWindowSystemBindingInfo* info) {
Display* display = glXGetCurrentDisplay();
const int kDefaultScreen = 0;
const char* vendor =
glXQueryServerString(display, kDefaultScreen, GLX_VENDOR);
const char* version =
glXQueryServerString(display, kDefaultScreen, GLX_VERSION);
const char* extensions =
glXQueryServerString(display, kDefaultScreen, GLX_EXTENSIONS);
*info = GLWindowSystemBindingInfo();
if (vendor)
info->vendor = vendor;
if (version)
info->version = version;
if (extensions)
info->extensions = extensions;
info->direct_rendering = !!glXIsDirect(display, glXGetCurrentContext());
return true;
}
} // namespace gfx

View File

@ -1,64 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_GL_GLX_API_IMPLEMENTATION_H_
#define UI_GL_GL_GLX_API_IMPLEMENTATION_H_
#include "base/compiler_specific.h"
#include "gl_bindings.h"
#include "ui/gl/gl_export.h"
namespace gfx {
class GLContext;
struct GLWindowSystemBindingInfo;
void InitializeStaticGLBindingsGLX();
void InitializeDebugGLBindingsGLX();
void ClearGLBindingsGLX();
bool GetGLWindowSystemBindingInfoGLX(GLWindowSystemBindingInfo* info);
class GL_EXPORT GLXApiBase : public GLXApi {
public:
// Include the auto-generated part of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
#include "gl_bindings_api_autogen_glx.h"
protected:
GLXApiBase();
~GLXApiBase() override;
void InitializeBase(DriverGLX* driver);
DriverGLX* driver_;
};
class GL_EXPORT RealGLXApi : public GLXApiBase {
public:
RealGLXApi();
~RealGLXApi() override;
void Initialize(DriverGLX* driver);
};
// Inserts a TRACE for every GLX call.
class GL_EXPORT TraceGLXApi : public GLXApi {
public:
TraceGLXApi(GLXApi* glx_api) : glx_api_(glx_api) { }
~TraceGLXApi() override;
// Include the auto-generated part of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
#include "gl_bindings_api_autogen_glx.h"
private:
GLXApi* glx_api_;
};
} // namespace gfx
#endif // UI_GL_GL_GLX_API_IMPLEMENTATION_H_

View File

@ -48,16 +48,7 @@ void CleanupNativeLibraries(void* unused) {
base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls = NULL;
OSMESAApi* g_current_osmesa_context;
#if defined(USE_X11)
EGLApi* g_current_egl_context;
GLXApi* g_current_glx_context;
#elif defined(USE_OZONE)
EGLApi* g_current_egl_context;
#elif defined(OS_ANDROID)
#if defined(OS_ANDROID)
EGLApi* g_current_egl_context;

View File

@ -15,6 +15,37 @@
namespace gfx {
#if defined(OS_LINUX)
// On Linux, we always use the OSMesa implementation of GL so we hardcode these
// functions here.
void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationOSMesaGL);
}
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
DCHECK_EQ(implementation, kGLImplementationOSMesaGL);
InitializeDynamicGLBindingsGL(context);
return true;
}
bool InitializeStaticGLBindings(GLImplementation implementation) {
DCHECK_EQ(implementation, kGLImplementationOSMesaGL);
return InitializeStaticGLBindingsOSMesaGL();
}
void InitializeDebugGLBindings() {
InitializeDebugGLBindingsOSMESA();
}
void ClearGLBindings() {
ClearGLBindingsOSMESA();
SetGLImplementation(kGLImplementationNone);
UnloadGLNativeLibraries();
}
#endif
base::NativeLibrary LoadLibraryAndPrintError(const base::FilePath& filename) {
base::NativeLibraryLoadError error;
base::NativeLibrary library = base::LoadNativeLibrary(filename, &error);

View File

@ -1,203 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#include "base/command_line.h"
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context_stub_with_extensions.h"
#include "ui/gl/gl_egl_api_implementation.h"
#include "ui/gl/gl_gl_api_implementation.h"
#include "ui/gl/gl_glx_api_implementation.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_implementation_osmesa.h"
#include "ui/gl/gl_osmesa_api_implementation.h"
#include "ui/gl/gl_switches.h"
namespace gfx {
namespace {
// TODO(piman): it should be Desktop GL marshalling from double to float. Today
// on native GLES, we do float->double->float.
void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) {
glClearDepthf(static_cast<GLclampf>(depth));
}
void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near,
GLclampd z_far) {
glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far));
}
#if defined(OS_OPENBSD)
const char kGLLibraryName[] = "libGL.so";
#else
const char kGLLibraryName[] = "libGL.so.1";
#endif
const char kGLESv2LibraryName[] = "libGLESv2.so.2";
const char kEGLLibraryName[] = "libEGL.so.1";
} // namespace
void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
impls->push_back(kGLImplementationDesktopGL);
impls->push_back(kGLImplementationEGLGLES2);
impls->push_back(kGLImplementationOSMesaGL);
}
bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
// Allow the main thread or another to initialize these bindings
// after instituting restrictions on I/O. Going forward they will
// likely be used in the browser process on most platforms. The
// one-time initialization cost is small, between 2 and 5 ms.
base::ThreadRestrictions::ScopedAllowIO allow_io;
switch (implementation) {
case kGLImplementationOSMesaGL:
return InitializeStaticGLBindingsOSMesaGL();
case kGLImplementationDesktopGL: {
base::NativeLibrary library = NULL;
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kTestGLLib))
library = LoadLibraryAndPrintError(
command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str());
if (!library) {
library = LoadLibraryAndPrintError(kGLLibraryName);
}
if (!library)
return false;
GLGetProcAddressProc get_proc_address =
reinterpret_cast<GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(
library, "glXGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "glxGetProcAddress not found.";
base::UnloadNativeLibrary(library);
return false;
}
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(library);
SetGLImplementation(kGLImplementationDesktopGL);
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsGLX();
break;
}
case kGLImplementationEGLGLES2: {
base::NativeLibrary gles_library =
LoadLibraryAndPrintError(kGLESv2LibraryName);
if (!gles_library)
return false;
base::NativeLibrary egl_library =
LoadLibraryAndPrintError(kEGLLibraryName);
if (!egl_library) {
base::UnloadNativeLibrary(gles_library);
return false;
}
GLGetProcAddressProc get_proc_address =
reinterpret_cast<GLGetProcAddressProc>(
base::GetFunctionPointerFromNativeLibrary(
egl_library, "eglGetProcAddress"));
if (!get_proc_address) {
LOG(ERROR) << "eglGetProcAddress not found.";
base::UnloadNativeLibrary(egl_library);
base::UnloadNativeLibrary(gles_library);
return false;
}
SetGLGetProcAddressProc(get_proc_address);
AddGLNativeLibrary(egl_library);
AddGLNativeLibrary(gles_library);
SetGLImplementation(kGLImplementationEGLGLES2);
InitializeStaticGLBindingsGL();
InitializeStaticGLBindingsEGL();
// These two functions take single precision float rather than double
// precision float parameters in GLES.
::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
break;
}
case kGLImplementationMockGL: {
SetGLImplementation(kGLImplementationMockGL);
InitializeStaticGLBindingsGL();
break;
}
default:
return false;
}
return true;
}
bool InitializeDynamicGLBindings(GLImplementation implementation,
GLContext* context) {
switch (implementation) {
case kGLImplementationOSMesaGL:
case kGLImplementationDesktopGL:
case kGLImplementationEGLGLES2:
InitializeDynamicGLBindingsGL(context);
break;
case kGLImplementationMockGL:
if (!context) {
scoped_refptr<GLContextStubWithExtensions> mock_context(
new GLContextStubWithExtensions());
mock_context->SetGLVersionString("3.0");
InitializeDynamicGLBindingsGL(mock_context.get());
} else
InitializeDynamicGLBindingsGL(context);
break;
default:
return false;
}
return true;
}
void InitializeDebugGLBindings() {
InitializeDebugGLBindingsEGL();
InitializeDebugGLBindingsGL();
InitializeDebugGLBindingsGLX();
InitializeDebugGLBindingsOSMESA();
}
void ClearGLBindings() {
ClearGLBindingsEGL();
ClearGLBindingsGL();
ClearGLBindingsGLX();
ClearGLBindingsOSMESA();
SetGLImplementation(kGLImplementationNone);
UnloadGLNativeLibraries();
}
bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) {
switch (GetGLImplementation()) {
case kGLImplementationDesktopGL:
return GetGLWindowSystemBindingInfoGLX(info);
case kGLImplementationEGLGLES2:
return GetGLWindowSystemBindingInfoEGL(info);
default:
return false;
}
return false;
}
} // namespace gfx

View File

@ -1,21 +0,0 @@
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gl/gl_mock.h"
namespace gfx {
MockGLInterface::MockGLInterface() {
}
MockGLInterface::~MockGLInterface() {
}
MockGLInterface* MockGLInterface::interface_;
void MockGLInterface::SetGLInterface(MockGLInterface* gl_interface) {
interface_ = gl_interface;
}
} // namespace gfx

View File

@ -1,45 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file implements mock GL Interface for unit testing. The interface
// corresponds to the set of functionally distinct GL functions defined in
// generate_bindings.py, which may originate from either desktop GL or GLES.
#ifndef UI_GL_GL_MOCK_H_
#define UI_GL_GL_MOCK_H_
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gl/gl_bindings.h"
namespace gfx {
class MockGLInterface {
public:
MockGLInterface();
virtual ~MockGLInterface();
// Set the functions called from the mock GL implementation for the purposes
// of testing.
static void SetGLInterface(MockGLInterface* gl_interface);
// Find an entry point to the mock GL implementation.
static void* GL_BINDING_CALL GetGLProcAddress(const char* name);
// Include the auto-generated parts of this class. We split this because
// it means we can easily edit the non-auto generated parts right here in
// this file instead of having to edit some template or the code generator.
// Member functions
#include "gl_mock_autogen_gl.h"
private:
static MockGLInterface* interface_;
// Static mock functions that invoke the member functions of interface_.
#include "gl_bindings_autogen_mock.h"
};
} // namespace gfx
#endif // UI_GL_GL_MOCK_H_

View File

@ -1,697 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
extern "C" {
#include <X11/Xlib.h>
}
#include "ui/gl/gl_surface_glx.h"
#include "base/basictypes.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/cancellation_flag.h"
#include "base/synchronization/lock.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_connection.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/sync_control_vsync_provider.h"
namespace gfx {
namespace {
Display* g_display = NULL;
const char* g_glx_extensions = NULL;
bool g_glx_context_create = false;
bool g_glx_create_context_robustness_supported = false;
bool g_glx_texture_from_pixmap_supported = false;
bool g_glx_oml_sync_control_supported = false;
// Track support of glXGetMscRateOML separately from GLX_OML_sync_control as a
// whole since on some platforms (e.g. crosbug.com/34585), glXGetMscRateOML
// always fails even though GLX_OML_sync_control is reported as being supported.
bool g_glx_get_msc_rate_oml_supported = false;
bool g_glx_sgi_video_sync_supported = false;
static const base::TimeDelta kGetVSyncParametersMinPeriod =
#if defined(OS_LINUX)
// See crbug.com/373489
// On Linux, querying the vsync parameters might burn CPU for up to an
// entire vsync, so we only query periodically to reduce CPU usage.
// 5 seconds is chosen somewhat abitrarily as a balance between:
// a) Drift in the phase of our signal.
// b) Potential janks from periodically pegging the CPU.
base::TimeDelta::FromSeconds(5);
#else
base::TimeDelta::FromSeconds(0);
#endif
class OMLSyncControlVSyncProvider
: public gfx::SyncControlVSyncProvider {
public:
explicit OMLSyncControlVSyncProvider(gfx::AcceleratedWidget window)
: SyncControlVSyncProvider(),
window_(window) {
}
~OMLSyncControlVSyncProvider() override {}
protected:
bool GetSyncValues(int64* system_time,
int64* media_stream_counter,
int64* swap_buffer_counter) override {
return glXGetSyncValuesOML(g_display, window_, system_time,
media_stream_counter, swap_buffer_counter);
}
bool GetMscRate(int32* numerator, int32* denominator) override {
if (!g_glx_get_msc_rate_oml_supported)
return false;
if (!glXGetMscRateOML(g_display, window_, numerator, denominator)) {
// Once glXGetMscRateOML has been found to fail, don't try again,
// since each failing call may spew an error message.
g_glx_get_msc_rate_oml_supported = false;
return false;
}
return true;
}
private:
XID window_;
DISALLOW_COPY_AND_ASSIGN(OMLSyncControlVSyncProvider);
};
class SGIVideoSyncThread
: public base::Thread,
public base::NonThreadSafe,
public base::RefCounted<SGIVideoSyncThread> {
public:
static scoped_refptr<SGIVideoSyncThread> Create() {
if (!g_video_sync_thread) {
g_video_sync_thread = new SGIVideoSyncThread();
g_video_sync_thread->Start();
}
return g_video_sync_thread;
}
private:
friend class base::RefCounted<SGIVideoSyncThread>;
SGIVideoSyncThread() : base::Thread("SGI_video_sync") {
DCHECK(CalledOnValidThread());
}
~SGIVideoSyncThread() override {
DCHECK(CalledOnValidThread());
g_video_sync_thread = NULL;
Stop();
}
static SGIVideoSyncThread* g_video_sync_thread;
DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncThread);
};
class SGIVideoSyncProviderThreadShim {
public:
explicit SGIVideoSyncProviderThreadShim(XID window)
: window_(window),
context_(NULL),
task_runner_(base::ThreadTaskRunnerHandle::Get()),
cancel_vsync_flag_(),
vsync_lock_() {
// This ensures that creation of |window_| has occured when this shim
// is executing in the same process as the call to create |window_|.
XSync(g_display, False);
}
virtual ~SGIVideoSyncProviderThreadShim() {
if (context_) {
glXDestroyContext(display_, context_);
context_ = NULL;
}
}
base::CancellationFlag* cancel_vsync_flag() {
return &cancel_vsync_flag_;
}
base::Lock* vsync_lock() {
return &vsync_lock_;
}
void Initialize() {
DCHECK(display_);
XWindowAttributes attributes;
if (!XGetWindowAttributes(display_, window_, &attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window " <<
window_ << ".";
return;
}
XVisualInfo visual_info_template;
visual_info_template.visualid = XVisualIDFromVisual(attributes.visual);
int visual_info_count = 0;
gfx::XScopedPtr<XVisualInfo> visual_info_list(XGetVisualInfo(
display_, VisualIDMask, &visual_info_template, &visual_info_count));
DCHECK(visual_info_list.get());
if (visual_info_count == 0) {
LOG(ERROR) << "No visual info for visual ID.";
return;
}
context_ = glXCreateContext(display_, visual_info_list.get(), NULL, True);
DCHECK(NULL != context_);
}
void GetVSyncParameters(const VSyncProvider::UpdateVSyncCallback& callback) {
base::TimeTicks now;
{
// Don't allow |window_| destruction while we're probing vsync.
base::AutoLock locked(vsync_lock_);
if (!context_ || cancel_vsync_flag_.IsSet())
return;
glXMakeCurrent(display_, window_, context_);
unsigned int retrace_count = 0;
if (glXWaitVideoSyncSGI(1, 0, &retrace_count) != 0)
return;
TRACE_EVENT_INSTANT0("gpu", "vblank", TRACE_EVENT_SCOPE_THREAD);
now = base::TimeTicks::Now();
glXMakeCurrent(display_, 0, 0);
}
const base::TimeDelta kDefaultInterval =
base::TimeDelta::FromSeconds(1) / 60;
task_runner_->PostTask(
FROM_HERE, base::Bind(callback, now, kDefaultInterval));
}
private:
// For initialization of display_ in GLSurface::InitializeOneOff before
// the sandbox goes up.
friend class gfx::GLSurfaceGLX;
static Display* display_;
XID window_;
GLXContext context_;
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::CancellationFlag cancel_vsync_flag_;
base::Lock vsync_lock_;
DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncProviderThreadShim);
};
class SGIVideoSyncVSyncProvider
: public gfx::VSyncProvider,
public base::SupportsWeakPtr<SGIVideoSyncVSyncProvider> {
public:
explicit SGIVideoSyncVSyncProvider(gfx::AcceleratedWidget window)
: vsync_thread_(SGIVideoSyncThread::Create()),
shim_(new SGIVideoSyncProviderThreadShim(window)),
cancel_vsync_flag_(shim_->cancel_vsync_flag()),
vsync_lock_(shim_->vsync_lock()) {
vsync_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&SGIVideoSyncProviderThreadShim::Initialize,
base::Unretained(shim_.get())));
}
~SGIVideoSyncVSyncProvider() override {
{
base::AutoLock locked(*vsync_lock_);
cancel_vsync_flag_->Set();
}
// Hand-off |shim_| to be deleted on the |vsync_thread_|.
vsync_thread_->message_loop()->DeleteSoon(
FROM_HERE,
shim_.release());
}
void GetVSyncParameters(
const VSyncProvider::UpdateVSyncCallback& callback) override {
if (kGetVSyncParametersMinPeriod > base::TimeDelta()) {
base::TimeTicks now = base::TimeTicks::Now();
base::TimeDelta delta = now - last_get_vsync_parameters_time_;
if (delta < kGetVSyncParametersMinPeriod)
return;
last_get_vsync_parameters_time_ = now;
}
// Only one outstanding request per surface.
if (!pending_callback_) {
pending_callback_.reset(
new VSyncProvider::UpdateVSyncCallback(callback));
vsync_thread_->message_loop()->PostTask(
FROM_HERE,
base::Bind(&SGIVideoSyncProviderThreadShim::GetVSyncParameters,
base::Unretained(shim_.get()),
base::Bind(
&SGIVideoSyncVSyncProvider::PendingCallbackRunner,
AsWeakPtr())));
}
}
private:
void PendingCallbackRunner(const base::TimeTicks timebase,
const base::TimeDelta interval) {
DCHECK(pending_callback_);
pending_callback_->Run(timebase, interval);
pending_callback_.reset();
}
scoped_refptr<SGIVideoSyncThread> vsync_thread_;
// Thread shim through which the sync provider is accessed on |vsync_thread_|.
scoped_ptr<SGIVideoSyncProviderThreadShim> shim_;
scoped_ptr<VSyncProvider::UpdateVSyncCallback> pending_callback_;
// Raw pointers to sync primitives owned by the shim_.
// These will only be referenced before we post a task to destroy
// the shim_, so they are safe to access.
base::CancellationFlag* cancel_vsync_flag_;
base::Lock* vsync_lock_;
base::TimeTicks last_get_vsync_parameters_time_;
DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider);
};
SGIVideoSyncThread* SGIVideoSyncThread::g_video_sync_thread = NULL;
// In order to take advantage of GLX_SGI_video_sync, we need a display
// for use on a separate thread. We must allocate this before the sandbox
// goes up (rather than on-demand when we start the thread).
Display* SGIVideoSyncProviderThreadShim::display_ = NULL;
} // namespace
GLSurfaceGLX::GLSurfaceGLX(
const gfx::SurfaceConfiguration& requested_configuration)
: GLSurface(requested_configuration) {
}
bool GLSurfaceGLX::InitializeOneOff() {
static bool initialized = false;
if (initialized)
return true;
// http://crbug.com/245466
setenv("force_s3tc_enable", "true", 1);
// SGIVideoSyncProviderShim (if instantiated) will issue X commands on
// it's own thread.
gfx::InitializeThreadedX11();
g_display = gfx::GetXDisplay();
if (!g_display) {
LOG(ERROR) << "XOpenDisplay failed.";
return false;
}
int major, minor;
if (!glXQueryVersion(g_display, &major, &minor)) {
LOG(ERROR) << "glxQueryVersion failed";
return false;
}
if (major == 1 && minor < 3) {
LOG(ERROR) << "GLX 1.3 or later is required.";
return false;
}
g_glx_extensions = glXQueryExtensionsString(g_display, 0);
g_glx_context_create =
HasGLXExtension("GLX_ARB_create_context");
g_glx_create_context_robustness_supported =
HasGLXExtension("GLX_ARB_create_context_robustness");
g_glx_texture_from_pixmap_supported =
HasGLXExtension("GLX_EXT_texture_from_pixmap");
g_glx_oml_sync_control_supported =
HasGLXExtension("GLX_OML_sync_control");
g_glx_get_msc_rate_oml_supported = g_glx_oml_sync_control_supported;
g_glx_sgi_video_sync_supported =
HasGLXExtension("GLX_SGI_video_sync");
if (!g_glx_get_msc_rate_oml_supported && g_glx_sgi_video_sync_supported)
SGIVideoSyncProviderThreadShim::display_ = gfx::OpenNewXDisplay();
initialized = true;
return true;
}
// static
const char* GLSurfaceGLX::GetGLXExtensions() {
return g_glx_extensions;
}
// static
bool GLSurfaceGLX::HasGLXExtension(const char* name) {
return ExtensionsContain(GetGLXExtensions(), name);
}
// static
bool GLSurfaceGLX::IsCreateContextSupported() {
return g_glx_context_create;
}
// static
bool GLSurfaceGLX::IsCreateContextRobustnessSupported() {
return g_glx_create_context_robustness_supported;
}
// static
bool GLSurfaceGLX::IsTextureFromPixmapSupported() {
return g_glx_texture_from_pixmap_supported;
}
// static
bool GLSurfaceGLX::IsOMLSyncControlSupported() {
return g_glx_oml_sync_control_supported;
}
void* GLSurfaceGLX::GetDisplay() {
return g_display;
}
GLSurfaceGLX::~GLSurfaceGLX() {}
NativeViewGLSurfaceGLX::NativeViewGLSurfaceGLX(
gfx::AcceleratedWidget window,
const gfx::SurfaceConfiguration& requested_configuration)
: GLSurfaceGLX(requested_configuration),
parent_window_(window),
window_(0),
config_(NULL) {
}
gfx::AcceleratedWidget NativeViewGLSurfaceGLX::GetDrawableHandle() const {
return window_;
}
bool NativeViewGLSurfaceGLX::Initialize() {
XWindowAttributes attributes;
if (!XGetWindowAttributes(g_display, parent_window_, &attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window " << parent_window_
<< ".";
return false;
}
size_ = gfx::Size(attributes.width, attributes.height);
// Create a child window, with a CopyFromParent visual (to avoid inducing
// extra blits in the driver), that we can resize exactly in Resize(),
// correctly ordered with GL, so that we don't have invalid transient states.
// See https://crbug.com/326995.
window_ = XCreateWindow(g_display,
parent_window_,
0,
0,
size_.width(),
size_.height(),
0,
CopyFromParent,
InputOutput,
CopyFromParent,
0,
NULL);
XMapWindow(g_display, window_);
ui::PlatformEventSource* event_source =
ui::PlatformEventSource::GetInstance();
// Can be NULL in tests, when we don't care about Exposes.
if (event_source) {
XSelectInput(g_display, window_, ExposureMask);
ui::PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
}
XFlush(g_display);
gfx::AcceleratedWidget window_for_vsync = window_;
if (g_glx_oml_sync_control_supported)
vsync_provider_.reset(new OMLSyncControlVSyncProvider(window_for_vsync));
else if (g_glx_sgi_video_sync_supported)
vsync_provider_.reset(new SGIVideoSyncVSyncProvider(window_for_vsync));
return true;
}
void NativeViewGLSurfaceGLX::Destroy() {
if (window_) {
ui::PlatformEventSource* event_source =
ui::PlatformEventSource::GetInstance();
if (event_source)
event_source->RemovePlatformEventDispatcher(this);
XDestroyWindow(g_display, window_);
XFlush(g_display);
}
}
bool NativeViewGLSurfaceGLX::CanDispatchEvent(const ui::PlatformEvent& event) {
return event->type == Expose && event->xexpose.window == window_;
}
uint32_t NativeViewGLSurfaceGLX::DispatchEvent(const ui::PlatformEvent& event) {
XEvent forwarded_event = *event;
forwarded_event.xexpose.window = parent_window_;
XSendEvent(g_display, parent_window_, False, ExposureMask,
&forwarded_event);
XFlush(g_display);
return ui::POST_DISPATCH_STOP_PROPAGATION;
}
bool NativeViewGLSurfaceGLX::Resize(const gfx::Size& size) {
size_ = size;
glXWaitGL();
XResizeWindow(g_display, window_, size.width(), size.height());
glXWaitX();
return true;
}
bool NativeViewGLSurfaceGLX::IsOffscreen() {
return false;
}
bool NativeViewGLSurfaceGLX::SwapBuffers() {
TRACE_EVENT2("gpu", "NativeViewGLSurfaceGLX:RealSwapBuffers",
"width", GetSize().width(),
"height", GetSize().height());
glXSwapBuffers(g_display, GetDrawableHandle());
return true;
}
gfx::Size NativeViewGLSurfaceGLX::GetSize() {
return size_;
}
void* NativeViewGLSurfaceGLX::GetHandle() {
return reinterpret_cast<void*>(GetDrawableHandle());
}
bool NativeViewGLSurfaceGLX::SupportsPostSubBuffer() {
return gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer;
}
void* NativeViewGLSurfaceGLX::GetConfig() {
if (!config_) {
// This code path is expensive, but we only take it when
// attempting to use GLX_ARB_create_context_robustness, in which
// case we need a GLXFBConfig for the window in order to create a
// context for it.
//
// TODO(kbr): this is not a reliable code path. On platforms which
// support it, we should use glXChooseFBConfig in the browser
// process to choose the FBConfig and from there the X Visual to
// use when creating the window in the first place. Then we can
// pass that FBConfig down rather than attempting to reconstitute
// it.
//
// TODO(iansf): Perhaps instead of kbr's suggestion above, we can
// now use GLSurface::GetSurfaceConfiguration to use the returned
// gfx::SurfaceConfiguration with glXChooseFBConfig in a manner
// similar to that used in NativeViewGLSurfaceEGL::GetConfig.
XWindowAttributes attributes;
if (!XGetWindowAttributes(
g_display,
window_,
&attributes)) {
LOG(ERROR) << "XGetWindowAttributes failed for window " <<
window_ << ".";
return NULL;
}
int visual_id = XVisualIDFromVisual(attributes.visual);
int num_elements = 0;
gfx::XScopedPtr<GLXFBConfig> configs(
glXGetFBConfigs(g_display, DefaultScreen(g_display), &num_elements));
if (!configs.get()) {
LOG(ERROR) << "glXGetFBConfigs failed.";
return NULL;
}
if (!num_elements) {
LOG(ERROR) << "glXGetFBConfigs returned 0 elements.";
return NULL;
}
bool found = false;
int i;
for (i = 0; i < num_elements; ++i) {
int value;
if (glXGetFBConfigAttrib(
g_display, configs.get()[i], GLX_VISUAL_ID, &value)) {
LOG(ERROR) << "glXGetFBConfigAttrib failed.";
return NULL;
}
if (value == visual_id) {
found = true;
break;
}
}
if (found) {
config_ = configs.get()[i];
}
}
return config_;
}
bool NativeViewGLSurfaceGLX::PostSubBuffer(
int x, int y, int width, int height) {
DCHECK(gfx::g_driver_glx.ext.b_GLX_MESA_copy_sub_buffer);
glXCopySubBufferMESA(g_display, GetDrawableHandle(), x, y, width, height);
return true;
}
VSyncProvider* NativeViewGLSurfaceGLX::GetVSyncProvider() {
return vsync_provider_.get();
}
NativeViewGLSurfaceGLX::~NativeViewGLSurfaceGLX() {
Destroy();
}
PbufferGLSurfaceGLX::PbufferGLSurfaceGLX(
const gfx::Size& size,
const gfx::SurfaceConfiguration& requested_configuration)
: GLSurfaceGLX(requested_configuration),
size_(size),
config_(NULL),
pbuffer_(0) {
// Some implementations of Pbuffer do not support having a 0 size. For such
// cases use a (1, 1) surface.
if (size_.GetArea() == 0)
size_.SetSize(1, 1);
}
bool PbufferGLSurfaceGLX::Initialize() {
DCHECK(!pbuffer_);
static const int config_attributes[] = {
GLX_BUFFER_SIZE, 32,
GLX_ALPHA_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_RED_SIZE, 8,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_DOUBLEBUFFER, False,
0
};
int num_elements = 0;
gfx::XScopedPtr<GLXFBConfig> configs(glXChooseFBConfig(
g_display, DefaultScreen(g_display), config_attributes, &num_elements));
if (!configs.get()) {
LOG(ERROR) << "glXChooseFBConfig failed.";
return false;
}
if (!num_elements) {
LOG(ERROR) << "glXChooseFBConfig returned 0 elements.";
return false;
}
config_ = configs.get()[0];
const int pbuffer_attributes[] = {
GLX_PBUFFER_WIDTH, size_.width(),
GLX_PBUFFER_HEIGHT, size_.height(),
0
};
pbuffer_ = glXCreatePbuffer(g_display,
static_cast<GLXFBConfig>(config_),
pbuffer_attributes);
if (!pbuffer_) {
Destroy();
LOG(ERROR) << "glXCreatePbuffer failed.";
return false;
}
return true;
}
void PbufferGLSurfaceGLX::Destroy() {
if (pbuffer_) {
glXDestroyPbuffer(g_display, pbuffer_);
pbuffer_ = 0;
}
config_ = NULL;
}
bool PbufferGLSurfaceGLX::IsOffscreen() {
return true;
}
bool PbufferGLSurfaceGLX::SwapBuffers() {
NOTREACHED() << "Attempted to call SwapBuffers on a pbuffer.";
return false;
}
gfx::Size PbufferGLSurfaceGLX::GetSize() {
return size_;
}
void* PbufferGLSurfaceGLX::GetHandle() {
return reinterpret_cast<void*>(pbuffer_);
}
void* PbufferGLSurfaceGLX::GetConfig() {
return config_;
}
PbufferGLSurfaceGLX::~PbufferGLSurfaceGLX() {
Destroy();
}
} // namespace gfx

View File

@ -1,127 +0,0 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_GL_GL_SURFACE_GLX_H_
#define UI_GL_GL_SURFACE_GLX_H_
#include <string>
#include "base/compiler_specific.h"
#include "ui/events/platform/platform_event_dispatcher.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/vsync_provider.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_export.h"
#include "ui/gl/gl_surface.h"
namespace gfx {
// Base class for GLX surfaces.
class GL_EXPORT GLSurfaceGLX : public GLSurface {
public:
explicit GLSurfaceGLX(
const gfx::SurfaceConfiguration& requested_configuration);
static bool InitializeOneOff();
// These aren't particularly tied to surfaces, but since we already
// have the static InitializeOneOff here, it's easiest to reuse its
// initialization guards.
static const char* GetGLXExtensions();
static bool HasGLXExtension(const char* name);
static bool IsCreateContextSupported();
static bool IsCreateContextRobustnessSupported();
static bool IsTextureFromPixmapSupported();
static bool IsOMLSyncControlSupported();
void* GetDisplay() override;
// Get the FB config that the surface was created with or NULL if it is not
// a GLX drawable.
void* GetConfig() override = 0;
protected:
~GLSurfaceGLX() override;
private:
DISALLOW_COPY_AND_ASSIGN(GLSurfaceGLX);
};
// A surface used to render to a view.
class GL_EXPORT NativeViewGLSurfaceGLX : public GLSurfaceGLX,
public ui::PlatformEventDispatcher {
public:
NativeViewGLSurfaceGLX(
gfx::AcceleratedWidget window,
const gfx::SurfaceConfiguration& requested_configuration);
// Implement GLSurfaceGLX.
bool Initialize() override;
void Destroy() override;
bool Resize(const gfx::Size& size) override;
bool IsOffscreen() override;
bool SwapBuffers() override;
gfx::Size GetSize() override;
void* GetHandle() override;
bool SupportsPostSubBuffer() override;
void* GetConfig() override;
bool PostSubBuffer(int x, int y, int width, int height) override;
VSyncProvider* GetVSyncProvider() override;
protected:
~NativeViewGLSurfaceGLX() override;
private:
// The handle for the drawable to make current or swap.
gfx::AcceleratedWidget GetDrawableHandle() const;
// PlatformEventDispatcher implementation
bool CanDispatchEvent(const ui::PlatformEvent& event) override;
uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
// Window passed in at creation. Always valid.
gfx::AcceleratedWidget parent_window_;
// Child window, used to control resizes so that they're in-order with GL.
gfx::AcceleratedWidget window_;
void* config_;
gfx::Size size_;
scoped_ptr<VSyncProvider> vsync_provider_;
DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLX);
};
// A surface used to render to an offscreen pbuffer.
class GL_EXPORT PbufferGLSurfaceGLX : public GLSurfaceGLX {
public:
PbufferGLSurfaceGLX(
const gfx::Size& size,
const gfx::SurfaceConfiguration& requested_configuration);
// Implement GLSurfaceGLX.
bool Initialize() override;
void Destroy() override;
bool IsOffscreen() override;
bool SwapBuffers() override;
gfx::Size GetSize() override;
void* GetHandle() override;
void* GetConfig() override;
protected:
~PbufferGLSurfaceGLX() override;
private:
gfx::Size size_;
void* config_;
XID pbuffer_;
DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceGLX);
};
} // namespace gfx
#endif // UI_GL_GL_SURFACE_GLX_H_

View File

@ -5,8 +5,7 @@
#ifndef UI_GL_GL_SURFACE_OSMESA_X11_H_
#define UI_GL_GL_SURFACE_OSMESA_X11_H_
#include <EGL/eglplatform.h> // For Pixmap
#include "third_party/khronos/EGL/eglplatform.h" // For Pixmap
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_surface.h"