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/. */
8 extern crate webrender;
11 #[path = "common/boilerplate.rs"]
14 use crate::boilerplate::{Example, HandyDandyRectBuilder};
16 use webrender::ShaderPrecacheFlags;
17 use webrender::api::*;
18 use webrender::render_api::*;
19 use webrender::api::units::*;
24 boilerplate::main_wrapper(&mut app, None);
30 impl Example for App {
31 // Make this the only example to test all shaders for compile errors.
32 const PRECACHE_SHADER_FLAGS: ShaderPrecacheFlags = ShaderPrecacheFlags::FULL_COMPILE;
37 builder: &mut DisplayListBuilder,
38 txn: &mut Transaction,
40 pipeline_id: PipelineId,
41 _document_id: DocumentId,
43 let content_bounds = LayoutRect::from_size(LayoutSize::new(800.0, 600.0));
44 let root_space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);
45 let spatial_id = root_space_and_clip.spatial_id;
47 builder.push_simple_stacking_context(
50 PrimitiveFlags::IS_BACKFACE_VISIBLE,
53 let image_mask_key = api.generate_image_key();
56 ImageDescriptor::new(2, 2, ImageFormat::R8, ImageDescriptorFlags::IS_OPAQUE),
57 ImageData::new(vec![0, 80, 180, 255]),
60 let mask = ImageMask {
61 image: image_mask_key,
62 rect: (75, 75).by(100, 100),
65 let complex = ComplexClipRegion::new(
66 (50, 50).to(150, 150),
67 BorderRadius::uniform(20.0),
70 let mask_clip_id = builder.define_clip_image_mask(
76 let clip_id = builder.define_clip_rounded_rect(
78 spatial_id: root_space_and_clip.spatial_id,
79 clip_id: mask_clip_id,
85 &CommonItemProperties::new(
86 (100, 100).to(200, 200),
87 SpaceAndClipInfo { spatial_id, clip_id },
89 (100, 100).to(200, 200),
90 ColorF::new(0.0, 1.0, 0.0, 1.0),
94 &CommonItemProperties::new(
95 (250, 100).to(350, 200),
96 SpaceAndClipInfo { spatial_id, clip_id },
98 (250, 100).to(350, 200),
99 ColorF::new(0.0, 1.0, 0.0, 1.0),
101 let border_side = BorderSide {
102 color: ColorF::new(0.0, 0.0, 1.0, 1.0),
103 style: BorderStyle::Groove,
105 let border_widths = LayoutSideOffsets::new_all_same(10.0);
106 let border_details = BorderDetails::Normal(NormalBorder {
111 radius: BorderRadius::uniform(20.0),
115 let bounds = (100, 100).to(200, 200);
117 &CommonItemProperties::new(
119 SpaceAndClipInfo { spatial_id, clip_id },
128 let simple_box_bounds = (20, 200).by(50, 50);
129 let offset = vec2(10.0, 10.0);
130 let color = ColorF::new(1.0, 1.0, 1.0, 1.0);
131 let blur_radius = 0.0;
132 let spread_radius = 0.0;
133 let simple_border_radius = 8.0;
134 let box_shadow_type = BoxShadowClipMode::Inset;
136 builder.push_box_shadow(
137 &CommonItemProperties::new(content_bounds, root_space_and_clip),
143 BorderRadius::uniform(simple_border_radius),
148 builder.pop_stacking_context();