iframe.rs (3293B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 extern crate gleam; 6 extern crate glutin; 7 extern crate webrender; 8 extern crate winit; 9 10 #[path = "common/boilerplate.rs"] 11 mod boilerplate; 12 13 use crate::boilerplate::{Example, HandyDandyRectBuilder}; 14 use webrender::api::*; 15 use webrender::render_api::*; 16 use webrender::api::units::*; 17 18 // This example uses the push_iframe API to nest a second pipeline's displaylist 19 // inside the root pipeline's display list. When it works, a green square is 20 // shown. If it fails, a red square is shown. 21 22 struct App {} 23 24 impl Example for App { 25 fn render( 26 &mut self, 27 api: &mut RenderApi, 28 builder: &mut DisplayListBuilder, 29 _txn: &mut Transaction, 30 _device_size: DeviceIntSize, 31 pipeline_id: PipelineId, 32 document_id: DocumentId, 33 ) { 34 // All the sub_* things are for the nested pipeline 35 let sub_size = DeviceIntSize::new(100, 100); 36 let sub_bounds = (0, 0).to(sub_size.width as i32, sub_size.height as i32); 37 38 let sub_pipeline_id = PipelineId(pipeline_id.0, 42); 39 let mut sub_builder = DisplayListBuilder::new(sub_pipeline_id); 40 let mut space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id); 41 sub_builder.begin(); 42 43 sub_builder.push_simple_stacking_context( 44 sub_bounds.min, 45 space_and_clip.spatial_id, 46 PrimitiveFlags::IS_BACKFACE_VISIBLE, 47 ); 48 49 // green rect visible == success 50 sub_builder.push_rect( 51 &CommonItemProperties::new(sub_bounds, space_and_clip), 52 sub_bounds, 53 ColorF::new(0.0, 1.0, 0.0, 1.0) 54 ); 55 sub_builder.pop_stacking_context(); 56 57 let mut txn = Transaction::new(); 58 txn.set_display_list( 59 Epoch(0), 60 sub_builder.end(), 61 ); 62 api.send_transaction(document_id, txn); 63 64 space_and_clip.spatial_id = builder.push_reference_frame( 65 sub_bounds.min, 66 space_and_clip.spatial_id, 67 TransformStyle::Flat, 68 PropertyBinding::Binding(PropertyBindingKey::new(42), LayoutTransform::identity()), 69 ReferenceFrameKind::Transform { 70 is_2d_scale_translation: false, 71 should_snap: false, 72 paired_with_perspective: false, 73 }, 74 SpatialTreeItemKey::new(0, 0), 75 ); 76 77 // And this is for the root pipeline 78 builder.push_simple_stacking_context( 79 sub_bounds.min, 80 space_and_clip.spatial_id, 81 PrimitiveFlags::IS_BACKFACE_VISIBLE, 82 ); 83 84 // red rect under the iframe: if this is visible, things have gone wrong 85 builder.push_rect( 86 &CommonItemProperties::new(sub_bounds, space_and_clip), 87 sub_bounds, 88 ColorF::new(1.0, 0.0, 0.0, 1.0) 89 ); 90 builder.push_iframe(sub_bounds, sub_bounds, &space_and_clip, sub_pipeline_id, false); 91 builder.pop_stacking_context(); 92 builder.pop_reference_frame(); 93 } 94 } 95 96 fn main() { 97 let mut app = App {}; 98 boilerplate::main_wrapper(&mut app, None); 99 }