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

Handle zero-width sized borders without crashing. #2822

Merged
merged 1 commit into from Jun 18, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1471,9 +1471,10 @@ impl BrushPrimitive {
)
}
BorderSource::Border { ref handle, .. } => {
let rt_handle = handle
.as_ref()
.expect("bug: render task handle not allocated");
let rt_handle = match *handle {
Some(ref handle) => handle,
None => return None,
};
let rt_cache_entry = resource_cache
.get_cached_render_task(rt_handle);
resource_cache.get_texture_cache_item(&rt_cache_entry.handle)
@@ -604,7 +604,7 @@ impl BorderRenderTaskInfo {
widths: &BorderWidths,
scale: LayoutToDeviceScale,
brush_segments: &mut Vec<BrushSegment>,
) -> Self {
) -> Option<Self> {
let mut border_segments = Vec::new();

let dp_width_top = (widths.top * scale.0).ceil();
@@ -684,6 +684,10 @@ impl BorderRenderTaskInfo {
dp_size_tl.height.max(dp_size_tr.height) + inner_height + dp_size_bl.height.max(dp_size_br.height),
);

if size.width == 0.0 || size.height == 0.0 {
return None;
}

add_edge_segment(
LayoutRect::from_floats(
rect.origin.x,
@@ -860,10 +864,10 @@ impl BorderRenderTaskInfo {
brush_segments,
);

BorderRenderTaskInfo {
Some(BorderRenderTaskInfo {
border_segments,
size: size.to_i32(),
}
})
}

pub fn build_instances(&self, border: &NormalBorder) -> Vec<BorderInstance> {
@@ -1424,39 +1424,39 @@ impl PrimitiveStore {
if needs_update {
cache_key.scale = scale_au;

*task_info = Some(BorderRenderTaskInfo::new(
*task_info = BorderRenderTaskInfo::new(
&metadata.local_rect,
border,
widths,
scale,
&mut new_segments,
));
);
}

let task_info = task_info.as_ref().unwrap();

*handle = Some(frame_state.resource_cache.request_render_task(
RenderTaskCacheKey {
size: DeviceIntSize::zero(),
kind: RenderTaskCacheKeyKind::Border(cache_key.clone()),
},
frame_state.gpu_cache,
frame_state.render_tasks,
None,
false, // todo
|render_tasks| {
let task = RenderTask::new_border(
task_info.size,
task_info.build_instances(border),
);

let task_id = render_tasks.add(task);

pic_state.tasks.push(task_id);

task_id
}
));
*handle = task_info.as_ref().map(|task_info| {
frame_state.resource_cache.request_render_task(
RenderTaskCacheKey {
size: DeviceIntSize::zero(),
kind: RenderTaskCacheKeyKind::Border(cache_key.clone()),
},
frame_state.gpu_cache,
frame_state.render_tasks,
None,
false, // todo
|render_tasks| {
let task = RenderTask::new_border(
task_info.size,
task_info.build_instances(border),
);

let task_id = render_tasks.add(task);

pic_state.tasks.push(task_id);

task_id
}
)
});

if needs_update {
brush.segment_desc = Some(BrushSegmentDescriptor {
@@ -0,0 +1,3 @@
---
root:

@@ -18,3 +18,4 @@ platform(linux,mac) == border-image.yaml border-image-ref.png
== border-no-bogus-line.yaml border-no-bogus-line-ref.png
platform(linux,mac) == dotted-corner-small-radius.yaml dotted-corner-small-radius.png
== overlapping.yaml overlapping.png
== zero-width.yaml blank.yaml
@@ -0,0 +1,12 @@
root:
items:
- type: stacking-context
bounds: [0, 0, 500, 500]
items:
- type: border
bounds: [ 0, 0, 50, 50 ]
width: [ 0, 0, 0, 0 ]
border-type: normal
style: [ solid, solid, solid, solid ]
color: [ blue, blue, blue, blue ]

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.