Skip to content

Commit c4a0c01

Browse files
author
bors-servo
authored
Auto merge of #592 - mrobinson:aux-list, r=glennw
Simplify display list construction in the API This makes it a bit less complicated to use the WebRender API and hides some details that might change later. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/592) <!-- Reviewable:end -->
2 parents 90ca811 + 35fd4d6 commit c4a0c01

File tree

7 files changed

+144
-143
lines changed

7 files changed

+144
-143
lines changed

Cargo.lock

Lines changed: 66 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sample/src/main.rs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ extern crate euclid;
77
use euclid::{Size2D, Point2D, Rect, Matrix4D};
88
use gleam::gl;
99
use std::path::PathBuf;
10-
use std::ffi::CStr;
11-
use webrender_traits::{AuxiliaryListsBuilder, ColorF, Epoch, GlyphInstance};
10+
use webrender_traits::{ColorF, Epoch, GlyphInstance};
1211
use webrender_traits::{ImageData, ImageFormat, PipelineId, RendererKind};
1312
use std::fs::File;
1413
use std::io::Read;
@@ -33,11 +32,6 @@ impl Notifier {
3332
}
3433
}
3534

36-
pub struct WebRenderFrameBuilder {
37-
pub root_pipeline_id: PipelineId,
38-
pub next_scroll_layer_id: usize,
39-
}
40-
4135
impl webrender_traits::RenderNotifier for Notifier {
4236
fn new_frame_ready(&mut self) {
4337
self.window_proxy.wakeup_event_loop();
@@ -102,24 +96,21 @@ fn main() {
10296
let notifier = Box::new(Notifier::new(window.create_window_proxy()));
10397
renderer.set_render_notifier(notifier);
10498

105-
let pipeline_id = PipelineId(0, 0);
10699
let epoch = Epoch(0);
107100
let root_background_color = ColorF::new(0.3, 0.0, 0.0, 1.0);
108101

109-
let mut auxiliary_lists_builder = AuxiliaryListsBuilder::new();
110-
let mut builder = webrender_traits::DisplayListBuilder::new();
102+
let pipeline_id = PipelineId(0, 0);
103+
let mut builder = webrender_traits::DisplayListBuilder::new(pipeline_id);
111104

112105
let bounds = Rect::new(Point2D::new(0.0, 0.0), Size2D::new(width as f32, height as f32));
113-
builder.push_stacking_context(
114-
webrender_traits::StackingContext::new(webrender_traits::ScrollPolicy::Scrollable,
115-
bounds,
116-
bounds,
117-
0,
118-
&Matrix4D::identity(),
119-
&Matrix4D::identity(),
120-
webrender_traits::MixBlendMode::Normal,
121-
Vec::new(),
122-
&mut auxiliary_lists_builder));
106+
builder.push_stacking_context(webrender_traits::ScrollPolicy::Scrollable,
107+
bounds,
108+
bounds,
109+
0,
110+
&Matrix4D::identity(),
111+
&Matrix4D::identity(),
112+
webrender_traits::MixBlendMode::Normal,
113+
Vec::new());
123114

124115
let clip_region = {
125116
let mask = webrender_traits::ImageMask {
@@ -132,10 +123,7 @@ fn main() {
132123
Rect::new(Point2D::new(50.0, 50.0), Size2D::new(100.0, 100.0)),
133124
radius);
134125

135-
webrender_traits::ClipRegion::new(&bounds,
136-
vec![complex],
137-
Some(mask),
138-
&mut auxiliary_lists_builder)
126+
builder.new_clip_region(&bounds, vec![complex], Some(mask))
139127
};
140128

141129
builder.push_rect(Rect::new(Point2D::new(100.0, 100.0), Size2D::new(100.0, 100.0)),
@@ -207,24 +195,13 @@ fn main() {
207195
},
208196
];
209197

210-
// builder.push_text(text_bounds,
211-
// clip_region,
212-
// glyphs,
213-
// font_key,
214-
// ColorF::new(1.0, 1.0, 0.0, 1.0),
215-
// Au::from_px(32),
216-
// Au::from_px(0),
217-
// &mut frame_builder.auxiliary_lists_builder);
218-
219198
builder.pop_stacking_context();
220199

221200
api.set_root_display_list(
222201
root_background_color,
223202
epoch,
224-
pipeline_id,
225203
Size2D::new(width as f32, height as f32),
226-
builder.finalize(),
227-
auxiliary_lists_builder.finalize());
204+
builder);
228205
api.set_root_pipeline(pipeline_id);
229206

230207
for event in window.wait_events() {

webrender/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "webrender"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
55
license = "MPL-2.0"
66
repository = "https://github.com/servo/webrender"

webrender_traits/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "webrender_traits"
3-
version = "0.10.0"
3+
version = "0.11.0"
44
authors = ["Glenn Watson <gw@intuitionlibrary.com>"]
55
license = "MPL-2.0"
66
repository = "https://github.com/servo/webrender"

webrender_traits/src/api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use channel::{self, MsgSender, PayloadHelperMethods, PayloadSender};
77
use euclid::{Point2D, Size2D};
88
use offscreen_gl_context::{GLContextAttributes, GLLimits};
99
use std::cell::Cell;
10-
use {ApiMsg, AuxiliaryLists, BuiltDisplayList, ColorF, Epoch};
10+
use {ApiMsg, ColorF, DisplayListBuilder, Epoch};
1111
use {FontKey, IdNamespace, ImageFormat, ImageKey, NativeFontHandle, PipelineId};
1212
use {RenderApiSender, ResourceId, ScrollEventPhase, ScrollLayerState, ServoScrollRootId};
1313
use {GlyphKey, GlyphDimensions, ImageData, WebGLContextId, WebGLCommand};
@@ -165,10 +165,10 @@ impl RenderApi {
165165
pub fn set_root_display_list(&self,
166166
background_color: ColorF,
167167
epoch: Epoch,
168-
pipeline_id: PipelineId,
169168
viewport_size: Size2D<f32>,
170-
display_list: BuiltDisplayList,
171-
auxiliary_lists: AuxiliaryLists) {
169+
builder: DisplayListBuilder) {
170+
let pipeline_id = builder.pipeline_id;
171+
let (display_list, auxiliary_lists) = builder.finalize();
172172
let msg = ApiMsg::SetRootDisplayList(background_color,
173173
epoch,
174174
pipeline_id,

webrender_traits/src/display_list.rs

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use app_units::Au;
6-
use euclid::{Point2D, Rect, Size2D};
6+
use euclid::{Matrix4D, Point2D, Rect, Size2D};
77
use std::mem;
88
use std::slice;
99
use {AuxiliaryLists, AuxiliaryListsDescriptor, BorderDisplayItem, BorderRadius};
1010
use {BorderSide, BoxShadowClipMode, BoxShadowDisplayItem, BuiltDisplayList};
1111
use {BuiltDisplayListDescriptor, ClipRegion, ComplexClipRegion, ColorF};
1212
use {DisplayItem, DisplayListMode, FilterOp, YuvColorSpace};
1313
use {FontKey, GlyphInstance, GradientDisplayItem, GradientStop, IframeDisplayItem};
14-
use {ImageDisplayItem, YuvImageDisplayItem, ImageKey, ImageRendering, ItemRange, PipelineId,};
14+
use {ImageDisplayItem, ImageKey, ImageMask, ImageRendering, ItemRange, MixBlendMode, PipelineId};
1515
use {PushScrollLayerItem, PushStackingContextDisplayItem, RectangleDisplayItem, ScrollLayerId};
16-
use {SpecificDisplayItem, StackingContext, TextDisplayItem, WebGLContextId, WebGLDisplayItem};
16+
use {ScrollPolicy, ServoScrollRootId, SpecificDisplayItem, StackingContext, TextDisplayItem};
17+
use {WebGLContextId, WebGLDisplayItem, YuvImageDisplayItem};
1718

1819
impl BuiltDisplayListDescriptor {
1920
pub fn size(&self) -> usize {
@@ -47,13 +48,19 @@ impl BuiltDisplayList {
4748
pub struct DisplayListBuilder {
4849
pub mode: DisplayListMode,
4950
pub list: Vec<DisplayItem>,
51+
auxiliary_lists_builder: AuxiliaryListsBuilder,
52+
pub pipeline_id: PipelineId,
53+
next_scroll_layer_id: usize,
5054
}
5155

5256
impl DisplayListBuilder {
53-
pub fn new() -> DisplayListBuilder {
57+
pub fn new(pipeline_id: PipelineId) -> DisplayListBuilder {
5458
DisplayListBuilder {
5559
mode: DisplayListMode::Default,
5660
list: Vec::new(),
61+
auxiliary_lists_builder: AuxiliaryListsBuilder::new(),
62+
pipeline_id: pipeline_id,
63+
next_scroll_layer_id: 0,
5764
}
5865
}
5966

@@ -146,8 +153,7 @@ impl DisplayListBuilder {
146153
font_key: FontKey,
147154
color: ColorF,
148155
size: Au,
149-
blur_radius: Au,
150-
auxiliary_lists_builder: &mut AuxiliaryListsBuilder) {
156+
blur_radius: Au) {
151157
// Sanity check - anything with glyphs bigger than this
152158
// is probably going to consume too much memory to render
153159
// efficiently anyway. This is specifically to work around
@@ -157,7 +163,7 @@ impl DisplayListBuilder {
157163
if size < Au::from_px(4096) {
158164
let item = TextDisplayItem {
159165
color: color,
160-
glyphs: auxiliary_lists_builder.add_glyph_instances(&glyphs),
166+
glyphs: self.auxiliary_lists_builder.add_glyph_instances(&glyphs),
161167
font_key: font_key,
162168
size: size,
163169
blur_radius: blur_radius,
@@ -232,12 +238,11 @@ impl DisplayListBuilder {
232238
clip: ClipRegion,
233239
start_point: Point2D<f32>,
234240
end_point: Point2D<f32>,
235-
stops: Vec<GradientStop>,
236-
auxiliary_lists_builder: &mut AuxiliaryListsBuilder) {
241+
stops: Vec<GradientStop>) {
237242
let item = GradientDisplayItem {
238243
start_point: start_point,
239244
end_point: end_point,
240-
stops: auxiliary_lists_builder.add_gradient_stops(&stops),
245+
stops: self.auxiliary_lists_builder.add_gradient_stops(&stops),
241246
};
242247

243248
let display_item = DisplayItem {
@@ -249,7 +254,26 @@ impl DisplayListBuilder {
249254
self.list.push(display_item);
250255
}
251256

252-
pub fn push_stacking_context(&mut self, stacking_context: StackingContext) {
257+
pub fn push_stacking_context(&mut self,
258+
scroll_policy: ScrollPolicy,
259+
bounds: Rect<f32>,
260+
overflow: Rect<f32>,
261+
z_index: i32,
262+
transform: &Matrix4D<f32>,
263+
perspective: &Matrix4D<f32>,
264+
mix_blend_mode: MixBlendMode,
265+
filters: Vec<FilterOp>) {
266+
let stacking_context = StackingContext {
267+
scroll_policy: scroll_policy,
268+
bounds: bounds,
269+
overflow: overflow,
270+
z_index: z_index,
271+
transform: transform.clone(),
272+
perspective: perspective.clone(),
273+
mix_blend_mode: mix_blend_mode,
274+
filters: self.auxiliary_lists_builder.add_filters(&filters),
275+
};
276+
253277
let item = DisplayItem {
254278
item: SpecificDisplayItem::PushStackingContext(PushStackingContextDisplayItem {
255279
stacking_context: stacking_context
@@ -272,10 +296,13 @@ impl DisplayListBuilder {
272296
pub fn push_scroll_layer(&mut self,
273297
clip: Rect<f32>,
274298
content_size: Size2D<f32>,
275-
id: ScrollLayerId) {
299+
scroll_root_id: ServoScrollRootId) {
300+
let scroll_layer_id = self.next_scroll_layer_id;
301+
self.next_scroll_layer_id += 1;
302+
276303
let item = PushScrollLayerItem {
277304
content_size: content_size,
278-
id: id,
305+
id: ScrollLayerId::new(self.pipeline_id, scroll_layer_id, scroll_root_id),
279306
};
280307

281308
let item = DisplayItem {
@@ -304,19 +331,28 @@ impl DisplayListBuilder {
304331
self.list.push(item);
305332
}
306333

307-
pub fn finalize(self) -> BuiltDisplayList {
334+
pub fn new_clip_region(&mut self,
335+
rect: &Rect<f32>,
336+
complex: Vec<ComplexClipRegion>,
337+
image_mask: Option<ImageMask>)
338+
-> ClipRegion {
339+
ClipRegion::new(rect, complex, image_mask, &mut self.auxiliary_lists_builder)
340+
}
341+
342+
pub fn finalize(self) -> (BuiltDisplayList, AuxiliaryLists) {
308343
unsafe {
309344
let blob = convert_pod_to_blob(&self.list).to_vec();
310345
let display_list_items_size = blob.len();
311346

312-
BuiltDisplayList {
313-
descriptor: BuiltDisplayListDescriptor {
314-
mode: self.mode,
315-
display_list_items_size: display_list_items_size,
316-
display_items_size: 0,
317-
},
318-
data: blob,
319-
}
347+
(BuiltDisplayList {
348+
descriptor: BuiltDisplayListDescriptor {
349+
mode: self.mode,
350+
display_list_items_size: display_list_items_size,
351+
display_items_size: 0,
352+
},
353+
data: blob,
354+
},
355+
self.auxiliary_lists_builder.finalize())
320356
}
321357
}
322358
}

webrender_traits/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ mod stacking_context;
4242
mod webgl;
4343

4444
pub use api::RenderApi;
45-
pub use display_list::{AuxiliaryListsBuilder, DisplayListBuilder};
45+
pub use display_list::DisplayListBuilder;
4646
pub use units::*;

0 commit comments

Comments
 (0)