Skip to content

Commit b5f63b3

Browse files
author
bors-servo
authored
Auto merge of #602 - nical:more-units-api, r=glennw
Use strongly typed geometry - Part 2 Use strongly typed geometry in the public API. This changeset adds the LayoutPixel unit which is basically an alias to LayerPixel. I think that it's best to keep the "Layer" terminology internal to webrender, and since the 1-1 correspondence between the api's layout pixels and internal layer pixels is somewhat coincidental, it will help to have separate names if things like async zoom introduce an actual difference between the two coordinate spaces (as it does in Gecko). Using an alias instead of a separate type comes from a mix of laziness (not having to cast from layout t layer pixels all over frame.rs) and the fact that currently layer and layout pixels are the same thing, but I'll add a separate unit if there is a preference for it. I did not introduce ParentLayoutPixel. I don't know the API well enough yet to be sure whether some geometry is passed in a stacking context's parent coordinate space, but if so we should consider introducing a special unit for it, if only for the sake of proper documentation. This PR is a lot easier to rebase than part 1 and is a breaking change to the public API, so it's fine to wait a bit if there are cross-crates changes that we want to coordinate before having to adapt servo to this (although it should be easy to do). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/602) <!-- Reviewable:end -->
2 parents 996f2ba + 28bc050 commit b5f63b3

22 files changed

+254
-260
lines changed

replay/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ 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::any::TypeId;
1413
use std::mem;
1514
use std::io::Read;
1615
use std::fs::File;
1716
use std::path::{Path, PathBuf};
1817
use std::env;
19-
use webrender_traits::{ApiMsg, RenderApi, PipelineId};
18+
use webrender_traits::{ApiMsg, RenderApi, PipelineId, LayerSize, DeviceUintSize};
2019
use webrender_traits::channel::PayloadHelperMethods;
2120
use glutin::{Event, ElementState, VirtualKeyCode as Key};
2221

@@ -40,7 +39,7 @@ impl webrender_traits::RenderNotifier for Notifier {
4039

4140
fn pipeline_size_changed(&mut self,
4241
_pid: PipelineId,
43-
_size: Option<Size2D<f32>>) {
42+
_size: Option<LayerSize>) {
4443
}
4544

4645
fn new_scroll_frame_ready(&mut self, _composite_needed: bool) {
@@ -145,7 +144,7 @@ fn main() {
145144
println!("Rendering frame {}.", frame_num);
146145
gl::clear(gl::COLOR_BUFFER_BIT);
147146
renderer.update();
148-
renderer.render(Size2D::new(width, height));
147+
renderer.render(DeviceUintSize::new(width, height));
149148
window.swap_buffers().unwrap();
150149
}
151150
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

0 commit comments

Comments
 (0)