Skip to content

Commit 3e6f421

Browse files
committed
Disable GPU acceleration and add perf. enhancing switches in OSR (cztomczak#463)
1 parent 2630244 commit 3e6f421

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

examples/screenshot.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
try:
4545
from PIL import Image, PILLOW_VERSION
46-
except:
46+
except ImportError:
4747
print("[screenshot.py] Error: PIL module not available. To install"
4848
" type: pip install Pillow")
4949
sys.exit(1)
@@ -64,9 +64,26 @@ def main():
6464
os.remove(SCREENSHOT_PATH)
6565
command_line_arguments()
6666
# Off-screen-rendering requires setting "windowless_rendering_enabled"
67-
# option, so that RenderHandler callbacks are called.
68-
cef.Initialize(settings={"windowless_rendering_enabled": True})
69-
create_browser()
67+
# option.
68+
settings = {
69+
"windowless_rendering_enabled": True,
70+
}
71+
switches = {
72+
# GPU acceleration is not supported in OSR mode, so must disable
73+
# it using these Chromium switches (Issue #240 and #463)
74+
"disable-gpu": "",
75+
"disable-gpu-compositing": "",
76+
# Tweaking OSR performance by setting the same Chromium flags
77+
# as in upstream cefclient (Issue #240).
78+
"enable-begin-frame-scheduling": "",
79+
"disable-surfaces": "", # This is required for PDF ext to work
80+
}
81+
browser_settings = {
82+
# Tweaking OSR performance (Issue #240)
83+
"windowless_frame_rate": 30, # Default frame rate in CEF is 30
84+
}
85+
cef.Initialize(settings=settings, switches=switches)
86+
create_browser(browser_settings)
7087
cef.MessageLoop()
7188
cef.Shutdown()
7289
print("[screenshot.py] Opening screenshot with default application")
@@ -108,7 +125,7 @@ def command_line_arguments():
108125
sys.exit(1)
109126

110127

111-
def create_browser():
128+
def create_browser(settings):
112129
# Create browser in off-screen-rendering mode (windowless mode)
113130
# by calling SetAsOffscreen method. In such mode parent window
114131
# handle can be NULL (0).
@@ -120,6 +137,7 @@ def create_browser():
120137
print("[screenshot.py] Loading url: {url}"
121138
.format(url=URL))
122139
browser = cef.CreateBrowserSync(window_info=window_info,
140+
settings=settings,
123141
url=URL)
124142
browser.SetClientHandler(LoadHandler())
125143
browser.SetClientHandler(RenderHandler())

unittests/osr_test.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
font-size: 11pt;
2424
}
2525
</style>
26-
26+
2727
<script>
2828
function print(msg) {
2929
console.log(msg+" [JS]");
@@ -92,8 +92,23 @@ def test_osr(self):
9292
settings["debug"] = True
9393
settings["log_severity"] = cef.LOGSEVERITY_WARNING
9494

95+
switches = {
96+
# GPU acceleration is not supported in OSR mode, so must disable
97+
# it using these Chromium switches (Issue #240 and #463)
98+
"disable-gpu": "",
99+
"disable-gpu-compositing": "",
100+
# Tweaking OSR performance by setting the same Chromium flags
101+
# as in upstream cefclient (Issue #240).
102+
"enable-begin-frame-scheduling": "",
103+
"disable-surfaces": "", # This is required for PDF ext to work
104+
}
105+
browser_settings = {
106+
# Tweaking OSR performance (Issue #240)
107+
"windowless_frame_rate": 30, # Default frame rate in CEF is 30
108+
}
109+
95110
# Initialize
96-
cef.Initialize(settings)
111+
cef.Initialize(settings=settings, switches=switches)
97112
subtest_message("cef.Initialize() ok")
98113

99114
# Accessibility handler
@@ -111,6 +126,7 @@ def test_osr(self):
111126
window_info = cef.WindowInfo()
112127
window_info.SetAsOffscreen(0)
113128
browser = cef.CreateBrowserSync(window_info=window_info,
129+
settings=browser_settings,
114130
url=g_datauri)
115131

116132
# Javascript bindings
@@ -231,7 +247,7 @@ def GetViewRect(self, rect_out, **_):
231247
rect_out.extend([0, 0, 800, 600])
232248
return True
233249

234-
def OnPaint(self, browser, element_type, paint_buffer, **_):
250+
def OnPaint(self, element_type, paint_buffer, **_):
235251
"""Called when an element should be painted."""
236252
if element_type == cef.PET_VIEW:
237253
self.test_case.assertEqual(paint_buffer.width, 800)

0 commit comments

Comments
 (0)