Skip to content

Commit

Permalink
Clean up the base software video driver
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseTG committed Apr 24, 2024
1 parent bb8ee25 commit 5d5ebf9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/libretro/drivers/video/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self, drivers: DriverMap, preferred: HardwareContext = HardwareCont
self._preferred = preferred
self._drivers = dict(drivers)
self._supported_contexts = frozenset(self._drivers.keys())
self._current_type = preferred
self._current = self._drivers[preferred](_INITIAL_CALLBACK)

if not isinstance(self._current, VideoDriver):
Expand All @@ -85,7 +84,7 @@ def supported_contexts(self) -> Set[HardwareContext]:
@property
@override
def active_context(self) -> HardwareContext:
return self._current_type
return self._current.active_context

@property
@override
Expand Down
57 changes: 46 additions & 11 deletions src/libretro/drivers/video/software/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,82 @@


class SoftwareVideoDriver(VideoDriver, ABC):
@final
def set_context(self, callback: retro_hw_render_callback) -> retro_hw_render_callback | None:
# Software-rendered drivers don't need retro_hw_render_callback
return None
"""
A base class for software-only video drivers.
Provides common overrides that would be the same
for all software-only drivers.
"""

@property
@override
@final
def supported_contexts(self) -> Set[HardwareContext]:
"""
:return: A set containing only ``HardwareContext.NONE``.
"""
return _EMPTY

@property
@override
@final
def active_context(self) -> HardwareContext | None:
return None
def active_context(self) -> HardwareContext:
"""
:return: ``HardwareContext.NONE``.
"""
return HardwareContext.NONE

@property
@override
@final
def preferred_context(self) -> HardwareContext | None:
return None
def preferred_context(self) -> HardwareContext:
return HardwareContext.NONE

@preferred_context.setter
@override
@final
def preferred_context(self, context: HardwareContext) -> None:
pass
if context != HardwareContext.NONE:
raise RuntimeError("Software-rendered drivers only support HardwareContext.NONE")

@preferred_context.deleter
@override
@final
def preferred_context(self) -> None:
pass
raise RuntimeError("Software-rendered drivers only support HardwareContext.NONE")

@override
@final
def set_context(self, callback: retro_hw_render_callback) -> retro_hw_render_callback | None:
"""
:return: ``None``, as software-rendered drivers don't need any hardware context.
"""
return None

@property
@override
@final
def can_dupe(self) -> bool:
def can_dupe(self) -> bool | None:
return True

@can_dupe.setter
@override
@final
def can_dupe(self, value: bool) -> None:
raise RuntimeError("Software-rendered drivers always support frame duplication")

@can_dupe.deleter
@override
@final
def can_dupe(self) -> None:
raise RuntimeError("Software-rendered drivers always support frame duplication")

@override
@final
def get_hw_framebuffer(self) -> int:
return 0

@override
@final
def get_proc_address(self, sym: bytes) -> retro_proc_address_t | None:
return None
Expand All @@ -73,16 +105,19 @@ def shared_context(self) -> bool:
return False

@shared_context.setter
@override
@final
def shared_context(self, value: bool) -> None:
# Software-rendered drivers don't need any hardware context
raise UnsupportedEnvCall("Shared context is not supported")

@override
@final
def context_reset(self) -> None:
# There's no context to reset
pass

@override
@final
def context_destroy(self) -> None:
# There's no context to destroy
Expand Down

0 comments on commit 5d5ebf9

Please sign in to comment.