servo: Merge #14938 - Various cleanup around gfx_traits (from servo:gfx-traits); r=nox
authorMs2ger <Ms2ger@gmail.com>
Tue, 10 Jan 2017 07:02:23 -0800
changeset 340533 b62924e6cb7089e573fb625b84f42db45a36b10c
parent 340532 63eb8900674a35c995f01f03b138c6cde3c26c8a
child 340534 0a395e249841107d616822332bf2c26b03c3e01b
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnox
servo: Merge #14938 - Various cleanup around gfx_traits (from servo:gfx-traits); r=nox Source-Repo: https://github.com/servo/servo Source-Revision: f674a9db8b7164dae667875c5cf19b3aabb18ef2
servo/Cargo.lock
servo/components/compositing/compositor.rs
servo/components/gfx/Cargo.toml
servo/components/gfx/display_list/mod.rs
servo/components/gfx/lib.rs
servo/components/gfx_traits/Cargo.toml
servo/components/gfx_traits/lib.rs
servo/components/layout/display_list_builder.rs
servo/components/layout/webrender_helpers.rs
--- a/servo/Cargo.lock
+++ b/servo/Cargo.lock
@@ -921,17 +921,16 @@ dependencies = [
  "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "msg 0.0.1",
  "net_traits 0.0.1",
  "ordered-float 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "plugins 0.0.1",
  "range 0.0.1",
- "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "servo-fontconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "servo_atoms 0.0.1",
  "servo_geometry 0.0.1",
  "servo_url 0.0.1",
  "simd 0.1.1 (git+https://github.com/huonw/simd)",
  "smallvec 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -955,17 +954,16 @@ dependencies = [
 [[package]]
 name = "gfx_traits"
 version = "0.0.1"
 dependencies = [
  "heapsize 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "plugins 0.0.1",
  "range 0.0.1",
- "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_derive 0.8.20 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "gif"
 version = "0.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
--- a/servo/components/compositing/compositor.rs
+++ b/servo/components/compositing/compositor.rs
@@ -6,18 +6,18 @@ use CompositionPipeline;
 use SendableFrameTree;
 use compositor_thread::{CompositorProxy, CompositorReceiver};
 use compositor_thread::{InitialCompositorState, Msg, RenderListener};
 use delayed_composition::DelayedCompositionTimerProxy;
 use euclid::Point2D;
 use euclid::point::TypedPoint2D;
 use euclid::scale_factor::ScaleFactor;
 use euclid::size::TypedSize2D;
-use gfx_traits::{DevicePixel, LayerPixel, ScrollRootId};
-use gfx_traits::{Epoch, FrameTreeId, FragmentType};
+use gfx_traits::{DevicePixel, ScrollRootId};
+use gfx_traits::{Epoch, FragmentType};
 use gleam::gl;
 use gleam::gl::types::{GLint, GLsizei};
 use image::{DynamicImage, ImageFormat, RgbImage};
 use ipc_channel::ipc::{self, IpcSender, IpcSharedMemory};
 use msg::constellation_msg::{Key, KeyModifiers, KeyState, CONTROL};
 use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId, TraversalDirection};
 use net_traits::image::base::{Image, PixelFormat};
 use profile_traits::time::{self, ProfilerCategory, profile};
@@ -103,16 +103,32 @@ impl ConvertFragmentTypeFromWebRender fo
 /// safe to save the output image.
 #[derive(Copy, Clone, PartialEq)]
 enum ReadyState {
     Unknown,
     WaitingForConstellationReply,
     ReadyToSaveImage,
 }
 
+#[derive(PartialEq, Eq, Debug, Copy, Clone)]
+struct FrameTreeId(u32);
+
+impl FrameTreeId {
+    pub fn next(&mut self) {
+        self.0 += 1;
+    }
+}
+
+/// One pixel in layer coordinate space.
+///
+/// This unit corresponds to a "pixel" in layer coordinate space, which after scaling and
+/// transformation becomes a device pixel.
+#[derive(Copy, Clone, Debug)]
+enum LayerPixel {}
+
 /// NB: Never block on the constellation, because sometimes the constellation blocks on us.
 pub struct IOCompositor<Window: WindowMethods> {
     /// The application window.
     window: Rc<Window>,
 
     /// The port on which we receive messages.
     port: Box<CompositorReceiver>,
 
--- a/servo/components/gfx/Cargo.toml
+++ b/servo/components/gfx/Cargo.toml
@@ -24,17 +24,16 @@ ipc-channel = "0.5"
 lazy_static = "0.2"
 libc = "0.2"
 log = "0.3.5"
 msg = {path = "../msg"}
 net_traits = {path = "../net_traits"}
 ordered-float = "0.2.2"
 plugins = {path = "../plugins"}
 range = {path = "../range"}
-rustc-serialize = "0.3"
 serde = "0.8"
 servo_atoms = {path = "../atoms"}
 servo_geometry = {path = "../geometry"}
 servo_url = {path = "../url"}
 serde_derive = "0.8"
 smallvec = "0.1"
 style = {path = "../style"}
 style_traits = {path = "../style_traits"}
--- a/servo/components/gfx/display_list/mod.rs
+++ b/servo/components/gfx/display_list/mod.rs
@@ -14,32 +14,32 @@
 //! They are therefore not exactly analogous to constructs like Skia pictures, which consist of
 //! low-level drawing primitives.
 
 use app_units::Au;
 use euclid::{Matrix4D, Point2D, Rect, Size2D};
 use euclid::num::{One, Zero};
 use euclid::rect::TypedRect;
 use euclid::side_offsets::SideOffsets2D;
-use gfx_traits::{ScrollPolicy, ScrollRootId, StackingContextId};
+use gfx_traits::{ScrollRootId, StackingContextId};
 use gfx_traits::print_tree::PrintTree;
 use ipc_channel::ipc::IpcSharedMemory;
 use msg::constellation_msg::PipelineId;
 use net_traits::image::base::{Image, PixelFormat};
 use range::Range;
 use servo_geometry::{au_rect_to_f32_rect, f32_rect_to_au_rect, max_rect};
 use std::cmp::{self, Ordering};
 use std::collections::HashMap;
 use std::fmt;
 use std::sync::Arc;
 use style::computed_values::{border_style, filter, image_rendering, mix_blend_mode};
 use style_traits::cursor::Cursor;
 use text::TextRun;
 use text::glyph::ByteIndex;
-use webrender_traits::{self, ColorF, GradientStop, WebGLContextId};
+use webrender_traits::{self, ColorF, GradientStop, ScrollPolicy, WebGLContextId};
 
 pub use style::dom::OpaqueNode;
 
 /// The factor that we multiply the blur radius by in order to inflate the boundaries of display
 /// items that involve a blur. This ensures that the display item boundaries include all the ink.
 pub static BLUR_INFLATION_FACTOR: i32 = 3;
 
 #[derive(HeapSizeOf, Deserialize, Serialize)]
@@ -124,17 +124,17 @@ impl DisplayList {
                         stacking_context: &StackingContext,
                         translated_point: &Point2D<Au>,
                         client_point: &Point2D<Au>,
                         scroll_offsets: &ScrollOffsetMap,
                         result: &mut Vec<DisplayItemMetadata>) {
         // Convert the parent translated point into stacking context local transform space if the
         // stacking context isn't fixed.  If it's fixed, we need to use the client point anyway.
         debug_assert!(stacking_context.context_type == StackingContextType::Real);
-        let is_fixed = stacking_context.scroll_policy == ScrollPolicy::FixedPosition;
+        let is_fixed = stacking_context.scroll_policy == ScrollPolicy::Fixed;
         let translated_point = if is_fixed {
             *client_point
         } else {
             let point = *translated_point - stacking_context.bounds.origin;
             let inv_transform = stacking_context.transform.inverse().unwrap();
             let frac_point = inv_transform.transform_point(&Point2D::new(point.x.to_f32_px(),
                                                                          point.y.to_f32_px()));
             Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y))
@@ -246,25 +246,25 @@ impl<'a> Iterator for DisplayListTravers
 
         None
     }
 }
 
 /// Display list sections that make up a stacking context. Each section  here refers
 /// to the steps in CSS 2.1 Appendix E.
 ///
