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

Extract common key and template data.

  • Loading branch information
djg committed Dec 5, 2018
commit ce799fb1b4df2659ed1dc70de45ca4c844ec45ab
@@ -623,10 +623,27 @@ impl From<LayoutPoint> for PointKey {
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct PrimitiveKey {
pub struct PrimKeyCommonData {
pub is_backface_visible: bool,
pub prim_rect: RectangleKey,
pub clip_rect: RectangleKey,
}

impl PrimKeyCommonData {
pub fn with_info(info: &LayoutPrimitiveInfo) -> Self {
PrimKeyCommonData {
is_backface_visible: info.is_backface_visible,
prim_rect: info.rect.into(),
clip_rect: info.clip_rect.into(),
}
}
}

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct PrimitiveKey {
pub common: PrimKeyCommonData,
pub kind: PrimitiveKeyKind,
}

@@ -638,9 +655,11 @@ impl PrimitiveKey {
kind: PrimitiveKeyKind,
) -> Self {
PrimitiveKey {
is_backface_visible,
prim_rect: prim_rect.into(),
clip_rect: clip_rect.into(),
common: PrimKeyCommonData {
is_backface_visible,
prim_rect: prim_rect.into(),
clip_rect: clip_rect.into(),
},
kind,
}
}
@@ -969,11 +988,10 @@ impl PrimitiveKeyKind {

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct PrimitiveTemplate {
pub struct PrimTemplateCommonData {
pub is_backface_visible: bool,
pub prim_rect: LayoutRect,
pub clip_rect: LayoutRect,
pub kind: PrimitiveTemplateKind,
pub opacity: PrimitiveOpacity,
/// The GPU cache handle for a primitive template. Since this structure
/// is retained across display lists by interning, this GPU cache handle
@@ -982,23 +1000,47 @@ pub struct PrimitiveTemplate {
pub gpu_cache_handle: GpuCacheHandle,
}

impl From<PrimitiveKey> for PrimitiveTemplate {
fn from(item: PrimitiveKey) -> Self {
let prim_rect = item.prim_rect.into();
let clip_rect = item.clip_rect.into();
let kind = item.kind.into_template(&prim_rect);

PrimitiveTemplate {
is_backface_visible: item.is_backface_visible,
prim_rect,
clip_rect,
kind,
impl PrimTemplateCommonData {
pub fn with_key_common(common: PrimKeyCommonData) -> Self {
PrimTemplateCommonData {
is_backface_visible: common.is_backface_visible,
prim_rect: common.prim_rect.into(),
clip_rect: common.clip_rect.into(),
gpu_cache_handle: GpuCacheHandle::new(),
opacity: PrimitiveOpacity::translucent(),
}
}
}

#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct PrimitiveTemplate {
pub common: PrimTemplateCommonData,
pub kind: PrimitiveTemplateKind,
}

impl ops::Deref for PrimitiveTemplate {
type Target = PrimTemplateCommonData;
fn deref(&self) -> &Self::Target {
&self.common
}
}

impl ops::DerefMut for PrimitiveTemplate {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.common
}
}

impl From<PrimitiveKey> for PrimitiveTemplate {
fn from(item: PrimitiveKey) -> Self {
let common = PrimTemplateCommonData::with_key_common(item.common);
let kind = item.kind.into_template(&common.prim_rect);

PrimitiveTemplate { common, kind, }
}
}

impl PrimitiveTemplateKind {
/// Write any GPU blocks for the primitive template to the given request object.
fn write_prim_gpu_blocks(
@@ -1173,10 +1215,10 @@ impl PrimitiveTemplate {
surface_index: SurfaceIndex,
frame_state: &mut FrameBuildingState,
) {
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.gpu_cache_handle) {
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.common.gpu_cache_handle) {
self.kind.write_prim_gpu_blocks(
&mut request,
self.prim_rect.size,
self.common.prim_rect.size,
);
self.kind.write_segment_gpu_blocks(&mut request);
}
@@ -1215,8 +1257,8 @@ impl PrimitiveTemplate {
// then we just assume the gradient is translucent for now.
// (In the future we could consider segmenting in some cases).
let stride = stretch_size + tile_spacing;
if stride.width >= self.prim_rect.size.width &&
stride.height >= self.prim_rect.size.height {
if stride.width >= self.common.prim_rect.size.width &&
stride.height >= self.common.prim_rect.size.height {
stops_opacity
} else {
PrimitiveOpacity::translucent()
@@ -3,31 +3,30 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{AuHelpers, ColorF, DevicePixelScale, GlyphInstance, LayoutPrimitiveInfo};
use api::{LayoutRect, LayoutToWorldTransform, LayoutVector2DAu, RasterSpace};
use api::{LayoutToWorldTransform, LayoutVector2DAu, RasterSpace};
use api::Shadow;
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};
use gpu_cache::GpuCache;
use intern;
use prim_store::{PrimitiveOpacity, PrimitiveSceneData, PrimitiveScratchBuffer};
use prim_store::{PrimitiveStore, RectangleKey};
use prim_store::{PrimitiveStore, PrimKeyCommonData, PrimTemplateCommonData};
use render_task::{RenderTaskTree};
use renderer::{MAX_VERTEX_TEXTURE_WIDTH};
use resource_cache::{ResourceCache};
use tiling::SpecialRenderPasses;
use util::{MatrixHelpers};
use prim_store::PrimitiveInstanceKind;
use std::ops;
use storage;

/// A run of glyphs, with associated font information.
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct TextRunKey {
pub is_backface_visible: bool,
pub prim_rect: RectangleKey,
pub clip_rect: RectangleKey,
pub common: PrimKeyCommonData,
pub font: FontInstance,
pub offset: LayoutVector2DAu,
pub glyphs: Vec<GlyphInstance>,
@@ -37,9 +36,7 @@ pub struct TextRunKey {
impl TextRunKey {
pub fn new(info: &LayoutPrimitiveInfo, text_run: TextRun) -> Self {
TextRunKey {
is_backface_visible: info.is_backface_visible,
prim_rect: info.rect.into(),
clip_rect: info.clip_rect.into(),
common: PrimKeyCommonData::with_info(info),
font: text_run.font,
offset: text_run.offset.into(),
glyphs: text_run.glyphs,
@@ -69,31 +66,33 @@ impl AsInstanceKind<TextRunDataHandle> for TextRunKey {
#[cfg_attr(feature = "capture", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub struct TextRunTemplate {
pub is_backface_visible: bool,
pub prim_rect: LayoutRect,
pub clip_rect: LayoutRect,
pub common: PrimTemplateCommonData,
pub font: FontInstance,
pub offset: LayoutVector2DAu,
pub glyphs: Vec<GlyphInstance>,
pub opacity: PrimitiveOpacity,
/// The GPU cache handle for a primitive template. Since this structure
/// is retained across display lists by interning, this GPU cache handle
/// also remains valid, which reduces the number of updates to the GPU
/// cache when a new display list is processed.
pub gpu_cache_handle: GpuCacheHandle,
}

impl ops::Deref for TextRunTemplate {
type Target = PrimTemplateCommonData;
fn deref(&self) -> &Self::Target {
&self.common
}
}

impl ops::DerefMut for TextRunTemplate {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.common
}
}

impl From<TextRunKey> for TextRunTemplate {
fn from(item: TextRunKey) -> Self {
let common = PrimTemplateCommonData::with_key_common(item.common);
TextRunTemplate {
is_backface_visible: item.is_backface_visible,
prim_rect: item.prim_rect.into(),
clip_rect: item.clip_rect.into(),
common,
font: item.font,
offset: item.offset,
glyphs: item.glyphs,
opacity: PrimitiveOpacity::translucent(),
gpu_cache_handle: GpuCacheHandle::new(),
}
}
}
@@ -115,7 +114,7 @@ impl TextRunTemplate {
&mut self,
frame_state: &mut FrameBuildingState,
) {
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.gpu_cache_handle) {
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.common.gpu_cache_handle) {
request.push(ColorF::from(self.font.color).premultiplied());
// this is the only case where we need to provide plain color to GPU
let bg_color = ColorF::from(self.font.bg_color);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.