/components/gfx_traits/lib.rs

https://gitlab.com/Srijancse/servo · Rust · 154 lines · 103 code · 21 blank · 30 comment · 2 complexity · ac67b611d200e65b8f77531e65a39968 MD5 · raw file

  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #![feature(custom_derive, plugin)]
  5. #![plugin(heapsize_plugin, plugins, serde_macros)]
  6. #![crate_name = "gfx_traits"]
  7. #![crate_type = "rlib"]
  8. extern crate azure;
  9. extern crate euclid;
  10. extern crate heapsize;
  11. extern crate layers;
  12. extern crate msg;
  13. extern crate serde;
  14. extern crate util;
  15. pub mod color;
  16. mod paint_listener;
  17. pub use paint_listener::PaintListener;
  18. use azure::azure_hl::Color;
  19. use euclid::matrix::Matrix4;
  20. use euclid::rect::Rect;
  21. use msg::constellation_msg::{Failure, PipelineId};
  22. use std::fmt::{self, Debug, Formatter};
  23. /// Messages from the paint task to the constellation.
  24. #[derive(Deserialize, Serialize)]
  25. pub enum PaintMsg {
  26. Failure(Failure),
  27. }
  28. #[derive(Clone, Copy, Debug, PartialEq)]
  29. pub enum LayerKind {
  30. NoTransform,
  31. HasTransform,
  32. }
  33. #[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)]
  34. pub enum LayerType {
  35. /// A layer for the fragment body itself.
  36. FragmentBody,
  37. /// An extra layer created for a DOM fragments with overflow:scroll.
  38. OverflowScroll,
  39. /// A layer created to contain ::before pseudo-element content.
  40. BeforePseudoContent,
  41. /// A layer created to contain ::after pseudo-element content.
  42. AfterPseudoContent,
  43. }
  44. /// The scrolling policy of a layer.
  45. #[derive(Clone, PartialEq, Eq, Copy, Deserialize, Serialize, Debug, HeapSizeOf)]
  46. pub enum ScrollPolicy {
  47. /// These layers scroll when the parent receives a scrolling message.
  48. Scrollable,
  49. /// These layers do not scroll when the parent receives a scrolling message.
  50. FixedPosition,
  51. }
  52. #[derive(Clone, PartialEq, Eq, Copy, Hash, Deserialize, Serialize, HeapSizeOf)]
  53. pub struct LayerId(
  54. /// The type of the layer. This serves to differentiate layers that share fragments.
  55. LayerType,
  56. /// The identifier for this layer's fragment, derived from the fragment memory address.
  57. usize,
  58. /// An index for identifying companion layers, synthesized to ensure that
  59. /// content on top of this layer's fragment has the proper rendering order.
  60. usize
  61. );
  62. impl Debug for LayerId {
  63. fn fmt(&self, f: &mut Formatter) -> fmt::Result {
  64. let LayerId(layer_type, id, companion) = *self;
  65. let type_string = match layer_type {
  66. LayerType::FragmentBody => "-FragmentBody",
  67. LayerType::OverflowScroll => "-OverflowScroll",
  68. LayerType::BeforePseudoContent => "-BeforePseudoContent",
  69. LayerType::AfterPseudoContent => "-AfterPseudoContent",
  70. };
  71. write!(f, "{}{}-{}", id, type_string, companion)
  72. }
  73. }
  74. impl LayerId {
  75. /// FIXME(#2011, pcwalton): This is unfortunate. Maybe remove this in the future.
  76. pub fn null() -> LayerId {
  77. LayerId(LayerType::FragmentBody, 0, 0)
  78. }
  79. pub fn new_of_type(layer_type: LayerType, fragment_id: usize) -> LayerId {
  80. LayerId(layer_type, fragment_id, 0)
  81. }
  82. pub fn companion_layer_id(&self) -> LayerId {
  83. let LayerId(layer_type, id, companion) = *self;
  84. LayerId(layer_type, id, companion + 1)
  85. }
  86. pub fn original(&self) -> LayerId {
  87. let LayerId(layer_type, id, _) = *self;
  88. LayerId(layer_type, id, 0)
  89. }
  90. }
  91. /// All layer-specific information that the painting task sends to the compositor other than the
  92. /// buffer contents of the layer itself.
  93. #[derive(Copy, Clone, HeapSizeOf)]
  94. pub struct LayerProperties {
  95. /// An opaque ID. This is usually the address of the flow and index of the box within it.
  96. pub id: LayerId,
  97. /// The id of the parent layer.
  98. pub parent_id: Option<LayerId>,
  99. /// The position and size of the layer in pixels.
  100. pub rect: Rect<f32>,
  101. /// The background color of the layer.
  102. pub background_color: Color,
  103. /// The scrolling policy of this layer.
  104. pub scroll_policy: ScrollPolicy,
  105. /// The transform for this layer
  106. pub transform: Matrix4,
  107. /// The perspective transform for this layer
  108. pub perspective: Matrix4,
  109. /// The subpage that this layer represents. If this is `Some`, this layer represents an
  110. /// iframe.
  111. pub subpage_pipeline_id: Option<PipelineId>,
  112. /// Whether this layer establishes a new 3d rendering context.
  113. pub establishes_3d_context: bool,
  114. /// Whether this layer scrolls its overflow area.
  115. pub scrolls_overflow_area: bool,
  116. }
  117. /// A newtype struct for denoting the age of messages; prevents race conditions.
  118. #[derive(PartialEq, Eq, Debug, Copy, Clone, PartialOrd, Ord, Deserialize, Serialize)]
  119. pub struct Epoch(pub u32);
  120. impl Epoch {
  121. pub fn next(&mut self) {
  122. let Epoch(ref mut u) = *self;
  123. *u += 1;
  124. }
  125. }
  126. #[derive(PartialEq, Eq, Debug, Copy, Clone)]
  127. pub struct FrameTreeId(pub u32);
  128. impl FrameTreeId {
  129. pub fn next(&mut self) {
  130. let FrameTreeId(ref mut u) = *self;
  131. *u += 1;
  132. }
  133. }