Skip to content

Commit 3c613a9

Browse files
committed
Add strongly typed units to the public API.
1 parent 3a6725a commit 3c613a9

16 files changed

+200
-199
lines changed

replay/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ extern crate webrender_traits;
88

99
use bincode::serde::deserialize;
1010
use byteorder::{LittleEndian, ReadBytesExt};
11-
use euclid::Size2D;
1211
use gleam::gl;
1312
use std::io::Read;
1413
use std::fs::File;
1514
use std::path::{Path, PathBuf};
1615
use std::env;
17-
use webrender_traits::{RenderApi, PipelineId};
16+
use webrender_traits::{RenderApi, PipelineId, LayerSize, DeviceUintSize};
1817
use webrender_traits::channel::PayloadHelperMethods;
1918
use glutin::{Event, ElementState, VirtualKeyCode as Key};
2019

@@ -38,7 +37,7 @@ impl webrender_traits::RenderNotifier for Notifier {
3837

3938
fn pipeline_size_changed(&mut self,
4039
_pid: PipelineId,
41-
_size: Option<Size2D<f32>>) {
40+
_size: Option<LayerSize>) {
4241
}
4342

4443
fn new_scroll_frame_ready(&mut self, _composite_needed: bool) {
@@ -133,7 +132,7 @@ fn main() {
133132
println!("Rendering frame {}.", frame_num);
134133
gl::clear(gl::COLOR_BUFFER_BIT);
135134
renderer.update();
136-
renderer.render(Size2D::new(width, height));
135+
renderer.render(DeviceUintSize::new(width, height));
137136
window.swap_buffers().unwrap();
138137
}
139138
Event::KeyboardInput(ElementState::Pressed, _, Some(Key::Right)) =>{

sample/src/main.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ extern crate webrender_traits;
66
extern crate euclid;
77

88
use app_units::Au;
9-
use euclid::{Size2D, Point2D, Rect, Matrix4D};
109
use gleam::gl;
1110
use std::path::PathBuf;
1211
use webrender_traits::{ColorF, Epoch, GlyphInstance};
1312
use webrender_traits::{ImageData, ImageFormat, PipelineId, RendererKind};
13+
use webrender_traits::{LayoutSize, LayoutPoint, LayoutRect, LayoutTransform, DeviceUintSize};
1414
use std::fs::File;
1515
use std::io::Read;
1616
use std::env;
@@ -45,7 +45,7 @@ impl webrender_traits::RenderNotifier for Notifier {
4545

4646
fn pipeline_size_changed(&mut self,
4747
_: PipelineId,
48-
_: Option<Size2D<f32>>) {
48+
_: Option<LayoutSize>) {
4949
}
5050
}
5151

@@ -100,10 +100,10 @@ fn main() {
100100
let pipeline_id = PipelineId(0, 0);
101101
let mut builder = webrender_traits::DisplayListBuilder::new(pipeline_id);
102102

103-
let bounds = Rect::new(Point2D::new(0.0, 0.0), Size2D::new(width as f32, height as f32));
103+
let bounds = LayoutRect::new(LayoutPoint::new(0.0, 0.0), LayoutSize::new(width as f32, height as f32));
104104
let clip_region = {
105105
let complex = webrender_traits::ComplexClipRegion::new(
106-
Rect::new(Point2D::new(50.0, 50.0), Size2D::new(100.0, 100.0)),
106+
LayoutRect::new(LayoutPoint::new(50.0, 50.0), LayoutSize::new(100.0, 100.0)),
107107
webrender_traits::BorderRadius::uniform(20.0));
108108

109109
builder.new_clip_region(&bounds, vec![complex], None)
@@ -113,36 +113,36 @@ fn main() {
113113
bounds,
114114
clip_region,
115115
0,
116-
&Matrix4D::identity(),
117-
&Matrix4D::identity(),
116+
&LayoutTransform::identity(),
117+
&LayoutTransform::identity(),
118118
webrender_traits::MixBlendMode::Normal,
119119
Vec::new());
120120

121121
let sub_clip = {
122122
let mask = webrender_traits::ImageMask {
123123
image: api.add_image(2, 2, None, ImageFormat::A8, ImageData::new(vec![0,80, 180, 255])),
124-
rect: Rect::new(Point2D::new(75.0, 75.0), Size2D::new(100.0, 100.0)),
124+
rect: LayoutRect::new(LayoutPoint::new(75.0, 75.0), LayoutSize::new(100.0, 100.0)),
125125
repeat: false,
126126
};
127127
let complex = webrender_traits::ComplexClipRegion::new(
128-
Rect::new(Point2D::new(50.0, 50.0), Size2D::new(100.0, 100.0)),
128+
LayoutRect::new(LayoutPoint::new(50.0, 50.0), LayoutSize::new(100.0, 100.0)),
129129
webrender_traits::BorderRadius::uniform(20.0));
130130

131131
builder.new_clip_region(&bounds, vec![complex], Some(mask))
132132
};
133133

134-
builder.push_rect(Rect::new(Point2D::new(100.0, 100.0), Size2D::new(100.0, 100.0)),
134+
builder.push_rect(LayoutRect::new(LayoutPoint::new(100.0, 100.0), LayoutSize::new(100.0, 100.0)),
135135
sub_clip,
136136
ColorF::new(0.0, 1.0, 0.0, 1.0));
137-
builder.push_rect(Rect::new(Point2D::new(250.0, 100.0), Size2D::new(100.0, 100.0)),
137+
builder.push_rect(LayoutRect::new(LayoutPoint::new(250.0, 100.0), LayoutSize::new(100.0, 100.0)),
138138
sub_clip,
139139
ColorF::new(0.0, 1.0, 0.0, 1.0));
140140

141141
if false { // draw text?
142142
let font_bytes = load_file("res/FreeSans.ttf");
143143
let font_key = api.add_raw_font(font_bytes);
144144

145-
let text_bounds = Rect::new(Point2D::new(100.0, 200.0), Size2D::new(700.0, 300.0));
145+
let text_bounds = LayoutRect::new(LayoutPoint::new(100.0, 200.0), LayoutSize::new(700.0, 300.0));
146146

147147
let glyphs = vec![
148148
GlyphInstance {
@@ -221,15 +221,15 @@ fn main() {
221221
api.set_root_display_list(
222222
root_background_color,
223223
epoch,
224-
Size2D::new(width as f32, height as f32),
224+
LayoutSize::new(width as f32, height as f32),
225225
builder);
226226
api.set_root_pipeline(pipeline_id);
227227

228228
for event in window.wait_events() {
229229
gl::clear(gl::COLOR_BUFFER_BIT);
230230
renderer.update();
231231

232-
renderer.render(Size2D::new(width, height));
232+
renderer.render(DeviceUintSize::new(width, height));
233233

234234
window.swap_buffers().ok();
235235

webrender/src/frame.rs

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use app_units::Au;
6-
use euclid::{Point2D, Point3D, Rect, Size2D};
6+
use euclid::Point3D;
77
use fnv::FnvHasher;
88
use geometry::ray_intersects_rect;
99
use internal_types::{ANGLE_FLOAT_TO_FIXED, AxisDirection};
@@ -22,8 +22,8 @@ use webrender_traits::{ClipRegion, ColorF, DisplayItem, StackingContext, FilterO
2222
use webrender_traits::{ScrollEventPhase, ScrollLayerInfo, ScrollLocation, SpecificDisplayItem, ScrollLayerState};
2323
use webrender_traits::{LayerRect, LayerPoint, LayerSize};
2424
use webrender_traits::{ServoScrollRootId, ScrollLayerRect, as_scroll_parent_rect, ScrollLayerPixel};
25-
use webrender_traits::WorldPoint4D;
26-
use webrender_traits::{LayerTransform, LayerToScrollTransform, ScrollToWorldTransform};
25+
use webrender_traits::{WorldPoint, WorldPoint4D};
26+
use webrender_traits::{LayerToScrollTransform, ScrollToWorldTransform};
2727

2828
#[cfg(target_os = "macos")]
2929
const CAN_OVERSCROLL: bool = true;
@@ -38,7 +38,7 @@ static DEFAULT_SCROLLBAR_COLOR: ColorF = ColorF { r: 0.3, g: 0.3, b: 0.3, a: 0.6
3838

3939
struct FlattenContext<'a> {
4040
scene: &'a Scene,
41-
pipeline_sizes: &'a mut HashMap<PipelineId, Size2D<f32>>,
41+
pipeline_sizes: &'a mut HashMap<PipelineId, LayerSize>,
4242
builder: &'a mut FrameBuilder,
4343
}
4444

@@ -234,7 +234,7 @@ impl Frame {
234234
old_layer_scrolling_states
235235
}
236236

237-
pub fn get_scroll_layer(&self, cursor: &Point2D<f32>, scroll_layer_id: ScrollLayerId)
237+
pub fn get_scroll_layer(&self, cursor: &WorldPoint, scroll_layer_id: ScrollLayerId)
238238
-> Option<ScrollLayerId> {
239239
self.layers.get(&scroll_layer_id).and_then(|layer| {
240240
for child_layer_id in layer.children.iter().rev() {
@@ -286,7 +286,7 @@ impl Frame {
286286
result.push(ScrollLayerState {
287287
pipeline_id: scroll_layer.pipeline_id,
288288
scroll_root_id: servo_scroll_root_id,
289-
scroll_offset: scroll_layer.scrolling.offset.to_untyped(),
289+
scroll_offset: scroll_layer.scrolling.offset,
290290
})
291291
}
292292
ScrollLayerInfo::Fixed => {}
@@ -297,7 +297,7 @@ impl Frame {
297297

298298
/// Returns true if any layers actually changed position or false otherwise.
299299
pub fn scroll_layers(&mut self,
300-
origin: Point2D<f32>,
300+
origin: LayerPoint,
301301
pipeline_id: PipelineId,
302302
scroll_root_id: ServoScrollRootId)
303303
-> bool {
@@ -330,7 +330,7 @@ impl Frame {
330330
/// Returns true if any layers actually changed position or false otherwise.
331331
pub fn scroll(&mut self,
332332
scroll_location: ScrollLocation,
333-
cursor: Point2D<f32>,
333+
cursor: WorldPoint,
334334
phase: ScrollEventPhase)
335335
-> bool {
336336
let root_scroll_layer_id = match self.root_scroll_layer_id {
@@ -460,7 +460,7 @@ impl Frame {
460460

461461
pub fn create(&mut self,
462462
scene: &Scene,
463-
pipeline_sizes: &mut HashMap<PipelineId, Size2D<f32>>,
463+
pipeline_sizes: &mut HashMap<PipelineId, LayerSize>,
464464
device_pixel_ratio: f32) {
465465
let root_pipeline_id = match scene.root_pipeline_id {
466466
Some(root_pipeline_id) => root_pipeline_id,
@@ -497,9 +497,9 @@ impl Frame {
497497
// Insert global position: fixed elements layer
498498
debug_assert!(self.layers.is_empty());
499499
let root_fixed_layer_id = ScrollLayerId::create_fixed(root_pipeline_id);
500-
let root_viewport = LayerRect::new(LayerPoint::zero(), LayerSize::from_untyped(&root_pipeline.viewport_size));
500+
let root_viewport = LayerRect::new(LayerPoint::zero(), root_pipeline.viewport_size);
501501
let layer = Layer::new(&root_viewport,
502-
LayerSize::from_untyped(&root_clip.main.size),
502+
root_clip.main.size,
503503
&LayerToScrollTransform::identity(),
504504
root_pipeline_id);
505505
self.layers.insert(root_fixed_layer_id, layer.clone());
@@ -589,7 +589,7 @@ impl Frame {
589589
LayerSize::new(content_size.width + clip.origin.x,
590590
content_size.height + clip.origin.y));
591591
context.builder.push_layer(layer_rect,
592-
&ClipRegion::simple(&layer_rect.to_untyped()),
592+
&ClipRegion::simple(&layer_rect),
593593
LayerToScrollTransform::identity(),
594594
pipeline_id,
595595
current_scroll_layer_id,
@@ -640,14 +640,11 @@ impl Frame {
640640
}
641641
}
642642

643-
// TODO(nical): make them LayerTransforms in the public API.
644-
let sc_transform: LayerTransform = unsafe { ::std::mem::transmute(stacking_context.transform) };
645-
let sc_perspective: LayerTransform = unsafe { ::std::mem::transmute(stacking_context.perspective) };
646643
let transform = layer_relative_transform.pre_translated(stacking_context.bounds.origin.x,
647644
stacking_context.bounds.origin.y,
648645
0.0)
649-
.pre_mul(&sc_transform)
650-
.pre_mul(&sc_perspective);
646+
.pre_mul(&stacking_context.transform)
647+
.pre_mul(&stacking_context.perspective);
651648

652649
// Build world space transform
653650
let scroll_layer_id = match stacking_context.scroll_policy {
@@ -676,7 +673,7 @@ impl Frame {
676673

677674
// Adding a dummy layer for this rectangle in order to disable clipping.
678675
let no_clip = ClipRegion::simple(&clip_region.main);
679-
context.builder.push_layer(LayerRect::from_untyped(&clip_region.main),
676+
context.builder.push_layer(clip_region.main,
680677
&no_clip,
681678
transform,
682679
pipeline_id,
@@ -685,7 +682,7 @@ impl Frame {
685682

686683
//Note: we don't use the original clip region here,
687684
// it's already processed by the layer we just pushed.
688-
context.builder.add_solid_rectangle(&LayerRect::from_untyped(&clip_region.main),
685+
context.builder.add_solid_rectangle(&clip_region.main,
689686
&no_clip,
690687
&root_background_color,
691688
PrimitiveFlags::None);
@@ -694,7 +691,7 @@ impl Frame {
694691
}
695692

696693
// TODO(gw): Int with overflow etc
697-
context.builder.push_layer(LayerRect::from_untyped(&clip_region.main),
694+
context.builder.push_layer(clip_region.main,
698695
&clip_region,
699696
transform,
700697
pipeline_id,
@@ -712,7 +709,7 @@ impl Frame {
712709
if level == 0 && self.frame_builder_config.enable_scrollbars {
713710
let scrollbar_rect = LayerRect::new(LayerPoint::zero(), LayerSize::new(10.0, 70.0));
714711
context.builder.add_solid_rectangle(&scrollbar_rect,
715-
&ClipRegion::simple(&scrollbar_rect.to_untyped()),
712+
&ClipRegion::simple(&scrollbar_rect),
716713
&DEFAULT_SCROLLBAR_COLOR,
717714
PrimitiveFlags::Scrollbar(self.root_scroll_layer_id.unwrap(),
718715
4.0));
@@ -723,7 +720,7 @@ impl Frame {
723720

724721
fn flatten_iframe<'a>(&mut self,
725722
pipeline_id: PipelineId,
726-
bounds: &Rect<f32>,
723+
bounds: &LayerRect,
727724
context: &mut FlattenContext,
728725
current_scroll_layer_id: ScrollLayerId,
729726
layer_relative_transform: LayerToScrollTransform) {
@@ -750,7 +747,7 @@ impl Frame {
750747

751748
self.pipeline_epoch_map.insert(pipeline_id, pipeline.epoch);
752749

753-
let iframe_rect = &LayerRect::new(LayerPoint::zero(), LayerSize::from_untyped(&bounds.size));
750+
let iframe_rect = &LayerRect::new(LayerPoint::zero(), bounds.size);
754751
let transform = layer_relative_transform.pre_translated(bounds.origin.x,
755752
bounds.origin.y,
756753
0.0);
@@ -759,7 +756,7 @@ impl Frame {
759756
let iframe_scroll_layer_id = ScrollLayerId::root(pipeline_id);
760757

761758
let layer = Layer::new(iframe_rect,
762-
LayerSize::from_untyped(&iframe_clip.main.size),
759+
iframe_clip.main.size,
763760
&transform,
764761
pipeline_id);
765762
self.layers.insert(iframe_fixed_layer_id, layer.clone());
@@ -790,27 +787,27 @@ impl Frame {
790787
while let Some(item) = traversal.next() {
791788
match item.item {
792789
SpecificDisplayItem::WebGL(ref info) => {
793-
context.builder.add_webgl_rectangle(LayerRect::from_untyped(&item.rect),
790+
context.builder.add_webgl_rectangle(item.rect,
794791
&item.clip, info.context_id);
795792
}
796793
SpecificDisplayItem::Image(ref info) => {
797-
context.builder.add_image(LayerRect::from_untyped(&item.rect),
794+
context.builder.add_image(item.rect,
798795
&item.clip,
799-
&LayerSize::from_untyped(&info.stretch_size),
800-
&LayerSize::from_untyped(&info.tile_spacing),
796+
&info.stretch_size,
797+
&info.tile_spacing,
801798
info.image_key,
802799
info.image_rendering);
803800
}
804801
SpecificDisplayItem::YuvImage(ref info) => {
805-
context.builder.add_yuv_image(LayerRect::from_untyped(&item.rect),
802+
context.builder.add_yuv_image(item.rect,
806803
&item.clip,
807804
info.y_image_key,
808805
info.u_image_key,
809806
info.v_image_key,
810807
info.color_space);
811808
}
812809
SpecificDisplayItem::Text(ref text_info) => {
813-
context.builder.add_text(LayerRect::from_untyped(&item.rect),
810+
context.builder.add_text(item.rect,
814811
&item.clip,
815812
text_info.font_key,
816813
text_info.size,
@@ -819,30 +816,30 @@ impl Frame {
819816
text_info.glyphs);
820817
}
821818
SpecificDisplayItem::Rectangle(ref info) => {
822-
context.builder.add_solid_rectangle(&LayerRect::from_untyped(&item.rect),
819+
context.builder.add_solid_rectangle(&item.rect,
823820
&item.clip,
824821
&info.color,
825822
PrimitiveFlags::None);
826823
}
827824
SpecificDisplayItem::Gradient(ref info) => {
828-
context.builder.add_gradient(LayerRect::from_untyped(&item.rect),
825+
context.builder.add_gradient(item.rect,
829826
&item.clip,
830-
LayerPoint::from_untyped(&info.start_point),
831-
LayerPoint::from_untyped(&info.end_point),
827+
info.start_point,
828+
info.end_point,
832829
info.stops);
833830
}
834831
SpecificDisplayItem::BoxShadow(ref box_shadow_info) => {
835-
context.builder.add_box_shadow(&LayerRect::from_untyped(&box_shadow_info.box_bounds),
832+
context.builder.add_box_shadow(&box_shadow_info.box_bounds,
836833
&item.clip,
837-
&LayerPoint::from_untyped(&box_shadow_info.offset),
834+
&box_shadow_info.offset,
838835
&box_shadow_info.color,
839836
box_shadow_info.blur_radius,
840837
box_shadow_info.spread_radius,
841838
box_shadow_info.border_radius,
842839
box_shadow_info.clip_mode);
843840
}
844841
SpecificDisplayItem::Border(ref info) => {
845-
context.builder.add_border(LayerRect::from_untyped(&item.rect), &item.clip, info);
842+
context.builder.add_border(item.rect, &item.clip, info);
846843
}
847844
SpecificDisplayItem::PushStackingContext(ref info) => {
848845
self.flatten_stacking_context(traversal,
@@ -863,8 +860,8 @@ impl Frame {
863860
current_scroll_layer_id,
864861
layer_relative_transform,
865862
level,
866-
&LayerRect::from_untyped(&item.rect),
867-
&LayerSize::from_untyped(&info.content_size),
863+
&item.rect,
864+
&info.content_size,
868865
info.id);
869866
}
870867
SpecificDisplayItem::Iframe(ref info) => {

0 commit comments

Comments
 (0)