Fix bug where font sprites would be freed in the wrong context

slava 2006-03-21 08:04:36 +00:00
parent c94ba8665b
commit 36635a9b13
5 changed files with 22 additions and 12 deletions

View File

@ -6,8 +6,8 @@ DEFER: FactorView
USING: arrays cocoa errors freetype gadgets gadgets-launchpad USING: arrays cocoa errors freetype gadgets gadgets-launchpad
gadgets-layouts gadgets-listener gadgets-panes hashtables kernel gadgets-layouts gadgets-listener gadgets-panes hashtables kernel
lists math namespaces objc objc-NSApplication objc-NSEvent lists math namespaces objc objc-NSApplication objc-NSEvent
objc-NSObject objc-NSOpenGLView objc-NSView objc-NSWindow objc-NSObject objc-NSOpenGLContext objc-NSOpenGLView objc-NSView
sequences threads ; objc-NSWindow sequences threads ;
! Cocoa backend for Factor UI ! Cocoa backend for Factor UI
@ -75,7 +75,7 @@ H{ } clone views set-global
"NSOpenGLView" "FactorView" { "NSOpenGLView" "FactorView" {
{ "drawRect:" "void" { "id" "SEL" "NSRect" } { "drawRect:" "void" { "id" "SEL" "NSRect" }
[ 2drop [ view draw-world ] with-gl-view ] [ 2drop view draw-world ]
} }
{ "mouseMoved:" "void" { "id" "SEL" "id" } { "mouseMoved:" "void" { "id" "SEL" "id" }
@ -171,6 +171,12 @@ IN: gadgets
: in-window ( gadget status dim title -- ) : in-window ( gadget status dim title -- )
>r <world> r> <FactorWindow> drop ; >r <world> r> <FactorWindow> drop ;
: select-gl-context ( handle -- )
[openGLContext] [makeCurrentContext] ;
: flush-gl-context ( handle -- )
[openGLContext] [flushBuffer] ;
IN: shells IN: shells
: ui : ui

View File

@ -11,14 +11,6 @@ objc-NSOpenGLView objc-NSView opengl sequences ;
dup 1 [setPostsBoundsChangedNotifications:] dup 1 [setPostsBoundsChangedNotifications:]
dup 1 [setPostsFrameChangedNotifications:] ; dup 1 [setPostsFrameChangedNotifications:] ;
: with-gl-context ( context quot -- )
swap
[ [makeCurrentContext] call glFlush ] keep
[flushBuffer] ; inline
: with-gl-view ( view quot -- | quot: view -- )
>r dup [openGLContext] r> with-gl-context ; inline
: view-dim [bounds] dup NSRect-w swap NSRect-h 0 3array ; : view-dim [bounds] dup NSRect-w swap NSRect-h 0 3array ;
: NSViewFrameDidChangeNotification : NSViewFrameDidChangeNotification

View File

@ -1,5 +1,14 @@
IN: gadgets IN: gadgets
USING: kernel opengl ;
DEFER: repaint-handle ( handle -- ) DEFER: repaint-handle ( handle -- )
DEFER: in-window ( gadget status dim title -- ) DEFER: in-window ( gadget status dim title -- )
DEFER: select-gl-context ( handle -- )
DEFER: flush-gl-context ( handle -- )
: with-gl-context ( handle quot -- )
swap [ select-gl-context call ] keep
glFlush flush-gl-context gl-error ; inline

View File

@ -65,7 +65,9 @@ DEFER: draw-gadget
: draw-world ( world -- ) : draw-world ( world -- )
[ [
dup rect-dim init-gl dup world set draw-gadget gl-error dup world-handle [
dup rect-dim init-gl dup world set draw-gadget
] with-gl-context
] with-scope ; ] with-scope ;
! Pen paint properties ! Pen paint properties

View File

@ -19,6 +19,7 @@ TUPLE: world glass status focus fonts handle ;
world-fonts [ drop V{ } clone ] cache ; world-fonts [ drop V{ } clone ] cache ;
: close-world ( world -- ) : close-world ( world -- )
dup world-handle select-gl-context
f over request-focus* f over request-focus*
dup remove-notify dup remove-notify
dup free-fonts dup free-fonts