Skip to content

Commit 27be710

Browse files
committed
Block until the pipeline is ready, before rendering.
1 parent 42a25b4 commit 27be710

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

direct-composition/src/main.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ extern crate webrender;
88
extern crate winit;
99

1010
use direct_composition::DirectComposition;
11+
use std::sync::mpsc;
1112
use webrender::api;
1213
use winit::os::windows::WindowExt;
1314

1415
fn main() {
1516
let mut events_loop = winit::EventsLoop::new();
16-
let notifier = Box::new(Notifier { events_proxy: events_loop.create_proxy() });
17+
18+
let (tx, rx) = mpsc::channel();
19+
let notifier = Box::new(Notifier { events_proxy: events_loop.create_proxy(), tx });
1720

1821
let window = winit::WindowBuilder::new()
19-
.with_title("Hello, world!")
22+
.with_title("WebRender + ANGLE + DirectComposition")
2023
.with_dimensions(1024, 768)
2124
.build(&events_loop)
2225
.unwrap();
@@ -31,12 +34,8 @@ fn main() {
3134
Rectangle::new(&composition, &notifier, factor, size(300, 200), 0., 0.2, 0.4, 1.),
3235
Rectangle::new(&composition, &notifier, factor, size(400, 300), 0., 0.5, 0., 0.5),
3336
];
34-
rects[0].render(factor);
35-
rects[1].render(factor);
36-
37-
// FIXME: what shows up on screen for each visual seems to be one frame late?
38-
rects[0].render(factor);
39-
rects[1].render(factor);
37+
rects[0].render(factor, &rx);
38+
rects[1].render(factor, &rx);
4039

4140
rects[0].visual.set_offset_x(100.);
4241
rects[0].visual.set_offset_y(50.);
@@ -71,7 +70,7 @@ fn main() {
7170
let rect = &mut rects[clicks % 2];
7271
rect.color.g += 0.1;
7372
rect.color.g %= 1.;
74-
rect.render(factor)
73+
rect.render(factor, &rx)
7574
}
7675
_ => {}
7776
}
@@ -123,7 +122,7 @@ impl Rectangle {
123122
}
124123
}
125124

126-
fn render(&mut self, device_pixel_ratio: f32) {
125+
fn render(&mut self, device_pixel_ratio: f32, rx: &mpsc::Receiver<()>) {
127126
self.visual.make_current();
128127

129128
let pipeline_id = api::PipelineId(0, 0);
@@ -152,6 +151,7 @@ impl Rectangle {
152151
transaction.set_root_pipeline(pipeline_id);
153152
transaction.generate_frame();
154153
self.api.send_transaction(self.document_id, transaction);
154+
rx.recv().unwrap();
155155
let renderer = self.renderer.as_mut().unwrap();
156156
renderer.update();
157157
renderer.render(self.size).unwrap();
@@ -169,6 +169,7 @@ impl Drop for Rectangle {
169169
#[derive(Clone)]
170170
struct Notifier {
171171
events_proxy: winit::EventsLoopProxy,
172+
tx: mpsc::Sender<()>,
172173
}
173174

174175
impl api::RenderNotifier for Notifier {
@@ -177,6 +178,7 @@ impl api::RenderNotifier for Notifier {
177178
}
178179

179180
fn wake_up(&self) {
181+
self.tx.send(()).unwrap();
180182
let _ = self.events_proxy.wakeup();
181183
}
182184

0 commit comments

Comments
 (0)