]> gitweb.factorcode.org Git - factor.git/commitdiff
seed of X11 offscreen backend
authorJoe Groff <arcata@gmail.com>
Fri, 12 Dec 2008 00:50:37 +0000 (16:50 -0800)
committerJoe Groff <arcata@gmail.com>
Fri, 12 Dec 2008 00:50:37 +0000 (16:50 -0800)
basis/ui/gadgets/worlds/worlds.factor
basis/ui/x11/x11.factor
basis/x11/glx/glx.factor
basis/x11/windows/windows.factor
basis/x11/xlib/xlib.factor
extra/ui/offscreen/offscreen.factor

index 9290af1f6426b012bc77d4a23f4888a60e97342e..732a438203496df1400c2654eaed6eb487cff55b 100644 (file)
@@ -13,8 +13,6 @@ title status
 fonts handle
 window-loc ;
 
-TUPLE: offscreen-world < world ;
-
 : find-world ( gadget -- world/f ) [ world? ] find-parent ;
 
 : show-status ( string/f gadget -- )
@@ -53,8 +51,6 @@ M: world request-focus-on ( child gadget -- )
 
 : <world> ( gadget title status -- world )
     world new-world ;
-: <offscreen-world> ( gadget title status -- world )
-    offscreen-world new-world ;
 
 M: world layout*
     dup call-next-method
index e5a3a8306b6572f4c10c6a17e0c0ee216e17a9a4..b65185967a17878d583797c0579b15968bd02202 100755 (executable)
@@ -14,9 +14,12 @@ SINGLETON: x11-ui-backend
 
 : XA_NET_WM_NAME ( -- atom ) "_NET_WM_NAME" x-atom ;
 
-TUPLE: x11-handle window glx xic ;
+TUPLE: x11-handle-base glx ;
+TUPLE: x11-handle < x11-handle-base xic window ;
+TUPLE: x11-pixmap-handle < x11-handle-base pixmap glx-pixmap ;
 
 C: <x11-handle> x11-handle
+C: <x11-pixmap-handle> x11-pixmap-handle
 
 M: world expose-event nip relayout ;
 
@@ -185,7 +188,7 @@ M: world client-event
 
 : gadget-window ( world -- )
     dup window-loc>> over rect-dim glx-window
-    over "Factor" create-xic <x11-handle>
+    over "Factor" create-xic rot <x11-handle>
     2dup window>> register-window
     >>handle drop ;
 
@@ -250,12 +253,31 @@ M: x11-ui-backend raise-window* ( world -- )
 
 M: x11-handle select-gl-context ( handle -- )
     dpy get swap
-    dup window>> swap glx>> glXMakeCurrent
+    [ window>> ] [ glx>> ] bi glXMakeCurrent
     [ "Failed to set current GLX context" throw ] unless ;
 
 M: x11-handle flush-gl-context ( handle -- )
     dpy get swap window>> glXSwapBuffers ;
 
