Skip to content

Commit 08163f7

Browse files
committed
BF: For pyglet 1.3 we really have to use retina displays now
Trying to acoid this just caused the size of hte screen to appear wrong and I couldn't work out where the code is that forces the issue (reverting to pyglet 1.2 gets rid of the problem). This seems OK but I've forced the setting useRetina to be True and raised an error if the user tries to set it to False to ensure that everyone knows it changed
1 parent 2f0bcd9 commit 08163f7

File tree

1 file changed

+31
-41
lines changed

1 file changed

+31
-41
lines changed

psychopy/visual/window.py

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
DEBUG = False
108108
IOHUB_ACTIVE = False
109-
109+
retinaContext = None # only needed for retina-ready displays
110110

111111
# keep track of windows that have been opened
112112
# Use a list of weak references so that we don't stop the window being deleted
@@ -165,7 +165,7 @@ def __init__(self,
165165
name='window1',
166166
checkTiming=True,
167167
useFBO=False,
168-
useRetina=False,
168+
useRetina=True,
169169
autoLog=True):
170170
"""
171171
These attributes can only be set at initialization. See further down
@@ -238,10 +238,10 @@ def __init__(self,
238238
this will be enabled.
239239
You can switch between left and right-eye scenes for drawing
240240
operations using :func:`~psychopy.visual.Window.setBuffer`
241-
useRetina : True or *False*
242-
Try to use the full resolution of the Retina display (only on
243-
certain Macs). By default the display's reduced resolution will
244-
be used. NB when you use Retina display the initial win size
241+
useRetina : *True* or False
242+
In PsychoPy >1.85.3 this should always be True as pyglet
243+
(or Apple) no longer allows us to create a non-retina display.
244+
NB when you use Retina display the initial win size
245245
request will be in the larger pixels but subsequent use of
246246
units='pix' should refer to the tiny Retina pixels. Window.size
247247
will give the actual size of the screen in Retina pixels
@@ -273,6 +273,14 @@ def __init__(self,
273273
self.useFBO = useFBO
274274
self.useRetina = useRetina
275275

276+
if sys.platform=='darwin' and not useRetina and pyglet.version >= "1.3":
277+
raise ValueError("As of PsychoPy 1.85.3 OSX windows should all be "
278+
"set to useRetina=True (or remove the argument). "
279+
"Pyglet 1.3 appears to be forcing "
280+
"us to use retina on any retina-capable screen "
281+
"so setting to False has no effect.")
282+
283+
276284
self._toLog = []
277285
self._toCall = []
278286
# settings for the monitor: local settings (if available) override
@@ -1447,36 +1455,6 @@ def _setupPyglet(self):
14471455
samples=aa_samples, stencil_size=stencil_size, stereo=self.stereo,
14481456
vsync=vsync)
14491457

1450-
# monkey patches for retina display if needed
1451-
def retinaAttach(self, canvas):
1452-
"""Replaces pyglet.gl.cocoa.CocoaContext.attach method
1453-
"""
1454-
super(CocoaContext, self).attach(canvas)
1455-
self._nscontext.setView_(canvas.nsview)
1456-
try:
1457-
self._nscontext.view().setWantsBestResolutionOpenGLSurface_(1)
1458-
except AttributeError:
1459-
pass
1460-
self.set_current()
1461-
1462-
def retina_on_resize(self, width, height):
1463-
"""Insert as method """
1464-
view = self.context._nscontext.view()
1465-
bounds = view.convertRectToBacking_(view.bounds()).size
1466-
back_width, back_height = (int(bounds.width), int(bounds.height))
1467-
1468-
GL.glViewport(0, 0, back_width, back_height)
1469-
GL.glMatrixMode(GL.GL_PROJECTION)
1470-
GL.glLoadIdentity()
1471-
GL.glOrtho(0, width, 0, height, -1, 1)
1472-
GL.glMatrixMode(GL.GL_MODELVIEW)
1473-
1474-
if self.useRetina and sys.platform == 'darwin':
1475-
from pyglet.gl.cocoa import CocoaContext
1476-
CocoaContext.attach = retinaAttach
1477-
from pyglet.window.cocoa import CocoaWindow
1478-
CocoaWindow.on_resize = retina_on_resize
1479-
14801458
defDisp = pyglet.window.get_platform().get_default_display()
14811459
allScrs = defDisp.get_screens()
14821460
# Screen (from Exp Settings) is 1-indexed,
@@ -1515,16 +1493,18 @@ def retina_on_resize(self, width, height):
15151493
else:
15161494
self._hw_handle = self.winHandle._hwnd
15171495
elif sys.platform == 'darwin':
1496+
if self.useRetina:
1497+
global retinaContext
1498+
retinaContext = self.winHandle.context._nscontext
1499+
view = retinaContext.view()
1500+
bounds = view.convertRectToBacking_(view.bounds()).size
1501+
self.size = (int(bounds.width), int(bounds.height))
15181502
try:
15191503
# python 32bit (1.4. or 1.2 pyglet)
15201504
self._hw_handle = self.winHandle._window.value
15211505
except Exception:
15221506
# pyglet 1.2 with 64bit python?
15231507
self._hw_handle = self.winHandle._nswindow.windowNumber()
1524-
if self.useRetina:
1525-
view = self.context._nscontext.view()
1526-
bounds = view.convertRectToBacking_(view.bounds()).size
1527-
self.size = (int(bounds.width), int(bounds.height))
15281508
elif sys.platform == 'linux2':
15291509
self._hw_handle = self.winHandle._window
15301510

@@ -2053,9 +2033,19 @@ def _onResize(width, height):
20532033
Override this event handler with your own to create another
20542034
projection, for example in perspective.
20552035
"""
2036+
global retinaContext
2037+
20562038
if height == 0:
20572039
height = 1
2058-
GL.glViewport(0, 0, width, height)
2040+
2041+
if retinaContext is not None:
2042+
view = retinaContext.view()
2043+
bounds = view.convertRectToBacking_(view.bounds()).size
2044+
back_width, back_height = (int(bounds.width), int(bounds.height))
2045+
else:
2046+
back_width, back_height = width, height
2047+
2048+
GL.glViewport(0, 0, back_width, back_height)
20592049
GL.glMatrixMode(GL.GL_PROJECTION)
20602050
GL.glLoadIdentity()
20612051
GL.glOrtho(-1, 1, -1, 1, -1, 1)

0 commit comments

Comments
 (0)