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
file annotate diff log raw
nkeynes@94
     1
/**
nkeynes@94
     2
 * $Id: video_gtk.c,v 1.1 2006-02-05 04:05:27 nkeynes Exp $
nkeynes@94
     3
 *
nkeynes@94
     4
 * The PC side of the video support (responsible for actually displaying / 
nkeynes@94
     5
 * rendering frames)
nkeynes@94
     6
 *
nkeynes@94
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@94
     8
 *
nkeynes@94
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@94
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@94
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@94
    12
 * (at your option) any later version.
nkeynes@94
    13
 *
nkeynes@94
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@94
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@94
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@94
    17
 * GNU General Public License for more details.
nkeynes@94
    18
 */
nkeynes@94
    19
nkeynes@94
    20
#include <gnome.h>
nkeynes@94
    21
#include <gdk/gdkx.h>
nkeynes@94
    22
#include <stdint.h>
nkeynes@94
    23
#include "video.h"
nkeynes@94
    24
#include "drivers/video_x11.h"
nkeynes@94
    25
nkeynes@94
    26
GdkImage *video_img = NULL;
nkeynes@94
    27
GtkWindow *video_win = NULL;
nkeynes@94
    28
GtkWidget *video_area = NULL;
nkeynes@94
    29
uint32_t video_width = 640;
nkeynes@94
    30
uint32_t video_height = 480;
nkeynes@94
    31
uint32_t video_frame_count = 0;
nkeynes@94
    32
nkeynes@94
    33
gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
nkeynes@94
    34
				      int colour_format );
nkeynes@94
    35
gboolean video_gtk_display_frame( video_buffer_t frame );
nkeynes@94
    36
gboolean video_gtk_blank( uint32_t rgb );
nkeynes@94
    37
nkeynes@94
    38
struct video_driver video_gtk_driver = { "Gtk", video_gtk_set_output_format,
nkeynes@94
    39
					 video_gtk_display_frame,
nkeynes@94
    40
					 video_gtk_blank };
nkeynes@94
    41
nkeynes@94
    42
gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,  
nkeynes@94
    43
				      int colour_format )
nkeynes@94
    44
{
nkeynes@94
    45
    video_width = width;
nkeynes@94
    46
    video_height = height;
nkeynes@94
    47
    if( video_win == NULL ) {
nkeynes@94
    48
	video_win = GTK_WINDOW(gtk_window_new( GTK_WINDOW_TOPLEVEL ));
nkeynes@94
    49
	gtk_window_set_title( video_win, "DreamOn! - Emulation Window" );
nkeynes@94
    50
	gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );
nkeynes@94
    51
	gtk_window_set_default_size( video_win, width, height );
nkeynes@94
    52
    
nkeynes@94
    53
	video_area = gtk_image_new();
nkeynes@94
    54
	gtk_widget_show( GTK_WIDGET(video_area) );
nkeynes@94
    55
	gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );
nkeynes@94
    56
	gtk_widget_show( GTK_WIDGET(video_win) );
nkeynes@94
    57
	video_x11_set_display( gdk_x11_display_get_xdisplay( gtk_widget_get_display(video_area)),
nkeynes@94
    58
			       gdk_x11_screen_get_xscreen( gtk_widget_get_screen(video_area)),
nkeynes@94
    59
			       GDK_WINDOW_XWINDOW( GTK_WIDGET(video_win)->window ) );
nkeynes@94
    60
			       
nkeynes@94
    61
    }
nkeynes@94
    62
    gtk_window_set_default_size( video_win, width, height );
nkeynes@94
    63
    video_img = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(),
nkeynes@94
    64
			       width, height );
nkeynes@94
    65
    gtk_image_set_from_image( GTK_IMAGE(video_area), video_img, NULL );
nkeynes@94
    66
    /* Note old image is auto de-refed */
nkeynes@94
    67
    return TRUE;
nkeynes@94
    68
}
nkeynes@94
    69
nkeynes@94
    70
nkeynes@94
    71
