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 112:a3008ac0765a
prev108:565de331ccec
next144:7f0714e89aaa
author nkeynes
date Thu Mar 16 12:42:28 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Use GL to display frames
view annotate diff log raw
     1 /**
     2  * $Id: video_gtk.c,v 1.5 2006-03-16 12:42:28 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_set_render_format( uint32_t width, uint32_t height,  
    36 				      int colour_format );
    37 gboolean video_gtk_display_frame( video_buffer_t frame );
    38 gboolean video_gtk_blank( uint32_t rgb );
    40 struct video_driver video_gtk_driver = { "gtk", 
    41 					 NULL,
    42 					 NULL,
    43 					 video_gtk_set_output_format,
    44 					 video_gtk_set_render_format,
    45 					 video_gtk_display_frame,
    46 					 video_gtk_blank,
    47 					 video_glx_swap_buffers };
    49 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
    50 				      int colour_format )
    51 {
    52     video_width = width;
    53     video_height = height;
    54     if( video_win == NULL ) {
    55 	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
    56 	gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );
    57 	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
    58 	gtk_window_set_default_size( video_win, width, height );
    60 	video_area = gtk_image_new();
    61 	gtk_widget_show( GTK_WIDGET(video_area) );
    62 	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
    63 	gtk_widget_show( GTK_WIDGET(video_win) );
    64 	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
    65 			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
    66 			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
    68     }
    69     gtk_window_set_default_size( video_win, width, height );
    70     video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
    71 			       width, height );
    72     gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
    73     /* Note old image is auto de-refed */
    74     return TRUE;
    75 }
    78 /**
    79  * Fill the entire frame with the specified colour (00RRGGBB)
    80  */
    81 gboolean video_gtk_blank( uint32_t colour ) 
    82 {
    83     char *p = video_img->mem;
    84     int i;
    85     for( i=0; i<video_width*video_height; i++ ) {
    86 	*p++ = (colour>>16) & 0xFF;
    87 	*p++ = (colour>>8) & 0xFF;
    88 	*p++ = (colour) & 0xFF;
    89 	*p++ = 0;
    90     }
    91 }
    93 gboolean video_gtk_display_frame( video_buffer_t frame ) 
    94 {
    95     uint32_t bytes_per_line, x, y;
    96     char *src = frame->data;
    97     char *dest = video_img->mem;
    99     return video_glx_display_frame( frame );
   101     switch( frame->colour_format ) {
   102     case COLFMT_ARGB1555:
   103 	for( y=0; y < frame->vres; y++ ) {
   104 	    uint16_t *p = (uint16_t *)src;
   105 	    for( x=0; x < frame->hres; x++ ) {
   106 		uint16_t pixel = *p++;
   107 		*dest++ = (pixel & 0x1F) << 3;
   108 		*dest++ = (pixel & 0x3E0) >> 2;
   109 		*dest++ = (pixel & 0x7C00) >> 7;
   110 		*dest++ = 0;
   111 	    }
   112 	    src += frame->rowstride;
   113 	}
   114 	break;
   115     case COLFMT_RGB565:
   116 	for( y=0; y < frame->vres; y++ ) {
   117 	    uint16_t *p = (uint16_t *)src;
   118 	    for( x=0; x < frame->hres; x++ ) {
   119 		uint16_t pixel = *p++;
   120 		*dest++ = (pixel & 0x1F) << 3;
   121 		*dest++ = (pixel & 0x7E0) >> 3;
   122 		*dest++ = (pixel & 0xF800) >> 8;
   123 		*dest++ = 0;
   124 	    }
   125 	    src += frame->rowstride;
   126 	}
   127 	break;
   128     case COLFMT_RGB888:
   129 	for( y=0; y< frame->vres; y++ ) {
   130 	    char *p = src;
   131 	    for( x=0; x < frame->hres; x++ ) {
   132 		*dest++ = *p++;
   133 		*dest++ = *p++;
   134 		*dest++ = *p++;
   135 		*dest++ = 0;
   136 	    }
   137 	    src += frame->rowstride;
   138 	}
   139 	break;
   140     case COLFMT_ARGB8888:
   141 	bytes_per_line = frame->hres << 2;
   142 	if( bytes_per_line == frame->rowstride ) {
   143 	    /* A little bit faster */
   144 	    memcpy( dest, src, bytes_per_line * frame->vres );
   145 	} else {
   146 	    for( y=0; y< frame->vres; y++ ) {
   147 		memcpy( dest, src, bytes_per_line );
   148 		src += frame->rowstride;
   149 		dest += bytes_per_line;
   150 	    }
   151 	}
   152 	break;
   153     }
   154     gtk_widget_queue_draw( video_area );
   155     return TRUE;
   156 }
   158 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,  
   159 				      int colour_format )
   160 {
   161     return video_glx_set_render_format( 0, 0, width, height );
   162 }
.