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 euclid;
6 extern crate gleam;
7 extern crate glutin;
8 extern crate webrender;
9 extern crate winit;
10
11 #[path = "common/boilerplate.rs"]
12 mod boilerplate;
13
14 use crate::boilerplate::{Example, HandyDandyRectBuilder};
15 use euclid::vec2;
16 use webrender::ShaderPrecacheFlags;
17 use webrender::api::*;
18 use webrender::render_api::*;
19 use webrender::api::units::*;
20
main()21 fn main() {
22 let mut app = App {
23 };
24 boilerplate::main_wrapper(&mut app, None);
25 }
26
27 struct App {
28 }
29
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;
33
render( &mut self, api: &mut RenderApi, builder: &mut DisplayListBuilder, txn: &mut Transaction, _: DeviceIntSize, pipeline_id: PipelineId, _document_id: DocumentId, )34 fn render(
35 &mut self,
36 api: &mut RenderApi,
37 builder: &mut DisplayListBuilder,
38 txn: &mut Transaction,
39 _: DeviceIntSize,
40 pipeline_id: PipelineId,
41 _document_id: DocumentId,
42 ) {
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;
46
47 builder.push_simple_stacking_context(
48 content_bounds.min,
49 spatial_id,
50 PrimitiveFlags::IS_BACKFACE_VISIBLE,
51 );
52
53 let image_mask_key = api.generate_image_key();
54 txn.add_image(
55 image_mask_key,
56 ImageDescriptor::new(2, 2, ImageFormat::R8, ImageDescriptorFlags::IS_OPAQUE),
57 ImageData::new(vec![0, 80, 180, 255]),
58 None,
59 );
60 let mask = ImageMask {
61 image: image_mask_key,
62 rect: (75, 75).by(100, 100),
63 repeat: false,
64 };
65 let complex = ComplexClipRegion::new(
66 (50, 50).to(150, 150),
67 BorderRadius::uniform(20.0),
68 ClipMode::Clip
69 );
70 let mask_clip_id = builder.define_clip_image_mask(
71 &root_space_and_clip,
72 mask,
73 &vec![],
74 FillRule::Nonzero,
75 );
76 let clip_id = builder.define_clip_rounded_rect(
77 &SpaceAndClipInfo {
78 spatial_id: root_space_and_clip.spatial_id,
79 clip_id: mask_clip_id,
80 },
81 complex,
82 );
83
84 builder.push_rect(
85 &CommonItemProperties::new(
86 (100, 100).to(200, 200),
87 SpaceAndClipInfo { spatial_id, clip_id },
88 ),
89 (100, 100).to(200, 200),
90 ColorF::new(0.0, 1.0, 0.0, 1.0),
91 );
92
93 builder.push_rect(
94 &CommonItemProperties::new(
95 (250, 100).to(350, 200),
96 SpaceAndClipInfo { spatial_id, clip_id },
97 ),
98 (250, 100).to(350, 200),
99 ColorF::new(0.0, 1.0, 0.0, 1.0),
100 );
101 let border_side = BorderSide {
102 color: ColorF::new(0.0, 0.0, 1.0, 1.0),
103 style: BorderStyle::Groove,
104 };
105 let border_widths = LayoutSideOffsets::new_all_same(10.0);
106 let border_details = BorderDetails::Normal(NormalBorder {
107 top: border_side,
108 right: border_side,
109 bottom: border_side,
110 left: border_side,
111 radius: BorderRadius::uniform(20.0),
112 do_aa: true,
113 });
114
115 let bounds = (100, 100).to(200, 200);
116 builder.push_border(
117 &CommonItemProperties::new(
118 bounds,
119 SpaceAndClipInfo { spatial_id, clip_id },
120 ),
121 bounds,
122 border_widths,
123 border_details,
124 );
125
126 if false {
127 // draw box shadow?
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;
135
136 builder.push_box_shadow(
137 &CommonItemProperties::new(content_bounds, root_space_and_clip),
138 simple_box_bounds,
139 offset,
140 color,
141 blur_radius,
142 spread_radius,
143 BorderRadius::uniform(simple_border_radius),
144 box_shadow_type,
145 );
146 }
147
148 builder.pop_stacking_context();
149 }
150 }
151