Bug 1406494 - Add a WR_RESOURCE_PATH environment variable that lets you set a resource override path for webrender. r?kats
This allows easier testing of shader changes. If you point this environment
variable at your gfx/webrender/res/ directory, the shaders will be read from
that directory when Firefox is launched, so you can test shader changes just by
restarting Firefox and don't need to recompile.
MozReview-Commit-ID: 9Dt6MhErnGS
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -59,16 +59,25 @@ bool is_glcontext_egl(void* glcontext_pt
return glcontext->GetContextType() == mozilla::gl::GLContextType::EGL;
}
bool gfx_use_wrench()
{
return gfxEnv::EnableWebRenderRecording();
}
+const char* gfx_wr_resource_path_override()
+{
+ const char* resourcePath = PR_GetEnv("WR_RESOURCE_PATH");
+ if (!resourcePath || resourcePath[0] == '\0') {
+ return nullptr;
+ }
+ return resourcePath;
+}
+
void gfx_critical_note(const char* msg)
{
gfxCriticalNote << msg;
}
void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname)
{
MOZ_ASSERT(glcontext_ptr);
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -1,9 +1,9 @@
-use std::ffi::CString;
+use std::ffi::{CStr, CString};
use std::{mem, slice};
use std::path::PathBuf;
use std::ptr;
use std::sync::Arc;
use std::os::raw::{c_void, c_char, c_float};
use gleam::gl;
use webrender_api::*;
@@ -410,16 +410,17 @@ extern "C" {
fn is_in_main_thread() -> bool;
fn is_glcontext_egl(glcontext_ptr: *mut c_void) -> bool;
// Enables binary recording that can be used with `wrench replay`
// Outputs a wr-record-*.bin file for each window that is shown
// Note: wrench will panic if external images are used, they can
// be disabled in WebRenderBridgeParent::ProcessWebRenderCommands
// by commenting out the path that adds an external image ID
fn gfx_use_wrench() -> bool;
+ fn gfx_wr_resource_path_override() -> *const c_char;
fn gfx_critical_note(msg: *const c_char);
}
struct CppNotifier {
window_id: WrWindowId,
}
unsafe impl Send for CppNotifier {}
@@ -639,16 +640,27 @@ pub extern "C" fn wr_window_new(window_i
let opts = RendererOptions {
enable_aa: true,
enable_subpixel_aa: true,
recorder: recorder,
blob_image_renderer: Some(Box::new(Moz2dImageRenderer::new(workers.clone()))),
workers: Some(workers.clone()),
enable_render_on_scroll: false,
+ resource_override_path: unsafe {
+ let override_charptr = gfx_wr_resource_path_override();
+ if override_charptr.is_null() {
+ None
+ } else {
+ match CStr::from_ptr(override_charptr).to_str() {
+ Ok(override_str) => Some(PathBuf::from(override_str)),
+ _ => None
+ }
+ }
+ },
..Default::default()
};
let (renderer, sender) = match Renderer::new(gl, opts) {
Ok((renderer, sender)) => (renderer, sender),
Err(e) => {
println!(" Failed to create a Renderer: {:?}", e);
let msg = CString::new(format!("wr_window_new: {:?}", e)).unwrap();
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -16,16 +16,17 @@ extern "C" {
// Functions invoked from Rust code
// ----
bool is_in_compositor_thread();
bool is_in_main_thread();
bool is_in_render_thread();
bool is_glcontext_egl(void* glcontext_ptr);
bool gfx_use_wrench();
+const char* gfx_wr_resource_path_override();
void gfx_critical_note(const char* msg);
void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname);
} // extern "C"
// Some useful defines to stub out webrender binding functions for when we
// build gecko without webrender. We try to tell the compiler these functions
// are unreachable in that case, but VC++ emits a warning if it finds any
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -1,13 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-/* Generated with cbindgen:0.1.23 */
+/* Generated with cbindgen:0.1.25 */
/* DO NOT MODIFY THIS MANUALLY! This file was generated using cbindgen.
* To generate this file:
* 1. Get the latest cbindgen using `cargo install --force cbindgen`
* a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
* 2. Run `rustup run nightly cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
*/
@@ -758,16 +758,18 @@ struct FontInstancePlatformOptions {
* a. Alternatively, you can clone `https://github.com/rlhunt/cbindgen` and use a tagged release
* 2. Run `rustup run nightly cbindgen toolkit/library/rust/ --crate webrender_bindings -o gfx/webrender_bindings/webrender_ffi_generated.h`
*/
extern void gfx_critical_note(const char *aMsg);
extern bool gfx_use_wrench();
+extern const char *gfx_wr_resource_path_override();
+
extern bool is_glcontext_egl(void *aGlcontextPtr);
extern bool is_in_compositor_thread();
extern bool is_in_main_thread();
extern bool is_in_render_thread();