Skip to content
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

Clip stack collapse path #595

Merged
merged 5 commits into from Nov 28, 2016
Merged
Next

Added ClipRegion to StackingContext/Layer instead of the local rectan…

…gle.

Renamed prim_store::PrimitiveClipSource to mask_cache::ClipSource.
Creating dependent tasks for the layers.
clip copy shader.
Nested clipping and some text for the wr-sample.
  • Loading branch information
kvark committed Nov 28, 2016
commit 0152a5ef18fd7cb2ccf66288f1a94685f8511279
@@ -1,9 +1,11 @@
extern crate app_units;
extern crate webrender;
extern crate glutin;
extern crate gleam;
extern crate webrender_traits;
extern crate euclid;

use app_units::Au;
use euclid::{Size2D, Point2D, Rect, Matrix4D};
use gleam::gl;
use std::path::PathBuf;
@@ -13,7 +15,7 @@ use std::fs::File;
use std::io::Read;
use std::env;

fn _load_file(name: &str) -> Vec<u8> {
fn load_file(name: &str) -> Vec<u8> {
let mut file = File::open(name).unwrap();
let mut buffer = vec![];
file.read_to_end(&mut buffer).unwrap();
@@ -89,10 +91,6 @@ fn main() {
let (mut renderer, sender) = webrender::renderer::Renderer::new(opts);
let api = sender.create_api();

// let font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf";
// let font_bytes = load_file(font_path);
// let font_key = api.add_raw_font(font_bytes);

let notifier = Box::new(Notifier::new(window.create_window_proxy()));
renderer.set_render_notifier(notifier);

@@ -103,16 +101,28 @@ fn main() {
let mut builder = webrender_traits::DisplayListBuilder::new(pipeline_id);

let bounds = Rect::new(Point2D::new(0.0, 0.0), Size2D::new(width as f32, height as f32));
let clip_region = {
let radius = webrender_traits::BorderRadius::uniform(20.0);
let complex = webrender_traits::ComplexClipRegion::new(
Rect::new(Point2D::new(50.0, 50.0), Size2D::new(100.0, 100.0)),
radius);

webrender_traits::ClipRegion::new(&bounds,
vec![complex],
None,
&mut auxiliary_lists_builder)
};

builder.push_stacking_context(webrender_traits::ScrollPolicy::Scrollable,
bounds,
bounds,
clip_region,
0,
&Matrix4D::identity(),
&Matrix4D::identity(),
webrender_traits::MixBlendMode::Normal,
Vec::new());

let clip_region = {
let sub_clip = {
let mask = webrender_traits::ImageMask {
image: api.add_image(2, 2, None, ImageFormat::A8, ImageData::new(vec![0,80, 180, 255])),
rect: Rect::new(Point2D::new(75.0, 75.0), Size2D::new(100.0, 100.0)),
@@ -127,73 +137,90 @@ fn main() {
};

builder.push_rect(Rect::new(Point2D::new(100.0, 100.0), Size2D::new(100.0, 100.0)),
clip_region,
sub_clip,
ColorF::new(0.0, 1.0, 0.0, 1.0));
builder.push_rect(Rect::new(Point2D::new(250.0, 100.0), Size2D::new(100.0, 100.0)),
sub_clip,
ColorF::new(0.0, 1.0, 0.0, 1.0));

let _text_bounds = Rect::new(Point2D::new(100.0, 200.0), Size2D::new(700.0, 300.0));

let _glyphs = vec![
GlyphInstance {
index: 48,
x: 100.0,
y: 100.0,
},
GlyphInstance {
index: 68,
x: 150.0,
y: 100.0,
},
GlyphInstance {
index: 80,
x: 200.0,
y: 100.0,
},
GlyphInstance {
index: 82,
x: 250.0,
y: 100.0,
},
GlyphInstance {
index: 81,
x: 300.0,
y: 100.0,
},
GlyphInstance {
index: 3,
x: 350.0,
y: 100.0,
},
GlyphInstance {
index: 86,
x: 400.0,
y: 100.0,
},
GlyphInstance {
index: 79,
x: 450.0,
y: 100.0,
},
GlyphInstance {
index: 72,
x: 500.0,
y: 100.0,
},
GlyphInstance {
index: 83,
x: 550.0,
y: 100.0,
},
GlyphInstance {
index: 87,
x: 600.0,
y: 100.0,
},
GlyphInstance {
index: 17,
x: 650.0,
y: 100.0,
},
];
if false { // draw text?
let font_bytes = load_file("res/FreeSans.ttf");
let font_key = api.add_raw_font(font_bytes);

let text_bounds = Rect::new(Point2D::new(100.0, 200.0), Size2D::new(700.0, 300.0));

let glyphs = vec![
GlyphInstance {
index: 48,
x: 100.0,
y: 100.0,
},
GlyphInstance {
index: 68,
x: 150.0,
y: 100.0,
},
GlyphInstance {
index: 80,
x: 200.0,
y: 100.0,
},
GlyphInstance {
index: 82,
x: 250.0,
y: 100.0,
},
GlyphInstance {
index: 81,
x: 300.0,
y: 100.0,
},
GlyphInstance {
index: 3,
x: 350.0,
y: 100.0,
},
GlyphInstance {
index: 86,
x: 400.0,
y: 100.0,
},
GlyphInstance {
index: 79,
x: 450.0,
y: 100.0,
},
GlyphInstance {
index: 72,
x: 500.0,
y: 100.0,
},
GlyphInstance {
index: 83,
x: 550.0,
y: 100.0,
},
GlyphInstance {
index: 87,
x: 600.0,
y: 100.0,
},
GlyphInstance {
index: 17,
x: 650.0,
y: 100.0,
},
];

builder.push_text(text_bounds,
webrender_traits::ClipRegion::simple(&bounds),
glyphs,
font_key,
ColorF::new(1.0, 1.0, 0.0, 1.0),
Au::from_px(32),
Au::from_px(0),
&mut auxiliary_lists_builder);
}

builder.pop_stacking_context();

@@ -9,6 +9,7 @@ struct CacheClipInstance {
int render_task_index;
int layer_index;
int data_index;
int base_task_index;
};

CacheClipInstance fetch_clip_item(int index) {
@@ -21,6 +22,7 @@ CacheClipInstance fetch_clip_item(int index) {
cci.render_task_index = data0.x;
cci.layer_index = data0.y;
cci.data_index = data0.z;
cci.base_task_index = data0.w;

return cci;
}
@@ -0,0 +1,8 @@
/* 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/. */

void main(void) {
float alpha = texelFetch(sCache, ivec3(vClipMaskUv), 0).a;
oFragColor = vec4(1.0, 1.0, 1.0, alpha);
}
@@ -0,0 +1,19 @@
#line 1
/* 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/. */

void main(void) {
CacheClipInstance cci = fetch_clip_item(gl_InstanceID);
ClipArea area = fetch_clip_area(cci.render_task_index);
ClipArea source = fetch_clip_area(cci.base_task_index);

vec2 final_pos = mix(area.task_bounds.xy, area.task_bounds.zw, aPosition.xy);

gl_Position = uTransform * vec4(final_pos, 0.0, 1.0);

// convert to the source task space via the screen space
vec2 tuv = final_pos - area.task_bounds.xy + area.screen_origin_target_index.xy +
source.task_bounds.xy - source.screen_origin_target_index.xy;
vClipMaskUv = vec3(tuv, source.screen_origin_target_index.z);
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.