/**
nkeynes@94
    72
 * Fill the entire frame with the specified colour (00RRGGBB)
nkeynes@94
    73
 */
nkeynes@94
    74
gboolean video_gtk_blank( uint32_t colour ) 
nkeynes@94
    75
{
nkeynes@94
    76
    char *p = video_img->mem;
nkeynes@94
    77
    int i;
nkeynes@94
    78
    for( i=0; i<video_width*video_height; i++ ) {
nkeynes@94
    79
	*p++ = (colour>>16) & 0xFF;
nkeynes@94
    80
	*p++ = (colour>>8) & 0xFF;
nkeynes@94
    81
	*p++ = (colour) & 0xFF;
nkeynes@94
    82
	*p++ = 0;
nkeynes@94
    83
    }
nkeynes@94
    84
}
nkeynes@94
    85
nkeynes@94
    86
gboolean video_gtk_display_frame( video_buffer_t frame ) 
nkeynes@94
    87
{
nkeynes@94
    88
    uint32_t bytes_per_line, x, y;
nkeynes@94
    89
    char *src = frame->data;
nkeynes@94
    90
    char *dest = video_img->mem;
nkeynes@94
    91
nkeynes@94
    92
    switch( frame->colour_format ) {
nkeynes@94
    93
    case COLFMT_RGB15:
nkeynes@94
    94
	for( y=0; y < frame->vres; y++ ) {
nkeynes@94
    95
	    uint16_t *p = (uint16_t *)src;
nkeynes@94
    96
	    for( x=0; x < frame->vres; x++ ) {
nkeynes@94
    97
		uint16_t pixel = *p++;
nkeynes@94
    98
		*dest++ = (pixel & 0x1F) << 3;
nkeynes@94
    99
		*dest++ = (pixel & 0x3E0) >> 2;
nkeynes@94
   100
		*dest++ = (pixel & 0x7C00) >> 7;
nkeynes@94
   101
		*dest++ = 0;
nkeynes@94
   102
	    }
nkeynes@94
   103
	    src += frame->rowstride;
nkeynes@94
   104
	}
nkeynes@94
   105
	break;
nkeynes@94
   106
    case COLFMT_RGB16:
nkeynes@94
   107
	for( y=0; y < frame->vres; y++ ) {
nkeynes@94
   108
	    uint16_t *p = (uint16_t *)src;
nkeynes@94
   109
	    for( x=0; x < frame->vres; x++ ) {
nkeynes@94
   110
		uint16_t pixel = *p++;
nkeynes@94
   111
		*dest++ = (pixel & 0x1F) << 3;
nkeynes@94
   112
		*dest++ = (pixel & 0x7E0) >> 3;
nkeynes@94
   113
		*dest++ = (pixel & 0xF800) >> 8;
nkeynes@94
   114
		*dest++ = 0;
nkeynes@94
   115
	    }
nkeynes@94
   116
	    src += frame->rowstride;
nkeynes@94
   117
	}
nkeynes@94
   118
	break;
nkeynes@94
   119
    case COLFMT_RGB32:
nkeynes@94
   120
	bytes_per_line = frame->hres << 2;
nkeynes@94
   121
	if( bytes_per_line == frame->rowstride ) {
nkeynes@94
   122
	    /* A little bit faster */
nkeynes@94
   123
	    memcpy( dest, src, bytes_per_line * frame->vres );
nkeynes@94
   124
	} else {
nkeynes@94
   125
	    for( y=0; y< frame->vres; y++ ) {
nkeynes@94
   126
		memcpy( dest, src, bytes_per_line );
nkeynes@94
   127
		src += frame->rowstride;
nkeynes@94
   128
		dest += bytes_per_line;
nkeynes@94
   129
	    }
nkeynes@94
   130
	}
nkeynes@94
   131
	break;
nkeynes@94
   132
    }
nkeynes@94
   133
    gtk_widget_queue_draw( video_area );
nkeynes@94
   134
    return TRUE;
nkeynes@94
   135
}
nkeynes@94
   136
.