From a20455fd6be939ddb3a53f84bef7fb79f4e5fb3c Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Mon, 18 Mar 2019 20:31:43 +0800 Subject: [PATCH] WR update: APIs update --- .../gfx/platform/freetype/font_template.rs | 3 +- components/gfx/platform/windows/font.rs | 3 +- components/gfx/platform/windows/font_list.rs | 5 --- .../gfx/platform/windows/font_template.rs | 16 ++++++--- components/layout/display_list/builder.rs | 1 + .../layout/display_list/webrender_helpers.rs | 35 ++++++++++++++----- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/components/gfx/platform/freetype/font_template.rs b/components/gfx/platform/freetype/font_template.rs index 625f47395c6..b1b356d0f25 100644 --- a/components/gfx/platform/freetype/font_template.rs +++ b/components/gfx/platform/freetype/font_template.rs @@ -6,6 +6,7 @@ use servo_atoms::Atom; use std::fmt; use std::fs::File; use std::io::{Error, Read}; +use std::path::PathBuf; use webrender_api::NativeFontHandle; /// Platform specific font representation for Linux. @@ -61,7 +62,7 @@ impl FontTemplateData { pub fn native_font(&self) -> Option { if self.bytes.is_none() { Some(NativeFontHandle { - pathname: String::from(&*self.identifier), + path: PathBuf::from(&*self.identifier), index: 0, }) } else { diff --git a/components/gfx/platform/windows/font.rs b/components/gfx/platform/windows/font.rs index 6c183066a9b..7ee36b91aa8 100644 --- a/components/gfx/platform/windows/font.rs +++ b/components/gfx/platform/windows/font.rs @@ -280,7 +280,8 @@ impl FontHandleMethods for FontHandle { let face = font_file .unwrap() - .create_face(0, dwrote::DWRITE_FONT_SIMULATIONS_NONE); + .create_face(0, dwrote::DWRITE_FONT_SIMULATIONS_NONE) + .map_err(|_| ())?; let info = FontInfo::new_from_face(&face)?; (info, face) } else { diff --git a/components/gfx/platform/windows/font_list.rs b/components/gfx/platform/windows/font_list.rs index cd963618cfd..d9d1261dba9 100644 --- a/components/gfx/platform/windows/font_list.rs +++ b/components/gfx/platform/windows/font_list.rs @@ -64,11 +64,6 @@ where } } -pub fn descriptor_from_atom(ident: &Atom) -> FontDescriptor { - let fonts = FONT_ATOM_MAP.lock().unwrap(); - fonts.get(ident).unwrap().clone() -} - pub fn font_from_atom(ident: &Atom) -> Font { let fonts = FONT_ATOM_MAP.lock().unwrap(); FontCollection::system() diff --git a/components/gfx/platform/windows/font_template.rs b/components/gfx/platform/windows/font_template.rs index 3a438ac6970..8576e3f6fc8 100644 --- a/components/gfx/platform/windows/font_template.rs +++ b/components/gfx/platform/windows/font_template.rs @@ -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 https://mozilla.org/MPL/2.0/. */ -use crate::platform::windows::font_list::{descriptor_from_atom, font_from_atom}; +use crate::platform::windows::font_list::font_from_atom; use servo_atoms::Atom; use std::fmt; use std::io; @@ -59,10 +59,16 @@ impl FontTemplateData { } pub fn native_font(&self) -> Option { - if self.bytes.is_none() { - Some(descriptor_from_atom(&self.identifier)) - } else { - None + if self.bytes.is_some() { + return None; } + let font = font_from_atom(&self.identifier); + let face = font.create_font_face(); + let files = face.get_files(); + let path = files.iter().next()?.get_font_file_path()?; + Some(NativeFontHandle { + path, + index: face.get_index(), + }) } } diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 73343c3a4f2..cc2585c3043 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -2012,6 +2012,7 @@ impl Fragment { offset: LayoutVector2D::new(shadow.horizontal.px(), shadow.vertical.px()), color: self.style.resolve_color(shadow.color).to_layout(), blur_radius: shadow.blur.px(), + should_inflate: true, }, }, ))); diff --git a/components/layout/display_list/webrender_helpers.rs b/components/layout/display_list/webrender_helpers.rs index a90b9711e0d..099a1d1807a 100644 --- a/components/layout/display_list/webrender_helpers.rs +++ b/components/layout/display_list/webrender_helpers.rs @@ -10,8 +10,10 @@ use crate::display_list::items::{ClipScrollNode, ClipScrollNodeType}; use crate::display_list::items::{DisplayItem, DisplayList, StackingContextType}; use msg::constellation_msg::PipelineId; -use webrender_api::{self, ClipId, DisplayListBuilder, RasterSpace, SpaceAndClipInfo, SpatialId}; -use webrender_api::{LayoutPoint, SpecificDisplayItem}; +use webrender_api::{ + self, ClipId, DisplayListBuilder, RasterSpace, ReferenceFrameKind, SpaceAndClipInfo, SpatialId, +}; +use webrender_api::{LayoutPoint, PropertyBinding, SpecificDisplayItem}; pub trait WebRenderDisplayListConverter { fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder; @@ -204,18 +206,32 @@ impl WebRenderDisplayItemConverter for DisplayItem { let mut info = webrender_api::LayoutPrimitiveInfo::new(stacking_context.bounds); let spatial_id = if let Some(frame_index) = stacking_context.established_reference_frame { - debug_assert!( - stacking_context.transform.is_some() || - stacking_context.perspective.is_some() - ); + let (transform, ref_frame) = + match (stacking_context.transform, stacking_context.perspective) { + (None, Some(p)) => ( + p, + ReferenceFrameKind::Perspective { + scrolling_relative_to: None, + }, + ), + (Some(t), None) => (t, ReferenceFrameKind::Transform), + (Some(t), Some(p)) => ( + t.pre_mul(&p), + ReferenceFrameKind::Perspective { + scrolling_relative_to: None, + }, + ), + (None, None) => unreachable!(), + }; let spatial_id = builder.push_reference_frame( &stacking_context.bounds, state.active_spatial_id, stacking_context.transform_style, - stacking_context.transform.map(Into::into), - stacking_context.perspective, + PropertyBinding::Value(transform), + ref_frame, ); + state.spatial_ids[frame_index.to_index()] = Some(spatial_id); state.clip_ids[frame_index.to_index()] = Some(cur_clip_id); @@ -233,7 +249,9 @@ impl WebRenderDisplayItemConverter for DisplayItem { stacking_context.transform_style, stacking_context.mix_blend_mode, &stacking_context.filters, + &[], RasterSpace::Screen, + /* cache_tiles = */ false, ); }, DisplayItem::PopStackingContext(_) => builder.pop_stacking_context(), @@ -273,6 +291,7 @@ impl WebRenderDisplayItemConverter for DisplayItem { node.clip.complex.clone(), None, scroll_sensitivity, + webrender_api::LayoutVector2D::zero(), ); state.clip_ids[item.node_index.to_index()] = Some(space_clip_info.clip_id);