Skip to content

Commit

Permalink
extension: Log used renderer.
Browse files Browse the repository at this point in the history
Log which renderer-backend was actually used in the
browser console.
  • Loading branch information
iwannabethedev committed May 2, 2023
1 parent 182ae6c commit e54ffb9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions render/canvas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ impl RenderBackend for WebCanvasRenderBackend {
Cow::Borrowed("Renderer: Canvas")
}

fn name(&self) -> &'static str {
"canvas"
}

fn set_quality(&mut self, _quality: StageQuality) {}
}

Expand Down
4 changes: 4 additions & 0 deletions render/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub trait RenderBackend: Downcast {
fn context3d_present(&mut self, context: &mut dyn Context3D) -> Result<(), Error>;

fn debug_info(&self) -> Cow<'static, str>;
/// An internal name that is used to identify the render-backend.
/// For valid values, look at:
/// web/packages/core/src/load-options.ts:RenderBackend
fn name(&self) -> &'static str;

fn set_quality(&mut self, quality: StageQuality);
}
Expand Down
4 changes: 4 additions & 0 deletions render/src/backend/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,9 @@ impl RenderBackend for NullRenderer {
Cow::Borrowed("Renderer: Null")
}

fn name(&self) -> &'static str {
""
}

fn set_quality(&mut self, _quality: StageQuality) {}
}
4 changes: 4 additions & 0 deletions render/webgl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,10 @@ impl RenderBackend for WebGlRenderBackend {
Cow::Owned(result.join("\n"))
}

fn name(&self) -> &'static str {
"webgl"
}

fn set_quality(&mut self, _quality: StageQuality) {}
}

Expand Down
4 changes: 4 additions & 0 deletions render/wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ impl<T: RenderTarget + 'static> RenderBackend for WgpuRenderBackend<T> {
Cow::Owned(result.join("\n"))
}

fn name(&self) -> &'static str {
"webgpu"
}

fn set_quality(&mut self, quality: StageQuality) {
self.surface = Surface::new(
&self.descriptors,
Expand Down
11 changes: 9 additions & 2 deletions web/packages/core/src/ruffle-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,17 @@ export class RufflePlayer extends HTMLElement {
this.loadedConfig
);
this._cachedDebugInfo = this.instance!.renderer_debug_info();

const actuallyUsedRendererName = this.instance!.renderer_name();

console.log(
"New Ruffle instance created (WebAssembly extensions: " +
"%c" +
"New Ruffle instance created (WebAssembly extensions: " +
(ruffleConstructor.is_wasm_simd_used() ? "ON" : "OFF") +
")"
" | Used renderer: " +
(actuallyUsedRendererName ?? "") +
")",
"background: #37528C; color: #FFAD33"
);

// In Firefox, AudioContext.state is always "suspended" when the object has just been created.
Expand Down
5 changes: 5 additions & 0 deletions web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ impl Ruffle {
.unwrap_or(JsValue::NULL)
}

pub fn renderer_name(&self) -> JsValue {
self.with_core(|core| JsValue::from_str(core.renderer().name()))
.unwrap_or(JsValue::NULL)
}

// after the context menu is closed, remember to call `clear_custom_menu_items`!
pub fn prepare_context_menu(&mut self) -> JsValue {
self.with_core_mut(|core| {
Expand Down

0 comments on commit e54ffb9

Please sign in to comment.