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 180:e6dcf9b65658
prev160:17c4c0e4f9ce
next335:fb890e1814c0
author nkeynes
date Sun Jul 02 04:59:00 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Merge changes made on the MILESTONE1 branch back into head (mostly
release touchups)
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.8 2006-07-02 04:59:00 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 "dream.h"
    24 #include "display.h"
    25 #include "drivers/video_x11.h"
    27 GdkImage *video_img = NULL;
    28 GtkWindow *video_win = NULL;
    29 GtkWidget *video_area = NULL;
    30 uint32_t video_width = 640;
    31 uint32_t video_height = 480;
    32 uint32_t video_frame_count = 0;
    34 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    35 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    36 				      int colour_format );
    37 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,  
    38 				      int colour_format, gboolean texture );
    39 gboolean video_gtk_display_frame( video_buffer_t frame );
    40 gboolean video_gtk_blank( uint32_t rgb );
    42 struct display_driver display_gtk_driver = { "gtk", 
    43 					   NULL,
    44 					   NULL,
    45 					   video_gtk_resolve_keysym,
    46 					   video_gtk_set_output_format,
    47 					   video_gtk_set_render_format,
    48 					   video_gtk_display_frame,
    49 					   video_gtk_blank,
    50 					   video_glx_swap_buffers };
    52 gboolean video_gtk_keydown_callback(GtkWidget       *widget,
    53 				     GdkEventKey     *event,
    54 				     gpointer         user_data)
    55 {
    56     input_event_keydown( event->keyval );
    57 }
    59 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    60 {
    61     int val = gdk_keyval_from_name( keysym );
    62     if( val == GDK_VoidSymbol )
    63 	return 0;
    64     return (uint16_t)val;
    65 }
    67 gboolean video_gtk_keyup_callback(GtkWidget       *widget,
    68 				  GdkEventKey     *event,
    69 				  gpointer         user_data)
    70 {
    71     input_event_keyup( event->keyval );
    72 }
    74 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    75 				      int colour_format )
    76 {
    77     video_width = width;
    78     video_height = height;
    79     if( video_win == NULL ) {
    80 	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    81 	gtk_window_set_title( video_win, APP_NAME " - Emulation Window" );
    82 	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    83 	gtk_window_set_default_size( video_win, width, height );
    85 	g_signal_connect( video_win, "key_press_event", 
    86 			  G_CALLBACK(video_gtk_keydown_callback), NULL );
    87 	g_signal_connect( video_win, "key_release_event", 
    88 			  G_CALLBACK(video_gtk_keyup_callback), NULL );
    89 	gtk_widget_add_events( GTK_WIDGET(video_win), 
    90 			       GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
    91 			       GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
    92 	video_area = gtk_image_new();
    93 	gtk_widget_show( GTK_WIDGET(video_area) );
    94 	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    95 	gtk_widget_show( GTK_WIDGET(video_win) );
    96 	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
    97 			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
    98 			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
   100     }
   101     gtk_window_set_default_size( video_win, width, height );
   102     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
   103 			       width, height );
   104     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
   105     /* Note old image is auto de-refed */
   106     return TRUE;
   107 }
   110 /**
   111  * Fill the entire frame with the specified colour (00RRGGBB)
   112  */
   113 gboolean video_gtk_blank( uint32_t colour ) 
   114 {
   115     video_glx_blank( video_width, video_height, colour );
   116 }
   118 gboolean video_gtk_display_frame( video_buffer_t frame ) 
   119 {
   120     uint32_t bytes_per_line, x, y;
   121     char *src = frame->data;
   122     char *dest = video_img->mem;
   124     return video_glx_display_frame( frame );
   126     switch( frame->colour_format ) {
   127     case COLFMT_ARGB1555:
   128 	for( y=0; y < frame->vres; y++ ) {
   129 	    uint16_t *p = (uint16_t *)src;
   130 	    for( x=0; x < frame->hres; x++ ) {
   131 		uint16_t pixel = *p++;
   132 		*dest++ = (pixel & 0x1F) << 3;
   133 		*dest++ = (pixel & 0x3E0) >> 2;
   134 		*dest++ = (pixel & 0x7C00) >> 7;
   135 		*dest++ = 0;
   136 	    }
   137 	    src += frame->rowstride;
   138 	}
   139 	break;
   140     case COLFMT_RGB565:
   141 	for( y=0; y < frame->vres; y++ ) {
   142 	    uint16_t *p = (uint16_t *)src;
   143 	    for( x=0; x < frame->hres; x++ ) {
   144 		uint16_t pixel = *p++;
   145 		*dest++ = (pixel & 0x1F) << 3;
   146 		*dest++ = (pixel & 0x7E0) >> 3;
   147 		*dest++ = (pixel & 0xF800) >> 8;
   148 		*dest++ = 0;
   149 	    }
   150 	    src += frame->rowstride;
   151 	}
   152 	break;
   153     case COLFMT_RGB888:
   154 	for( y=0; y< frame->vres; y++ ) {
   155 	    char *p = src;
   156 	    for( x=0; x < frame->hres; x++ ) {
   157 		*dest++ = *p++;
   158 		*dest++ = *p++;
   159 		*dest++ = *p++;
   160 		*dest++ = 0;
   161 	    }
   162 	    src += frame->rowstride;
   163 	}
   164 	break;
   165     case COLFMT_ARGB8888:
   166 	bytes_per_line = frame->hres << 2;
   167 	if( bytes_per_line == frame->rowstride ) {
   168 	    /* A little bit faster */
   169 	    memcpy( dest, src, bytes_per_line * frame->vres );
   170 	} else {
   171 	    for( y=0; y< frame->vres; y++ ) {
   172 		memcpy( dest, src, bytes_per_line );
   173 		src += frame->rowstride;
   174 		dest += bytes_per_line;
   175 	    }
   176 	}
   177 	break;
   178     }
   179     gtk_widget_queue_draw( video_area );
   180     return TRUE;
   181 }
   183 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,  
   184 				      int colour_format, gboolean texture )
   185 {
   186     return video_glx_set_render_format( 0, 0, width, height );
   187 }
.