Skip to content

Commit

Permalink
Move LayerKind and ScrollPolicy enums to gfx_traits
Browse files Browse the repository at this point in the history
This also moves LayerId and LayerProperties to gfx_traits.

Fixes #8836.
  • Loading branch information
nerith committed Dec 21, 2015
1 parent a900196 commit 637afec
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 115 deletions.
5 changes: 2 additions & 3 deletions components/compositing/compositor.rs
Expand Up @@ -14,7 +14,7 @@ use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use euclid::{Matrix4, Point2D, Rect, Size2D};
use gfx::paint_task::{ChromeToPaintMsg, PaintRequest};
use gfx_traits::color;
use gfx_traits::{color, LayerId, LayerKind, LayerProperties, ScrollPolicy};
use gleam::gl;
use gleam::gl::types::{GLint, GLsizei};
use image::{DynamicImage, ImageFormat, RgbImage};
Expand All @@ -27,8 +27,7 @@ use layers::rendergl;
use layers::rendergl::RenderContext;
use layers::scene::Scene;
use layout_traits::LayoutControlChan;
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerKind};
use msg::compositor_msg::{LayerProperties, ScrollPolicy};
use msg::compositor_msg::{Epoch, FrameTreeId};
use msg::constellation_msg::{AnimationState, Image, PixelFormat};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, MouseButton};
use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData};
Expand Down
3 changes: 2 additions & 1 deletion components/compositing/compositor_layer.rs
Expand Up @@ -8,10 +8,11 @@ use euclid::length::Length;
use euclid::point::{Point2D, TypedPoint2D};
use euclid::rect::Rect;
use euclid::size::TypedSize2D;
use gfx_traits::{LayerId, LayerProperties, ScrollPolicy};
use layers::color::Color;
use layers::geometry::LayerPixel;
use layers::layers::{Layer, LayerBufferSet};
use msg::compositor_msg::{Epoch, LayerId, LayerProperties, ScrollPolicy};
use msg::compositor_msg::Epoch;
use msg::constellation_msg::{MouseEventType, PipelineId};
use script_traits::CompositorEvent;
use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent};
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/compositor_task.rs
Expand Up @@ -8,12 +8,12 @@ use CompositorMsg as ConstellationMsg;
use compositor;
use euclid::point::Point2D;
use euclid::size::Size2D;
use gfx_traits::PaintListener;
use gfx_traits::{LayerId, LayerProperties, PaintListener};
use headless;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use layers::layers::{BufferRequest, LayerBufferSet};
use layers::platform::surface::{NativeDisplay, NativeSurface};
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerProperties};
use msg::compositor_msg::{Epoch, FrameTreeId};
use msg::constellation_msg::{AnimationState, PipelineId};
use msg::constellation_msg::{Image, Key, KeyModifiers, KeyState};
use profile_traits::mem;
Expand Down
3 changes: 1 addition & 2 deletions components/gfx/display_list/mod.rs
Expand Up @@ -21,9 +21,8 @@ use display_list::optimizer::DisplayListOptimizer;
use euclid::approxeq::ApproxEq;
use euclid::num::Zero;
use euclid::{Matrix2D, Matrix4, Point2D, Rect, SideOffsets2D, Size2D};
use gfx_traits::color;
use gfx_traits::{color, LayerId, LayerKind, ScrollPolicy};
use libc::uintptr_t;
use msg::compositor_msg::{LayerId, LayerKind, ScrollPolicy};
use msg::constellation_msg::PipelineId;
use net_traits::image::base::Image;
use paint_context::PaintContext;
Expand Down
3 changes: 1 addition & 2 deletions components/gfx/paint_context.rs
Expand Up @@ -26,8 +26,7 @@ use euclid::side_offsets::SideOffsets2D;
use euclid::size::Size2D;
use filters;
use font_context::FontContext;
use gfx_traits::color;
use msg::compositor_msg::LayerKind;
use gfx_traits::{color, LayerKind};
use net_traits::image::base::{Image, PixelFormat};
use std::default::Default;
use std::sync::Arc;
Expand Down
4 changes: 2 additions & 2 deletions components/gfx/paint_task.rs
Expand Up @@ -15,11 +15,11 @@ use euclid::rect::Rect;
use euclid::size::Size2D;
use font_cache_task::FontCacheTask;
use font_context::FontContext;
use gfx_traits::{color, PaintListener, PaintMsg as ConstellationMsg};
use gfx_traits::{color, LayerId, LayerKind, LayerProperties, PaintListener, PaintMsg as ConstellationMsg, ScrollPolicy};
use ipc_channel::ipc::IpcSender;
use layers::layers::{BufferRequest, LayerBuffer, LayerBufferSet};
use layers::platform::surface::{NativeDisplay, NativeSurface};
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerKind, LayerProperties, ScrollPolicy};
use msg::compositor_msg::{Epoch, FrameTreeId};
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use paint_context::PaintContext;
use profile_traits::mem::{self, ReportsChan};
Expand Down
7 changes: 7 additions & 0 deletions components/gfx_traits/Cargo.toml
Expand Up @@ -18,6 +18,13 @@ features = ["plugins"]
[dependencies.msg]
path = "../msg"

