2 * $Id: video_gtk.c,v 1.2 2006-03-13 12:39:07 nkeynes Exp $
4 * The PC side of the video support (responsible for actually displaying /
7 * Copyright (c) 2005 Nathan Keynes.
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.
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.
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,
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",
41 video_gtk_set_output_format,
43 video_gtk_display_frame,
47 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,
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 ) );
67 gtk_window_set_default_size( video_win, width, height );
68 video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
70 gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
71 /* Note old image is auto de-refed */
77 * Fill the entire frame with the specified colour (00RRGGBB)
79 gboolean video_gtk_blank( uint32_t colour )
81 char *p = video_img->mem;
83 for( i=0; i<video_width*video_height; i++ ) {
84 *p++ = (colour>>16) & 0xFF;
85 *p++ = (colour>>8) & 0xFF;
86 *p++ = (colour) & 0xFF;
91 gboolean video_gtk_display_frame( video_buffer_t frame )
93 uint32_t bytes_per_line, x, y;
94 char *src = frame->data;
95 char *dest = video_img->mem;
97 switch( frame->colour_format ) {
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;
108 src += frame->rowstride;
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;
121 src += frame->rowstride;
125 for( y=0; y< frame->vres; y++ ) {
127 for( x=0; x < frame->hres; x++ ) {
133 src += frame->rowstride;
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 );
142 for( y=0; y< frame->vres; y++ ) {
143 memcpy( dest, src, bytes_per_line );
144 src += frame->rowstride;
145 dest += bytes_per_line;
150 gtk_widget_queue_draw( video_area );
.