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

Separate interning text run #3369

Merged
merged 10 commits into from Dec 6, 2018

Preparation for separate ItemUids.

  • Loading branch information
djg committed Dec 5, 2018
commit d1d0d4a9b1d5a312681cc7d6f72ec8eb08c45714
@@ -104,7 +104,6 @@ pub type ClipDataStore = intern::DataStore<ClipItemKey, ClipNode, ClipDataMarker
pub type ClipDataHandle = intern::Handle<ClipDataMarker>;
pub type ClipDataUpdateList = intern::UpdateList<ClipItemKey>;
pub type ClipDataInterner = intern::Interner<ClipItemKey, ClipItemSceneData, ClipDataMarker>;
pub type ClipUid = intern::ItemUid<ClipDataMarker>;

// Result of comparing a clip node instance against a local rect.
#[derive(Debug)]
@@ -7,6 +7,7 @@ use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
use std::{mem, ops, u64};
use std::sync::atomic::{AtomicUsize, Ordering};
use util::VecHelper;

/*
@@ -64,26 +65,37 @@ pub struct UpdateList<S> {
data: Vec<S>,
}

lazy_static! {
static ref NEXT_UID: AtomicUsize = AtomicUsize::new(0);
}

/// A globally, unique identifier
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
pub struct ItemUid<T> {
pub struct ItemUid {
uid: usize,
_marker: PhantomData<T>,
}

impl ItemUid {
pub fn next_uid() -> ItemUid {
let uid = NEXT_UID.fetch_add(1, Ordering::Relaxed);
ItemUid { uid }
}
}

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Copy, Clone)]
pub struct Handle<T> {
pub struct Handle<M: Copy> {
index: u32,
epoch: Epoch,
uid: ItemUid<T>,
_marker: PhantomData<T>,
uid: ItemUid,
_marker: PhantomData<M>,
}

impl <T> Handle<T> where T: Copy {
pub fn uid(&self) -> ItemUid<T> {
impl <M> Handle<M> where M: Copy {
pub fn uid(&self) -> ItemUid {
self.uid
}
}
@@ -160,7 +172,9 @@ impl<S, T, M> DataStore<S, T, M> where S: Debug, T: From<S>, M: Debug {
}

/// Retrieve an item from the store via handle
impl<S, T, M> ops::Index<Handle<M>> for DataStore<S, T, M> {
impl<S, T, M> ops::Index<Handle<M>> for DataStore<S, T, M>
where M: Copy
{
type Output = T;
fn index(&self, handle: Handle<M>) -> &T {
let item = &self.items[handle.index as usize];
@@ -171,7 +185,10 @@ impl<S, T, M> ops::Index<Handle<M>> for DataStore<S, T, M> {

/// Retrieve a mutable item from the store via handle
/// Retrieve an item from the store via handle
impl<S, T, M> ops::IndexMut<Handle<M>> for DataStore<S, T, M> {
impl<S, T, M> ops::IndexMut<Handle<M>> for DataStore<S, T, M>
where
M: Copy
{
fn index_mut(&mut self, handle: Handle<M>) -> &mut T {
let item = &mut self.items[handle.index as usize];
assert_eq!(item.epoch, handle.epoch);
@@ -186,7 +203,11 @@ impl<S, T, M> ops::IndexMut<Handle<M>> for DataStore<S, T, M> {
/// an update list of additions / removals.
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
pub struct Interner<S, D, M>
where
S: Eq + Hash + Clone + Debug,
M: Copy
{
/// Uniquely map an interning key to a handle
map: FastHashMap<S, Handle<M>>,
/// List of free slots in the data store for re-use.
@@ -197,8 +218,6 @@ pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
update_data: Vec<S>,
/// The current epoch for the interner.
current_epoch: Epoch,
/// Incrementing counter for identifying stable values.
next_uid: usize,
/// The information associated with each interned
/// item that can be accessed by the interner.
local_data: Vec<Item<D>>,
@@ -216,13 +235,16 @@ where
updates: Vec::new(),
update_data: Vec::new(),
current_epoch: Epoch(1),
next_uid: 0,
local_data: Vec::new(),
}
}
}

impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + Debug {
impl<S, D, M> Interner<S, D, M>
where
S: Eq + Hash + Clone + Debug,
M: Copy + Debug
{
/// Intern a data structure, and return a handle to
/// that data. The handle can then be stored in the
/// frame builder, and safely accessed via the data
@@ -273,17 +295,13 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
let handle = Handle {
index: index as u32,
epoch: self.current_epoch,
uid: ItemUid {
uid: self.next_uid,
_marker: PhantomData,
},
uid: ItemUid::next_uid(),
_marker: PhantomData,
};

// Store this handle so the next time it is
// interned, it gets re-used.
self.map.insert(data.clone(), handle);
self.next_uid += 1;

// Create the local data for this item that is
// being interned.
@@ -343,7 +361,11 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
}

/// Retrieve the local data for an item from the interner via handle
impl<S, D, M> ops::Index<Handle<M>> for Interner<S, D, M> where S: Eq + Clone + Hash + Debug, M: Copy + Debug {
impl<S, D, M> ops::Index<Handle<M>> for Interner<S, D, M>
where
S: Eq + Clone + Hash + Debug,
M: Copy + Debug
{
type Output = D;
fn index(&self, handle: Handle<M>) -> &D {
let item = &self.local_data[handle.index as usize];
@@ -7,18 +7,19 @@ use api::{DeviceIntRect, DevicePoint, LayoutRect, PictureToRasterTransform, Layo
use api::{DevicePixelScale, RasterRect, RasterSpace, PictureSize, DeviceIntPoint, ColorF, ImageKey, DirtyRect};
use api::{PicturePixel, RasterPixel, WorldPixel, WorldRect, ImageFormat, ImageDescriptor};
use box_shadow::{BLUR_SAMPLE_SCALE};
use clip::{ClipNodeCollector, ClipStore, ClipChainId, ClipChainNode, ClipUid};
use clip::{ClipNodeCollector, ClipStore, ClipChainId, ClipChainNode};
use clip_scroll_tree::{ROOT_SPATIAL_NODE_INDEX, ClipScrollTree, SpatialNodeIndex};
use device::TextureFilter;
use euclid::{TypedScale, vec3, TypedRect, TypedPoint2D, TypedSize2D};
use euclid::approxeq::ApproxEq;
use intern::ItemUid;
use internal_types::{FastHashMap, PlaneSplitter};
use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureState, PictureContext};
use gpu_cache::{GpuCache, GpuCacheAddress, GpuCacheHandle};
use gpu_types::{TransformPalette, TransformPaletteId, UvRectKind};
use internal_types::FastHashSet;
use plane_split::{Clipper, Polygon, Splitter};
use prim_store::{PictureIndex, PrimitiveInstance, SpaceMapper, VisibleFace, PrimitiveInstanceKind, PrimitiveUid};
use prim_store::{PictureIndex, PrimitiveInstance, SpaceMapper, VisibleFace, PrimitiveInstanceKind};
use prim_store::{get_raster_rects, PrimitiveDataInterner, PrimitiveDataStore, CoordinateSpaceMapping};
use prim_store::{OpacityBindingStorage, PrimitiveTemplateKind, ImageInstanceStorage, OpacityBindingIndex, SizeKey};
use render_task::{ClearMode, RenderTask, RenderTaskCacheEntryHandle, TileBlit};
@@ -236,11 +237,11 @@ pub struct TileTransformIndex(u32);
pub struct TileDescriptor {
/// List of primitive unique identifiers. The uid is guaranteed
/// to uniquely describe the content of the primitive.
pub prim_uids: Vec<PrimitiveUid>,
pub prim_uids: Vec<ItemUid>,

/// List of clip node unique identifiers. The uid is guaranteed
/// to uniquely describe the content of the clip node.
pub clip_uids: Vec<ClipUid>,
pub clip_uids: Vec<ItemUid>,

/// List of local tile transform ids that are used to position
/// the primitive and clip items above.
@@ -648,7 +649,7 @@ impl TileCache {
// Build the list of resources that this primitive has dependencies on.
let mut opacity_bindings: SmallVec<[PropertyBindingId; 4]> = SmallVec::new();
let mut clip_chain_spatial_nodes: SmallVec<[SpatialNodeIndex; 8]> = SmallVec::new();
let mut clip_chain_uids: SmallVec<[ClipUid; 8]> = SmallVec::new();
let mut clip_chain_uids: SmallVec<[ItemUid; 8]> = SmallVec::new();
let mut image_keys: SmallVec<[ImageKey; 8]> = SmallVec::new();
let mut current_clip_chain_id = prim_instance.clip_chain_id;

@@ -1472,7 +1472,6 @@ pub type PrimitiveDataStore = intern::DataStore<PrimitiveKey, PrimitiveTemplate,
pub type PrimitiveDataHandle = intern::Handle<PrimitiveDataMarker>;
pub type PrimitiveDataUpdateList = intern::UpdateList<PrimitiveKey>;
pub type PrimitiveDataInterner = intern::Interner<PrimitiveKey, PrimitiveSceneData, PrimitiveDataMarker>;
pub type PrimitiveUid = intern::ItemUid<PrimitiveDataMarker>;

// Maintains a list of opacity bindings that have been collapsed into
// the color of a single primitive. This is an important optimization
@@ -3,11 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{LayoutPixel, PicturePixel, RasterSpace};
use clip::{ClipChainId, ClipStore, ClipUid};
use clip::{ClipChainId, ClipStore};
use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
use euclid::TypedTransform3D;
use intern::ItemUid;
use internal_types::FastHashSet;
use prim_store::{CoordinateSpaceMapping, PrimitiveUid, PrimitiveInstance, PrimitiveInstanceKind};
use prim_store::{CoordinateSpaceMapping, PrimitiveInstance, PrimitiveInstanceKind};
use std::hash;
use util::ScaleOffset;

@@ -165,10 +166,10 @@ impl<F, T> From<CoordinateSpaceMapping<F, T>> for TransformKey {
pub struct SurfaceCacheKey {
/// The list of primitives that are part of this surface.
/// The uid uniquely identifies the content of the primitive.
pub primitive_ids: Vec<PrimitiveUid>,
pub primitive_ids: Vec<ItemUid>,
/// The list of clips that affect the primitives on this surface.
/// The uid uniquely identifies the content of the clip.
pub clip_ids: Vec<ClipUid>,
pub clip_ids: Vec<ItemUid>,
/// A list of transforms that can affect the contents of primitives
/// and/or clips on this picture surface.
pub transforms: Vec<TransformKey>,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.