diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/wr/examples/iframe.rs | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/wr/examples/iframe.rs')
-rw-r--r-- | gfx/wr/examples/iframe.rs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/gfx/wr/examples/iframe.rs b/gfx/wr/examples/iframe.rs new file mode 100644 index 0000000000..9bd785fbda --- /dev/null +++ b/gfx/wr/examples/iframe.rs @@ -0,0 +1,96 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +extern crate gleam; +extern crate glutin; +extern crate webrender; +extern crate winit; + +#[path = "common/boilerplate.rs"] +mod boilerplate; + +use crate::boilerplate::{Example, HandyDandyRectBuilder}; +use webrender::api::*; +use webrender::render_api::*; +use webrender::api::units::*; + +// This example uses the push_iframe API to nest a second pipeline's displaylist +// inside the root pipeline's display list. When it works, a green square is +// shown. If it fails, a red square is shown. + +struct App {} + +impl Example for App { + fn render( + &mut self, + api: &mut RenderApi, + builder: &mut DisplayListBuilder, + _txn: &mut Transaction, + _device_size: DeviceIntSize, + pipeline_id: PipelineId, + document_id: DocumentId, + ) { + // All the sub_* things are for the nested pipeline + let sub_size = DeviceIntSize::new(100, 100); + let sub_bounds = (0, 0).to(sub_size.width as i32, sub_size.height as i32); + + let sub_pipeline_id = PipelineId(pipeline_id.0, 42); + let mut sub_builder = DisplayListBuilder::new(sub_pipeline_id); + let mut space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id); + + sub_builder.push_simple_stacking_context( + sub_bounds.origin, + space_and_clip.spatial_id, + PrimitiveFlags::IS_BACKFACE_VISIBLE, + ); + + // green rect visible == success + sub_builder.push_rect( + &CommonItemProperties::new(sub_bounds, space_and_clip), + sub_bounds, + ColorF::new(0.0, 1.0, 0.0, 1.0) + ); + sub_builder.pop_stacking_context(); + + let mut txn = Transaction::new(); + txn.set_display_list( + Epoch(0), + None, + sub_bounds.size, + sub_builder.finalize(), + true, + ); + api.send_transaction(document_id, txn); + + space_and_clip.spatial_id = builder.push_reference_frame( + sub_bounds.origin, + space_and_clip.spatial_id, + TransformStyle::Flat, + PropertyBinding::Binding(PropertyBindingKey::new(42), LayoutTransform::identity()), + ReferenceFrameKind::Transform, + ); + + // And this is for the root pipeline + builder.push_simple_stacking_context( + sub_bounds.origin, + space_and_clip.spatial_id, + PrimitiveFlags::IS_BACKFACE_VISIBLE, + ); + + // red rect under the iframe: if this is visible, things have gone wrong + builder.push_rect( + &CommonItemProperties::new(sub_bounds, space_and_clip), + sub_bounds, + ColorF::new(1.0, 0.0, 0.0, 1.0) + ); + builder.push_iframe(sub_bounds, sub_bounds, &space_and_clip, sub_pipeline_id, false); + builder.pop_stacking_context(); + builder.pop_reference_frame(); + } +} + +fn main() { + let mut app = App {}; + boilerplate::main_wrapper(&mut app, None); +} |