Skip to content

Commit 27d99b3

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

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

webrender/src/render_backend.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ enum DocumentOp {
124124
Rendered(RendererFrame),
125125
}
126126

127+
/// The unique id for WR resource identification. This id is not thread safe.
128+
/// The RenderBackend should be created in the same thread.
129+
static mut NEXT_NAMESPACE_ID: IdNamespace = IdNamespace(1);
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,11 @@ 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 = NEXT_NAMESPACE_ID;
459+
NEXT_NAMESPACE_ID = IdNamespace(NEXT_NAMESPACE_ID.0 + 1);
460+
sender.send(namespace).unwrap();
461+
}
458462
}
459463
ApiMsg::AddDocument(document_id, initial_size) => {
460464
let document = Document::new(

0 commit comments

Comments
 (0)