mirror of https://github.com/kivy/kivy.git
Graphics: Add Sdl2 vsync (#4854)
* Add support for vsync configuration. * Accept all integers. * Bump config version. * The added version is now 2.1.0.
This commit is contained in:
parent
a35b0531bd
commit
0b7b6a19fb
|
@ -238,6 +238,12 @@ Available configuration tokens
|
|||
`allow_screensaver`: int, one of 0 or 1, defaults to 1
|
||||
Allow the device to show a screen saver, or to go to sleep
|
||||
on mobile devices. Only works for the sdl2 window provider.
|
||||
`vsync`: `none`, empty value, or integers
|
||||
Whether vsync is enabled, currently only used with sdl2 window.
|
||||
Possible values are `none` or empty value -- leaves it unchanged,
|
||||
``0`` -- disables vsync, ``1`` or larger -- sets vsync interval,
|
||||
``-1`` sets adaptive vsync. It falls back to 1 if setting to ``2+``
|
||||
or ``-1`` failed. See ``SDL_GL_SetSwapInterval``.
|
||||
|
||||
:input:
|
||||
|
||||
|
@ -309,6 +315,9 @@ Available configuration tokens
|
|||
Check the specific module's documentation for a list of accepted
|
||||
arguments.
|
||||
|
||||
.. versionchanged:: 2.1.0
|
||||
`vsync` has been added to the graphics section
|
||||
|
||||
.. versionchanged:: 1.10.0
|
||||
`min_state_time` and `allow_screensaver` have been added
|
||||
to the `graphics` section.
|
||||
|
@ -360,7 +369,7 @@ from weakref import ref
|
|||
_is_rpi = exists('/opt/vc/include/bcm_host.h')
|
||||
|
||||
# Version number of current configuration format
|
||||
KIVY_CONFIG_VERSION = 21
|
||||
KIVY_CONFIG_VERSION = 22
|
||||
|
||||
Config = None
|
||||
'''The default Kivy configuration object. This is a :class:`ConfigParser`
|
||||
|
@ -750,7 +759,6 @@ if not environ.get('KIVY_DOC_INCLUDE'):
|
|||
Config.setdefault('graphics', 'rotation', '0')
|
||||
Config.setdefault('graphics', 'show_cursor', '1')
|
||||
Config.setdefault('graphics', 'top', '0')
|
||||
Config.setdefault('graphics', 'vsync', '1')
|
||||
Config.setdefault('graphics', 'width', '800')
|
||||
|
||||
# input configuration
|
||||
|
@ -786,7 +794,6 @@ if not environ.get('KIVY_DOC_INCLUDE'):
|
|||
Config.setdefault('widgets', 'list_trigger_distance', '5')
|
||||
|
||||
elif version == 1:
|
||||
Config.remove_option('graphics', 'vsync')
|
||||
Config.set('graphics', 'maxfps', '60')
|
||||
|
||||
elif version == 2:
|
||||
|
@ -880,6 +887,9 @@ if not environ.get('KIVY_DOC_INCLUDE'):
|
|||
elif version == 20:
|
||||
Config.setdefault('network', 'useragent', 'curl')
|
||||
|
||||
elif version == 21:
|
||||
Config.setdefault('graphics', 'vsync', '')
|
||||
|
||||
else:
|
||||
# for future.
|
||||
break
|
||||
|
|
|
@ -233,6 +233,22 @@ cdef class _WindowSDL2Storage:
|
|||
if not self.ctx:
|
||||
self.die()
|
||||
|
||||
# vsync
|
||||
vsync = Config.get('graphics', 'vsync')
|
||||
if vsync and vsync != 'none':
|
||||
vsync = Config.getint('graphics', 'vsync')
|
||||
|
||||
Logger.debug(f'WindowSDL: setting vsync interval=={vsync}')
|
||||
res = SDL_GL_SetSwapInterval(vsync)
|
||||
|
||||
if res == -1:
|
||||
status = ''
|
||||
if vsync not in (0, 1):
|
||||
res = SDL_GL_SetSwapInterval(1)
|
||||
status = ', trying fallback to 1: ' + 'failed' if res == -1 else 'succeeded'
|
||||
|
||||
Logger.debug('WindowSDL: requested vsync failed' + status)
|
||||
|
||||
# Open all available joysticks
|
||||
cdef int joy_i
|
||||
for joy_i in range(SDL_NumJoysticks()):
|
||||
|
|
Loading…
Reference in New Issue