Skip to content

Commit c551f5f

Browse files
committed
Use a global static variable for IdNamespace counting.
1 parent b0372a8 commit c551f5f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

webrender/src/render_backend.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use resource_cache::ResourceCache;
2222
use scene::Scene;
2323
#[cfg(feature = "debugger")]
2424
use serde_json;
25+
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
2526
use std::sync::{Arc, Mutex};
2627
use std::sync::mpsc::Sender;
2728
use std::u32;
@@ -124,6 +125,9 @@ enum DocumentOp {
124125
Rendered(RendererFrame),
125126
}
126127

128+
/// The unique id for WR resource identification.
129+
static NEXT_NAMESPACE_ID: AtomicUsize = ATOMIC_USIZE_INIT;
130+
127131
/// The render backend is responsible for transforming high level display lists into
128132
/// GPU-friendly work which is then submitted to the renderer in the form of a frame::Frame.
129133
///
@@ -133,7 +137,6 @@ pub struct RenderBackend {
133137
payload_rx: PayloadReceiver,
134138
payload_tx: PayloadSender,
135139
result_tx: Sender<ResultMsg>,
136-
next_namespace_id: IdNamespace,
137140
default_device_pixel_ratio: f32,
138141

139142
gpu_cache: GpuCache,
@@ -163,6 +166,9 @@ impl RenderBackend {
163166
blob_image_renderer: Option<Box<BlobImageRenderer>>,
164167
enable_render_on_scroll: bool,
165168
) -> RenderBackend {
169+
// The namespace_id should start from 1.
170+
NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed);
171+
166172
let resource_cache = ResourceCache::new(texture_cache, workers, blob_image_renderer);
167173

168174
register_thread_with_profiler("Backend".to_string());
@@ -177,7 +183,6 @@ impl RenderBackend {
177183
gpu_cache: GpuCache::new(),
178184
frame_config,
179185
documents: FastHashMap::default(),
180-
next_namespace_id: IdNamespace(1),
181186
notifier,
182187
recorder,
183188

@@ -421,6 +426,10 @@ impl RenderBackend {
421426
}
422427
}
423428

429+
fn next_namespace_id(&self) -> IdNamespace {
430+
IdNamespace(NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed) as u32)
431+
}
432+
424433
pub fn run(&mut self, mut profile_counters: BackendProfileCounters) {
425434
let mut frame_counter: u32 = 0;
426435

@@ -463,9 +472,7 @@ impl RenderBackend {
463472
tx.send(glyph_indices).unwrap();
464473
}
465474
ApiMsg::CloneApi(sender) => {
466-
let namespace = self.next_namespace_id;
467-
self.next_namespace_id = IdNamespace(namespace.0 + 1);
468-
sender.send(namespace).unwrap();
475+
sender.send(self.next_namespace_id()).unwrap();
469476
}
470477
ApiMsg::AddDocument(document_id, initial_size) => {
471478
let document = Document::new(

0 commit comments

Comments
 (0)