Skip to content

Commit 5dbd9d6

Browse files
committed
Update pysdl2.py example - support for Windows, performance fixes
1 parent c7553bc commit 5dbd9d6

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

examples/README-examples.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ workarounds.
4545
library (GTK 3). Currently broken on Mac ([#310](../../../issues/310)).
4646
- [pysdl2.py](pysdl2.py): off-screen rendering example for
4747
[PySDL2](https://github.com/marcusva/py-sdl2) library. Currently tested
48-
only on Linux ([#324](../../../issues/324)).
48+
and works fine on Linux and Windows. For Mac support and performance
49+
tweaking see Issue [#324](../../../issues/324).
4950
- [pywin32.py](pywin32.py): example for [pywin32](https://github.com/mhammond/pywin32)
5051
library
5152
- [qt.py](qt.py): example for [PyQt4](https://wiki.python.org/moin/PyQt4),

examples/pysdl2.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
Requires PySDL2 and SDL2 libraries.
88
99
Tested configurations:
10+
- Windows 7: SDL 2.0.7 and PySDL2 0.9.6
1011
- Fedora 25: SDL2 2.0.5 with PySDL2 0.9.3
1112
- Ubuntu 14.04: SDL2 with PySDL2 0.9.6
1213
1314
Install instructions:
1415
1. Install SDL libraries for your OS, e.g:
16+
- Windows: Download SDL2.dll from http://www.libsdl.org/download-2.0.php
17+
and put SDL2.dll in C:\Python27\ (where you've installed Python)
1518
- Fedora: sudo dnf install SDL2 SDL2_ttf SDL2_image SDL2_gfx SDL2_mixer
1619
- Ubuntu: sudo apt-get install libsdl2-dev
1720
2. Install PySDL2 using pip package manager:
1821
pip install PySDL2
1922
2023
Missing functionality:
24+
- Performance is still not perfect, see Issue #379 for further details
2125
- Keyboard modifiers that are not yet handled in this example:
2226
ctrl, marking text inputs with the shift key.
2327
- Mouse dragging
@@ -69,10 +73,23 @@ def main():
6973
browserHeight = height - headerHeight
7074
browserWidth = width
7175
# Mouse wheel fudge to enhance scrolling
72-
scrollEnhance = 20
76+
scrollEnhance = 40
7377
# Initialise CEF for offscreen rendering
7478
sys.excepthook = cef.ExceptHook
75-
cef.Initialize(settings={"windowless_rendering_enabled": True})
79+
switches = {
80+
# Tweaking OSR performance by setting the same Chromium flags
81+
# as in upstream cefclient (Issue #240).
82+
"disable-surfaces": "",
83+
"disable-gpu": "",
84+
"disable-gpu-compositing": "",
85+
"enable-begin-frame-scheduling": "",
86+
}
87+
browser_settings = {
88+
# Tweaking OSR performance (Issue #240)
89+
"windowless_frame_rate": 100
90+
}
91+
cef.Initialize(settings={"windowless_rendering_enabled": True},
92+
switches=switches)
7693
window_info = cef.WindowInfo()
7794
window_info.SetAsOffscreen(0)
7895
# Initialise SDL2 for video (add other init constants if you
@@ -96,7 +113,9 @@ def main():
96113
# Set-up the RenderHandler, passing in the SDL2 renderer
97114
renderHandler = RenderHandler(renderer, width, height - headerHeight)
98115
# Create the browser instance
99-
browser = cef.CreateBrowserSync(window_info, url="https://www.google.com/")
116+
browser = cef.CreateBrowserSync(window_info,
117+
url="https://www.google.com/",
118+
settings=browser_settings)
100119
browser.SetClientHandler(LoadHandler())
101120
browser.SetClientHandler(renderHandler)
102121
# Must call WasResized at least once to let know CEF that

0 commit comments

Comments
 (0)