From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / OSX / XScreenSaverGLView.m
index 989f8eb9258f36a3a7193bc902f629b4b25e93b2..57b0c7c74b8c57351af4d050b4518b860eb13af7 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 2006-2016 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2006-2017 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -41,14 +41,19 @@ extern void check_gl_error (const char *type);
 @implementation XScreenSaverGLView
 
 
-#ifdef USE_IPHONE
 /* With GL programs, drawing at full resolution isn't a problem.
  */
 - (CGFloat) hackedContentScaleFactor
 {
+# ifdef USE_IPHONE
   return [self contentScaleFactor];
+# else
+  return self.window.backingScaleFactor;
+# endif
 }
 
+# ifdef USE_IPHONE
+
 - (BOOL)ignoreRotation
 {
   return FALSE;                // Allow xwindow and the glViewport to change shape
@@ -121,7 +126,7 @@ extern void check_gl_error (const char *type);
   BOOL was_initted_p = initted_p;
   [super render_x11];
 
-  if (! was_initted_p)
+  if (! was_initted_p && xdpy)
     _suppressRotationAnimation =
       get_boolean_resource (xdpy,
                             "suppressRotationAnimation",
@@ -262,6 +267,31 @@ extern void check_gl_error (const char *type);
   return kCAGravityCenter;
 }
 
+- (void) startAnimation
+{
+  [super startAnimation];
+  if (ogl_ctx) /* Almost always true. */
+    _glesState = jwzgles_make_state ();
+}
+
+- (void) stopAnimation
+{
+  [super stopAnimation];
+#ifdef USE_IPHONE
+  if (_glesState) {
+    [EAGLContext setCurrentContext:ogl_ctx];
+    jwzgles_make_current (_glesState);
+    jwzgles_free_state ();
+  }
+#endif
+}
+
+- (void) prepareContext
+{
+  [super prepareContext];
+  jwzgles_make_current (_glesState);
+}
+
 #endif // !USE_IPHONE
 
 
@@ -307,10 +337,6 @@ init_GL (ModeInfo *mi)
 
   // OpenGL initialization is in [XScreenSaverView startAnimation].
 
-# ifdef USE_IPHONE
-  jwzgles_reset ();
-# endif // USE_IPHONE
-
   // I don't know why this is necessary, but it beats randomly having some
   // textures be upside down.
   //