Auto merge of #14938 - servo:gfx-traits, r=nox

Various cleanup around gfx_traits.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14938)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-01-10 07:02:23 -08:00 committed by GitHub
commit f674a9db8b
9 changed files with 30 additions and 99 deletions

View file

@ -11,8 +11,8 @@ 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};
@ -108,6 +108,22 @@ enum ReadyState {
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.

View file

@ -29,7 +29,6 @@ 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"}

View file

@ -19,7 +19,7 @@ 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;
@ -34,7 +34,7 @@ use style::computed_values::{border_style, filter, image_rendering, mix_blend_mo
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;
@ -129,7 +129,7 @@ impl DisplayList {
// 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 {
@ -251,7 +251,7 @@ impl<'a> Iterator for DisplayListTraversal<'a> {
/// 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,
@ -259,7 +259,7 @@ pub enum DisplayListSection {
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,

View file

@ -58,7 +58,6 @@ 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;

View file

@ -14,6 +14,5 @@ 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"

View file

@ -14,7 +14,6 @@ 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;
@ -41,43 +40,9 @@ const SPECIAL_STACKING_CONTEXT_ID_MASK: usize = 0xffff;
/// 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);
@ -88,15 +53,6 @@ impl Epoch {
}
}
#[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(
@ -128,37 +84,11 @@ impl StackingContextId {
}
}
/// 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.
@ -211,11 +141,6 @@ impl ScrollRootId {
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.
@ -246,7 +171,7 @@ impl FragmentType {
}
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)]

View file

@ -27,7 +27,7 @@ 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;
@ -58,7 +58,7 @@ use style::values::computed::{AngleOrCorner, Gradient, GradientKind, LengthOrPer
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;
@ -1912,7 +1912,7 @@ impl BlockFlowDisplayListBuilding for BlockFlow {
parent_scroll_root_id: ScrollRootId,
state: &mut DisplayListBuildState) {
let scroll_policy = if self.is_fixed() {
ScrollPolicy::FixedPosition
ScrollPolicy::Fixed
} else {
ScrollPolicy::Scrollable
};

View file

@ -11,7 +11,7 @@ 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};
@ -337,16 +337,11 @@ impl WebRenderDisplayItemConverter for DisplayItem {
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,