Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move code to the new transaction API. #2298

Merged
merged 3 commits into from Jan 18, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -92,9 +92,9 @@ impl Example for App {
let new_transform = self.transform
.pre_rotate(0.0, 0.0, 1.0, Angle::radians(angle))
.post_translate(LayoutVector3D::new(offset_x, offset_y, 0.0));
api.generate_frame(
document_id,
Some(DynamicProperties {
let mut txn = Transaction::new();
txn.update_dynamic_properties(
DynamicProperties {
transforms: vec![
PropertyValue {
key: self.property_key,
@@ -107,8 +107,10 @@ impl Example for App {
value: self.opacity,
}
],
}),
},
);
txn.generate_frame();
api.send_transaction(document_id, txn);
self.transform = new_transform;
}
_ => (),
@@ -355,21 +355,25 @@ impl Example for App {
}

fn on_event(&mut self, event: glutin::Event, api: &RenderApi, document_id: DocumentId) -> bool {
let mut txn = Transaction::new();
match event {
glutin::Event::Touch(touch) => match self.touch_state.handle_event(touch) {
TouchResult::Pan(pan) => {
api.set_pan(document_id, pan);
api.generate_frame(document_id, None);
txn.set_pan(pan);
}
TouchResult::Zoom(zoom) => {
api.set_pinch_zoom(document_id, ZoomFactor::new(zoom));
api.generate_frame(document_id, None);
txn.set_pinch_zoom(ZoomFactor::new(zoom));
}
TouchResult::None => {}
},
_ => (),
}

if !txn.is_empty() {
txn.generate_frame();
api.send_transaction(document_id, txn);
}

false
}
}
@@ -177,24 +177,26 @@ pub fn main_wrapper<E: Example>(
pipeline_id,
document_id,
);
api.set_display_list(
document_id,
let mut txn = Transaction::new();
txn.set_display_list(
epoch,
None,
layout_size,
builder.finalize(),
true,
resources,
);
api.set_root_pipeline(document_id, pipeline_id);
api.generate_frame(document_id, None);
txn.update_resources(resources);
txn.set_root_pipeline(pipeline_id);
txn.generate_frame();
api.send_transaction(document_id, txn);

println!("Entering event loop");
'outer: for event in window.wait_events() {
let mut events = Vec::new();
events.push(event);
events.extend(window.poll_events());

let mut txn = Transaction::new();
for event in events {
match event {
glutin::Event::Closed |
@@ -248,8 +250,7 @@ pub fn main_wrapper<E: Example>(
_,
Some(glutin::VirtualKeyCode::Key1),
) => {
api.set_window_parameters(
document_id,
txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
1.0
@@ -260,8 +261,7 @@ pub fn main_wrapper<E: Example>(
_,
Some(glutin::VirtualKeyCode::Key2),
) => {
api.set_window_parameters(
document_id,
txn.set_window_parameters(
framebuffer_size,
DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size),
2.0
@@ -298,19 +298,19 @@ pub fn main_wrapper<E: Example>(
pipeline_id,
document_id,
);
api.set_display_list(
document_id,
txn.set_display_list(
epoch,
None,
layout_size,
builder.finalize(),
true,
resources,
);
api.generate_frame(document_id, None);
txn.update_resources(resources);
txn.generate_frame();
}
}
}
api.send_transaction(document_id, txn);

renderer.update();
renderer.render(framebuffer_size).unwrap();
@@ -67,12 +67,10 @@ impl App {
let bounds = DeviceUintRect::new(offset, size);

let document_id = api.add_document(size, layer);
api.set_window_parameters(document_id,
framebuffer_size,
bounds,
1.0
);
api.set_root_pipeline(document_id, pipeline_id);
let mut txn = Transaction::new();
txn.set_window_parameters(framebuffer_size, bounds, 1.0);
txn.set_root_pipeline(pipeline_id);
api.send_transaction(document_id, txn);

self.documents.push(Document {
id: document_id,
@@ -127,17 +125,16 @@ impl Example for App {
);
builder.pop_stacking_context();

api.set_display_list(
doc.id,
let mut txn = Transaction::new();
txn.set_display_list(
Epoch(0),
None,
doc.content_rect.size,
builder.finalize(),
true,
ResourceUpdates::new(),
);

api.generate_frame(doc.id, None);
txn.generate_frame();
api.send_transaction(doc.id, txn);
}
}
}
@@ -88,8 +88,6 @@ impl App {
let bounds = DeviceUintRect::new(DeviceUintPoint::zero(), framebuffer_size);
let document_id = api.add_document(framebuffer_size, layer);

api.set_root_pipeline(document_id, pipeline_id);

let document = Document {
id: document_id,
pipeline_id,
@@ -116,18 +114,19 @@ impl App {
builder.push_rect(&info, ColorF::new(1.0, 1.0, 0.0, 1.0));
builder.pop_stacking_context();

api.enable_frame_output(document.id, document.pipeline_id, true);
api.set_display_list(
document.id,
let mut txn = Transaction::new();
txn.set_root_pipeline(pipeline_id);
txn.enable_frame_output(document.pipeline_id, true);
txn.update_resources(resources);
txn.set_display_list(
Epoch(0),
Some(document.color),
document.content_rect.size,
builder.finalize(),
true,
resources,
);

api.generate_frame(document.id, None);
txn.generate_frame();
api.send_transaction(document.id, txn);
self.output_document = Some(document);
}
}
@@ -50,15 +50,15 @@ impl Example for App {
sub_builder.push_rect(&info, ColorF::new(0.0, 1.0, 0.0, 1.0));
sub_builder.pop_stacking_context();

api.set_display_list(
document_id,
let mut txn = Transaction::new();
txn.set_display_list(
Epoch(0),
None,
sub_bounds.size,
sub_builder.finalize(),
true,
ResourceUpdates::new(),
);
api.send_transaction(document_id, txn);

// And this is for the root pipeline
builder.push_stacking_context(
@@ -100,8 +100,10 @@ impl Example for App {
ImageData::new(image_data),
None,
);
api.update_resources(updates);
api.generate_frame(document_id, None);
let mut txn = Transaction::new();
txn.update_resources(updates);
txn.generate_frame();
api.send_transaction(document_id, txn);
}
_ => {}
}
@@ -137,6 +137,7 @@ impl Example for App {
}

fn on_event(&mut self, event: glutin::Event, api: &RenderApi, document_id: DocumentId) -> bool {
let mut txn = Transaction::new();
match event {
glutin::Event::KeyboardInput(glutin::ElementState::Pressed, _, Some(key)) => {
let offset = match key {
@@ -147,8 +148,7 @@ impl Example for App {
_ => return false,
};

api.scroll(
document_id,
txn.scroll(
ScrollLocation::Delta(LayoutVector2D::new(offset.0, offset.1)),
self.cursor_position,
ScrollEventPhase::Start,
@@ -168,8 +168,7 @@ impl Example for App {
glutin::MouseScrollDelta::PixelDelta(dx, dy) => (dx, dy),
};

api.scroll(
document_id,
txn.scroll(
ScrollLocation::Delta(LayoutVector2D::new(dx, dy)),
self.cursor_position,
ScrollEventPhase::Start,
@@ -178,6 +177,8 @@ impl Example for App {
_ => (),
}

api.send_transaction(document_id, txn);

false
}
}
@@ -241,21 +241,25 @@ impl Example for App {
}

fn on_event(&mut self, event: glutin::Event, api: &RenderApi, document_id: DocumentId) -> bool {
let mut txn = Transaction::new();
match event {
glutin::Event::Touch(touch) => match self.touch_state.handle_event(touch) {
TouchResult::Pan(pan) => {
api.set_pan(document_id, pan);
api.generate_frame(document_id, None);
txn.set_pan(pan);
}
TouchResult::Zoom(zoom) => {
api.set_pinch_zoom(document_id, ZoomFactor::new(zoom));
api.generate_frame(document_id, None);
txn.set_pinch_zoom(ZoomFactor::new(zoom));
}
TouchResult::None => {}
},
_ => (),
}

if !txn.is_empty() {
txn.generate_frame();
api.send_transaction(document_id, txn);
}

false
}
}
@@ -298,14 +298,7 @@ impl RenderBackend {
content_size,
list_descriptor,
preserve_frame_state,
resources,
} => {
// TODO: this will be removed from the SetDisplayList message soon.
self.resource_cache.update_resources(
resources,
&mut profile_counters.resources
);

profile_scope!("SetDisplayList");

let mut data;
@@ -379,17 +372,6 @@ impl RenderBackend {
doc.frame_ctx.update_epoch(pipeline_id, epoch);
DocumentOps::nop()
}
DocumentMsg::UpdatePipelineResources { resources, pipeline_id, epoch } => {
profile_scope!("UpdateResources");

self.resource_cache
.update_resources(resources, &mut profile_counters.resources);

doc.scene.update_epoch(pipeline_id, epoch);
doc.frame_ctx.update_epoch(pipeline_id, epoch);

DocumentOps::nop()
}
DocumentMsg::SetRootPipeline(pipeline_id) => {
profile_scope!("SetRootPipeline");

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.