-#[derive(Clone, Copy, Debug, Deserialize, Eq, HeapSizeOf, Ord, PartialEq, PartialOrd, RustcEncodable, Serialize)]
+#[derive(Clone, Copy, Debug, Deserialize, Eq, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
 pub enum DisplayListSection {
     BackgroundAndBorders,
     BlockBackgroundsAndBorders,
     Content,
     Outlines,
 }
 
-#[derive(Clone, Copy, Debug, Deserialize, Eq, HeapSizeOf, Ord, PartialEq, PartialOrd, RustcEncodable, Serialize)]
+#[derive(Clone, Copy, Debug, Deserialize, Eq, HeapSizeOf, Ord, PartialEq, PartialOrd, Serialize)]
 pub enum StackingContextType {
     Real,
     PseudoPositioned,
     PseudoFloat,
     PseudoScrollingArea,
 }
 
 #[derive(Clone, HeapSizeOf, Deserialize, Serialize)]
--- a/servo/components/gfx/lib.rs
+++ b/servo/components/gfx/lib.rs
@@ -53,17 +53,16 @@ extern crate lazy_static;
 extern crate libc;
 #[macro_use]
 extern crate log;
 extern crate msg;
 extern crate net_traits;
 extern crate ordered_float;
 #[macro_use]
 extern crate range;
