Skip to content

Commit

Permalink
Stop using [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed Feb 7, 2025
1 parent 466ec12 commit 8846253
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 16 deletions.
1 change: 0 additions & 1 deletion webrender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ rayon = "1"
ron = { optional = true, version = "0.8" }
serde = { optional = true, version = "1.0", features = ["serde_derive"] }
smallvec = "1"
time = "0.1"
api = { version = "0.66.0", path = "../webrender_api", package = "webrender_api" }
webrender_build = { version = "0.0.2", path = "../webrender_build" }
malloc_size_of = { version = "0.0.3", path = "../wr_malloc_size_of", package = "wr_malloc_size_of" }
Expand Down
1 change: 0 additions & 1 deletion webrender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ extern crate rayon;
extern crate ron;
#[macro_use]
extern crate smallvec;
extern crate time;
#[cfg(all(feature = "capture", feature = "png"))]
extern crate png;
#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions webrender/src/prim_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ impl PrimitiveScratchBuffer {
const LINE_HEIGHT: f32 = 20.0;
const X0: f32 = 32.0;
const Y0: f32 = 32.0;
let now = time::precise_time_ns();
let now = api::precise_time_ns();

let msgs_to_remove = self.messages.len().max(MSGS_TO_RETAIN) - MSGS_TO_RETAIN;
let mut msgs_removed = 0;
Expand Down Expand Up @@ -1438,7 +1438,7 @@ impl PrimitiveScratchBuffer {
) {
self.messages.push(DebugMessage {
msg,
timestamp: time::precise_time_ns(),
timestamp: api::precise_time_ns(),
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions webrender/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! - A '|' token to start a new column.
//! - A '_' token to start a new row.
use api::{ColorF, ColorU};
use api::{ColorF, ColorU, precise_time_ns};
use glyph_rasterizer::profiler::GlyphRasterizeProfiler;
use crate::renderer::DebugRenderer;
use crate::device::query::GpuTimer;
Expand All @@ -32,7 +32,6 @@ use std::fmt::{Write, Debug};
use std::f32;
use std::ops::Range;
use std::time::Duration;
use time::precise_time_ns;

macro_rules! set_text {
($dst:expr, $($arg:tt)*) => {
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/render_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#![deny(missing_docs)]

use api::precise_time_ns;
use std::cell::Cell;
use std::fmt;
use std::marker::PhantomData;
use std::path::PathBuf;
use std::sync::Arc;
use std::u32;
use api::{HitTestFlags, MinimapData, SnapshotImageKey};
use time::precise_time_ns;
use crate::api::channel::{Sender, single_msg_channel, unbounded_channel};
use crate::api::{BuiltDisplayList, IdNamespace, ExternalScrollId, Parameter, BoolParameter};
use crate::api::{FontKey, FontInstanceKey, NativeFontHandle};
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/render_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use api::{DocumentId, ExternalScrollId, HitTestResult};
use api::{IdNamespace, PipelineId, RenderNotifier, SampledScrollOffset};
use api::{NotificationRequest, Checkpoint, QualitySettings};
use api::{FramePublishId, PrimitiveKeyKind, RenderReasons};
use api::precise_time_ns;
use api::units::*;
use api::channel::{single_msg_channel, Sender, Receiver};
use crate::bump_allocator::ChunkPool;
Expand Down Expand Up @@ -71,7 +72,6 @@ use std::{mem, u32};
use std::path::PathBuf;
#[cfg(feature = "replay")]
use crate::frame_builder::Frame;
use time::precise_time_ns;
use core::time::Duration;
use crate::util::{Recycler, VecHelper, drain_filter};

Expand Down
2 changes: 1 addition & 1 deletion webrender/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use api::{PipelineId, ImageRendering, Checkpoint, NotificationRequest, ImageBuff
#[cfg(feature = "replay")]
use api::ExternalImage;
use api::FramePublishId;
use api::precise_time_ns;
use api::units::*;
use api::channel::{Sender, Receiver};
pub use api::DebugFlags;
Expand Down Expand Up @@ -114,7 +115,6 @@ use std::{
};
#[cfg(any(feature = "capture", feature = "replay"))]
use std::collections::hash_map::Entry;
use time::precise_time_ns;

mod debug;
mod gpu_buffer;
Expand Down
3 changes: 1 addition & 2 deletions webrender/src/renderer/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{ImageBufferKind, units::DeviceSize};
use api::{precise_time_ns, ImageBufferKind, units::DeviceSize};
use crate::batch::{BatchKey, BatchKind, BrushBatchKind, BatchFeatures};
use crate::composite::{CompositeFeatures, CompositeSurfaceFormat};
use crate::device::{Device, Program, ShaderError};
Expand All @@ -17,7 +17,6 @@ use crate::renderer::{
use crate::profiler::{self, TransactionProfile, ns_to_ms};

use gleam::gl::GlType;
use time::precise_time_ns;

use std::cell::RefCell;
use std::rc::Rc;
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/renderer/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
//! here relies on submitting draw calls via the renderer.

use api::precise_time_ns;
use std::mem;
use std::collections::VecDeque;
use std::sync::Arc;
use std::time::Duration;
use euclid::{Transform3D, point2};
use time::precise_time_ns;
use malloc_size_of::MallocSizeOfOps;
use api::units::*;
use api::{ExternalImageSource, ImageBufferKind, ImageFormat};
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/scene_builder_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use api::{DocumentId, PipelineId, ExternalEvent, BlobImageRequest};
use api::{NotificationRequest, Checkpoint, IdNamespace, QualitySettings};
use api::{PrimitiveKeyKind, GlyphDimensionRequest, GlyphIndexRequest};
use api::channel::{unbounded_channel, single_msg_channel, Receiver, Sender};
use api::precise_time_ns;
use api::units::*;
use crate::render_api::{ApiMsg, FrameMsg, SceneMsg, ResourceUpdate, TransactionMsg, MemoryReport};
use crate::box_shadow::BoxShadow;
Expand Down Expand Up @@ -35,7 +36,6 @@ use crate::spatial_tree::{SceneSpatialTree, SpatialTreeUpdates};
use crate::telemetry::Telemetry;
use crate::SceneBuilderHooks;
use std::iter;
use time::precise_time_ns;
use crate::util::drain_filter;
use std::thread;
use std::time::Duration;
Expand Down
11 changes: 10 additions & 1 deletion webrender_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ malloc_size_of_derive = "0.1"
serde = { version = "1.0", features = ["rc"] }
serde_derive = "1.0"
serde_bytes = "0.11"
time = "0.1"
malloc_size_of = { version = "0.0.3", path = "../wr_malloc_size_of", package = "wr_malloc_size_of" }
peek-poke = { version = "0.3", path = "../peek-poke", features = ["extras"] }
crossbeam-channel = "0.5"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
mach2 = { version = "0.4" }

[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))'.dependencies]
libc = { version = "0.2" }

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.59", features = ["Win32_System_Performance"] }

2 changes: 1 addition & 1 deletion webrender_api/src/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::marker::PhantomData;
use std::ops::Range;
use std::mem;
use std::collections::HashMap;
use time::precise_time_ns;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
// local imports
use crate::display_item as di;
Expand All @@ -25,6 +24,7 @@ use crate::gradient_builder::GradientBuilder;
use crate::color::ColorF;
use crate::font::{FontInstanceKey, GlyphInstance, GlyphOptions};
use crate::image::{ColorDepth, ImageKey};
use crate::precise_time_ns;
use crate::units::*;


Expand Down
3 changes: 2 additions & 1 deletion webrender_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ extern crate malloc_size_of_derive;
extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate time;

extern crate malloc_size_of;
extern crate peek_poke;
Expand All @@ -49,6 +48,7 @@ mod display_list;
mod font;
mod gradient_builder;
mod image;
mod precise_time_ns;
mod tile_pool;
pub mod units;

Expand All @@ -59,6 +59,7 @@ pub use crate::display_list::*;
pub use crate::font::*;
pub use crate::gradient_builder::*;
pub use crate::image::*;
pub use crate::precise_time_ns::precise_time_ns;
pub use crate::tile_pool::*;

use crate::units::*;
Expand Down
119 changes: 119 additions & 0 deletions webrender_api/src/precise_time_ns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright 2024 The Servo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn precise_time_ns() -> u64 {
platform::now()
}

#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))]
mod platform {
use libc::timespec;

#[allow(unsafe_code)]
pub(super) fn now() -> u64 {
// SAFETY: libc::timespec is zero initializable.
let time = unsafe {
let mut time: timespec = std::mem::zeroed();
libc::clock_gettime(libc::CLOCK_MONOTONIC, &mut time);
time
};
(time.tv_sec as u64) * 1000000000 + (time.tv_nsec as u64)
}
}

#[cfg(any(target_os = "macos", target_os = "ios"))]
mod platform {
use std::sync::LazyLock;

use mach2::mach_time::{mach_absolute_time, mach_timebase_info};

#[allow(unsafe_code)]
fn timebase_info() -> &'static mach_timebase_info {
static TIMEBASE_INFO: LazyLock<mach_timebase_info> = LazyLock::new(|| {
let mut timebase_info = mach_timebase_info { numer: 0, denom: 0 };
unsafe { mach_timebase_info(&mut timebase_info) };
timebase_info
});
&TIMEBASE_INFO
}

#[allow(unsafe_code)]
pub(super) fn now() -> u64 {
let timebase_info = timebase_info();
let absolute_time = unsafe { mach_absolute_time() };
absolute_time * timebase_info.numer as u64 / timebase_info.denom as u64
}
}

#[cfg(target_os = "windows")]
mod platform {
use std::sync::atomic::{AtomicU64, Ordering};

use windows_sys::Win32::System::Performance::{
QueryPerformanceCounter, QueryPerformanceFrequency,
};

/// The frequency of the value returned by `QueryPerformanceCounter` in counts per
/// second. This is taken from the Rust source code at:
/// <https://github.com/rust-lang/rust/blob/1a1cc050d8efc906ede39f444936ade1fdc9c6cb/library/std/src/sys/pal/windows/time.rs#L197>
#[allow(unsafe_code)]
fn frequency() -> i64 {
// Either the cached result of `QueryPerformanceFrequency` or `0` for
// uninitialized. Storing this as a single `AtomicU64` allows us to use
// `Relaxed` operations, as we are only interested in the effects on a
// single memory location.
static FREQUENCY: AtomicU64 = AtomicU64::new(0);

let cached = FREQUENCY.load(Ordering::Relaxed);
// If a previous thread has filled in this global state, use that.
if cached != 0 {
return cached as i64;
}
// ... otherwise learn for ourselves ...
let mut frequency = 0;
let result = unsafe { QueryPerformanceFrequency(&mut frequency) };

if result == 0 {
return 0;
}

FREQUENCY.store(frequency as u64, Ordering::Relaxed);
frequency
}

#[allow(unsafe_code)]
/// Get the current instant value in nanoseconds.
/// Originally from: <https://github.com/rust-lang/rust/blob/1a1cc050d8efc906ede39f444936ade1fdc9c6cb/library/std/src/sys/pal/windows/time.rs#L175>
pub(super) fn now() -> u64 {
let mut counter_value = 0;
unsafe { QueryPerformanceCounter(&mut counter_value) };

/// Computes (value*numer)/denom without overflow, as long as both
/// (numer*denom) and the overall result fit into i64 (which is the case
/// for our time conversions).
/// Originally from: <https://github.com/rust-lang/rust/blob/1a1cc050d8efc906ede39f444936ade1fdc9c6cb/library/std/src/sys_common/mod.rs#L75>
fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 {
let q = value / denom;
let r = value % denom;
// Decompose value as (value/denom*denom + value%denom),
// substitute into (value*numer)/denom and simplify.
// r < denom, so (denom*numer) is the upper bound of (r*numer)
q * numer + r * numer / denom
}

static NANOSECONDS_PER_SECOND: u64 = 1_000_000_000;
mul_div_u64(
counter_value as u64,
NANOSECONDS_PER_SECOND,
frequency() as u64,
)
}
}

0 comments on commit 8846253

Please sign in to comment.