[dependencies.plugins]
path = "../plugins"

[dependencies.util]
path = "../util"

[dependencies]
euclid = {version = "0.4", features = ["plugins"]}
serde = "0.6"
serde_macros = "0.6"
95 changes: 93 additions & 2 deletions components/gfx_traits/lib.rs
Expand Up @@ -3,23 +3,114 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]
#![plugin(plugins, serde_macros)]

#![crate_name = "gfx_traits"]
#![crate_type = "rlib"]

extern crate azure;
extern crate euclid;
extern crate layers;
extern crate msg;
extern crate serde;
extern crate util;

pub mod color;
mod paint_listener;

pub use paint_listener::PaintListener;
use msg::constellation_msg::Failure;
use azure::azure_hl::Color;
use euclid::matrix::Matrix4;
use euclid::rect::Rect;
use msg::compositor_msg::LayerType;
use msg::constellation_msg::{Failure, PipelineId};
use std::fmt::{self, Debug, Formatter};

/// Messages from the paint task to the constellation.
#[derive(Deserialize, Serialize)]
pub enum PaintMsg {
Failure(Failure),
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum LayerKind {
NoTransform,
HasTransform,
}

/// 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,
}

#[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)]
pub struct LayerId(
/// The type of the layer. This serves to differentiate layers that share fragments.
LayerType,
/// The identifier for this layer's fragment, derived from the fragment memory address.
usize,
/// An index for identifying companion layers, synthesized to ensure that
/// content on top of this layer's fragment has the proper rendering order.
usize
);

impl Debug for LayerId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let LayerId(layer_type, id, companion) = *self;
let type_string = match layer_type {
LayerType::FragmentBody => "-FragmentBody",
LayerType::OverflowScroll => "-OverflowScroll",
LayerType::BeforePseudoContent => "-BeforePseudoContent",
LayerType::AfterPseudoContent => "-AfterPseudoContent",
};

write!(f, "{}{}-{}", id, type_string, companion)
}
}

impl LayerId {
/// FIXME(#2011, pcwalton): This is unfortunate. Maybe remove this in the future.
pub fn null() -> LayerId {
LayerId(LayerType::FragmentBody, 0, 0)
}

pub fn new_of_type(layer_type: LayerType, fragment_id: usize) -> LayerId {
LayerId(layer_type, fragment_id, 0)
}

pub fn companion_layer_id(&self) -> LayerId {
let LayerId(layer_type, id, companion) = *self;
LayerId(layer_type, id, companion + 1)
}
}

/// All layer-specific information that the painting task sends to the compositor other than the
/// buffer contents of the layer itself.
#[derive(Copy, Clone)]
pub struct LayerProperties {
/// An opaque ID. This is usually the address of the flow and index of the box within it.
pub id: LayerId,
/// The id of the parent layer.
pub parent_id: Option<LayerId>,
/// The position and size of the layer in pixels.
pub rect: Rect<f32>,
/// The background color of the layer.
pub background_color: Color,
/// The scrolling policy of this layer.
pub scroll_policy: ScrollPolicy,
/// The transform for this layer
pub transform: Matrix4,
/// The perspective transform for this layer
pub perspective: Matrix4,
/// The subpage that this layer represents. If this is `Some`, this layer represents an
/// iframe.
pub subpage_pipeline_id: Option<PipelineId>,
/// Whether this layer establishes a new 3d rendering context.
pub establishes_3d_context: bool,
/// Whether this layer scrolls its overflow area.
pub scrolls_overflow_area: bool,
}
4 changes: 3 additions & 1 deletion components/gfx_traits/paint_listener.rs
Expand Up @@ -2,9 +2,11 @@
* 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 LayerId;
use LayerProperties;
use layers::layers::{BufferRequest, LayerBufferSet};
use layers::platform::surface::NativeDisplay;
use msg::compositor_msg::{Epoch, FrameTreeId, LayerId, LayerProperties};
use msg::compositor_msg::{Epoch, FrameTreeId};
use msg::constellation_msg::PipelineId;

