Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect WebGL support on BrowserInfo #6931

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions panel/io/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class BrowserInfo(Syncable):
webdriver = param.Boolean(default=None, doc="""
Indicates whether the user agent is controlled by automation.""")

webgl = param.Boolean(default=None, doc="""
Indicates whether the browser has WebGL support.""")

# Mapping from parameter name to bokeh model property name
_rename: ClassVar[Mapping[str, str | None]] = {"name": None}

Expand Down
2 changes: 2 additions & 0 deletions panel/models/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ class BrowserInfo(Model):
timezone_offset = Nullable(Float())

webdriver = Nullable(Bool())

webgl = Nullable(Bool())
23 changes: 17 additions & 6 deletions panel/models/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export class BrowserInfoView extends View {
if (timezone_offset != null) {
this.model.timezone_offset = timezone_offset
}
try {
const canvas = document.createElement("canvas")
this.model.webgl = !!(
window.WebGLRenderingContext &&
(canvas.getContext("webgl") || canvas.getContext("experimental-webgl"))
)
} catch (e) {
this.model.webgl = false
}
this._has_finished = true
this.notify_finished()
}
Expand All @@ -38,6 +47,7 @@ export namespace BrowserInfo {
timezone: p.Property<string | null>
timezone_offset: p.Property<number | null>
webdriver: p.Property<boolean | null>
webgl: p.Property<boolean | null>
}
}

Expand All @@ -56,12 +66,13 @@ export class BrowserInfo extends Model {
this.prototype.default_view = BrowserInfoView

this.define<BrowserInfo.Props>(({Bool, Nullable, Float, Str}) => ({
dark_mode: [ Nullable(Bool), null ],
device_pixel_ratio: [ Nullable(Float), null ],
language: [ Nullable(Str), null ],
timezone: [ Nullable(Str), null ],
timezone_offset: [ Nullable(Float), null ],
webdriver: [ Nullable(Bool), null ],
dark_mode: [ Nullable(Bool), null ],
device_pixel_ratio: [ Nullable(Float), null ],
language: [ Nullable(Str), null ],
timezone: [ Nullable(Str), null ],
timezone_offset: [ Nullable(Float), null ],
webdriver: [ Nullable(Bool), null ],
webgl: [ Nullable(Bool), null ],
}))
}
}
2 changes: 2 additions & 0 deletions panel/pane/holoviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ def _render(self, doc, comm, root):
Store.current_backend = loaded_backend
backend = self.backend or Store.current_backend
renderer = Store.renderers[backend]
if state.browser_info and 'webgl' in renderer.param:
renderer.webgl = state.browser_info.webgl
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
mode = 'server' if comm is None else 'default'
if backend == 'bokeh':
params = {}
Expand Down
Loading