Search
lxdream.org :: lxdream/src/drivers/video_gtk.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/drivers/video_gtk.c
changeset 160:17c4c0e4f9ce
prev144:7f0714e89aaa
next180:e6dcf9b65658
author nkeynes
date Sun Jun 18 11:55:25 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Change video blank to use GL, ie to actually work
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.7 2006-06-18 11:55:25 nkeynes Exp $
     3  *
     4  * The PC side of the video support (responsible for actually displaying / 
     5  * rendering frames)
     6  *
     7  * Copyright (c) 2005 Nathan Keynes.
     8  *
     9  * This program is free software; you can redistribute it and/or modify
    10  * it under the terms of the GNU General Public License as published by
    11  * the Free Software Foundation; either version 2 of the License, or
    12  * (at your option) any later version.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  */
    20 #include <gnome.h>
    21 #include <gdk/gdkx.h>
    22 #include <stdint.h>
    23 #include "display.h"
    24 #include "drivers/video_x11.h"
    26 GdkImage *video_img = NULL;
    27 GtkWindow *video_win = NULL;
    28 GtkWidget *video_area = NULL;
    29 uint32_t video_width = 640;
    30 uint32_t video_height = 480;
    31 uint32_t video_frame_count = 0;
    33 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    34 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    35 				      int colour_format );
    36 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,  
    37 				      int colour_format, gboolean texture );
    38 gboolean video_gtk_display_frame( video_buffer_t frame );
    39 gboolean video_gtk_blank( uint32_t rgb );
    41 struct display_driver display_gtk_driver = { "gtk", 
    42 					   NULL,
    43 					   NULL,
    44 					   video_gtk_resolve_keysym,
    45 					   video_gtk_set_output_format,
    46 					   video_gtk_set_render_format,
    47 					   video_gtk_display_frame,
    48 					   video_gtk_blank,
    49 					   video_glx_swap_buffers };
    51 gboolean video_gtk_keydown_callback(GtkWidget       *widget,
    52 				     GdkEventKey     *event,
    53 				     gpointer         user_data)
    54 {
    55     input_event_keydown( event->keyval );
    56 }
    58 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    59 {
    60     int val = gdk_keyval_from_name( keysym );
    61     if( val == GDK_VoidSymbol )
    62 	return 0;
    63     return (uint16_t)val;
    64 }
    66 gboolean video_gtk_keyup_callback(GtkWidget       *widget,
    67 				  GdkEventKey     *event,
    68 				  gpointer         user_data)
    69 {
    70     input_event_keyup( event->keyval );
    71 }
    73 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    74 				      int colour_format )
    75 {
    76     video_width = width;
    77     video_height = height;
    78     if( video_win == NULL ) {
    79 	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    80 	gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );
    81 	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    82 	gtk_window_set_default_size( video_win, width, height );
    84 	g_signal_connect( video_win, "key_press_event", 
    85 			  G_CALLBACK(video_gtk_keydown_callback), NULL );
    86 	g_signal_connect( video_win, "key_release_event", 
    87 			  G_CALLBACK(video_gtk_keyup_callback), NULL );
    88 	gtk_widget_add_events( GTK_WIDGET(video_win), 
    89 			       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
    90 			       GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
    91 	video_area = gtk_image_new();
    92 	gtk_widget_show( GTK_WIDGET(video_area) );
    93 	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    94 	gtk_widget_show( GTK_WIDGET(video_win) );
    95 	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
    96 			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
    97 			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
    99     }
   100     gtk_window_set_default_size( video_win, width, height );
   101     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
   102 			       width, height );
   103     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
   104     /* Note old image is auto de-refed */
   105     return TRUE;
   106 }
   109 /**
   110  * Fill the entire frame with the specified colour (00RRGGBB)
   111  */
   112 gboolean video_gtk_blank( uint32_t colour ) 
   113 {
   114     video_glx_blank( video_width, video_height, colour );
   115 }
   117 gboolean video_gtk_display_frame( video_buffer_t frame ) 
   118 {
   119     uint32_t bytes_per_line, x, y;
   120     char *src = frame->data;
   121     char *dest = video_img->mem;
   123     return video_glx_display_frame( frame );
   125     switch( frame->colour_format ) {
   126     case COLFMT_ARGB1555:
   127 	for( y=0; y < frame->vres; y++ ) {
   128 	    uint16_t *p = (uint16_t *)src;
   129 	    for( x=0; x < frame->hres; x++ ) {
   130 		uint16_t pixel = *p++;
   131 		*dest++ = (pixel & 0x1F) << 3;
   132 		*dest++ = (pixel & 0x3E0) >> 2;
   133 		*dest++ = (pixel & 0x7C00) >> 7;
   134 		*dest++ = 0;
   135 	    }
   136 	    src += frame->rowstride;
   137 	}
   138 	break;
   139     case COLFMT_RGB565:
   140 	for( y=0; y < frame->vres; y++ ) {
   141 	    uint16_t *p = (uint16_t *)src;
   142 	    for( x=0; x < frame->hres; x++ ) {
   143 		uint16_t pixel = *p++;
   144 		*dest++ = (pixel & 0x1F) << 3;
   145 		*dest++ = (pixel & 0x7E0) >> 3;
   146 		*dest++ = (pixel & 0xF800) >> 8;
   147 		*dest++ = 0;
   148 	    }
   149 	    src += frame->rowstride;
   150 	}
   151 	break;
   152     case COLFMT_RGB888:
   153 	for( y=0; y< frame->vres; y++ ) {
   154 	    char *p = src;
   155 	    for( x=0; x < frame->hres; x++ ) {
   156 		*dest++ = *p++;
   157 		*dest++ = *p++;
   158 		*dest++ = *p++;
   159 		*dest++ = 0;
   160 	    }
   161 	    src += frame->rowstride;
   162 	}
   163 	break;
   164     case COLFMT_ARGB8888:
   165 	bytes_per_line = frame->hres << 2;
   166 	if( bytes_per_line == frame->rowstride ) {
   167 	    /* A little bit faster */
   168 	    memcpy( dest, src, bytes_per_line * frame->vres );
   169 	} else {
   170 	    for( y=0; y< frame->vres; y++ ) {
   171 		memcpy( dest, src, bytes_per_line );
   172 		src += frame->rowstride;
   173 		dest += bytes_per_line;
   174 	    }
   175 	}
   176 	break;
   177     }
   178     gtk_widget_queue_draw( video_area );
   179     return TRUE;
   180 }
   182 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,  
   183 				      int colour_format, gboolean texture )
   184 {
   185     return video_glx_set_render_format( 0, 0, width, height );
   186 }
.