Skip to content

Commit d33e637

Browse files
kvarkwrupdater
authored and
wrupdater
committed
Bug 1531217 - Document origin rewrite and framebuffer coordinates r=gw,nical
The goal of this change was to simplify the semantics of our document placement and split the logical elements inside (display list) from the actual screen rectangle occupied by a document. To achieve that, we introduce the framebuffer space for things Y-flipped on screen. We fix the frame outputs, so that they get produced on the first frame without loopback from the frame building to scene building. Differential Revision: https://phabricator.services.mozilla.com/D21641 [wrupdater] From https://hg.mozilla.org/mozilla-central/rev/ee88f4e35d4fd18ee954609185445c3fd7e1cecd
1 parent 068d6b0 commit d33e637

29 files changed

+502
-443
lines changed

direct-composition/src/main_windows.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern crate gleam;
88
extern crate webrender;
99
extern crate winit;
1010

11+
use euclid::size2;
1112
use direct_composition::DirectComposition;
1213
use std::sync::mpsc;
1314
use webrender::api;
@@ -34,10 +35,9 @@ fn main() {
3435

3536
let mut clicks: usize = 0;
3637
let mut offset_y = 100.;
37-
let size = api::DeviceIntSize::new;
3838
let mut rects = [
39-
Rectangle::new(&composition, &notifier, factor, size(300, 200), 0., 0.2, 0.4, 1.),
40-
Rectangle::new(&composition, &notifier, factor, size(400, 300), 0., 0.5, 0., 0.5),
39+
Rectangle::new(&composition, &notifier, factor, size2(300, 200), 0., 0.2, 0.4, 1.),
40+
Rectangle::new(&composition, &notifier, factor, size2(400, 300), 0., 0.5, 0., 0.5),
4141
];
4242
rects[0].render(factor, &rx);
4343
rects[1].render(factor, &rx);
@@ -95,13 +95,13 @@ struct Rectangle {
9595
renderer: Option<webrender::Renderer>,
9696
api: api::RenderApi,
9797
document_id: api::DocumentId,
98-
size: api::DeviceIntSize,
98+
size: api::FramebufferIntSize,
9999
color: api::ColorF,
100100
}
101101

102102
impl Rectangle {
103103
fn new(composition: &DirectComposition, notifier: &Box<Notifier>,
104-
device_pixel_ratio: f32, size: api::DeviceIntSize, r: f32, g: f32, b: f32, a: f32)
104+
device_pixel_ratio: f32, size: api::FramebufferIntSize, r: f32, g: f32, b: f32, a: f32)
105105
-> Self {
106106
let visual = composition.create_angle_visual(size.width as u32, size.height as u32);
107107
visual.make_current();

examples/alpha_perf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Example for App {
2525
_api: &RenderApi,
2626
builder: &mut DisplayListBuilder,
2727
_txn: &mut Transaction,
28-
_framebuffer_size: DeviceIntSize,
28+
_framebuffer_size: FramebufferIntSize,
2929
pipeline_id: PipelineId,
3030
_document_id: DocumentId,
3131
) {

examples/animation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Example for App {
106106
_api: &RenderApi,
107107
builder: &mut DisplayListBuilder,
108108
_txn: &mut Transaction,
109-
_framebuffer_size: DeviceIntSize,
109+
_framebuffer_size: FramebufferIntSize,
110110
pipeline_id: PipelineId,
111111
_document_id: DocumentId,
112112
) {

examples/basic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl Example for App {
185185
api: &RenderApi,
186186
builder: &mut DisplayListBuilder,
187187
txn: &mut Transaction,
188-
_: DeviceIntSize,
188+
_: FramebufferIntSize,
189189
pipeline_id: PipelineId,
190190
_document_id: DocumentId,
191191
) {

examples/blob.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl Example for App {
199199
api: &RenderApi,
200200
builder: &mut DisplayListBuilder,
201201
txn: &mut Transaction,
202-
_framebuffer_size: api::DeviceIntSize,
202+
_framebuffer_size: api::FramebufferIntSize,
203203
pipeline_id: PipelineId,
204204
_document_id: DocumentId,
205205
) {

examples/common/boilerplate.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub trait Example {
7979
api: &RenderApi,
8080
builder: &mut DisplayListBuilder,
8181
txn: &mut Transaction,
82-
framebuffer_size: DeviceIntSize,
82+
framebuffer_size: FramebufferIntSize,
8383
pipeline_id: PipelineId,
8484
document_id: DocumentId,
8585
);
@@ -164,7 +164,7 @@ pub fn main_wrapper<E: Example>(
164164
.get_inner_size()
165165
.unwrap()
166166
.to_physical(device_pixel_ratio as f64);
167-
DeviceIntSize::new(size.width as i32, size.height as i32)
167+
FramebufferIntSize::new(size.width as i32, size.height as i32)
168168
};
169169
let notifier = Box::new(Notifier::new(events_loop.create_proxy()));
170170
let (mut renderer, sender) = webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
@@ -212,18 +212,19 @@ pub fn main_wrapper<E: Example>(
212212
let mut custom_event = true;
213213

214214
let old_flags = debug_flags;
215-
match global_event {
216-
winit::Event::WindowEvent {
217-
event: winit::WindowEvent::CloseRequested,
218-
..
219-
} => return winit::ControlFlow::Break,
220-
winit::Event::WindowEvent {
221-
event: winit::WindowEvent::KeyboardInput {
222-
input: winit::KeyboardInput {
223-
state: winit::ElementState::Pressed,
224-
virtual_keycode: Some(key),
225-
..
226-
},
215+
let win_event = match global_event {
216+
winit::Event::WindowEvent { event, .. } => event,
217+
_ => return winit::ControlFlow::Continue,
218+
};
219+
match win_event {
220+
winit::WindowEvent::CloseRequested => return winit::ControlFlow::Break,
221+
// skip high-frequency events
222+
winit::WindowEvent::AxisMotion { .. } |
223+
winit::WindowEvent::CursorMoved { .. } => return winit::ControlFlow::Continue,
224+
winit::WindowEvent::KeyboardInput {
225+
input: winit::KeyboardInput {
226+
state: winit::ElementState::Pressed,
227+
virtual_keycode: Some(key),
227228
..
228229
},
229230
..
@@ -241,14 +242,12 @@ pub fn main_wrapper<E: Example>(
241242
DebugFlags::NEW_FRAME_INDICATOR | DebugFlags::NEW_SCENE_INDICATOR
242243
),
243244
winit::VirtualKeyCode::G => debug_flags.toggle(DebugFlags::GPU_CACHE_DBG),
244-
winit::VirtualKeyCode::Key1 => txn.set_window_parameters(
245-
framebuffer_size,
246-
DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
245+
winit::VirtualKeyCode::Key1 => txn.set_document_view(
246+
framebuffer_size.into(),
247247
1.0
248248
),
249-
winit::VirtualKeyCode::Key2 => txn.set_window_parameters(
250-
framebuffer_size,
251-
DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size),
249+
winit::VirtualKeyCode::Key2 => txn.set_document_view(
250+
framebuffer_size.into(),
252251
2.0
253252
),
254253
winit::VirtualKeyCode::M => api.notify_memory_pressure(),
@@ -260,23 +259,18 @@ pub fn main_wrapper<E: Example>(
260259
api.save_capture(path, bits);
261260
},
262261
_ => {
263-
let win_event = match global_event {
264-
winit::Event::WindowEvent { event, .. } => event,
265-
_ => unreachable!()
266-
};
267262
custom_event = example.on_event(
268263
win_event,
269264
&api,
270265
document_id,
271266
)
272267
},
273268
},
274-
winit::Event::WindowEvent { event, .. } => custom_event = example.on_event(
275-
event,
269+
other => custom_event = example.on_event(
270+
other,
276271
&api,
277272
document_id,
278273
),
279-
_ => return winit::ControlFlow::Continue,
280274
};
281275

282276
if debug_flags != old_flags {

examples/document.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,52 @@ impl App {
3333
fn init(
3434
&mut self,
3535
api: &RenderApi,
36-
framebuffer_size: DeviceIntSize,
3736
device_pixel_ratio: f32,
3837
) {
3938
let init_data = vec![
4039
(
4140
PipelineId(1, 0),
42-
-1,
41+
1,
4342
ColorF::new(0.0, 1.0, 0.0, 1.0),
44-
DeviceIntPoint::new(0, 0),
43+
FramebufferIntPoint::new(0, 400),
4544
),
4645
(
4746
PipelineId(2, 0),
48-
-2,
47+
2,
4948
ColorF::new(1.0, 1.0, 0.0, 1.0),
50-
DeviceIntPoint::new(200, 0),
49+
FramebufferIntPoint::new(200, 400),
5150
),
5251
(
5352
PipelineId(3, 0),
54-
-3,
53+
3,
5554
ColorF::new(1.0, 0.0, 0.0, 1.0),
56-
DeviceIntPoint::new(200, 200),
55+
FramebufferIntPoint::new(200, 600),
5756
),
5857
(
5958
PipelineId(4, 0),
60-
-4,
59+
4,
6160
ColorF::new(1.0, 0.0, 1.0, 1.0),
62-
DeviceIntPoint::new(0, 200),
61+
FramebufferIntPoint::new(0, 600),
6362
),
6463
];
6564

6665
for (pipeline_id, layer, color, offset) in init_data {
67-
let size = DeviceIntSize::new(250, 250);
68-
let bounds = DeviceIntRect::new(offset, size);
66+
let size = FramebufferIntSize::new(250, 250);
67+
let bounds = FramebufferIntRect::new(offset, size);
6968

7069
let document_id = api.add_document(size, layer);
7170
let mut txn = Transaction::new();
72-
txn.set_window_parameters(framebuffer_size, bounds, device_pixel_ratio);
71+
txn.set_document_view(bounds, device_pixel_ratio);
7372
txn.set_root_pipeline(pipeline_id);
7473
api.send_transaction(document_id, txn);
7574

7675
self.documents.push(Document {
7776
id: document_id,
7877
pipeline_id,
79-
content_rect: bounds.to_f32() / TypedScale::new(device_pixel_ratio),
78+
content_rect: LayoutRect::new(
79+
LayoutPoint::origin(),
80+
bounds.size.to_f32() / TypedScale::new(device_pixel_ratio),
81+
),
8082
color,
8183
});
8284
}
@@ -89,7 +91,7 @@ impl Example for App {
8991
api: &RenderApi,
9092
base_builder: &mut DisplayListBuilder,
9193
_txn: &mut Transaction,
92-
framebuffer_size: DeviceIntSize,
94+
framebuffer_size: FramebufferIntSize,
9395
_pipeline_id: PipelineId,
9496
_: DocumentId,
9597
) {
@@ -98,7 +100,7 @@ impl Example for App {
98100
base_builder.content_size().width;
99101
// this is the first run, hack around the boilerplate,
100102
// which assumes an example only needs one document
101-
self.init(api, framebuffer_size, device_pixel_ratio);
103+
self.init(api, device_pixel_ratio);
102104
}
103105

104106
for doc in &self.documents {

examples/frame_output.rs

+18-13
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ struct ExternalHandler {
4242
}
4343

4444
impl webrender::OutputImageHandler for OutputHandler {
45-
fn lock(&mut self, _id: PipelineId) -> Option<(u32, DeviceIntSize)> {
46-
Some((self.texture_id, DeviceIntSize::new(500, 500)))
45+
fn lock(&mut self, _id: PipelineId) -> Option<(u32, FramebufferIntSize)> {
46+
Some((self.texture_id, FramebufferIntSize::new(500, 500)))
4747
}
4848

4949
fn unlock(&mut self, _id: PipelineId) {}
@@ -68,7 +68,7 @@ impl App {
6868
fn init_output_document(
6969
&mut self,
7070
api: &RenderApi,
71-
framebuffer_size: DeviceIntSize,
71+
framebuffer_size: FramebufferIntSize,
7272
device_pixel_ratio: f32,
7373
) {
7474
// Generate the external image key that will be used to render the output document to the root document.
@@ -77,24 +77,29 @@ impl App {
7777
let pipeline_id = PipelineId(1, 0);
7878
let layer = 1;
7979
let color = ColorF::new(1., 1., 0., 1.);
80-
let bounds = DeviceIntRect::new(DeviceIntPoint::zero(), framebuffer_size);
8180
let document_id = api.add_document(framebuffer_size, layer);
81+
api.enable_frame_output(document_id, pipeline_id, true);
82+
api.set_document_view(
83+
document_id,
84+
FramebufferIntRect::new(
85+
FramebufferIntPoint::new(0, 1000),
86+
framebuffer_size,
87+
),
88+
device_pixel_ratio,
89+
);
8290

8391
let document = Document {
8492
id: document_id,
8593
pipeline_id,
86-
content_rect: bounds.to_f32() / TypedScale::new(device_pixel_ratio),
94+
content_rect: LayoutRect::new(
95+
LayoutPoint::zero(),
96+
framebuffer_size.to_f32() / TypedScale::new(device_pixel_ratio),
97+
),
8798
color,
8899
};
89100

90101
let mut txn = Transaction::new();
91102

92-
txn.enable_frame_output(document.pipeline_id, true);
93-
94-
api.send_transaction(document.id, txn);
95-
96-
let mut txn = Transaction::new();
97-
98103
txn.add_image(
99104
self.external_image_key.unwrap(),
100105
ImageDescriptor::new(100, 100, ImageFormat::BGRA8, true, false),
@@ -141,14 +146,14 @@ impl Example for App {
141146
api: &RenderApi,
142147
builder: &mut DisplayListBuilder,
143148
_txn: &mut Transaction,
144-
framebuffer_size: DeviceIntSize,
149+
framebuffer_size: FramebufferIntSize,
145150
pipeline_id: PipelineId,
146151
_document_id: DocumentId,
147152
) {
148153
if self.output_document.is_none() {
149154
let device_pixel_ratio = framebuffer_size.width as f32 /
150155
builder.content_size().width;
151-
self.init_output_document(api, DeviceIntSize::new(200, 200), device_pixel_ratio);
156+
self.init_output_document(api, FramebufferIntSize::new(200, 200), device_pixel_ratio);
152157
}
153158

154159
let info = LayoutPrimitiveInfo::new((100, 100).to(200, 200));

examples/iframe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Example for App {
2525
api: &RenderApi,
2626
builder: &mut DisplayListBuilder,
2727
_txn: &mut Transaction,
28-
_framebuffer_size: DeviceIntSize,
28+
_framebuffer_size: FramebufferIntSize,
2929
pipeline_id: PipelineId,
3030
document_id: DocumentId,
3131
) {

examples/image_resize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl Example for App {
2525
_api: &RenderApi,
2626
builder: &mut DisplayListBuilder,
2727
txn: &mut Transaction,
28-
_framebuffer_size: DeviceIntSize,
28+
_framebuffer_size: FramebufferIntSize,
2929
pipeline_id: PipelineId,
3030
_document_id: DocumentId,
3131
) {

examples/multiwindow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl Window {
103103
.get_inner_size()
104104
.unwrap()
105105
.to_physical(device_pixel_ratio as f64);
106-
DeviceIntSize::new(size.width as i32, size.height as i32)
106+
FramebufferIntSize::new(size.width as i32, size.height as i32)
107107
};
108108
let notifier = Box::new(Notifier::new(events_loop.create_proxy()));
109109
let (renderer, sender) = webrender::Renderer::new(gl.clone(), notifier, opts, None).unwrap();
@@ -182,7 +182,7 @@ impl Window {
182182
.get_inner_size()
183183
.unwrap()
184184
.to_physical(device_pixel_ratio as f64);
185-
DeviceIntSize::new(size.width as i32, size.height as i32)
185+
FramebufferIntSize::new(size.width as i32, size.height as i32)
186186
};
187187
let layout_size = framebuffer_size.to_f32() / euclid::TypedScale::new(device_pixel_ratio);
188188
let mut txn = Transaction::new();

examples/scrolling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Example for App {
2626
_api: &RenderApi,
2727
builder: &mut DisplayListBuilder,
2828
_txn: &mut Transaction,
29-
_framebuffer_size: DeviceIntSize,
29+
_framebuffer_size: FramebufferIntSize,
3030
pipeline_id: PipelineId,
3131
_document_id: DocumentId,
3232
) {

examples/texture_cache_stress.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Example for App {
9090
api: &RenderApi,
9191
builder: &mut DisplayListBuilder,
9292
txn: &mut Transaction,
93-
_framebuffer_size: DeviceIntSize,
93+
_framebuffer_size: FramebufferIntSize,
9494
pipeline_id: PipelineId,
9595
_document_id: DocumentId,
9696
) {

examples/yuv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Example for App {
8787
api: &RenderApi,
8888
builder: &mut DisplayListBuilder,
8989
txn: &mut Transaction,
90-
_framebuffer_size: DeviceIntSize,
90+
_framebuffer_size: FramebufferIntSize,
9191
pipeline_id: PipelineId,
9292
_document_id: DocumentId,
9393
) {

0 commit comments

Comments
 (0)