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

Inset box shadow fixes #285

Merged
merged 3 commits into from Jun 9, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -141,6 +141,8 @@ void main(void) {
vec2 radii = vBorderRadii.xy;
float sigma = vBlurRadius / 2.0;
float value = color(pos, p0Rect, p1Rect, radii, sigma);
SetFragColor(vec4(vColor.rgb, max(value, 0.0)));

value = max(value, 0.0);
SetFragColor(vec4(vColor.rgb, vColor.a == 0.0 ? 1.0 - value : value));
}

@@ -642,7 +642,7 @@ impl<'a> BatchBuilder<'a> {
clip_mode: BoxShadowClipMode,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);

// Fast path.
if blur_radius == 0.0 && spread_radius == 0.0 && clip_mode == BoxShadowClipMode::None {
@@ -732,7 +732,7 @@ impl<'a> BatchBuilder<'a> {
// |##| |##|
// +--+------------------+--+

let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
@@ -812,13 +812,17 @@ impl<'a> BatchBuilder<'a> {
clip_mode: BoxShadowClipMode,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, clip_mode);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
border_radius,
clip_mode);

if clip_mode == BoxShadowClipMode::Inset && blur_radius == 0.0 {
return;
}

// Draw the sides.
//
// +--+------------------+--+
@@ -899,7 +903,7 @@ impl<'a> BatchBuilder<'a> {
border_radius: f32,
resource_cache: &ResourceCache,
frame_id: FrameId) {
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius);
let rect = compute_box_shadow_rect(box_bounds, box_offset, spread_radius, BoxShadowClipMode::Inset);
let metrics = BoxShadowMetrics::new(&rect, border_radius, blur_radius);

let clip_state = self.adjust_clip_for_box_shadow_clip_mode(box_bounds,
@@ -1880,11 +1884,17 @@ impl BoxShadowMetrics {

pub fn compute_box_shadow_rect(box_bounds: &Rect<f32>,
box_offset: &Point2D<f32>,
spread_radius: f32)
mut spread_radius: f32,
clip_mode: BoxShadowClipMode)
-> Rect<f32> {
let mut rect = (*box_bounds).clone();
rect.origin.x += box_offset.x;
rect.origin.y += box_offset.y;

if clip_mode == BoxShadowClipMode::Inset {
spread_radius = -spread_radius;
};

rect.inflate(spread_radius, spread_radius)
}

@@ -198,7 +198,8 @@ impl BuildRequiredResources for AABBTreeNode {

let box_rect = batch_builder::compute_box_shadow_rect(&info.box_bounds,
&info.offset,
info.spread_radius);
info.spread_radius,
info.clip_mode);
resource_list.add_box_shadow_corner(info.blur_radius,
info.border_radius,
&box_rect,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.