From 36635a9b13b21d0e7be95df27a49daf4abdc6b68 Mon Sep 17 00:00:00 2001 From: slava Date: Tue, 21 Mar 2006 08:04:36 +0000 Subject: [PATCH] Fix bug where font sprites would be freed in the wrong context --- library/cocoa/ui.factor | 12 +++++++++--- library/cocoa/view-utils.factor | 8 -------- library/ui/backend.factor | 9 +++++++++ library/ui/paint.factor | 4 +++- library/ui/world.factor | 1 + 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/library/cocoa/ui.factor b/library/cocoa/ui.factor index ed184b2a62..276ad70bd9 100644 --- a/library/cocoa/ui.factor +++ b/library/cocoa/ui.factor @@ -6,8 +6,8 @@ DEFER: FactorView USING: arrays cocoa errors freetype gadgets gadgets-launchpad gadgets-layouts gadgets-listener gadgets-panes hashtables kernel lists math namespaces objc objc-NSApplication objc-NSEvent -objc-NSObject objc-NSOpenGLView objc-NSView objc-NSWindow -sequences threads ; +objc-NSObject objc-NSOpenGLContext objc-NSOpenGLView objc-NSView +objc-NSWindow sequences threads ; ! Cocoa backend for Factor UI @@ -75,7 +75,7 @@ H{ } clone views set-global "NSOpenGLView" "FactorView" { { "drawRect:" "void" { "id" "SEL" "NSRect" } - [ 2drop [ view draw-world ] with-gl-view ] + [ 2drop view draw-world ] } { "mouseMoved:" "void" { "id" "SEL" "id" } @@ -171,6 +171,12 @@ IN: gadgets : in-window ( gadget status dim title -- ) >r r> drop ; +: select-gl-context ( handle -- ) + [openGLContext] [makeCurrentContext] ; + +: flush-gl-context ( handle -- ) + [openGLContext] [flushBuffer] ; + IN: shells : ui diff --git a/library/cocoa/view-utils.factor b/library/cocoa/view-utils.factor index e692f536c0..2ff6cea4bd 100644 --- a/library/cocoa/view-utils.factor +++ b/library/cocoa/view-utils.factor @@ -11,14 +11,6 @@ objc-NSOpenGLView objc-NSView opengl sequences ; dup 1 [setPostsBoundsChangedNotifications:] 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 ; : NSViewFrameDidChangeNotification diff --git a/library/ui/backend.factor b/library/ui/backend.factor index 0b7ad04b62..48bfc13834 100644 --- a/library/ui/backend.factor +++ b/library/ui/backend.factor @@ -1,5 +1,14 @@ IN: gadgets +USING: kernel opengl ; DEFER: repaint-handle ( handle -- ) 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 diff --git a/library/ui/paint.factor b/library/ui/paint.factor index f81bd9884c..9b8e3679de 100644 --- a/library/ui/paint.factor +++ b/library/ui/paint.factor @@ -65,7 +65,9 @@ DEFER: draw-gadget : 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 ; ! Pen paint properties diff --git a/library/ui/world.factor b/library/ui/world.factor index 6acbe10142..16ba82e401 100644 --- a/library/ui/world.factor +++ b/library/ui/world.factor @@ -19,6 +19,7 @@ TUPLE: world glass status focus fonts handle ; world-fonts [ drop V{ } clone ] cache ; : close-world ( world -- ) + dup world-handle select-gl-context f over request-focus* dup remove-notify dup free-fonts