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 94:8d80d9c7cc7d
next103:9b9cfc5855e0
author nkeynes
date Sun Feb 05 04:05:27 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Video code reshuffle to start getting real video happening.
Implement colourspace conversions
Various tweaks
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.1 2006-02-05 04:05:27 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", video_gtk_set_output_format,
    39 					 video_gtk_display_frame,
    40 					 video_gtk_blank };
    42 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    43 				      int colour_format )
    44 {
    45     video_width = width;
    46     video_height = height;
    47     if( video_win == NULL ) {
    48 	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    49 	gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );
    50 	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    51 	gtk_window_set_default_size( video_win, width, height );
    53 	video_area = gtk_image_new();
    54 	gtk_widget_show( GTK_WIDGET(video_area) );
    55 	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    56 	gtk_widget_show( GTK_WIDGET(video_win) );
    57 	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
    58 			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
    59 			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
    61     }
    62     gtk_window_set_default_size( video_win, width, height );
    63     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
    64 			       width, height );
    65     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
    66     /* Note old image is auto de-refed */
    67     return TRUE;
    68 }
    71 /**
    72  * Fill the entire frame with the specified colour (00RRGGBB)
    73  */
    74 gboolean video_gtk_blank( uint32_t colour ) 
    75 {
    76     char *p = video_img->mem;
    77     int i;
    78     for( i=0; i<video_width*video_height; i++ ) {
    79 	*p++ = (colour>>16) & 0xFF;
    80 	*p++ = (colour>>8) & 0xFF;
    81 	*p++ = (colour) & 0xFF;
    82 	*p++ = 0;
    83     }
    84 }
    86 gboolean video_gtk_display_frame( video_buffer_t frame ) 
    87 {
    88     uint32_t bytes_per_line, x, y;
    89     char *src = frame->data;
    90     char *dest = video_img->mem;
    92     switch( frame->colour_format ) {
    93     case COLFMT_RGB15:
    94 	for( y=0; y < frame->vres; y++ ) {
    95 	    uint16_t *p = (uint16_t *)src;
    96 	    for( x=0; x < frame->vres; x++ ) {
    97 		uint16_t pixel = *p++;
    98 		*dest++ = (pixel & 0x1F) << 3;
    99 		*dest++ = (pixel & 0x3E0) >> 2;
   100 		*dest++ = (pixel & 0x7C00) >> 7;
   101 		*dest++ = 0;
   102 	    }
   103 	    src += frame->rowstride;
   104 	}
   105 	break;
   106     case COLFMT_RGB16:
   107 	for( y=0; y < frame->vres; y++ ) {
   108 	    uint16_t *p = (uint16_t *)src;
   109 	    for( x=0; x < frame->vres; x++ ) {
   110 		uint16_t pixel = *p++;
   111 		*dest++ = (pixel & 0x1F) << 3;
   112 		*dest++ = (pixel & 0x7E0) >> 3;
   113 		*dest++ = (pixel & 0xF800) >> 8;
   114 		*dest++ = 0;
   115 	    }
   116 	    src += frame->rowstride;
   117 	}
   118 	break;
   119     case COLFMT_RGB32:
   120 	bytes_per_line = frame->hres << 2;
   121 	if( bytes_per_line == frame->rowstride ) {
   122 	    /* A little bit faster */
   123 	    memcpy( dest, src, bytes_per_line * frame->vres );
   124 	} else {
   125 	    for( y=0; y< frame->vres; y++ ) {
   126 		memcpy( dest, src, bytes_per_line );
   127 		src += frame->rowstride;
   128 		dest += bytes_per_line;
   129 	    }
   130 	}
   131 	break;
   132     }
   133     gtk_widget_queue_draw( video_area );
   134     return TRUE;
   135 }
.