+M: x11-pixmap-handle select-gl-context ( handle -- )
+    dpy get swap
+    [ glx-pixmap>> ] [ glx>> ] bi glXMakeCurrent
+    [ "Failed to set current GLX context" throw ] unless ;
+
+M: x11-pixmap-handle flush-gl-context ( handle -- )
+    drop ;
+
+M: x11-ui-backend (open-offscreen-buffer) ( world -- )
+    dup dim>> glx-pixmap <x11-pixmap-handle> >>handle drop ;
+M: x11-ui-backend (close-offscreen-buffer) ( handle -- )
+    dpy get swap
+    [ glx-pixmap>> glXDestroyGLXPixmap ]
+    [ pixmap>> XFreePixmap drop ]
+    [ glx>> glXDestroyContext ] 2tri ;
+
+M: x11-ui-backend offscreen-pixels ( world -- alien w h )
+    [ [ dim>> ] [ handle>> pixmap>> ] bi pixmap-bits ] [ dim>> first2 ] bi ;
+
 M: x11-ui-backend ui ( -- )
     [
         f [
index 1fab2832421094dc6f0951eb13be9f12aa1a567b..e0b786ce7d586792a74d53f890c160aa8e484cb0 100644 (file)
@@ -84,13 +84,13 @@ FUNCTION: void* glXGetProcAddress ( char* procname ) ;
 FUNCTION: void* glXGetProcAddressARB ( char* procname ) ;
 
 ! GLX Events
-! (also skipped for now. only has GLXPbufferClobberEvent, the rest is handled by xlib methinks
+! (also skipped for now. only has GLXPbufferClobberEvent, the rest is handled by xlib methinks)
 
-: choose-visual ( -- XVisualInfo* )
-    dpy get scr get
+: choose-visual ( flags -- XVisualInfo* )
+    [ dpy get scr get ] dip
     [
+        %
         GLX_RGBA ,
-        GLX_DOUBLEBUFFER ,
         GLX_DEPTH_SIZE , 16 ,
         0 ,
     ] int-array{ } make underlying>>
@@ -98,8 +98,8 @@ FUNCTION: void* glXGetProcAddressARB ( char* procname ) ;
     [ "Could not get a double-buffered GLX RGBA visual" throw ] unless* ;
 
 : create-glx ( XVisualInfo* -- GLXContext )
-    >r dpy get r> f 1 glXCreateContext
+    [ dpy get ] dip f 1 glXCreateContext
     [ "Failed to create GLX context" throw ] unless* ;
 
 : destroy-glx ( GLXContext -- )
-    dpy get swap glXDestroyContext ;
\ No newline at end of file
+    dpy get swap glXDestroyContext ;
index aed45655f6c08bd86e24ce7d73ddc2e6c19b4c6f..3c41a7858411f7118c782567501cec67fca1a3c5 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005, 2006 Eduardo Cavazos and Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types hashtables kernel math math.vectors
-math.bitwise namespaces sequences x11.xlib x11.constants x11.glx ;
+math.bitwise namespaces sequences x11.xlib x11.constants x11.glx
+arrays fry ;
 IN: x11.windows
 
 : create-window-mask ( -- n )
@@ -50,11 +51,30 @@ IN: x11.windows
     dup r> auto-position ;
 
 : glx-window ( loc dim -- window glx )
-    choose-visual
+    GLX_DOUBLEBUFFER 1array choose-visual
     [ create-window ] keep
     [ create-glx ] keep
     XFree ;
 
+: create-pixmap ( dim visual -- pixmap )
+    [ [ { 0 0 } swap ] dip create-window ] [
+        drop [ dpy get ] 2dip first2 24 XCreatePixmap
+        [ "Failed to create offscreen pixmap" throw ] unless*
+    ] 2bi ;
+
+: (create-glx-pixmap) ( pixmap visual -- pixmap glx-pixmap )
+    [ drop ] [
+        [ dpy get ] 2dip swap glXCreateGLXPixmap
+        [ "Failed to create offscreen GLXPixmap" throw ] unless*
+    ] 2bi ;
+
+: create-glx-pixmap ( dim visual -- pixmap glx-pixmap )
+    [ create-pixmap ] [ (create-glx-pixmap) ] bi ;
+
+: glx-pixmap ( dim -- glx pixmap glx-pixmap )
+    { } choose-visual
+    [ nip create-glx ] [ create-glx-pixmap ] [ nip XFree ] 2tri ;
+
 : destroy-window ( win -- )
     dpy get swap XDestroyWindow drop ;
 
@@ -65,3 +85,7 @@ IN: x11.windows
 : map-window ( win -- ) dpy get swap XMapWindow drop ;
 
 : unmap-window ( win -- ) dpy get swap XUnmapWindow drop ;
+
+: pixmap-bits ( dim pixmap -- alien )
+    swap first2 '[ dpy get _ 0 0 _ _ AllPlanes ZPixmap XGetImage ] call
+    [ XImage-pixels ] [ XDestroyImage drop ] bi ;
index 555eb573fc73c40b8b593e602afff9e916068564..996932e697a24939d9001fbd5bc8925a1034ce75 100644 (file)
@@ -272,6 +272,17 @@ FUNCTION: Window XGetSelectionOwner ( Display* display, Atom selection ) ;
 
 FUNCTION: int XConvertSelection ( Display* display, Atom selection, Atom target, Atom property, Window requestor, Time time ) ;
 
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+! 5 - Pixmap and Cursor Functions
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+! 5.1 - Creating and Freeing Pixmaps
+
+FUNCTION: Pixmap XCreatePixmap ( Display* display, Drawable d, uint width, uint height, uint depth ) ;
+FUNCTION: int XFreePixmap ( Display* display, Pixmap pixmap ) ;
+
+
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! 6 - Color Management Functions
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -429,6 +440,49 @@ FUNCTION: Status XDrawString (
         char* string,
         int length ) ;
 
+! 8.7 - Transferring Images between Client and Server
+
+: XYBitmap 0 ; inline
+: XYPixmap 1 ; inline
+: ZPixmap  2 ; inline
+: AllPlanes -1 ; inline
+
+C-STRUCT: XImage-funcs
+    { "void*" "create_image" }
+    { "void*" "destroy_image" }
+    { "void*" "get_pixel" }
+    { "void*" "put_pixel" }
+    { "void*" "sub_image" }
+    { "void*" "add_pixel" } ;
+
+C-STRUCT: XImage
+    { "int"          "width" }
+    { "int"          "height" }
+    { "int"          "xoffset" }
+    { "int"          "format" }
+    { "char*"        "data" }
+    { "int"          "byte_order" }
+    { "int"          "bitmap_unit" }
+    { "int"          "bitmap_bit_order" }
+    { "int"          "bitmap_pad" }
+    { "int"          "depth" }
+    { "int"          "bytes_per_line" }
+    { "int"          "bits_per_pixel" }
+    { "ulong"        "red_mask" }
+    { "ulong"        "green_mask" }
+    { "ulong"        "blue_mask" }
+    { "XPointer"     "obdata" }
+    { "XImage-funcs" "f" } ;
+
+FUNCTION: XImage* XGetImage ( Display* display, Drawable d, int x, int y, uint width, uint height, ulong plane_mask, int format ) ;
+FUNCTION: int XDestroyImage ( XImage *ximage ) ;
+
+: XImage-size ( ximage -- size )
+    [ XImage-height ] [ XImage-bytes_per_line ] bi * ;
+
+: XImage-pixels ( ximage -- byte-array )
+    [ XImage-data ] [ XImage-size ] bi memory>byte-array ;
+
 !
 ! 9 - Window and Session Manager Functions
 !
index 33d4a92f376448a04d82444cb4fb783b12003c24..be6638bed8c1db2c4c3f18a754228e4deaae434e 100755 (executable)
@@ -16,7 +16,8 @@ M: offscreen-world ungraft*
     [ reset-world ] tri ;
 
 : open-offscreen ( gadget -- world )
-    "" f <offscreen-world> [ open-world-window ] keep
+    "" f <offscreen-world>
+    [ open-world-window dup relayout-1 ] keep
     notify-queued ;
 
 : close-offscreen ( world -- )