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

Merge BuildKey trait with Internable trait.

  • Loading branch information
djg committed Dec 5, 2018
commit 30e29b8f2d4f1204c4acdee840e0f41ebc81fc0d
@@ -1040,11 +1040,11 @@ impl<'a> DisplayListFlattener<'a> {
) -> PrimitiveInstance
where
P: Internable<InternData=PrimitiveSceneData>,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
P::Source: AsInstanceKind<Handle<P::Marker>>,
DocumentResources: InternerMut<P>,
{
// Build a primitive key.
let prim_key = P::Source::build_key(info, prim);
let prim_key = prim.build_key(info);

// Get a tight bounding / culling rect for this primitive
// from its local rect intersection with minimal local
@@ -1120,7 +1120,7 @@ impl<'a> DisplayListFlattener<'a> {
)
where
P: Internable<InternData = PrimitiveSceneData> + IsVisible,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
P::Source: AsInstanceKind<Handle<P::Marker>>,
DocumentResources: InternerMut<P>,
ShadowItem: From<PendingPrimitive<P>>
{
@@ -1162,7 +1162,7 @@ impl<'a> DisplayListFlattener<'a> {
)
where
P: Internable<InternData = PrimitiveSceneData>,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
P::Source: AsInstanceKind<Handle<P::Marker>>,
DocumentResources: InternerMut<P>,
{
let prim_instance = self.create_primitive(
@@ -1880,7 +1880,7 @@ impl<'a> DisplayListFlattener<'a> {
)
where
P: Internable<InternData=PrimitiveSceneData> + CreateShadow,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
P::Source: AsInstanceKind<Handle<P::Marker>>,
DocumentResources: InternerMut<P>,
{
// Offset the local rect and clip rect by the shadow offset.
@@ -1905,7 +1905,7 @@ impl<'a> DisplayListFlattener<'a> {
fn add_shadow_prim_to_draw_list<P>(&mut self, pending_primitive: PendingPrimitive<P>)
where
P: Internable<InternData = PrimitiveSceneData> + IsVisible,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
P::Source: AsInstanceKind<Handle<P::Marker>>,
DocumentResources: InternerMut<P>,
{
// For a normal primitive, if it has alpha > 0, then we add this
@@ -2430,10 +2430,6 @@ pub trait AsInstanceKind<H> {
) -> PrimitiveInstanceKind;
}

pub trait BuildKey<S> {
fn build_key(info: &LayoutPrimitiveInfo, source: S) -> Self;
}

pub trait CreateShadow {
fn create_shadow(&self, shadow: &Shadow) -> Self;
}
@@ -2,6 +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::LayoutPrimitiveInfo;
use internal_types::FastHashMap;
use std::fmt::Debug;
use std::hash::Hash;
@@ -385,4 +386,7 @@ pub trait Internable {
type Source: Eq + Hash + Clone + Debug;
type StoreData: From<Self::Source>;
type InternData;

/// Build a new key from self with `info`.
fn build_key(self, info: &LayoutPrimitiveInfo) -> Self::Source;
}
@@ -16,7 +16,7 @@ use border::{BorderSegmentCacheKey, NormalBorderAu};
use clip::{ClipStore};
use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
use clip::{ClipDataStore, ClipNodeFlags, ClipChainId, ClipChainInstance, ClipItem, ClipNodeCollector};
use display_list_flattener::{AsInstanceKind, BuildKey, CreateShadow, IsVisible};
use display_list_flattener::{AsInstanceKind, CreateShadow, IsVisible};
use euclid::{SideOffsets2D, TypedTransform3D, TypedRect, TypedScale, TypedSize2D};
use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureContext, PictureState};
use frame_builder::PrimitiveContext;
@@ -725,20 +725,6 @@ impl AsInstanceKind<PrimitiveDataHandle> for PrimitiveKey {
}
}

impl BuildKey<PrimitiveKeyKind> for PrimitiveKey {
fn build_key(
info: &LayoutPrimitiveInfo,
prim_key_kind: PrimitiveKeyKind,
) -> PrimitiveKey {
PrimitiveKey::new(
info.is_backface_visible,
info.rect,
info.clip_rect,
prim_key_kind,
)
}
}

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct NormalBorderTemplate {
@@ -1436,6 +1422,15 @@ impl intern::Internable for PrimitiveKeyKind {
type Source = PrimitiveKey;
type StoreData = PrimitiveTemplate;
type InternData = PrimitiveSceneData;

fn build_key(self, info: &LayoutPrimitiveInfo) -> PrimitiveKey {
PrimitiveKey::new(
info.is_backface_visible,
info.rect,
info.clip_rect,
self,
)
}
}

pub type PrimitiveDataStore = intern::DataStore<PrimitiveKey, PrimitiveTemplate, PrimitiveDataMarker>;
@@ -5,8 +5,7 @@
use api::{AuHelpers, ColorF, DevicePixelScale, GlyphInstance, LayoutPrimitiveInfo};
use api::{LayoutRect, LayoutToWorldTransform, LayoutVector2DAu, RasterSpace};
use api::Shadow;
use display_list_flattener::{AsInstanceKind, BuildKey, CreateShadow};
use display_list_flattener::IsVisible;
use display_list_flattener::{AsInstanceKind, CreateShadow, IsVisible};
use frame_builder::{FrameBuildingState, PictureContext};
use glyph_rasterizer::{FontInstance, FontTransform, GlyphKey, FONT_SIZE_LIMIT};
use gpu_cache::{GpuCache, GpuCacheHandle};
@@ -67,13 +66,6 @@ impl AsInstanceKind<TextRunDataHandle> for TextRunKey {
}
}

impl BuildKey<TextRun> for TextRunKey {
/// Build a new key from self with `info`.
fn build_key(info: &LayoutPrimitiveInfo, source: TextRun) -> TextRunKey {
TextRunKey::new(info, source)
}
}

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct TextRunTemplate {
@@ -182,6 +174,11 @@ impl intern::Internable for TextRun {
type Source = TextRunKey;
type StoreData = TextRunTemplate;
type InternData = PrimitiveSceneData;

/// Build a new key from self with `info`.
fn build_key(self, info: &LayoutPrimitiveInfo) -> TextRunKey {
TextRunKey::new(info, self)
}
}

impl CreateShadow for TextRun {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.