Search
lxdream.org :: lxdream/src/drivers/video_gtk.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 352:f0df7a6d4703
prev335:fb890e1814c0
next370:3131ba1440fc
author nkeynes
date Sun Feb 11 10:09:32 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug 27: Implement opengl framebuffer objects
Rewrite much of the final video output stage. Now uses generic "render
buffers", implemented on GL using framebuffer objects + textures.
file annotate diff log raw
1.1 --- a/src/drivers/video_gtk.c Sat Jan 27 12:03:53 2007 +0000
1.2 +++ b/src/drivers/video_gtk.c Sun Feb 11 10:09:32 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: video_gtk.c,v 1.9 2007-01-27 12:03:53 nkeynes Exp $
1.6 + * $Id: video_gtk.c,v 1.10 2007-02-11 10:09:32 nkeynes Exp $
1.7 *
1.8 * The PC side of the video support (responsible for actually displaying /
1.9 * rendering frames)
1.10 @@ -29,25 +29,15 @@
1.11 GtkWidget *video_area = NULL;
1.12 uint32_t video_width = 640;
1.13 uint32_t video_height = 480;
1.14 -uint32_t video_frame_count = 0;
1.15
1.16 +gboolean video_gtk_init();
1.17 +void video_gtk_shutdown();
1.18 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
1.19 -gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,
1.20 - int colour_format );
1.21 -gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,
1.22 - int colour_format, gboolean texture );
1.23 -gboolean video_gtk_display_frame( video_buffer_t frame );
1.24 -gboolean video_gtk_blank( uint32_t rgb );
1.25
1.26 -struct display_driver display_gtk_driver = { "gtk",
1.27 - NULL,
1.28 - NULL,
1.29 - video_gtk_resolve_keysym,
1.30 - video_gtk_set_output_format,
1.31 - video_gtk_set_render_format,
1.32 - video_gtk_display_frame,
1.33 - video_gtk_blank,
1.34 - video_glx_swap_buffers };
1.35 +struct display_driver display_gtk_driver = { "gtk", video_gtk_init, NULL,
1.36 + video_gtk_resolve_keysym,
1.37 + NULL, NULL, NULL, NULL, NULL, NULL, NULL };
1.38 +
1.39
1.40 gboolean video_gtk_keydown_callback(GtkWidget *widget,
1.41 GdkEventKey *event,
1.42 @@ -71,115 +61,39 @@
1.43 input_event_keyup( event->keyval );
1.44 }
1.45
1.46 -gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,
1.47 - int colour_format )
1.48 +gboolean video_gtk_init()
1.49 {
1.50 - if( video_win == NULL ) {
1.51 - video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
1.52 - gtk_window_set_title( video_win, APP_NAME " - Emulation Window" );
1.53 - gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
1.54 - gtk_window_set_default_size( video_win, video_width, video_height );
1.55 + video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
1.56 + gtk_window_set_title( video_win, APP_NAME " - Emulation Window" );
1.57 + gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
1.58
1.59 - g_signal_connect( video_win, "key_press_event",
1.60 - G_CALLBACK(video_gtk_keydown_callback), NULL );
1.61 - g_signal_connect( video_win, "key_release_event",
1.62 - G_CALLBACK(video_gtk_keyup_callback), NULL );
1.63 - gtk_widget_add_events( GTK_WIDGET(video_win),
1.64 - GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
1.65 - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
1.66 - video_area = gtk_image_new();
1.67 - gtk_widget_show( GTK_WIDGET(video_area) );
1.68 - gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
1.69 - gtk_widget_show( GTK_WIDGET(video_win) );
1.70 - video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
1.71 - gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
1.72 - GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
1.73 -
1.74 - }
1.75 + g_signal_connect( video_win, "key_press_event",
1.76 + G_CALLBACK(video_gtk_keydown_callback), NULL );
1.77 + g_signal_connect( video_win, "key_release_event",
1.78 + G_CALLBACK(video_gtk_keyup_callback), NULL );
1.79 + gtk_widget_add_events( GTK_WIDGET(video_win),
1.80 + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
1.81 + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
1.82 + video_area = gtk_image_new();
1.83 + gtk_widget_show( GTK_WIDGET(video_area) );
1.84 + gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
1.85 + gtk_widget_show( GTK_WIDGET(video_win) );
1.86 + video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
1.87 + video_width, video_height );
1.88 + gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
1.89 +
1.90 gtk_window_set_default_size( video_win, video_width, video_height );
1.91 - video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
1.92 - video_width, video_height );
1.93 - gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
1.94 - /* Note old image is auto de-refed */
1.95 +
1.96 + video_glx_init( gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(video_win))),
1.97 + gdk_x11_screen_get_xscreen( gtk_widget_get_screen(GTK_WIDGET(video_win))),
1.98 + GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ),
1.99 + video_width, video_height, &display_gtk_driver );
1.100 return TRUE;
1.101 }
1.102
1.103 +void video_gtk_shutdown()
1.104 +{
1.105
1.106 -/**
1.107 - * Fill the entire frame with the specified colour (00RRGGBB)
1.108 - */
1.109 -gboolean video_gtk_blank( uint32_t colour )
1.110 -{
1.111 - video_glx_blank( video_width, video_height, colour );
1.112 +
1.113 }
1.114
1.115 -gboolean video_gtk_display_frame( video_buffer_t frame )
1.116 -{
1.117 - uint32_t bytes_per_line, x, y;
1.118 - char *src = frame->data;
1.119 - char *dest = video_img->mem;
1.120 -
1.121 - return video_glx_display_frame( frame );
1.122 -
1.123 - switch( frame->colour_format ) {
1.124 - case COLFMT_ARGB1555:
1.125 - for( y=0; y < frame->vres; y++ ) {
1.126 - uint16_t *p = (uint16_t *)src;
1.127 - for( x=0; x < frame->hres; x++ ) {
1.128 - uint16_t pixel = *p++;
1.129 - *dest++ = (pixel & 0x1F) << 3;
1.130 - *dest++ = (pixel & 0x3E0) >> 2;
1.131 - *dest++ = (pixel & 0x7C00) >> 7;
1.132 - *dest++ = 0;
1.133 - }
1.134 - src += frame->rowstride;
1.135 - }
1.136 - break;
1.137 - case COLFMT_RGB565:
1.138 - for( y=0; y < frame->vres; y++ ) {
1.139 - uint16_t *p = (uint16_t *)src;
1.140 - for( x=0; x < frame->hres; x++ ) {
1.141 - uint16_t pixel = *p++;
1.142 - *dest++ = (pixel & 0x1F) << 3;
1.143 - *dest++ = (pixel & 0x7E0) >> 3;
1.144 - *dest++ = (pixel & 0xF800) >> 8;
1.145 - *dest++ = 0;
1.146 - }
1.147 - src += frame->rowstride;
1.148 - }
1.149 - break;
1.150 - case COLFMT_RGB888:
1.151 - for( y=0; y< frame->vres; y++ ) {
1.152 - char *p = src;
1.153 - for( x=0; x < frame->hres; x++ ) {
1.154 - *dest++ = *p++;
1.155 - *dest++ = *p++;
1.156 - *dest++ = *p++;
1.157 - *dest++ = 0;
1.158 - }
1.159 - src += frame->rowstride;
1.160 - }
1.161 - break;
1.162 - case COLFMT_ARGB8888:
1.163 - bytes_per_line = frame->hres << 2;
1.164 - if( bytes_per_line == frame->rowstride ) {
1.165 - /* A little bit faster */
1.166 - memcpy( dest, src, bytes_per_line * frame->vres );
1.167 - } else {
1.168 - for( y=0; y< frame->vres; y++ ) {
1.169 - memcpy( dest, src, bytes_per_line );
1.170 - src += frame->rowstride;
1.171 - dest += bytes_per_line;
1.172 - }
1.173 - }
1.174 - break;
1.175 - }
1.176 - gtk_widget_queue_draw( video_area );
1.177 - return TRUE;
1.178 -}
1.179 -
1.180 -gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,
1.181 - int colour_format, gboolean texture )
1.182 -{
1.183 - return video_glx_set_render_format( 0, 0, width, height );
1.184 -}
.