-extern crate rustc_serialize;
 extern crate serde;
 #[macro_use]
 extern crate serde_derive;
 extern crate servo_geometry;
 extern crate servo_url;
 #[macro_use] extern crate servo_atoms;
 #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
 extern crate simd;
--- a/servo/components/gfx_traits/Cargo.toml
+++ b/servo/components/gfx_traits/Cargo.toml
@@ -9,11 +9,10 @@ publish = false
 name = "gfx_traits"
 path = "lib.rs"
 
 [dependencies]
 heapsize = "0.3.0"
 heapsize_derive = "0.1"
 plugins = {path = "../plugins"}
 range = {path = "../range"}
-rustc-serialize = "0.3"
 serde = "0.8"
 serde_derive = "0.8"
--- a/servo/components/gfx_traits/lib.rs
+++ b/servo/components/gfx_traits/lib.rs
@@ -9,17 +9,16 @@
 #![crate_type = "rlib"]
 
 #![deny(unsafe_code)]
 
 extern crate heapsize;
 #[macro_use] extern crate heapsize_derive;
 #[macro_use]
 extern crate range;
-extern crate rustc_serialize;
 extern crate serde;
 #[macro_use]
 extern crate serde_derive;
 
 pub mod print_tree;
 
 use range::RangeIndex;
 use std::sync::atomic::{ATOMIC_USIZE_INIT, AtomicUsize, Ordering};
@@ -36,72 +35,29 @@ static NEXT_SPECIAL_STACKING_CONTEXT_ID:
 /// Note that we assume that the top 16 bits of the address space are unused on the platform.
 const SPECIAL_STACKING_CONTEXT_ID_MASK: usize = 0xffff;
 
 // Units for use with euclid::length and euclid::scale_factor.
 
 /// One hardware pixel.
 ///
 /// This unit corresponds to the smallest addressable element of the display hardware.
-#[derive(Copy, Clone, RustcEncodable, Debug)]
+#[derive(Copy, Clone, Debug)]
 pub enum DevicePixel {}
 
-/// One pixel in layer coordinate space.
-///
-/// This unit corresponds to a "pixel" in layer coordinate space, which after scaling and
-/// transformation becomes a device pixel.
-#[derive(Copy, Clone, RustcEncodable, Debug)]
-pub enum LayerPixel {}
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum LayerKind {
-    NoTransform,
-    HasTransform,
-}
-
-#[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)]
-pub enum LayerType {
-    /// A layer for the fragment body itself.
-    FragmentBody,
-    /// An extra layer created for a DOM fragments with overflow:scroll.
-    OverflowScroll,
-    /// A layer created to contain ::before pseudo-element content.
-    BeforePseudoContent,
-    /// A layer created to contain ::after pseudo-element content.
-    AfterPseudoContent,
-}
-
-/// The scrolling policy of a layer.
-#[derive(Clone, PartialEq, Eq, Copy, Deserialize, Serialize, Debug, HeapSizeOf)]
-pub enum ScrollPolicy {
-    /// These layers scroll when the parent receives a scrolling message.
-    Scrollable,
-    /// These layers do not scroll when the parent receives a scrolling message.
-    FixedPosition,
-}
-
 /// A newtype struct for denoting the age of messages; prevents race conditions.
 #[derive(PartialEq, Eq, Debug, Copy, Clone, PartialOrd, Ord, Deserialize, Serialize)]
 pub struct Epoch(pub u32);
 
 impl Epoch {
     pub fn next(&mut self) {
         self.0 += 1;
     }
 }
 
-#[derive(PartialEq, Eq, Debug, Copy, Clone)]
-pub struct FrameTreeId(pub u32);
-
-impl FrameTreeId {
-    pub fn next(&mut self) {
-        self.0 += 1;
-    }
-}
-
 /// A unique ID for every stacking context.
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, PartialEq, Serialize)]
 pub struct StackingContextId(
     /// The identifier for this StackingContext, derived from the Flow's memory address
     /// and fragment type.  As a space optimization, these are combined into a single word.
     usize
 );
 
