Skip to content

Use a global static variable for IdNamespace counting. #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions webrender/src/render_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use resource_cache::ResourceCache;
use scene::Scene;
#[cfg(feature = "debugger")]
use serde_json;
use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The u32is not stable now. Use usize instead.

error: use of unstable library feature 'integer_atomics' (see issue #32976)
--> src\render_backend.rs:25:25
|
25 | use std::sync::atomic::{AtomicU32, Ordering};

use std::sync::{Arc, Mutex};
use std::sync::mpsc::Sender;
use std::u32;
Expand Down Expand Up @@ -124,6 +125,9 @@ enum DocumentOp {
Rendered(RendererFrame),
}

/// The unique id for WR resource identification.
static NEXT_NAMESPACE_ID: AtomicUsize = ATOMIC_USIZE_INIT;

/// The render backend is responsible for transforming high level display lists into
/// GPU-friendly work which is then submitted to the renderer in the form of a frame::Frame.
///
Expand All @@ -133,7 +137,6 @@ pub struct RenderBackend {
payload_rx: PayloadReceiver,
payload_tx: PayloadSender,
result_tx: Sender<ResultMsg>,
next_namespace_id: IdNamespace,
default_device_pixel_ratio: f32,

gpu_cache: GpuCache,
Expand Down Expand Up @@ -163,6 +166,9 @@ impl RenderBackend {
blob_image_renderer: Option<Box<BlobImageRenderer>>,
enable_render_on_scroll: bool,
) -> RenderBackend {
// The namespace_id should start from 1.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't set the value to 1 directly, so I just increase the value in RenderBackend::new().

error: std::sync::atomic::AtomicUsize::new is not yet stable as a const fn
--> src\render_backend.rs:129:41
|
129 | static NEXT_NAMESPACE_ID: AtomicUsize = AtomicUsize::new(1);
| ^^^^^^^^^^^^^^^^^^^
|
= help: in Nightly builds, add #![feature(const_atomic_usize_new)] to the crate attributes to enable

NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed);

let resource_cache = ResourceCache::new(texture_cache, workers, blob_image_renderer);

register_thread_with_profiler("Backend".to_string());
Expand All @@ -177,7 +183,6 @@ impl RenderBackend {
gpu_cache: GpuCache::new(),
frame_config,
documents: FastHashMap::default(),
next_namespace_id: IdNamespace(1),
notifier,
recorder,

Expand Down Expand Up @@ -421,6 +426,10 @@ impl RenderBackend {
}
}

fn next_namespace_id(&self) -> IdNamespace {
IdNamespace(NEXT_NAMESPACE_ID.fetch_add(1, Ordering::Relaxed) as u32)
}

pub fn run(&mut self, mut profile_counters: BackendProfileCounters) {
let mut frame_counter: u32 = 0;

Expand Down Expand Up @@ -463,9 +472,7 @@ impl RenderBackend {
tx.send(glyph_indices).unwrap();
}
ApiMsg::CloneApi(sender) => {
let namespace = self.next_namespace_id;
self.next_namespace_id = IdNamespace(namespace.0 + 1);
sender.send(namespace).unwrap();
sender.send(self.next_namespace_id()).unwrap();
}
ApiMsg::AddDocument(document_id, initial_size) => {
let document = Document::new(
Expand Down