Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions webrender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ pub use device::build_shader_strings;
pub use renderer::{CpuProfile, DebugFlags, GpuProfile, OutputImageHandler, RendererKind};
pub use renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource};
pub use renderer::{GraphicsApi, GraphicsApiInfo, ReadPixelsFormat, Renderer, RendererOptions};
pub use renderer::{ThreadListener};
pub use renderer::MAX_VERTEX_TEXTURE_WIDTH;
pub use webrender_api as api;
75 changes: 54 additions & 21 deletions webrender/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1787,33 +1787,57 @@ impl Renderer {
let debug_flags = options.debug_flags;
let payload_tx_for_backend = payload_tx.clone();
let recorder = options.recorder;
let worker_config = ThreadPoolConfig::new()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worker_config is only used when we don't have the thread pool. So, move the config into the worker's unwrap_or_else() block.

.thread_name(|idx| format!("WebRender:Worker#{}", idx))
.start_handler(|idx| {
register_thread_with_profiler(format!("WebRender:Worker#{}", idx));
});
let thread_listener = Arc::new(options.thread_listener);
let thread_listener_for_rayon_start = thread_listener.clone();
let thread_listener_for_rayon_end = thread_listener.clone();
let workers = options
.workers
.take()
.unwrap_or_else(|| Arc::new(ThreadPool::new(worker_config).unwrap()));
.unwrap_or_else(|| {
let worker_config = ThreadPoolConfig::new()
.thread_name(|idx|{ format!("WRWorker#{}", idx) })
.start_handler(move |idx| {
register_thread_with_profiler(format!("WRWorker#{}", idx));
if let Some(ref thread_listener) = *thread_listener_for_rayon_start {
thread_listener.thread_started(&format!("WRWorker#{}", idx));
}
})
.exit_handler(move |idx| {
if let Some(ref thread_listener) = *thread_listener_for_rayon_end {
thread_listener.thread_stopped(&format!("WRWorker#{}", idx));
}
});
Arc::new(ThreadPool::new(worker_config).unwrap())
});
let enable_render_on_scroll = options.enable_render_on_scroll;

let blob_image_renderer = options.blob_image_renderer.take();
try!{ thread::Builder::new().name("RenderBackend".to_string()).spawn(move || {
let mut backend = RenderBackend::new(api_rx,
payload_rx,
payload_tx_for_backend,
result_tx,
device_pixel_ratio,
texture_cache,
workers,
backend_notifier,
config,
recorder,
blob_image_renderer,
enable_render_on_scroll);
backend.run(backend_profile_counters);
})};
let thread_listener_for_render_backend = thread_listener.clone();
let thread_name = format!("WRRenderBackend#{}", options.renderer_id.unwrap_or(0));
try!{
thread::Builder::new().name(thread_name.clone()).spawn(move || {
register_thread_with_profiler(thread_name.clone());
if let Some(ref thread_listener) = *thread_listener_for_render_backend {
thread_listener.thread_started(&thread_name);
}
let mut backend = RenderBackend::new(api_rx,
payload_rx,
payload_tx_for_backend,
result_tx,
device_pixel_ratio,
texture_cache,
workers,
backend_notifier,
config,
recorder,
blob_image_renderer,
enable_render_on_scroll);
backend.run(backend_profile_counters);
if let Some(ref thread_listener) = *thread_listener_for_render_backend {
thread_listener.thread_stopped(&thread_name);
}
})
};

let gpu_cache_texture = CacheTexture::new(&mut device);

Expand Down Expand Up @@ -3826,6 +3850,11 @@ pub trait OutputImageHandler {
fn unlock(&mut self, pipeline_id: PipelineId);
}

pub trait ThreadListener {
fn thread_started(&self, thread_name: &str);
fn thread_stopped(&self, thread_name: &str);
}

pub struct RendererOptions {
pub device_pixel_ratio: f32,
pub resource_override_path: Option<PathBuf>,
Expand All @@ -3845,8 +3874,10 @@ pub struct RendererOptions {
pub workers: Option<Arc<ThreadPool>>,
pub blob_image_renderer: Option<Box<BlobImageRenderer>>,
pub recorder: Option<Box<ApiRecordingReceiver>>,
pub thread_listener: Option<Box<ThreadListener + Send + Sync>>,
pub enable_render_on_scroll: bool,
pub debug_flags: DebugFlags,
pub renderer_id: Option<u64>,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have multiple renderer in the same process. Use this renderer_id for identification.

}

impl Default for RendererOptions {
Expand All @@ -3871,7 +3902,9 @@ impl Default for RendererOptions {
workers: None,
blob_image_renderer: None,
recorder: None,
thread_listener: None,
enable_render_on_scroll: true,
renderer_id: None,
}
}
}
Expand Down