@@ -22,6 +22,7 @@ use resource_cache::ResourceCache;
22
22
use scene:: Scene ;
23
23
#[ cfg( feature = "debugger" ) ]
24
24
use serde_json;
25
+ use std:: sync:: atomic:: { ATOMIC_USIZE_INIT , AtomicUsize , Ordering } ;
25
26
use std:: sync:: { Arc , Mutex } ;
26
27
use std:: sync:: mpsc:: Sender ;
27
28
use std:: u32;
@@ -124,6 +125,9 @@ enum DocumentOp {
124
125
Rendered ( RendererFrame ) ,
125
126
}
126
127
128
+ /// The unique id for WR resource identification.
129
+ static mut NEXT_NAMESPACE_ID : AtomicUsize = ATOMIC_USIZE_INIT ;
130
+
127
131
/// The render backend is responsible for transforming high level display lists into
128
132
/// GPU-friendly work which is then submitted to the renderer in the form of a frame::Frame.
129
133
///
@@ -133,7 +137,6 @@ pub struct RenderBackend {
133
137
payload_rx : PayloadReceiver ,
134
138
payload_tx : PayloadSender ,
135
139
result_tx : Sender < ResultMsg > ,
136
- next_namespace_id : IdNamespace ,
137
140
default_device_pixel_ratio : f32 ,
138
141
139
142
gpu_cache : GpuCache ,
@@ -177,7 +180,6 @@ impl RenderBackend {
177
180
gpu_cache : GpuCache :: new ( ) ,
178
181
frame_config,
179
182
documents : FastHashMap :: default ( ) ,
180
- next_namespace_id : IdNamespace ( 1 ) ,
181
183
notifier,
182
184
recorder,
183
185
@@ -452,9 +454,10 @@ impl RenderBackend {
452
454
tx. send ( glyph_indices) . unwrap ( ) ;
453
455
}
454
456
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
+ }
458
461
}
459
462
ApiMsg :: AddDocument ( document_id, initial_size) => {
460
463
let document = Document :: new (
0 commit comments