@@ -123,47 +79,21 @@ impl StackingContextId {
         debug_assert_eq!(id & (fragment_type as usize), 0);
         if fragment_type == FragmentType::FragmentBody {
             StackingContextId(id)
         } else {
             StackingContextId(StackingContextId::next_special_id() | (fragment_type as usize))
         }
     }
 
-    /// Returns an ID for the stacking context that forms the outer stacking context of an element
-    /// with `overflow: scroll`.
-    #[inline(always)]
-    pub fn new_outer(fragment_type: FragmentType) -> StackingContextId {
-        StackingContextId(StackingContextId::next_special_id() | (fragment_type as usize))
-    }
-
-    #[inline]
-    pub fn fragment_type(&self) -> FragmentType {
-        FragmentType::from_usize(self.0 & 3)
-    }
-
-    #[inline]
-    pub fn id(&self) -> usize {
-        self.0 & !3
-    }
-
     /// Returns the stacking context ID for the outer document/layout root.
     #[inline]
     pub fn root() -> StackingContextId {
         StackingContextId(0)
     }
-
-    /// Returns true if this is a special stacking context.
-    ///
-    /// A special stacking context is a stacking context that is one of (a) the outer stacking
-    /// context of an element with `overflow: scroll`; (b) generated content; (c) both (a) and (b).
-    #[inline]
-    pub fn is_special(&self) -> bool {
-        (self.0 & !SPECIAL_STACKING_CONTEXT_ID_MASK) == 0
-    }
 }
 
 /// A unique ID for every scrolling root.
 #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, HeapSizeOf, PartialEq, Serialize)]
 pub struct ScrollRootId(
     /// The identifier for this StackingContext, derived from the Flow's memory address
     /// and fragment type.  As a space optimization, these are combined into a single word.
     pub usize
@@ -206,21 +136,16 @@ impl ScrollRootId {
     pub fn id(&self) -> usize {
         self.0 & !3
     }
 
     #[inline]
     pub fn fragment_type(&self) -> FragmentType {
         FragmentType::from_usize(self.0 & 3)
     }
-
-    #[inline]
-    pub fn to_stacking_context_id(&self) -> StackingContextId {
-        StackingContextId(self.0)
-    }
 }
 
 /// The type of fragment that a stacking context represents.
 ///
 /// This can only ever grow to maximum 4 entries. That's because we cram the value of this enum
 /// into the lower 2 bits of the `StackingContextId`, which otherwise contains a 32-bit-aligned
 /// heap address.
 #[derive(Clone, Debug, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)]
@@ -241,14 +166,14 @@ impl FragmentType {
             0 => FragmentType::FragmentBody,
             1 => FragmentType::BeforePseudoContent,
             _ => FragmentType::AfterPseudoContent,
         }
     }
 }
 
 int_range_index! {
-    #[derive(Deserialize, Serialize, RustcEncodable)]
+    #[derive(Deserialize, Serialize)]
     #[doc = "An index that refers to a byte offset in a text run. This could \
              point to the middle of a glyph."]
     #[derive(HeapSizeOf)]
     struct ByteIndex(isize)
 }
--- a/servo/components/layout/display_list_builder.rs
+++ b/servo/components/layout/display_list_builder.rs
@@ -22,17 +22,17 @@ use fragment::{CoordinateSystem, Fragmen
 use fragment::SpecificFragmentInfo;
 use gfx::display_list::{BLUR_INFLATION_FACTOR, BaseDisplayItem, BorderDisplayItem};
 use gfx::display_list::{BorderRadii, BoxShadowClipMode, BoxShadowDisplayItem, ClippingRegion};
 use gfx::display_list::{DisplayItem, DisplayItemMetadata, DisplayList, DisplayListSection};
 use gfx::display_list::{GradientDisplayItem, IframeDisplayItem, ImageDisplayItem};
 use gfx::display_list::{LineDisplayItem, OpaqueNode};
 use gfx::display_list::{SolidColorDisplayItem, ScrollRoot, StackingContext, StackingContextType};
 use gfx::display_list::{TextDisplayItem, TextOrientation, WebGLDisplayItem, WebRenderImageInfo};
-use gfx_traits::{ScrollPolicy, ScrollRootId, StackingContextId};
+use gfx_traits::{ScrollRootId, StackingContextId};
 use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFlow, LAST_FRAGMENT_OF_ELEMENT};
 use ipc_channel::ipc;
 use list_item::ListItemFlow;
 use model::{self, MaybeAuto};
 use net_traits::image::base::PixelFormat;
 use net_traits::image_cache_thread::UsePlaceholder;
 use range::Range;
 use servo_config::opts;
