mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 18:08:40 +02:00
graw: combine graw_init and graw_create_window functions
Different environments seem to want to create these in different orders. Abstract over this by combining the calls.
This commit is contained in:
parent
c267514470
commit
15321a55e5
3 changed files with 51 additions and 42 deletions
|
|
@ -19,20 +19,18 @@
|
|||
struct pipe_screen;
|
||||
struct pipe_context;
|
||||
|
||||
PUBLIC struct pipe_screen *graw_init( void );
|
||||
|
||||
/* Returns a handle to be used with flush_frontbuffer()/present().
|
||||
*
|
||||
* Query format support with screen::is_format_supported and usage
|
||||
* XXX.
|
||||
*/
|
||||
PUBLIC void *graw_create_window( int x,
|
||||
int y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
enum pipe_format format );
|
||||
PUBLIC struct pipe_screen *graw_create_window_and_screen( int x,
|
||||
int y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
enum pipe_format format,
|
||||
void **handle);
|
||||
|
||||
PUBLIC void graw_destroy_window( void *handle );
|
||||
PUBLIC void graw_set_display_func( void (*func)( void ) );
|
||||
PUBLIC void graw_main_loop( void );
|
||||
|
||||
|
|
|
|||
|
|
@ -32,18 +32,14 @@ static struct {
|
|||
} graw;
|
||||
|
||||
|
||||
struct pipe_screen *
|
||||
graw_init( void )
|
||||
static struct pipe_screen *
|
||||
graw_create_screen( void )
|
||||
{
|
||||
const char *default_driver;
|
||||
const char *driver;
|
||||
struct pipe_screen *screen = NULL;
|
||||
struct sw_winsys *winsys = NULL;
|
||||
|
||||
graw.display = XOpenDisplay(NULL);
|
||||
if (graw.display == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Create the underlying winsys, which performs presents to Xlib
|
||||
* drawables:
|
||||
*/
|
||||
|
|
@ -80,14 +76,16 @@ graw_init( void )
|
|||
|
||||
|
||||
|
||||
void *
|
||||
graw_create_window( int x,
|
||||
int y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
enum pipe_format format )
|
||||
struct pipe_screen *
|
||||
graw_create_window_and_screen( int x,
|
||||
int y,
|
||||
unsigned width,
|
||||
unsigned height,
|
||||
enum pipe_format format,
|
||||
void **handle)
|
||||
{
|
||||
struct xlib_drawable *handle = NULL;
|
||||
struct pipe_screen *screen = NULL;
|
||||
struct xlib_drawable *xlib_handle = NULL;
|
||||
XSetWindowAttributes attr;
|
||||
Window root;
|
||||
Window win = 0;
|
||||
|
|
@ -96,6 +94,9 @@ graw_create_window( int x,
|
|||
int n;
|
||||
int scrnum;
|
||||
|
||||
graw.display = XOpenDisplay(NULL);
|
||||
if (graw.display == NULL)
|
||||
return NULL;
|
||||
|
||||
scrnum = DefaultScreen( graw.display );
|
||||
root = RootWindow( graw.display, scrnum );
|
||||
|
|
@ -107,8 +108,8 @@ graw_create_window( int x,
|
|||
if (graw.display == NULL)
|
||||
goto fail;
|
||||
|
||||
handle = CALLOC_STRUCT(xlib_drawable);
|
||||
if (handle == NULL)
|
||||
xlib_handle = CALLOC_STRUCT(xlib_drawable);
|
||||
if (xlib_handle == NULL)
|
||||
goto fail;
|
||||
|
||||
|
||||
|
|
@ -150,7 +151,6 @@ graw_create_window( int x,
|
|||
None, (char **)NULL, 0, &sizehints);
|
||||
}
|
||||
|
||||
XFree(visinfo);
|
||||
XMapWindow(graw.display, win);
|
||||
while (1) {
|
||||
XEvent e;
|
||||
|
|
@ -160,14 +160,27 @@ graw_create_window( int x,
|
|||
}
|
||||
}
|
||||
|
||||
handle->visual = visinfo->visual;
|
||||
handle->drawable = (Drawable)win;
|
||||
handle->depth = visinfo->depth;
|
||||
return (void *)handle;
|
||||
xlib_handle->visual = visinfo->visual;
|
||||
xlib_handle->drawable = (Drawable)win;
|
||||
xlib_handle->depth = visinfo->depth;
|
||||
*handle = (void *)xlib_handle;
|
||||
|
||||
screen = graw_create_screen();
|
||||
if (screen == NULL)
|
||||
goto fail;
|
||||
|
||||
XFree(visinfo);
|
||||
return screen;
|
||||
|
||||
fail:
|
||||
FREE(handle);
|
||||
XFree(visinfo);
|
||||
if (screen)
|
||||
screen->destroy(screen);
|
||||
|
||||
if (xlib_handle)
|
||||
FREE(xlib_handle);
|
||||
|
||||
if (visinfo)
|
||||
XFree(visinfo);
|
||||
|
||||
if (win)
|
||||
XDestroyWindow(graw.display, win);
|
||||
|
|
@ -176,11 +189,6 @@ fail:
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
graw_destroy_window( void *xlib_drawable )
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
graw_set_display_func( void (*draw)( void ) )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,13 +53,20 @@ static void init( void )
|
|||
struct pipe_resource *tex, templat;
|
||||
int i;
|
||||
|
||||
/* It's hard to say whether window or screen should be created
|
||||
* first. Different environments would prefer one or the other.
|
||||
*
|
||||
* Also, no easy way of querying supported formats if the screen
|
||||
* cannot be created first.
|
||||
*/
|
||||
for (i = 0;
|
||||
window == NULL && formats[i] != PIPE_FORMAT_NONE;
|
||||
i++) {
|
||||
|
||||
window = graw_create_window(0,0,300,300, formats[i]);
|
||||
screen = graw_create_window_and_screen(0,0,300,300,
|
||||
formats[i],
|
||||
&window);
|
||||
}
|
||||
|
||||
if (window == NULL)
|
||||
exit(2);
|
||||
|
||||
|
|
@ -98,15 +105,11 @@ static void init( void )
|
|||
}
|
||||
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
screen = graw_init();
|
||||
if (screen == NULL)
|
||||
exit(1);
|
||||
|
||||
init();
|
||||
|
||||
|
||||
graw_set_display_func( draw );
|
||||
graw_main_loop();
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue