Remove X11-specific stuff from egldisplay, instead using x11display as common base

This commit is contained in:
rdb 2016-03-19 18:46:10 +01:00
parent bd1df2b9ad
commit 2abad9649b
10 changed files with 19 additions and 1764 deletions

View File

@ -4539,8 +4539,7 @@ if (PkgSkip("EGL")==0 and PkgSkip("GLES")==0 and PkgSkip("X11")==0 and not RUNTI
TargetAdd('pandagles_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx')
OPTS=['DIR:panda/metalibs/pandagles', 'BUILDING:PANDAGLES', 'GLES', 'EGL']
TargetAdd('pandagles_pandagles.obj', opts=OPTS, input='pandagles.cxx')
# Uncomment this as soon as x11-specific stuff is removed from p3egldisplay
#TargetAdd('libpandagles.dll', input='p3x11display_composite1.obj')
TargetAdd('libpandagles.dll', input='p3x11display_composite1.obj')
TargetAdd('libpandagles.dll', input='pandagles_pandagles.obj')
TargetAdd('libpandagles.dll', input='p3glesgsg_config_glesgsg.obj')
TargetAdd('libpandagles.dll', input='p3glesgsg_glesgsg.obj')
@ -4558,8 +4557,7 @@ if (PkgSkip("EGL")==0 and PkgSkip("GLES2")==0 and PkgSkip("X11")==0 and not RUNT
TargetAdd('pandagles2_egldisplay_composite1.obj', opts=OPTS, input='p3egldisplay_composite1.cxx')
OPTS=['DIR:panda/metalibs/pandagles2', 'BUILDING:PANDAGLES2', 'GLES2', 'EGL']
TargetAdd('pandagles2_pandagles2.obj', opts=OPTS, input='pandagles2.cxx')
# Uncomment this as soon as x11-specific stuff is removed from p3egldisplay
#TargetAdd('libpandagles2.dll', input='p3x11display_composite1.obj')
TargetAdd('libpandagles2.dll', input='p3x11display_composite1.obj')
TargetAdd('libpandagles2.dll', input='pandagles2_pandagles2.obj')
TargetAdd('libpandagles2.dll', input='p3gles2gsg_config_gles2gsg.obj')
TargetAdd('libpandagles2.dll', input='p3gles2gsg_gles2gsg.obj')

View File

@ -26,41 +26,6 @@ ConfigureFn(config_egldisplay) {
init_libegldisplay();
}
ConfigVariableString display_cfg
("display", "",
PRC_DESC("Specify the X display string for the default display. If this "
"is not specified, $DISPLAY is used."));
ConfigVariableBool x_error_abort
("x-error-abort", false,
PRC_DESC("Set this true to trigger and abort (and a stack trace) on receipt "
"of an error from the X window system. This can make it easier "
"to discover where these errors are generated."));
ConfigVariableInt x_wheel_up_button
("x-wheel-up-button", 4,
PRC_DESC("This is the mouse button index of the wheel_up event: which "
"mouse button number does the system report when the mouse wheel "
"is rolled one notch up?"));
ConfigVariableInt x_wheel_down_button
("x-wheel-down-button", 5,
PRC_DESC("This is the mouse button index of the wheel_down event: which "
"mouse button number does the system report when the mouse wheel "
"is rolled one notch down?"));
ConfigVariableInt x_wheel_left_button
("x-wheel-left-button", 6,
PRC_DESC("This is the mouse button index of the wheel_left event: which "
"mouse button number does the system report when one scrolls "
"to the left?"));
ConfigVariableInt x_wheel_right_button
("x-wheel-right-button", 7,
PRC_DESC("This is the mouse button index of the wheel_right event: which "
"mouse button number does the system report when one scrolls "
"to the right?"));
/**
* Initializes the library. This must be called at least once before any of
* the functions or classes in this library can be used. Normally it will be

View File

@ -39,12 +39,4 @@
extern EXPCL_PANDAGLES const string get_egl_error_string(int error);
#endif
extern ConfigVariableString display_cfg;
extern ConfigVariableBool x_error_abort;
extern ConfigVariableInt x_wheel_up_button;
extern ConfigVariableInt x_wheel_down_button;
extern ConfigVariableInt x_wheel_left_button;
extern ConfigVariableInt x_wheel_right_button;
#endif

View File

@ -10,49 +10,3 @@
* @author rdb
* @date 2009-05-21
*/
/**
* Returns a pointer to the X display associated with the pipe: the display on
* which to create the windows.
*/
INLINE X11_Display *eglGraphicsPipe::
get_display() const {
return _display;
}
/**
* Returns the X screen number associated with the pipe.
*/
INLINE int eglGraphicsPipe::
get_screen() const {
return _screen;
}
/**
* Returns the handle to the root window on the pipe's display.
*/
INLINE X11_Window eglGraphicsPipe::
get_root() const {
return _root;
}
/**
* Returns the input method opened for the pipe, or NULL if the input method
* could not be opened for some reason.
*/
INLINE XIM eglGraphicsPipe::
get_im() const {
return _im;
}
/**
* Returns an invisible Cursor suitable for assigning to windows that have the
* cursor_hidden property set.
*/
INLINE X11_Cursor eglGraphicsPipe::
get_hidden_cursor() {
if (_hidden_cursor == None) {
make_hidden_cursor();
}
return _hidden_cursor;
}

View File

@ -21,67 +21,11 @@
TypeHandle eglGraphicsPipe::_type_handle;
bool eglGraphicsPipe::_error_handlers_installed = false;
eglGraphicsPipe::ErrorHandlerFunc *eglGraphicsPipe::_prev_error_handler;
eglGraphicsPipe::IOErrorHandlerFunc *eglGraphicsPipe::_prev_io_error_handler;
LightReMutex eglGraphicsPipe::_x_mutex;
/**
*
*/
eglGraphicsPipe::
eglGraphicsPipe(const string &display) {
string display_spec = display;
if (display_spec.empty()) {
display_spec = display_cfg;
}
if (display_spec.empty()) {
display_spec = ExecutionEnvironment::get_environment_variable("DISPLAY");
}
if (display_spec.empty()) {
display_spec = ":0.0";
}
// The X docs say we should do this to get international character support
// from the keyboard.
setlocale(LC_ALL, "");
// But it's important that we use the "C" locale for numeric formatting,
// since all of the internal Panda code assumes this--we need a decimal
// point to mean a decimal point.
setlocale(LC_NUMERIC, "C");
_is_valid = false;
_supported_types = OT_window | OT_buffer | OT_texture_buffer;
_display = NULL;
_screen = 0;
_root = (X11_Window)NULL;
_im = (XIM)NULL;
_hidden_cursor = None;
_egl_display = NULL;
install_error_handlers();
_display = XOpenDisplay(display_spec.c_str());
if (!_display) {
egldisplay_cat.error()
<< "Could not open display \"" << display_spec << "\".\n";
return;
}
if (!XSupportsLocale()) {
egldisplay_cat.warning()
<< "X does not support locale " << setlocale(LC_ALL, NULL) << "\n";
}
XSetLocaleModifiers("");
_screen = DefaultScreen(_display);
_root = RootWindow(_display, _screen);
_display_width = DisplayWidth(_display, _screen);
_display_height = DisplayHeight(_display, _screen);
_is_valid = true;
eglGraphicsPipe(const string &display) : x11GraphicsPipe(display) {
_egl_display = eglGetDisplay((NativeDisplayType) _display);
if (!eglInitialize(_egl_display, NULL, NULL)) {
egldisplay_cat.error()
@ -94,38 +38,6 @@ eglGraphicsPipe(const string &display) {
<< "Couldn't bind EGL to the OpenGL ES API: "
<< get_egl_error_string(eglGetError()) << "\n";
}
// Connect to an input method for supporting international text entry.
_im = XOpenIM(_display, NULL, NULL, NULL);
if (_im == (XIM)NULL) {
egldisplay_cat.warning()
<< "Couldn't open input method.\n";
}
// What styles does the current input method support?
/*
XIMStyles *im_supported_styles;
XGetIMValues(_im, XNQueryInputStyle, &im_supported_styles, NULL);
for (int i = 0; i < im_supported_styles->count_styles; i++) {
XIMStyle style = im_supported_styles->supported_styles[i];
cerr << "style " << i << ". " << hex << style << dec << "\n";
}
XFree(im_supported_styles);
*/
// Get some X atom numbers.
_wm_delete_window = XInternAtom(_display, "WM_DELETE_WINDOW", false);
_net_wm_window_type = XInternAtom(_display, "_NET_WM_WINDOW_TYPE", false);
_net_wm_window_type_splash = XInternAtom(_display, "_NET_WM_WINDOW_TYPE_SPLASH", false);
_net_wm_window_type_fullscreen = XInternAtom(_display, "_NET_WM_WINDOW_TYPE_FULLSCREEN", false);
_net_wm_state = XInternAtom(_display, "_NET_WM_STATE", false);
_net_wm_state_fullscreen = XInternAtom(_display, "_NET_WM_STATE_FULLSCREEN", false);
_net_wm_state_above = XInternAtom(_display, "_NET_WM_STATE_ABOVE", false);
_net_wm_state_below = XInternAtom(_display, "_NET_WM_STATE_BELOW", false);
_net_wm_state_add = XInternAtom(_display, "_NET_WM_STATE_ADD", false);
_net_wm_state_remove = XInternAtom(_display, "_NET_WM_STATE_REMOVE", false);
}
/**
@ -133,13 +45,6 @@ eglGraphicsPipe(const string &display) {
*/
eglGraphicsPipe::
~eglGraphicsPipe() {
release_hidden_cursor();
if (_im) {
XCloseIM(_im);
}
if (_display) {
XCloseDisplay(_display);
}
if (_egl_display) {
if (!eglTerminate(_egl_display)) {
egldisplay_cat.error() << "Failed to terminate EGL display: "
@ -168,26 +73,6 @@ pipe_constructor() {
return new eglGraphicsPipe;
}
/**
* Returns an indication of the thread in which this GraphicsPipe requires its
* window processing to be performed: typically either the app thread (e.g.
* X) or the draw thread (Windows).
*/
GraphicsPipe::PreferredWindowThread
eglGraphicsPipe::get_preferred_window_thread() const {
// Actually, since we're creating the graphics context in open_window() now,
// it appears we need to ensure the open_window() call is performed in the
// draw thread for now, even though X wants all of its calls to be single-
// threaded.
// This means that all X windows may have to be handled by the same draw
// thread, which we didn't intend (though the global _x_mutex may allow them
// to be technically served by different threads, even though the actual X
// calls will be serialized). There might be a better way.
return PWT_draw;
}
/**
* Creates a new window on the pipe, if possible.
*/
@ -318,89 +203,3 @@ make_output(const string &name,
// Nothing else left to try.
return NULL;
}
/**
* Called once to make an invisible Cursor for return from
* get_hidden_cursor().
*/
void eglGraphicsPipe::
make_hidden_cursor() {
nassertv(_hidden_cursor == None);
unsigned int x_size, y_size;
XQueryBestCursor(_display, _root, 1, 1, &x_size, &y_size);
Pixmap empty = XCreatePixmap(_display, _root, x_size, y_size, 1);
XColor black;
memset(&black, 0, sizeof(black));
_hidden_cursor = XCreatePixmapCursor(_display, empty, empty,
&black, &black, x_size, y_size);
XFreePixmap(_display, empty);
}
/**
* Called once to release the invisible cursor created by
* make_hidden_cursor().
*/
void eglGraphicsPipe::
release_hidden_cursor() {
if (_hidden_cursor != None) {
XFreeCursor(_display, _hidden_cursor);
_hidden_cursor = None;
}
}
/**
* Installs new Xlib error handler functions if this is the first time this
* function has been called. These error handler functions will attempt to
* reduce Xlib's annoying tendency to shut down the client at the first error.
* Unfortunately, it is difficult to play nice with the client if it has
* already installed its own error handlers.
*/
void eglGraphicsPipe::
install_error_handlers() {
if (_error_handlers_installed) {
return;
}
_prev_error_handler = (ErrorHandlerFunc *)XSetErrorHandler(error_handler);
_prev_io_error_handler = (IOErrorHandlerFunc *)XSetIOErrorHandler(io_error_handler);
_error_handlers_installed = true;
}
/**
* This function is installed as the error handler for a non-fatal Xlib error.
*/
int eglGraphicsPipe::
error_handler(X11_Display *display, XErrorEvent *error) {
static const int msg_len = 80;
char msg[msg_len];
XGetErrorText(display, error->error_code, msg, msg_len);
egldisplay_cat.error()
<< msg << "\n";
if (x_error_abort) {
abort();
}
// We return to allow the application to continue running, unlike the
// default X error handler which exits.
return 0;
}
/**
* This function is installed as the error handler for a fatal Xlib error.
*/
int eglGraphicsPipe::
io_error_handler(X11_Display *display) {
egldisplay_cat.fatal()
<< "X fatal error on display " << (void *)display << "\n";
// Unfortunately, we can't continue from this function, even if we promise
// never to use X again. We're supposed to terminate without returning, and
// if we do return, the caller will exit anyway. Sigh. Very poor design on
// X's part.
return 0;
}

View File

@ -15,11 +15,7 @@
#define EGLGRAPHICSPIPE_H
#include "pandabase.h"
#include "graphicsWindow.h"
#include "graphicsPipe.h"
#include "lightMutex.h"
#include "lightReMutex.h"
#include "get_x11.h"
#include "x11GraphicsPipe.h"
#ifdef OPENGLES_2
#include "gles2gsg.h"
@ -46,7 +42,7 @@ class eglGraphicsWindow;
* This graphics pipe represents the interface for creating OpenGL ES graphics
* windows on an X-based (e.g. Unix) client.
*/
class eglGraphicsPipe : public GraphicsPipe {
class eglGraphicsPipe : public x11GraphicsPipe {
public:
eglGraphicsPipe(const string &display = string());
virtual ~eglGraphicsPipe();
@ -54,29 +50,6 @@ public:
virtual string get_interface_name() const;
static PT(GraphicsPipe) pipe_constructor();
INLINE X11_Display *get_display() const;
INLINE int get_screen() const;
INLINE X11_Window get_root() const;
INLINE XIM get_im() const;
INLINE X11_Cursor get_hidden_cursor();
public:
virtual PreferredWindowThread get_preferred_window_thread() const;
public:
// Atom specifications.
Atom _wm_delete_window;
Atom _net_wm_window_type;
Atom _net_wm_window_type_splash;
Atom _net_wm_window_type_fullscreen;
Atom _net_wm_state;
Atom _net_wm_state_fullscreen;
Atom _net_wm_state_above;
Atom _net_wm_state_below;
Atom _net_wm_state_add;
Atom _net_wm_state_remove;
protected:
virtual PT(GraphicsOutput) make_output(const string &name,
const FrameBufferProperties &fb_prop,
@ -89,40 +62,16 @@ protected:
bool &precertify);
private:
void make_hidden_cursor();
void release_hidden_cursor();
static void install_error_handlers();
static int error_handler(X11_Display *display, XErrorEvent *error);
static int io_error_handler(X11_Display *display);
X11_Display *_display;
int _screen;
X11_Window _root;
XIM _im;
EGLDisplay _egl_display;
X11_Cursor _hidden_cursor;
typedef int ErrorHandlerFunc(X11_Display *, XErrorEvent *);
typedef int IOErrorHandlerFunc(X11_Display *);
static bool _error_handlers_installed;
static ErrorHandlerFunc *_prev_error_handler;
static IOErrorHandlerFunc *_prev_io_error_handler;
public:
// This Mutex protects any X library calls, which all have to be single-
// threaded. In particular, it protects eglMakeCurrent().
static LightReMutex _x_mutex;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
GraphicsPipe::init_type();
x11GraphicsPipe::init_type();
register_type(_type_handle, "eglGraphicsPipe",
GraphicsPipe::get_class_type());
x11GraphicsPipe::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();

View File

@ -257,8 +257,9 @@ reset() {
// If "Mesa" is present, assume software. However, if "Mesa DRI" is found,
// it's actually a Mesa-based OpenGL layer running over a hardware driver.
if (_gl_renderer.find("Mesa") != string::npos &&
_gl_renderer.find("Mesa DRI") == string::npos) {
if (_gl_renderer == "Software Rasterizer" ||
(_gl_renderer.find("Mesa") != string::npos &&
_gl_renderer.find("Mesa DRI") == string::npos)) {
// It's Mesa, therefore probably a software context.
_fbprops.set_force_software(1);
_fbprops.set_force_hardware(0);

View File

@ -10,11 +10,3 @@
* @author rdb
* @date 2009-05-21
*/
/**
* Returns the X11 Window handle.
*/
INLINE X11_Window eglGraphicsWindow::
get_xwindow() const {
return _xwindow;
}

File diff suppressed because it is too large Load Diff

View File

@ -17,14 +17,12 @@
#include "pandabase.h"
#include "eglGraphicsPipe.h"
#include "graphicsWindow.h"
#include "buttonHandle.h"
#include "get_x11.h"
#include "x11GraphicsWindow.h"
/**
* An interface to the egl system for managing GLES windows under X.
*/
class eglGraphicsWindow : public GraphicsWindow {
class eglGraphicsWindow : public x11GraphicsWindow {
public:
eglGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
const string &name,
@ -40,70 +38,22 @@ public:
virtual void end_frame(FrameMode mode, Thread *current_thread);
virtual void end_flip();
virtual void process_events();
virtual void set_properties_now(WindowProperties &properties);
INLINE X11_Window get_xwindow() const;
protected:
virtual void close_window();
virtual bool open_window();
private:
void set_wm_properties(const WindowProperties &properties,
bool already_mapped);
void setup_colormap(XVisualInfo *visual);
void handle_keystroke(XKeyEvent &event);
void handle_keypress(XKeyEvent &event);
void handle_keyrelease(XKeyEvent &event);
ButtonHandle get_button(XKeyEvent &key_event, bool allow_shift);
ButtonHandle map_button(KeySym key);
ButtonHandle get_mouse_button(XButtonEvent &button_event);
static Bool check_event(X11_Display *display, XEvent *event, char *arg);
void open_raw_mice();
void poll_raw_mice();
private:
X11_Display *_display;
int _screen;
X11_Window _xwindow;
Colormap _colormap;
XIC _ic;
EGLDisplay _egl_display;
EGLSurface _egl_surface;
long _event_mask;
bool _awaiting_configure;
Atom _wm_delete_window;
Atom _net_wm_window_type;
Atom _net_wm_window_type_splash;
Atom _net_wm_window_type_fullscreen;
Atom _net_wm_state;
Atom _net_wm_state_fullscreen;
Atom _net_wm_state_above;
Atom _net_wm_state_below;
Atom _net_wm_state_add;
Atom _net_wm_state_remove;
struct MouseDeviceInfo {
int _fd;
int _input_device_index;
string _io_buffer;
};
pvector<MouseDeviceInfo> _mouse_device_info;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
GraphicsWindow::init_type();
x11GraphicsWindow::init_type();
register_type(_type_handle, "eglGraphicsWindow",
GraphicsWindow::get_class_type());
x11GraphicsWindow::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();