Read the renderer drawing now, the saved choice, what the next start
will use and whether "gpu" can be chosen.
The plugin reads the state once while it starts and keeps it for its menu.
Each call asks the player; gpu.available is false, with a reason, where
this player has no GPU renderer, without a user interface, or when the
driver is ruled out.
const state = await plugin.rendering.state().catch((error: PluginError) => {
if (error.code === "unsupported") return null; // a player before 0.5.13
throw error;
});
if (state && !state.gpu.available) console.log(state.gpu.reason?.message);
Save the user's rendering choice. The player writes it to its settings
at once; the running player keeps its renderer, and the next start
uses the choice whether or not the user restarts now. "auto" and
"software" are always accepted.
"auto", "gpu" or "software".
The new state; RenderingState.restartPending tells whether a restart would change the renderer.
unsupported (rejects) "gpu" where this player has no GPU
renderer on this system, or runs without a user interface; also any
value on a player before 0.5.13.
unavailable (rejects) "gpu" while it is ruled out: the
graphics driver is on the player's denylist, or GPU rendering crashed
at an earlier start. The message says which, with the adapter's name
and the driver version.
A Reset item returns the renderer to the player's own choice and tells
the user when it takes effect. setPreference saves the choice and
resolves with the new state; restartPending is true when the next
start will draw differently from this run. A refused save leaves the
old choice in place.
try {
const state = await plugin.rendering.setPreference("auto");
if (state.restartPending) await plugin.osd.show("Applies after a restart");
} catch (error) {
// `failed`: the player's settings file could not be written.
await plugin.osd.show("Not saved ({})", [(error as PluginError).code]);
}
Restart the player so that a changed choice applies now. Resolves once the player has accepted; the player then quits normally, which stops every plugin (this one included), and starts again with the same plugins. A local file that was open continues at its position, paused or playing as it was; a stream or another source that is not a file is not reopened.
busy (rejects) A restart is already under way, or this player
was itself started by a restart less than 30 seconds ago (so a plugin
that restarts on activation cannot make a loop).
After the user changed the renderer, the plugin offers to restart now.
confirm asks first, because a restart closes every window; once restartPlayer resolves, the player is quitting and
will stop this plugin, so nothing else is started after it.
const { confirmed } = await plugin.dialogs.confirm({
message: "Restart the player now?",
detail: "The new renderer is used from the restart on. The video continues where it is.",
confirm: "Restart",
});
if (confirmed)
await plugin.rendering.restartPlayer().catch((error: PluginError) => {
// `failed`: the new player could not start; this one keeps running.
void plugin.osd.show("Could not restart ({})", [error.code]);
});
plugin.rendering: the player's rendering choice, GPU or software: read it, change the saved choice, restart the player.Remarks
The choice works like a browser's hardware acceleration switch: the player saves it in its own settings at once, and the running player keeps its renderer. The next start uses it, whether the user restarts now through Rendering.restartPlayer or quits and starts the player later. The player can still rule the GPU out at a start (an environment variable, a graphics driver on its denylist, a GPU crash at an earlier start); RenderingState.nextMode and RenderingState.nextReason say what the next start will do.
The renderer is a choice for the whole player and a restart stops every plugin, so change it only when the user asks. A plugin that only needs to know whether render options work reads SystemInfo.rendering.
Example: Offer GPU rendering as a menu item
Settings ▸ GPU Rendering (Experimental) carries a check mark while the next start will draw on the GPU, is greyed out with the player's reason where the GPU cannot be chosen, and saves the other choice when picked.
state()reads the player's view once;setPreferencesaves the choice and resolves with the new state, which the item's bound values read again after the handler. The how-to guide adds the restart.See
Offer a GPU rendering switch
Player
0.5.13
Since
1.5.35