Skip to content

Redesigned clip and scroll API #3251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions direct-composition/src/main_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,21 @@ impl Rectangle {
api::BorderRadius::uniform(20.),
api::ClipMode::Clip
);
let clip_id = builder.define_clip(rect, vec![region], None);
builder.push_clip_id(clip_id);

builder.push_rect(&api::PrimitiveInfo::new(rect), self.color);
let clip_id = builder.define_clip(
&api::SpaceAndClipInfo::root_scroll(pipeline_id),
rect,
vec![region],
None,
);

builder.pop_clip_id();
builder.push_rect(
&api::PrimitiveInfo::new(rect),
&api::SpaceAndClipInfo {
spatial_id: api::SpatialId::root_scroll_node(pipeline_id),
clip_id,
},
self.color,
);

let mut transaction = api::Transaction::new();
transaction.set_display_list(
Expand Down
6 changes: 4 additions & 2 deletions examples/alpha_perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ impl Example for App {
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
pipeline_id: PipelineId,
_document_id: DocumentId,
) {
let bounds = (0, 0).to(1920, 1080);
let info = LayoutPrimitiveInfo::new(bounds);
let space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);

builder.push_stacking_context(
&info,
space_and_clip.spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
Expand All @@ -42,7 +44,7 @@ impl Example for App {
);

for _ in 0 .. self.rect_count {
builder.push_rect(&info, ColorF::new(1.0, 1.0, 1.0, 0.05));
builder.push_rect(&info, &space_and_clip, ColorF::new(1.0, 1.0, 1.0, 0.05));
}

builder.pop_stacking_context();
Expand Down
30 changes: 17 additions & 13 deletions examples/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl App {
bounds: LayoutRect,
color: ColorF,
builder: &mut DisplayListBuilder,
pipeline_id: PipelineId,
property_key: PropertyBindingKey<LayoutTransform>,
opacity_key: Option<PropertyBindingKey<f32>>,
) {
Expand All @@ -54,44 +55,47 @@ impl App {
}
};

let reference_frame_id = builder.push_reference_frame(
let spatial_id = builder.push_reference_frame(
&LayoutRect::new(bounds.origin, LayoutSize::zero()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile, I think this change belongs in some other patch and there's a different change needed here

SpatialId::root_scroll_node(pipeline_id),
TransformStyle::Flat,
Some(PropertyBinding::Binding(property_key, LayoutTransform::identity())),
None,
);

builder.push_clip_id(reference_frame_id);

builder.push_stacking_context(
&LayoutPrimitiveInfo::new(LayoutRect::zero()),
spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
&filters,
RasterSpace::Screen,
);

let space_and_clip = SpaceAndClipInfo {
spatial_id,
clip_id: ClipId::root(pipeline_id),
};
let clip_bounds = LayoutRect::new(LayoutPoint::zero(), bounds.size);
let complex_clip = ComplexClipRegion {
rect: clip_bounds,
radii: BorderRadius::uniform(30.0),
mode: ClipMode::Clip,
};
let clip_id = builder.define_clip(clip_bounds, vec![complex_clip], None);
builder.push_clip_id(clip_id);
let clip_id = builder.define_clip(&space_and_clip, clip_bounds, vec![complex_clip], None);

// Fill it with a white rect
builder.push_rect(
&LayoutPrimitiveInfo::new(LayoutRect::new(LayoutPoint::zero(), bounds.size)),
&SpaceAndClipInfo {
spatial_id,
clip_id,
},
color,
);

builder.pop_clip_id();

builder.pop_stacking_context();

builder.pop_clip_id();
builder.pop_reference_frame();
}
}
Expand All @@ -106,22 +110,22 @@ impl Example for App {
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
_framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
pipeline_id: PipelineId,
_document_id: DocumentId,
) {
let opacity_key = self.opacity_key;

let bounds = (150, 150).to(250, 250);
let key0 = self.property_key0;
self.add_rounded_rect(bounds, ColorF::new(1.0, 0.0, 0.0, 0.5), builder, key0, Some(opacity_key));
self.add_rounded_rect(bounds, ColorF::new(1.0, 0.0, 0.0, 0.5), builder, pipeline_id, key0, Some(opacity_key));

let bounds = (400, 400).to(600, 600);
let key1 = self.property_key1;
self.add_rounded_rect(bounds, ColorF::new(0.0, 1.0, 0.0, 0.5), builder, key1, None);
self.add_rounded_rect(bounds, ColorF::new(0.0, 1.0, 0.0, 0.5), builder, pipeline_id, key1, None);

let bounds = (200, 500).to(350, 580);
let key2 = self.property_key2;
self.add_rounded_rect(bounds, ColorF::new(0.0, 0.0, 1.0, 0.5), builder, key2, None);
self.add_rounded_rect(bounds, ColorF::new(0.0, 0.0, 1.0, 0.5), builder, pipeline_id, key2, None);
}

fn on_event(&mut self, win_event: winit::WindowEvent, api: &RenderApi, document_id: DocumentId) -> bool {
Expand Down
36 changes: 24 additions & 12 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,17 @@ impl Example for App {
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_: DeviceIntSize,
_pipeline_id: PipelineId,
pipeline_id: PipelineId,
_document_id: DocumentId,
) {
let bounds = LayoutRect::new(LayoutPoint::zero(), builder.content_size());
let info = LayoutPrimitiveInfo::new(bounds);
let root_space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);
let spatial_id = root_space_and_clip.spatial_id;

builder.push_stacking_context(
&info,
spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
Expand All @@ -217,14 +221,19 @@ impl Example for App {
BorderRadius::uniform(20.0),
ClipMode::Clip
);
let id = builder.define_clip(bounds, vec![complex], Some(mask));
builder.push_clip_id(id);
let clip_id = builder.define_clip(&root_space_and_clip, bounds, vec![complex], Some(mask));

let info = LayoutPrimitiveInfo::new((100, 100).to(200, 200));
builder.push_rect(&info, ColorF::new(0.0, 1.0, 0.0, 1.0));
builder.push_rect(
&LayoutPrimitiveInfo::new((100, 100).to(200, 200)),
&SpaceAndClipInfo { spatial_id, clip_id },
ColorF::new(0.0, 1.0, 0.0, 1.0),
);

let info = LayoutPrimitiveInfo::new((250, 100).to(350, 200));
builder.push_rect(&info, ColorF::new(0.0, 1.0, 0.0, 1.0));
builder.push_rect(
&LayoutPrimitiveInfo::new((250, 100).to(350, 200)),
&SpaceAndClipInfo { spatial_id, clip_id },
ColorF::new(0.0, 1.0, 0.0, 1.0),
);
let border_side = BorderSide {
color: ColorF::new(0.0, 0.0, 1.0, 1.0),
style: BorderStyle::Groove,
Expand All @@ -239,9 +248,12 @@ impl Example for App {
do_aa: true,
});

let info = LayoutPrimitiveInfo::new((100, 100).to(200, 200));
builder.push_border(&info, border_widths, border_details);
builder.pop_clip_id();
builder.push_border(
&LayoutPrimitiveInfo::new((100, 100).to(200, 200)),
&SpaceAndClipInfo { spatial_id, clip_id },
border_widths,
border_details,
);

if false {
// draw box shadow?
Expand All @@ -253,10 +265,10 @@ impl Example for App {
let spread_radius = 0.0;
let simple_border_radius = 8.0;
let box_shadow_type = BoxShadowClipMode::Inset;
let info = LayoutPrimitiveInfo::with_clip_rect(rect, bounds);

builder.push_box_shadow(
&info,
&LayoutPrimitiveInfo::with_clip_rect(rect, bounds),
&root_space_and_clip,
simple_box_bounds,
offset,
color,
Expand Down
18 changes: 10 additions & 8 deletions examples/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rayon::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
use webrender::api::{self, DisplayListBuilder, DocumentId, PipelineId, RenderApi, Transaction};
use webrender::api::ColorF;
use webrender::api::{ColorF, SpaceAndClipInfo};
use webrender::euclid::size2;

// This example shows how to implement a very basic BlobImageHandler that can only render
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Example for App {
builder: &mut DisplayListBuilder,
txn: &mut Transaction,
_framebuffer_size: api::DeviceIntSize,
_pipeline_id: PipelineId,
pipeline_id: PipelineId,
_document_id: DocumentId,
) {
let blob_img1 = api.generate_blob_image_key();
Expand All @@ -220,19 +220,21 @@ impl Example for App {
);

let bounds = api::LayoutRect::new(api::LayoutPoint::zero(), builder.content_size());
let info = api::LayoutPrimitiveInfo::new(bounds);
let space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);

builder.push_stacking_context(
&info,
&api::LayoutPrimitiveInfo::new(bounds),
space_and_clip.spatial_id,
None,
api::TransformStyle::Flat,
api::MixBlendMode::Normal,
&[],
api::RasterSpace::Screen,
);

let info = api::LayoutPrimitiveInfo::new((30, 30).by(500, 500));
builder.push_image(
&info,
&api::LayoutPrimitiveInfo::new((30, 30).by(500, 500)),
&space_and_clip,
api::LayoutSize::new(500.0, 500.0),
api::LayoutSize::new(0.0, 0.0),
api::ImageRendering::Auto,
Expand All @@ -241,9 +243,9 @@ impl Example for App {
ColorF::WHITE,
);

let info = api::LayoutPrimitiveInfo::new((600, 600).by(200, 200));
builder.push_image(
&info,
&api::LayoutPrimitiveInfo::new((600, 600).by(200, 200)),
&space_and_clip,
api::LayoutSize::new(200.0, 200.0),
api::LayoutSize::new(0.0, 0.0),
api::ImageRendering::Auto,
Expand Down
5 changes: 4 additions & 1 deletion examples/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Example for App {
base_builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
framebuffer_size: DeviceIntSize,
_: PipelineId,
_pipeline_id: PipelineId,
_: DocumentId,
) {
if self.documents.is_empty() {
Expand All @@ -102,6 +102,7 @@ impl Example for App {
}

for doc in &self.documents {
let space_and_clip = SpaceAndClipInfo::root_scroll(doc.pipeline_id);
let mut builder = DisplayListBuilder::new(
doc.pipeline_id,
doc.content_rect.size,
Expand All @@ -113,6 +114,7 @@ impl Example for App {

builder.push_stacking_context(
&LayoutPrimitiveInfo::new(doc.content_rect),
space_and_clip.spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
Expand All @@ -121,6 +123,7 @@ impl Example for App {
);
builder.push_rect(
&LayoutPrimitiveInfo::new(local_rect),
&space_and_clip,
doc.color,
);
builder.pop_stacking_context();
Expand Down
10 changes: 8 additions & 2 deletions examples/frame_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,23 @@ impl App {
);

let info = LayoutPrimitiveInfo::new(document.content_rect);
let space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);
let mut builder = DisplayListBuilder::new(
document.pipeline_id,
document.content_rect.size,
);

builder.push_stacking_context(
&info,
space_and_clip.spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
&[],
RasterSpace::Screen,
);

builder.push_rect(&info, ColorF::new(1.0, 1.0, 0.0, 1.0));
builder.push_rect(&info, &space_and_clip, ColorF::new(1.0, 1.0, 0.0, 1.0));
builder.pop_stacking_context();

txn.set_root_pipeline(pipeline_id);
Expand All @@ -145,7 +147,7 @@ impl Example for App {
builder: &mut DisplayListBuilder,
_txn: &mut Transaction,
framebuffer_size: DeviceIntSize,
_pipeline_id: PipelineId,
pipeline_id: PipelineId,
_document_id: DocumentId,
) {
if self.output_document.is_none() {
Expand All @@ -155,8 +157,11 @@ impl Example for App {
}

let info = LayoutPrimitiveInfo::new((100, 100).to(200, 200));
let space_and_clip = SpaceAndClipInfo::root_scroll(pipeline_id);

builder.push_stacking_context(
&info,
space_and_clip.spatial_id,
None,
TransformStyle::Flat,
MixBlendMode::Normal,
Expand All @@ -166,6 +171,7 @@ impl Example for App {

builder.push_image(
&info,
&space_and_clip,
info.rect.size,
LayoutSize::zero(),
ImageRendering::Auto,
Expand Down
Loading