Skip to content
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

Use a global static variable for IdNamespace counting. #1882

Merged
merged 1 commit into from Oct 20, 2017
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use a global static variable for IdNamespace counting.

  • Loading branch information
JerryShih committed Oct 20, 2017
commit c551f5f6e4b483183447435bf5e344ff8925d0bf
@@ -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};

This comment has been minimized.

@JerryShih

JerryShih Oct 16, 2017

Author Contributor

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;
@@ -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.
///
@@ -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,
@@ -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.

This comment has been minimized.

@JerryShih

JerryShih Oct 20, 2017

Author Contributor

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());
@@ -177,7 +183,6 @@ impl RenderBackend {
gpu_cache: GpuCache::new(),
frame_config,
documents: FastHashMap::default(),
next_namespace_id: IdNamespace(1),
notifier,
recorder,

@@ -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;

@@ -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(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.