Skip to content

Commit 10f7974

Browse files
committed
Use a global static variable for IdNamespace counting.
1 parent 0f4f519 commit 10f7974

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

webrender/src/render_backend.rs

+8-5
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 mut 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,
@@ -177,7 +180,6 @@ impl RenderBackend {
177180
gpu_cache: GpuCache::new(),
178181
frame_config,
179182
documents: FastHashMap::default(),
180-
next_namespace_id: IdNamespace(1),
181183
notifier,
182184
recorder,
183185

@@ -452,9 +454,10 @@ impl RenderBackend {
452454
tx.send(glyph_indices).unwrap();
453455
}
454456
ApiMsg::CloneApi(sender) => {
455-
let namespace = self.next_namespace_id;
456-
self.next_namespace_id = IdNamespace(namespace.0 + 1);
457-
sender.send(namespace).unwrap();
457+
unsafe {
458+
let namespace = IdNamespace(NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed) as u32);
459+
sender.send(namespace).unwrap();
460+
}
458461
}
459462
ApiMsg::AddDocument(document_id, initial_size) => {
460463
let document = Document::new(

0 commit comments

Comments
 (0)