Made vie_auto_test more robust in Linux when the X environment is broken.
BUG= TEST= Review URL: http://webrtc-codereview.appspot.com/329025 git-svn-id: http://webrtc.googlecode.com/svn/trunk@1354 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
0c0216f3f6
commit
dc9536dd0e
@ -66,58 +66,61 @@ int ViEAutoTestWindowManager::CreateWindows(AutoTestRect window1Size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ViEAutoTestWindowManager::ViECreateWindow(Window *outWindow,
|
int ViEAutoTestWindowManager::ViECreateWindow(Window *out_window,
|
||||||
Display **outDisplay, int xpos,
|
Display **out_display, int x_pos,
|
||||||
int ypos, int width, int height,
|
int y_pos, int width, int height,
|
||||||
char* title) {
|
char* title) {
|
||||||
int screen;
|
Display* display = XOpenDisplay(NULL);
|
||||||
XEvent evnt;
|
if (display == NULL) {
|
||||||
XSetWindowAttributes xswa; // window attribute struct
|
// There's no point to continue if this happens: nothing will work anyway.
|
||||||
XVisualInfo vinfo; // screen visual info struct
|
printf("Failed to connect to X server: X environment likely broken\n");
|
||||||
unsigned long mask; // attribute mask
|
exit(-1);
|
||||||
|
|
||||||
// get connection handle to xserver
|
|
||||||
Display* _display = XOpenDisplay(NULL);
|
|
||||||
|
|
||||||
// get screen number
|
|
||||||
screen = DefaultScreen(_display);
|
|
||||||
|
|
||||||
// put desired visual info for the screen in vinfo
|
|
||||||
// TODO(unknown): more display settings should be allowed
|
|
||||||
if (XMatchVisualInfo(_display, screen, 24, TrueColor, &vinfo) != 0) {
|
|
||||||
// printf( "Screen visual info match!\n" );
|
|
||||||
}
|
}
|
||||||
// set window attributes
|
|
||||||
xswa.colormap = XCreateColormap(_display, DefaultRootWindow(_display),
|
|
||||||
vinfo.visual, AllocNone);
|
|
||||||
xswa.event_mask = StructureNotifyMask | ExposureMask;
|
|
||||||
xswa.background_pixel = 0;
|
|
||||||
xswa.border_pixel = 0;
|
|
||||||
|
|
||||||
// value mask for attributes
|
int screen = DefaultScreen(display);
|
||||||
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
||||||
|
|
||||||
Window _window = XCreateWindow(_display, DefaultRootWindow(_display), xpos,
|
// Try to establish a 24-bit TrueColor display
|
||||||
ypos, width, height, 0, vinfo.depth,
|
// (our environment must allow this).
|
||||||
InputOutput, vinfo.visual, mask, &xswa);
|
XVisualInfo visual_info;
|
||||||
|
if (XMatchVisualInfo(display, screen, 24, TrueColor, &visual_info) == 0) {
|
||||||
|
printf("Failed to establish 24-bit TrueColor in X environment.\n");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
// Set window name
|
// Create suitable window attributes.
|
||||||
XStoreName(_display, _window, title);
|
XSetWindowAttributes window_attributes;
|
||||||
XSetIconName(_display, _window, title);
|
window_attributes.colormap = XCreateColormap(
|
||||||
|
display, DefaultRootWindow(display), visual_info.visual, AllocNone);
|
||||||
|
window_attributes.event_mask = StructureNotifyMask | ExposureMask;
|
||||||
|
window_attributes.background_pixel = 0;
|
||||||
|
window_attributes.border_pixel = 0;
|
||||||
|
|
||||||
// make x report events for mask
|
unsigned long attribute_mask = CWBackPixel | CWBorderPixel | CWColormap |
|
||||||
XSelectInput(_display, _window, StructureNotifyMask);
|
CWEventMask;
|
||||||
|
|
||||||
// map the window to the display
|
Window _window = XCreateWindow(display, DefaultRootWindow(display), x_pos,
|
||||||
XMapWindow(_display, _window);
|
y_pos, width, height, 0, visual_info.depth,
|
||||||
|
InputOutput, visual_info.visual,
|
||||||
|
attribute_mask, &window_attributes);
|
||||||
|
|
||||||
// wait for map event
|
// Set window name.
|
||||||
|
XStoreName(display, _window, title);
|
||||||
|
XSetIconName(display, _window, title);
|
||||||
|
|
||||||
|
// Make x report events for mask.
|
||||||
|
XSelectInput(display, _window, StructureNotifyMask);
|
||||||
|
|
||||||
|
// Map the window to the display.
|
||||||
|
XMapWindow(display, _window);
|
||||||
|
|
||||||
|
// Wait for map event.
|
||||||
|
XEvent event;
|
||||||
do {
|
do {
|
||||||
XNextEvent(_display, &evnt);
|
XNextEvent(display, &event);
|
||||||
} while (evnt.type != MapNotify || evnt.xmap.event != _window);
|
} while (event.type != MapNotify || event.xmap.event != _window);
|
||||||
|
|
||||||
*outWindow = _window;
|
*out_window = _window;
|
||||||
*outDisplay = _display;
|
*out_display = display;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user