Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rendercanvas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,9 @@ def _rc_get_present_info(self, present_methods: list[str]) -> dict | None:
selected presentation method.

The ``present_methods`` represents the supported methods of the
canvas-context, possibly filtered by a user-specified method. A canvas
backend must implement at least the "screen" or "bitmap" method.
canvas-context, in order of context-preference, possibly filtered by a
user-specified method. A canvas backend must implement at least the
"screen" or "bitmap" method.

The returned dict must contain at least the key 'method', which must
match one of the ``present_methods``. The remaining values represent
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/contexts/bitmapcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BitmapContext(BaseContext):

# Note: instantiating this class creates an instance of a sub-class, dedicated to the present method of the canvas.

present_methods = ["bitmap", "screen"]
present_methods = ["bitmap", "screen"] # in order of preference

def __new__(cls, present_info: dict):
# Instantiating this class actually produces a subclass
Expand Down
2 changes: 1 addition & 1 deletion rendercanvas/contexts/wgpucontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WgpuContext(BaseContext):

# Note: instantiating this class creates an instance of a sub-class, dedicated to the present method of the canvas.

present_methods = ["screen", "bitmap"]
present_methods = ["screen", "bitmap"] # in order of preference

def __new__(cls, present_info: dict):
# Instantiating this class actually produces a subclass
Expand Down
8 changes: 6 additions & 2 deletions rendercanvas/pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,18 @@ def _rc_gui_poll(self):
pass # Nothing to be done; the JS loop is always running (and Pyodide wraps that in a global asyncio loop)

def _rc_get_present_info(self, present_methods):
if "screen" in present_methods:
# Select method
the_method = present_methods[0]

# Apply
if the_method == "screen":
# wgpu-specific presentation. The wgpu.backends.pyodide.GPUCanvasContext must be able to consume this.
return {
"method": "screen",
"platform": "browser",
"window": self._canvas_element, # Just provide the canvas object
}
elif "bitmap" in present_methods:
elif the_method == "bitmap":
# Generic presentation
return {
"method": "bitmap",
Expand Down
15 changes: 3 additions & 12 deletions rendercanvas/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,14 @@ def _rc_gui_poll(self):
loop._app.processEvents()

def _rc_get_present_info(self, present_methods):
# Select what method the canvas prefers
preferred_method = "screen"
if SYSTEM_IS_WAYLAND:
# Select the method
the_method = present_methods[0]
if SYSTEM_IS_WAYLAND and "bitmap" in present_methods:
# Trying to render to screen on Wayland segfaults. This might be because
# the "display" is not the real display id. We can tell Qt to use
# XWayland, so we can use the X11 path. This worked at some point,
# but later this resulted in a Rust panic. So, until this is sorted
# out, we fall back to rendering via an image.
preferred_method = "bitmap"

# Select method
the_method = None
if preferred_method in present_methods:
the_method = preferred_method
elif "screen" in present_methods:
the_method = "screen"
elif "bitmap" in present_methods:
the_method = "bitmap"

# Apply
Expand Down
15 changes: 3 additions & 12 deletions rendercanvas/wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,10 @@ def _rc_gui_poll(self):
loop.process_wx_events()

def _rc_get_present_info(self, present_methods):
# Select what method the canvas prefers
preferred_method = "screen"
if SYSTEM_IS_WAYLAND:
preferred_method = "bitmap" # also see qt.py

# Select method
the_method = None
if preferred_method in present_methods:
the_method = preferred_method
elif "screen" in present_methods:
the_method = "screen"
elif "bitmap" in present_methods:
the_method = "bitmap"
the_method = present_methods[0]
if SYSTEM_IS_WAYLAND and "bitmap" in present_methods:
the_method = "bitmap" # also see qt.py

# Apply
if the_method == "screen":
Expand Down
2 changes: 1 addition & 1 deletion tests/test_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def test_run_loop_and_close_canvases(SomeLoop):
et = time.time() - t0

print(et)
assert 0.25 < et < 0.45 + leeway
assert 0.25 < et < 0.50 + leeway

assert canvas1._events.is_closed
assert canvas2._events.is_closed
Expand Down