/// The interface used by the painter to acquire draw targets for each paint frame and
Expand Down
2 changes: 1 addition & 1 deletion components/layout/block.rs
Expand Up @@ -44,12 +44,12 @@ use flow::{self, BaseFlow, EarlyAbsolutePositionInfo, Flow, FlowClass, ForceNonf
use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, HAS_LAYER};
use fragment::{SpecificFragmentInfo};
use gfx::display_list::{ClippingRegion, DisplayList};
use gfx_traits::LayerId;
use incremental::{REFLOW, REFLOW_OUT_OF_FLOW};
use layout_debug;
use layout_task::DISPLAY_PORT_SIZE_FACTOR;
use model::{CollapsibleMargins, MaybeAuto, specified, specified_or_none};
use model::{IntrinsicISizes, MarginCollapseInfo};
use msg::compositor_msg::LayerId;
use rustc_serialize::{Encodable, Encoder};
use std::cmp::{max, min};
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion components/layout/context.rs
Expand Up @@ -14,9 +14,9 @@ use fnv::FnvHasher;
use gfx::display_list::OpaqueNode;
use gfx::font_cache_task::FontCacheTask;
use gfx::font_context::FontContext;
use gfx_traits::LayerId;
use ipc_channel::ipc::{self, IpcSender};
use msg::ParseErrorReporter;
use msg::compositor_msg::LayerId;
use net_traits::image::base::Image;
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheTask, ImageResponse, ImageState};
use net_traits::image_cache_task::{UsePlaceholder};
Expand Down
3 changes: 1 addition & 2 deletions components/layout/display_list_builder.rs
Expand Up @@ -31,12 +31,11 @@ use gfx::display_list::{LineDisplayItem, OpaqueNode, SolidColorDisplayItem};
use gfx::display_list::{StackingContext, TextDisplayItem, TextOrientation};
use gfx::paint_task::THREAD_TINT_COLORS;
use gfx::text::glyph::CharIndex;
use gfx_traits::color;
use gfx_traits::{color, ScrollPolicy};
use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFlow, LAST_FRAGMENT_OF_ELEMENT};
use ipc_channel::ipc::{self, IpcSharedMemory};
use list_item::ListItemFlow;
use model::{self, MaybeAuto, ToGfxMatrix};
use msg::compositor_msg::ScrollPolicy;
use net_traits::image::base::{Image, PixelFormat};
use net_traits::image_cache_task::UsePlaceholder;
use std::default::Default;
Expand Down
3 changes: 2 additions & 1 deletion components/layout/flow.rs
Expand Up @@ -34,10 +34,11 @@ use flow_list::{FlowList, FlowListIterator, MutFlowListIterator};
use flow_ref::{self, FlowRef, WeakFlowRef};
use fragment::{Fragment, FragmentBorderBoxIterator, SpecificFragmentInfo};
use gfx::display_list::{ClippingRegion, DisplayList};
use gfx_traits::LayerId;
use incremental::{self, RECONSTRUCT_FLOW, REFLOW, REFLOW_OUT_OF_FLOW, RestyleDamage};
use inline::InlineFlow;
use model::{CollapsibleMargins, IntrinsicISizes, MarginCollapseInfo};
use msg::compositor_msg::{LayerId, LayerType};
use msg::compositor_msg::LayerType;
use multicol::MulticolFlow;
use parallel::FlowParallelInfo;
use rustc_serialize::{Encodable, Encoder};
Expand Down
3 changes: 2 additions & 1 deletion components/layout/fragment.rs
Expand Up @@ -17,13 +17,14 @@ use gfx;
use gfx::display_list::{BLUR_INFLATION_FACTOR, OpaqueNode};
use gfx::text::glyph::CharIndex;
use gfx::text::text_run::{TextRun, TextRunSlice};
use gfx_traits::LayerId;
use incremental::{self, RECONSTRUCT_FLOW, RestyleDamage};
use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragmentContext, InlineFragmentNodeInfo};
use inline::{InlineMetrics, LAST_FRAGMENT_OF_ELEMENT};
use ipc_channel::ipc::IpcSender;
use layout_debug;
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use msg::compositor_msg::{LayerId, LayerType};
use msg::compositor_msg::LayerType;
use msg::constellation_msg::PipelineId;
use net_traits::image::base::Image;
use net_traits::image_cache_task::UsePlaceholder;
Expand Down
4 changes: 2 additions & 2 deletions components/layout/layout_task.rs
Expand Up @@ -28,15 +28,15 @@ use gfx::font;
use gfx::font_cache_task::FontCacheTask;
use gfx::font_context;
use gfx::paint_task::{LayoutToPaintMsg, PaintLayer};
use gfx_traits::color;
use gfx_traits::{color, LayerId, ScrollPolicy};
use incremental::{LayoutDamageComputation, REFLOW, REFLOW_ENTIRE_DOCUMENT, REPAINT};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use ipc_channel::router::ROUTER;
use layout_debug;
use layout_traits::LayoutTaskFactory;
use log;
use msg::ParseErrorReporter;
use msg::compositor_msg::{Epoch, LayerId, ScrollPolicy};
use msg::compositor_msg::Epoch;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use net_traits::image_cache_task::{ImageCacheChan, ImageCacheResult, ImageCacheTask};
use parallel::{self, WorkQueueData};
Expand Down

0 comments on commit 637afec

Please sign in to comment.