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 106:9048bac046c3
prev103:9b9cfc5855e0
next108:565de331ccec
author nkeynes
date Tue Mar 14 12:45:53 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Move driver selection out to main at long last. Add video NULL driver for
headless operation
Make dcload exit() actually exit
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.3 2006-03-14 12:45:53 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 "video.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 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    34 				      int colour_format );
    35 gboolean video_gtk_display_frame( video_buffer_t frame );
    36 gboolean video_gtk_blank( uint32_t rgb );
    38 struct video_driver video_gtk_driver = { "gtk", 
    39 					 NULL,
    40 					 NULL,
    41 					 video_gtk_set_output_format,
    42 					 NULL,
    43 					 video_gtk_display_frame,
    44 					 video_gtk_blank,
    45 					 NULL };
    47 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    48 				      int colour_format )
    49 {
    50     video_width = width;
    51     video_height = height;
    52     if( video_win == NULL ) {
    53 	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    54 	gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );
    55 	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    56 	gtk_window_set_default_size( video_win, width, height );
    58 	video_area = gtk_image_new();
    59 	gtk_widget_show( GTK_WIDGET(video_area) );
    60 	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    61 	gtk_widget_show( GTK_WIDGET(video_win) );
    62 	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
    63 			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
    64 			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
    66     }
    67     gtk_window_set_default_size( video_win, width, height );
    68     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
    69 			       width, height );
    70     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
    71     /* Note old image is auto de-refed */
    72     return TRUE;
    73 }
    76 /**
    77  * Fill the entire frame with the specified colour (00RRGGBB)
    78  */
    79 gboolean video_gtk_blank( uint32_t colour ) 
    80 {
    81     char *p = video_img->mem;
    82     int i;
    83     for( i=0; i<video_width*video_height; i++ ) {
    84 	*p++ = (colour>>16) & 0xFF;
    85 	*p++ = (colour>>8) & 0xFF;
    86 	*p++ = (colour) & 0xFF;
    87 	*p++ = 0;
    88     }
    89 }
    91 gboolean video_gtk_display_frame( video_buffer_t frame ) 
    92 {
    93     uint32_t bytes_per_line, x, y;
    94     char *src = frame->data;
    95     char *dest = video_img->mem;
    97     switch( frame->colour_format ) {
    98     case COLFMT_ARGB1555:
    99 	for( y=0; y < frame->vres; y++ ) {
   100 	    uint16_t *p = (uint16_t *)src;
   101 	    for( x=0; x < frame->hres; x++ ) {
   102 		uint16_t pixel = *p++;
   103 		*dest++ = (pixel & 0x1F) << 3;
   104 		*dest++ = (pixel & 0x3E0) >> 2;
   105 		*dest++ = (pixel & 0x7C00) >> 7;
   106 		*dest++ = 0;
   107 	    }
   108 	    src += frame->rowstride;
   109 	}
   110 	break;
   111     case COLFMT_RGB565:
   112 	for( y=0; y < frame->vres; y++ ) {
   113 	    uint16_t *p = (uint16_t *)src;
   114 	    for( x=0; x < frame->hres; x++ ) {
   115 		uint16_t pixel = *p++;
   116 		*dest++ = (pixel & 0x1F) << 3;
   117 		*dest++ = (pixel & 0x7E0) >> 3;
   118 		*dest++ = (pixel & 0xF800) >> 8;
   119 		*dest++ = 0;
   120 	    }
   121 	    src += frame->rowstride;
   122 	}
   123 	break;
   124     case COLFMT_RGB888:
   125 	for( y=0; y< frame->vres; y++ ) {
   126 	    char *p = src;
   127 	    for( x=0; x < frame->hres; x++ ) {
   128 		*dest++ = *p++;
   129 		*dest++ = *p++;
   130 		*dest++ = *p++;
   131 		*dest++ = 0;
   132 	    }
   133 	    src += frame->rowstride;
   134 	}
   135 	break;
   136     case COLFMT_ARGB8888:
   137 	bytes_per_line = frame->hres << 2;
   138 	if( bytes_per_line == frame->rowstride ) {
   139 	    /* A little bit faster */
   140 	    memcpy( dest, src, bytes_per_line * frame->vres );
   141 	} else {
   142 	    for( y=0; y< frame->vres; y++ ) {
   143 		memcpy( dest, src, bytes_per_line );
   144 		src += frame->rowstride;
   145 		dest += bytes_per_line;
   146 	    }
   147 	}
   148 	break;
   149     }
   150     gtk_widget_queue_draw( video_area );
   151     return TRUE;
   152 }
.