@@ -53,17 +53,17 @@ use style::logical_geometry::{LogicalPoi
 use style::properties::{self, ServoComputedValues};
 use style::properties::style_structs;
 use style::servo::restyle_damage::REPAINT;
 use style::values::{RGBA, computed};
 use style::values::computed::{AngleOrCorner, Gradient, GradientKind, LengthOrPercentage, LengthOrPercentageOrAuto};
 use style::values::specified::{HorizontalDirection, VerticalDirection};
 use style_traits::cursor::Cursor;
 use table_cell::CollapsedBordersForCell;
-use webrender_traits::{ColorF, GradientStop};
+use webrender_traits::{ColorF, GradientStop, ScrollPolicy};
 
 trait RgbColor {
     fn rgb(r: u8, g: u8, b: u8) -> Self;
 }
 
 impl RgbColor for ColorF {
     fn rgb(r: u8, g: u8, b: u8) -> Self {
         ColorF {
@@ -1907,17 +1907,17 @@ impl BlockFlowDisplayListBuilding for Bl
     }
 
     fn create_real_stacking_context_for_block(&mut self,
                                               stacking_context_id: StackingContextId,
                                               parent_stacking_context_id: StackingContextId,
                                               parent_scroll_root_id: ScrollRootId,
                                               state: &mut DisplayListBuildState) {
         let scroll_policy = if self.is_fixed() {
-            ScrollPolicy::FixedPosition
+            ScrollPolicy::Fixed
         } else {
             ScrollPolicy::Scrollable
         };
 
         let stacking_context = self.fragment.create_stacking_context(
             stacking_context_id,
             &self.base,
             scroll_policy,
--- a/servo/components/layout/webrender_helpers.rs
+++ b/servo/components/layout/webrender_helpers.rs
@@ -6,17 +6,17 @@
 //           into WebRender display lists. In the future, this step should be completely removed.
 //           This might be achieved by sharing types between WR and Servo display lists, or
 //           completely converting layout to directly generate WebRender display lists, for example.
 
 use app_units::Au;
 use euclid::{Point2D, Rect, Size2D};
 use gfx::display_list::{BorderRadii, BoxShadowClipMode, ClippingRegion};
 use gfx::display_list::{DisplayItem, DisplayList, DisplayListTraversal, StackingContextType};
-use gfx_traits::{FragmentType, ScrollPolicy, ScrollRootId};
+use gfx_traits::{FragmentType, ScrollRootId};
 use msg::constellation_msg::PipelineId;
 use style::computed_values::{image_rendering, mix_blend_mode};
 use style::computed_values::filter::{self, Filter};
 use style::values::computed::BorderStyle;
 use webrender_traits::{self, DisplayListBuilder, LayoutTransform};
 
 pub trait WebRenderDisplayListConverter {
     fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder;
@@ -332,26 +332,21 @@ impl WebRenderDisplayItemConverter for D
                 let pipeline_id = item.iframe.to_webrender();
                 let clip = item.base.clip.to_clip_region(builder);
                 builder.push_iframe(rect, clip, pipeline_id);
             }
             DisplayItem::PushStackingContext(ref item) => {
                 let stacking_context = &item.stacking_context;
                 debug_assert!(stacking_context.context_type == StackingContextType::Real);
 
-                let webrender_scroll_policy = match stacking_context.scroll_policy {
-                    ScrollPolicy::Scrollable => webrender_traits::ScrollPolicy::Scrollable,
-                    ScrollPolicy::FixedPosition => webrender_traits::ScrollPolicy::Fixed,
-                };
-
                 let clip = builder.new_clip_region(&stacking_context.overflow.to_rectf(),
                                                    vec![],
                                                    None);
 
-                builder.push_stacking_context(webrender_scroll_policy,
+                builder.push_stacking_context(stacking_context.scroll_policy,
                                               stacking_context.bounds.to_rectf(),
                                               clip,
                                               stacking_context.z_index,
                                               &LayoutTransform::from_untyped(&stacking_context.transform),
                                               &LayoutTransform::from_untyped(&stacking_context.perspective),
                                               stacking_context.blend_mode.to_blend_mode(),
                                               stacking_context.filters.to_filter_ops());
             }