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 635:76c63aac3590
prev620:d9b28f78b952
next1066:ddffe9d2b332
author nkeynes
date Thu Feb 14 13:54:11 2008 +0000 (11 years ago)
branchlxdream-render
permissions -rw-r--r--
last change Commit render work in progress. Main changes:
* Preliminary OSMesa support
* Move the generic gl code out to pvr2/
* Implement scene data structure + reader
* Remove the 1/z adjustments
view annotate diff log raw
     1 /**
     2  * $Id$
     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 <gdk/gdkx.h>
    21 #include <gdk/gdkkeysyms.h>
    22 #include <stdint.h>
    23 #include "dream.h"
    24 #include "display.h"
    25 #include "dckeysyms.h"
    26 #include "drivers/video_glx.h"
    27 #include "drivers/video_gl.h"
    28 #include "pvr2/pvr2.h"
    29 #include "gtkui/gtkui.h"
    31 GtkWidget *gtk_video_win = NULL;
    32 int video_width = 640;
    33 int video_height = 480;
    35 gboolean video_gtk_init();
    36 void video_gtk_shutdown();
    37 gboolean video_gtk_display_blank( uint32_t colour );
    38 uint16_t video_gtk_resolve_keysym( const gchar *keysym );
    39 uint16_t video_gtk_keycode_to_dckeysym(uint16_t keycode);
    41 struct display_driver display_gtk_driver = { "gtk", video_gtk_init, video_gtk_shutdown,
    42 					     video_gtk_resolve_keysym,
    43 					     video_gtk_keycode_to_dckeysym,
    44 					     NULL,
    45 					     NULL, NULL, NULL, NULL, NULL, 
    46 					     video_gtk_display_blank, NULL };
    48 uint16_t video_gtk_resolve_keysym( const gchar *keysym )
    49 {
    50     int val = gdk_keyval_from_name( keysym );
    51     if( val == GDK_VoidSymbol )
    52 	return 0;
    53     return (uint16_t)val;
    54 }
    56 gboolean video_gtk_expose_callback(GtkWidget *widget, GdkEventExpose *event, gpointer data )
    57 {
    58     render_buffer_t buffer = pvr2_get_front_buffer();
    59     if( buffer == NULL ) {
    60 	display_gtk_driver.display_blank(pvr2_get_border_colour());
    61     } else {
    62 	display_gtk_driver.display_render_buffer(buffer);
    63     }
    64     return TRUE;
    65 }
    67 gboolean video_gtk_resize_callback(GtkWidget *widget, GdkEventConfigure *event, gpointer data )
    68 {
    69     video_width = event->width;
    70     video_height = event->height;
    71     video_gtk_expose_callback(widget, NULL, data);
    72     return TRUE;
    73 }
    75 uint16_t video_gtk_keycode_to_dckeysym(uint16_t keycode)
    76 {
    77     if( keycode >= 'a' && keycode <= 'z' ) {
    78 	return (keycode - 'a') + DCKB_A;
    79     } else if( keycode >= '1' && keycode <= '9' ) {
    80 	return (keycode - '1') + DCKB_1;
    81     }
    82     switch(keycode) {
    83     case GDK_0:         return DCKB_0;
    84     case GDK_Return:    return DCKB_ENTER;
    85     case GDK_Escape:    return DCKB_ESCAPE;
    86     case GDK_BackSpace: return DCKB_BACKSPACE;
    87     case GDK_Tab:       return DCKB_TAB;
    88     case GDK_space:     return DCKB_SPACE;
    89     case GDK_minus:     return DCKB_MINUS;
    90     case GDK_equal:     return DCKB_EQUAL;
    91     case GDK_bracketleft: return DCKB_LBRACKET;
    92     case GDK_bracketright: return DCKB_RBRACKET;
    93     case GDK_semicolon: return DCKB_SEMICOLON;
    94     case GDK_apostrophe:return DCKB_QUOTE;
    95     case GDK_grave : return DCKB_BACKQUOTE;
    96     case GDK_comma:     return DCKB_COMMA;
    97     case GDK_period:    return DCKB_PERIOD;
    98     case GDK_slash:     return DCKB_SLASH; 
    99     case GDK_Caps_Lock: return DCKB_CAPSLOCK;
   100     case GDK_F1:        return DCKB_F1;
   101     case GDK_F2:        return DCKB_F2;
   102     case GDK_F3:        return DCKB_F3;
   103     case GDK_F4:        return DCKB_F4;
   104     case GDK_F5:        return DCKB_F5;
   105     case GDK_F6:        return DCKB_F6;
   106     case GDK_F7:        return DCKB_F7;
   107     case GDK_F8:        return DCKB_F8;
   108     case GDK_F9:        return DCKB_F9;
   109     case GDK_F10:       return DCKB_F10;
   110     case GDK_F11:       return DCKB_F11;
   111     case GDK_F12:       return DCKB_F12;
   112     case GDK_Scroll_Lock: return DCKB_SCROLLLOCK;
   113     case GDK_Pause:     return DCKB_PAUSE;
   114     case GDK_Insert:    return DCKB_INSERT;
   115     case GDK_Home:      return DCKB_HOME;
   116     case GDK_Page_Up:   return DCKB_PAGEUP;
   117     case GDK_Delete:    return DCKB_DELETE;
   118     case GDK_End:       return DCKB_END;
   119     case GDK_Page_Down: return DCKB_PAGEDOWN;
   120     case GDK_Right:     return DCKB_RIGHT;
   121     case GDK_Left:      return DCKB_LEFT;
   122     case GDK_Down:      return DCKB_DOWN;
   123     case GDK_Up:        return DCKB_UP;
   124     case GDK_Num_Lock:  return DCKB_NUMLOCK;
   125     case GDK_KP_Divide: return DCKB_KP_SLASH;
   126     case GDK_KP_Multiply: return DCKB_KP_STAR;
   127     case GDK_KP_Subtract: return DCKB_KP_MINUS;
   128     case GDK_KP_Add:    return DCKB_KP_PLUS;
   129     case GDK_KP_Enter:  return DCKB_KP_ENTER;
   130     case GDK_KP_1:      return DCKB_KP_1;
   131     case GDK_KP_2:      return DCKB_KP_2;
   132     case GDK_KP_3:      return DCKB_KP_3;
   133     case GDK_KP_4:      return DCKB_KP_4;
   134     case GDK_KP_5:      return DCKB_KP_5;
   135     case GDK_KP_6:      return DCKB_KP_6;
   136     case GDK_KP_7:      return DCKB_KP_7;
   137     case GDK_KP_8:      return DCKB_KP_8;
   138     case GDK_KP_9:      return DCKB_KP_9;
   139     case GDK_KP_0:      return DCKB_KP_0;
   140     case GDK_KP_Decimal:return DCKB_KP_PERIOD;
   141     case GDK_backslash: return DCKB_BACKSLASH;
   142     case GDK_Control_L: return DCKB_CONTROL_L;
   143     case GDK_Shift_L:   return DCKB_SHIFT_L;
   144     case GDK_Alt_L:     return DCKB_ALT_L;
   145     case GDK_Meta_L:    return DCKB_S1;
   146     case GDK_Control_R: return DCKB_CONTROL_R;
   147     case GDK_Shift_R:   return DCKB_SHIFT_R;
   148     case GDK_Alt_R:     return DCKB_ALT_R;
   149     case GDK_Meta_R:    return DCKB_S2;
   150     }
   151     return DCKB_NONE;
   152 }
   154 gboolean video_gtk_init()
   155 {
   157     gtk_video_win = gtk_gui_get_renderarea();
   158     if( gtk_video_win == NULL ) {
   159 	return FALSE;
   160     }
   162     g_signal_connect( gtk_video_win, "expose_event",
   163 		      G_CALLBACK(video_gtk_expose_callback), NULL );
   164     g_signal_connect( gtk_video_win, "configure_event",
   165 		      G_CALLBACK(video_gtk_resize_callback), NULL );
   166     video_width = gtk_video_win->allocation.width;
   167     video_height = gtk_video_win->allocation.height;
   168     Display *display = gdk_x11_display_get_xdisplay( gtk_widget_get_display(GTK_WIDGET(gtk_video_win)));
   169     Window window = GDK_WINDOW_XWINDOW( GTK_WIDGET(gtk_video_win)->window );
   170 #ifdef HAVE_LIBOSMESA
   171     video_gdk_init_driver( &display_gtk_driver );
   172 #else
   173     if( ! video_glx_init_context( display, window ) ||
   174         ! video_glx_init_driver( &display_gtk_driver ) ) {
   175         return FALSE;
   176     }
   177 #endif
   179 #ifdef HAVE_LINUX_JOYSTICK
   180     linux_joystick_init();
   181 #endif
   182     return TRUE;
   183 }
   185 gboolean video_gtk_display_blank( uint32_t colour )
   186 {
   187     GdkGC *gc = gdk_gc_new(gtk_video_win->window);
   188     GdkColor color = {0, ((colour>>16)&0xFF)*257, ((colour>>8)&0xFF)*257, ((colour)&0xFF)*257 };
   189     GdkColormap *cmap = gdk_colormap_get_system();
   190     gdk_colormap_alloc_color( cmap, &color, TRUE, TRUE );
   191     gdk_gc_set_foreground( gc, &color );
   192     gdk_gc_set_background( gc, &color );
   193     gdk_draw_rectangle( gtk_video_win->window, gc, TRUE, 0, 0, video_width, video_height );
   194     gdk_gc_destroy(gc);
   195     gdk_colormap_free_colors( cmap, &color, 1 );
   196 }
   198 XVisualInfo *video_gtk_get_visual()
   199 {
   200 #ifdef HAVE_LIBOSMESA
   201     return NULL;
   202 #else
   203     return video_glx_get_visual();
   204 #endif
   205 }
   207 void video_gtk_shutdown()
   208 {
   209     if( gtk_video_win != NULL ) {
   210 #ifdef HAVE_LIBOSMESA
   211         video_gdk_shutdown();
   212 #else
   213 	video_glx_shutdown();
   214 #endif
   215     }
   216 #ifdef HAVE_LINUX_JOYSTICK
   217     linux_joystick_shutdown();
   218 #endif
   219 }
.