2 * $Id: video_gtk.c,v 1.4 2006-03-15 13:16:46 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_set_render_format( uint32_t width, uint32_t height,
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",
43 video_gtk_set_output_format,
44 video_gtk_set_render_format,
45 video_gtk_display_frame,
47 video_glx_swap_buffers };
49 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,
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 ) );
69 gtk_window_set_default_size( video_win, width, height );
70 video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
72 gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
73 /* Note old image is auto de-refed */
79 * Fill the entire frame with the specified colour (00RRGGBB)
81 gboolean video_gtk_blank( uint32_t colour )
83 char *p = video_img->mem;
85 for( i=0; i<video_width*video_height; i++ ) {
86 *p++ = (colour>>16) & 0xFF;
87 *p++ = (colour>>8) & 0xFF;
88 *p++ = (colour) & 0xFF;
93 gboolean video_gtk_display_frame( video_buffer_t frame )
95 uint32_t bytes_per_line, x, y;
96 char *src = frame->data;
97 char *dest = video_img->mem;
99 switch( frame->colour_format ) {
100 case COLFMT_ARGB1555:
101 for( y=0; y < frame->vres; y++ ) {
102 uint16_t *p = (uint16_t *)src;
103 for( x=0; x < frame->hres; x++ ) {
104 uint16_t pixel = *p++;
105 *dest++ = (pixel & 0x1F) << 3;
106 *dest++ = (pixel & 0x3E0) >> 2;
107 *dest++ = (pixel & 0x7C00) >> 7;
110 src += frame->rowstride;
114 for( y=0; y < frame->vres; y++ ) {
115 uint16_t *p = (uint16_t *)src;
116 for( x=0; x < frame->hres; x++ ) {
117 uint16_t pixel = *p++;
118 *dest++ = (pixel & 0x1F) << 3;
119 *dest++ = (pixel & 0x7E0) >> 3;
120 *dest++ = (pixel & 0xF800) >> 8;
123 src += frame->rowstride;
127 for( y=0; y< frame->vres; y++ ) {
129 for( x=0; x < frame->hres; x++ ) {
135 src += frame->rowstride;
138 case COLFMT_ARGB8888:
139 bytes_per_line = frame->hres << 2;
140 if( bytes_per_line == frame->rowstride ) {
141 /* A little bit faster */
142 memcpy( dest, src, bytes_per_line * frame->vres );
144 for( y=0; y< frame->vres; y++ ) {
145 memcpy( dest, src, bytes_per_line );
146 src += frame->rowstride;
147 dest += bytes_per_line;
152 gtk_widget_queue_draw( video_area );
156 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,
159 return video_glx_set_render_format( 0, 0, width, height );
.