winemac: Reattach OpenGL contexts to a view after it has been hidden and unhidden.

Ken Thomases ken at codeweavers.com
Thu Feb 2 15:16:27 CST 2017


Hiding a view seems to semi-detach any attached OpenGL contexts such that
rendering no longer works.  There's no GL surface for the view.  Calling
-[NSOpenGLContext update] is not sufficient to reattach the context.  So,
fully detach the contexts and reattach them.

Signed-off-by: Ken Thomases <ken at codeweavers.com>
---
 dlls/winemac.drv/cocoa_opengl.h |  2 ++
 dlls/winemac.drv/cocoa_opengl.m | 15 +++++++++++++--
 dlls/winemac.drv/cocoa_window.m | 35 ++++++++++++++++++++++++++++-------
 3 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/dlls/winemac.drv/cocoa_opengl.h b/dlls/winemac.drv/cocoa_opengl.h
index e7e1686..bcd257f 100644
--- a/dlls/winemac.drv/cocoa_opengl.h
+++ b/dlls/winemac.drv/cocoa_opengl.h
@@ -25,12 +25,14 @@ @interface WineOpenGLContext : NSOpenGLContext
 {
     NSView* latentView;
     BOOL needsUpdate;
+    BOOL needsReattach;
     BOOL shouldClearToBlack;
 
     GLint backing_size[2];
 }
 
 @property BOOL needsUpdate;
+ at property BOOL needsReattach;
 @property BOOL shouldClearToBlack;
 
 @end
diff --git a/dlls/winemac.drv/cocoa_opengl.m b/dlls/winemac.drv/cocoa_opengl.m
index debeb78..5a097a1 100644
--- a/dlls/winemac.drv/cocoa_opengl.m
+++ b/dlls/winemac.drv/cocoa_opengl.m
@@ -35,7 +35,7 @@ - (void) wine_updateBackingSize:(const CGSize*)size;
 
 
 @implementation WineOpenGLContext
- at synthesize latentView, needsUpdate, shouldClearToBlack;
+ at synthesize latentView, needsUpdate, needsReattach, shouldClearToBlack;
 
     - (void) dealloc
     {
@@ -215,6 +215,7 @@ - (void) removeFromViews:(BOOL)removeViews
                 [self setLatentView:nil];
         }
         needsUpdate = FALSE;
+        needsReattach = FALSE;
     }
 
 @end
@@ -279,6 +280,7 @@ void macdrv_make_context_current(macdrv_opengl_context c, macdrv_view v, CGRect
             if (context.needsUpdate)
             {
                 context.needsUpdate = FALSE;
+                context.needsReattach = FALSE;
                 if (context.view)
                     [context setView:[[context class] dummyView]];
                 [context wine_updateBackingSize:&r.size];
@@ -328,7 +330,9 @@ void macdrv_update_opengl_context(macdrv_opengl_context c)
 
     if (context.needsUpdate)
     {
+        BOOL reattach = context.needsReattach;
         context.needsUpdate = FALSE;
+        context.needsReattach = FALSE;
         if (context.latentView)
         {
             [context setView:context.latentView];
@@ -339,7 +343,14 @@ void macdrv_update_opengl_context(macdrv_opengl_context c)
         }
         else
         {
-            [context update];
+            if (reattach)
+            {
+                NSView* view = [[context.view retain] autorelease];
+                [context clearDrawableLeavingSurfaceOnScreen];
+                context.view = view;
+            }
+            else
+                [context update];
             [context resetSurfaceIfBackingSizeChanged];
         }
     }
diff --git a/dlls/winemac.drv/cocoa_window.m b/dlls/winemac.drv/cocoa_window.m
index 57587d9..118bf3c 100644
--- a/dlls/winemac.drv/cocoa_window.m
+++ b/dlls/winemac.drv/cocoa_window.m
@@ -500,10 +500,19 @@ - (void) removeGLContext:(WineOpenGLContext*)context
         [(WineWindow*)[self window] updateForGLSubviews];
     }
 
-    - (void) updateGLContexts
+    - (void) updateGLContexts:(BOOL)reattach
     {
         for (WineOpenGLContext* context in glContexts)
+        {
             context.needsUpdate = TRUE;
+            if (reattach)
+                context.needsReattach = TRUE;
+        }
+    }
+
+    - (void) updateGLContexts
+    {
+        [self updateGLContexts:NO];
     }
 
     - (BOOL) hasGLContext
@@ -605,6 +614,23 @@ - (BOOL) mouseDownCanMoveWindow
         return NO;
     }
 
+    - (void) viewDidHide
+    {
+        [super viewDidHide];
+        if ([self hasGLContext])
+            [self invalidateHasGLDescendant];
+    }
+
+    - (void) viewDidUnhide
+    {
+        [super viewDidUnhide];
+        if ([self hasGLContext])
+        {
+            [self updateGLContexts:YES];
+            [self invalidateHasGLDescendant];
+        }
+    }
+
     - (void) completeText:(NSString*)text
     {
         macdrv_event* event;
@@ -651,12 +677,6 @@ - (void) willRemoveSubview:(NSView*)subview
         [super willRemoveSubview:subview];
     }
 
-    - (void) setHidden:(BOOL)hidden
-    {
-        [super setHidden:hidden];
-        [self invalidateHasGLDescendant];
-    }
-
     /*
      * ---------- NSTextInputClient methods ----------
      */
@@ -3432,6 +3452,7 @@ void macdrv_set_view_hidden(macdrv_view v, int hidden)
 
     OnMainThreadAsync(^{
         [view setHidden:hidden];
+        [(WineWindow*)view.window updateForGLSubviews];
     });
 
     [pool release];
-- 
2.10.2




More information about the wine-patches mailing list