@@ -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 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 ,
@@ -163,6 +166,9 @@ impl RenderBackend {
163
166
blob_image_renderer : Option < Box < BlobImageRenderer > > ,
164
167
enable_render_on_scroll : bool ,
165
168
) -> RenderBackend {
169
+ // The namespace_id should start from 1.
170
+ NEXT_NAMESPACE_ID . fetch_add ( 1 , Ordering :: Relaxed ) ;
171
+
166
172
let resource_cache = ResourceCache :: new ( texture_cache, workers, blob_image_renderer) ;
167
173
168
174
register_thread_with_profiler ( "Backend" . to_string ( ) ) ;
@@ -177,7 +183,6 @@ impl RenderBackend {
177
183
gpu_cache : GpuCache :: new ( ) ,
178
184
frame_config,
179
185
documents : FastHashMap :: default ( ) ,
180
- next_namespace_id : IdNamespace ( 1 ) ,
181
186
notifier,
182
187
recorder,
183
188
@@ -421,6 +426,10 @@ impl RenderBackend {
421
426
}
422
427
}
423
428
429
+ fn next_namespace_id ( & self ) -> IdNamespace {
430
+ IdNamespace ( NEXT_NAMESPACE_ID . fetch_add ( 1 , Ordering :: Relaxed ) as u32 )
431
+ }
432
+
424
433
pub fn run ( & mut self , mut profile_counters : BackendProfileCounters ) {
425
434
let mut frame_counter: u32 = 0 ;
426
435
@@ -463,9 +472,7 @@ impl RenderBackend {
463
472
tx. send ( glyph_indices) . unwrap ( ) ;
464
473
}
465
474
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 ( ) ;
469
476
}
470
477
ApiMsg :: AddDocument ( document_id, initial_size) => {
471
478
let document = Document :: new (
0 commit comments