filename | src/drivers/video_gtk.c |
changeset | 94:8d80d9c7cc7d |
next | 103:9b9cfc5855e0 |
author | nkeynes |
date | Sun Feb 05 04:05:27 2006 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Video code reshuffle to start getting real video happening. Implement colourspace conversions Various tweaks |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/drivers/video_gtk.c Sun Feb 05 04:05:27 2006 +00001.3 @@ -0,0 +1,136 @@1.4 +/**1.5 + * $Id: video_gtk.c,v 1.1 2006-02-05 04:05:27 nkeynes Exp $1.6 + *1.7 + * The PC side of the video support (responsible for actually displaying /1.8 + * rendering frames)1.9 + *1.10 + * Copyright (c) 2005 Nathan Keynes.1.11 + *1.12 + * This program is free software; you can redistribute it and/or modify1.13 + * it under the terms of the GNU General Public License as published by1.14 + * the Free Software Foundation; either version 2 of the License, or1.15 + * (at your option) any later version.1.16 + *1.17 + * This program is distributed in the hope that it will be useful,1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.20 + * GNU General Public License for more details.1.21 + */1.22 +1.23 +#include <gnome.h>1.24 +#include <gdk/gdkx.h>1.25 +#include <stdint.h>1.26 +#include "video.h"1.27 +#include "drivers/video_x11.h"1.28 +1.29 +GdkImage *video_img = NULL;1.30 +GtkWindow *video_win = NULL;1.31 +GtkWidget *video_area = NULL;1.32 +uint32_t video_width = 640;1.33 +uint32_t video_height = 480;1.34 +uint32_t video_frame_count = 0;1.35 +1.36 +gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,1.37 + int colour_format );1.38 +gboolean video_gtk_display_frame( video_buffer_t frame );1.39 +gboolean video_gtk_blank( uint32_t rgb );1.40 +1.41 +struct video_driver video_gtk_driver = { "Gtk", video_gtk_set_output_format,1.42 + video_gtk_display_frame,1.43 + video_gtk_blank };1.44 +1.45 +gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,1.46 + int colour_format )1.47 +{1.48 + video_width = width;1.49 + video_height = height;1.50 + if( video_win == NULL ) {1.51 + video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));1.52 + gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );1.53 + gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );1.54 + gtk_window_set_default_size( video_win, width, height );1.55 +1.56 + video_area = gtk_image_new();1.57 + gtk_widget_show( GTK_WIDGET(video_area) );1.58 + gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );1.59 + gtk_widget_show( GTK_WIDGET(video_win) );1.60 + video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),1.61 + gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),1.62 + GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );1.63 +1.64 + }1.65 + gtk_window_set_default_size( video_win, width, height );1.66 + video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),1.67 + width, height );1.68 + gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );1.69 + /* Note old image is auto de-refed */1.70 + return TRUE;1.71 +}1.72 +1.73 +1.74 +/**1.75 + * Fill the entire frame with the specified colour (00RRGGBB)1.76 + */1.77 +gboolean video_gtk_blank( uint32_t colour )1.78 +{1.79 + char *p = video_img->mem;1.80 + int i;1.81 + for( i=0; i<video_width*video_height; i++ ) {1.82 + *p++ = (colour>>16) & 0xFF;1.83 + *p++ = (colour>>8) & 0xFF;1.84 + *p++ = (colour) & 0xFF;1.85 + *p++ = 0;1.86 + }1.87 +}1.88 +1.89 +gboolean video_gtk_display_frame( video_buffer_t frame )1.90 +{1.91 + uint32_t bytes_per_line, x, y;1.92 + char *src = frame->data;1.93 + char *dest = video_img->mem;1.94 +1.95 + switch( frame->colour_format ) {1.96 + case COLFMT_RGB15:1.97 + for( y=0; y < frame->vres; y++ ) {1.98 + uint16_t *p = (uint16_t *)src;1.99 + for( x=0; x < frame->vres; x++ ) {1.100 + uint16_t pixel = *p++;1.101 + *dest++ = (pixel & 0x1F) << 3;1.102 + *dest++ = (pixel & 0x3E0) >> 2;1.103 + *dest++ = (pixel & 0x7C00) >> 7;1.104 + *dest++ = 0;1.105 + }1.106 + src += frame->rowstride;1.107 + }1.108 + break;1.109 + case COLFMT_RGB16:1.110 + for( y=0; y < frame->vres; y++ ) {1.111 + uint16_t *p = (uint16_t *)src;1.112 + for( x=0; x < frame->vres; x++ ) {1.113 + uint16_t pixel = *p++;1.114 + *dest++ = (pixel & 0x1F) << 3;1.115 + *dest++ = (pixel & 0x7E0) >> 3;1.116 + *dest++ = (pixel & 0xF800) >> 8;1.117 + *dest++ = 0;1.118 + }1.119 + src += frame->rowstride;1.120 + }1.121 + break;1.122 + case COLFMT_RGB32:1.123 + bytes_per_line = frame->hres << 2;1.124 + if( bytes_per_line == frame->rowstride ) {1.125 + /* A little bit faster */1.126 + memcpy( dest, src, bytes_per_line * frame->vres );1.127 + } else {1.128 + for( y=0; y< frame->vres; y++ ) {1.129 + memcpy( dest, src, bytes_per_line );1.130 + src += frame->rowstride;1.131 + dest += bytes_per_line;1.132 + }1.133 + }1.134 + break;1.135 + }1.136 + gtk_widget_queue_draw( video_area );1.137 + return TRUE;1.138 +}1.139 +
.