Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gw3583 committed Aug 24, 2018
1 parent 1887943 commit fc4b78f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 98 deletions.
113 changes: 42 additions & 71 deletions webrender/src/clip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,61 +867,45 @@ impl ClipItem {
transform: &LayoutToWorldTransform,
prim_rect: &WorldRect,
) -> ClipResult {
match *self {
ClipItem::Rectangle(ref clip_rect, ClipMode::Clip) => {
if let Some(inner_clip_rect) = project_inner_rect(transform, clip_rect) {
if inner_clip_rect.contains_rect(prim_rect) {
return ClipResult::Accept;
}
}

let outer_clip_rect = match project_rect(transform, clip_rect) {
Some(outer_clip_rect) => outer_clip_rect,
None => return ClipResult::Partial,
};

match outer_clip_rect.intersection(prim_rect) {
Some(..) => {
ClipResult::Partial
}
None => {
ClipResult::Reject
}
}
let (clip_rect, inner_rect) = match *self {
ClipItem::Rectangle(clip_rect, ClipMode::Clip) => {
(clip_rect, Some(clip_rect))
}
ClipItem::RoundedRectangle(ref clip_rect, ref radius, ClipMode::Clip) => {
let inner_clip_rect = extract_inner_rect_safe(clip_rect, radius)
.and_then(|ref inner_clip_rect| {
project_inner_rect(transform, inner_clip_rect)
});

if let Some(inner_clip_rect) = inner_clip_rect {
if inner_clip_rect.contains_rect(prim_rect) {
return ClipResult::Accept;
}
}

let outer_clip_rect = match project_rect(transform, clip_rect) {
Some(outer_clip_rect) => outer_clip_rect,
None => return ClipResult::Partial,
};

match outer_clip_rect.intersection(prim_rect) {
Some(..) => {
ClipResult::Partial
}
None => {
ClipResult::Reject
}
}
let inner_clip_rect = extract_inner_rect_safe(clip_rect, radius);
(*clip_rect, inner_clip_rect)
}
ClipItem::Rectangle(_, ClipMode::ClipOut) |
ClipItem::RoundedRectangle(_, _, ClipMode::ClipOut) |
ClipItem::Image(..) |
ClipItem::BoxShadow(..) |
ClipItem::LineDecoration(..) => {
return ClipResult::Partial
}
};

let inner_clip_rect = inner_rect.and_then(|ref inner_rect| {
project_inner_rect(transform, inner_rect)
});

if let Some(inner_clip_rect) = inner_clip_rect {
if inner_clip_rect.contains_rect(prim_rect) {
return ClipResult::Accept;
}
}

let outer_clip_rect = match project_rect(transform, &clip_rect) {
Some(outer_clip_rect) => outer_clip_rect,
None => return ClipResult::Partial,
};

match outer_clip_rect.intersection(prim_rect) {
Some(..) => {
ClipResult::Partial
}
None => {
ClipResult::Reject
}
}
}

Expand Down Expand Up @@ -1129,32 +1113,19 @@ pub fn project_inner_rect(
transform: &LayoutToWorldTransform,
rect: &LayoutRect,
) -> Option<WorldRect> {
let homogens = [
transform.transform_point2d_homogeneous(&rect.origin),
transform.transform_point2d_homogeneous(&rect.top_right()),
transform.transform_point2d_homogeneous(&rect.bottom_left()),
transform.transform_point2d_homogeneous(&rect.bottom_right()),
let points = [
transform.transform_point2d(&rect.origin)?,
transform.transform_point2d(&rect.top_right())?,
transform.transform_point2d(&rect.bottom_left())?,
transform.transform_point2d(&rect.bottom_right())?,
];

// Note: we only do the full frustum collision when the polygon approaches the camera plane.
// Otherwise, it will be clamped to the screen bounds anyway.
if homogens.iter().any(|h| h.w <= 0.0) {
None
} else {
// we just checked for all the points to be in positive hemisphere, so `unwrap` is valid
let points = [
homogens[0].to_point2d().unwrap(),
homogens[1].to_point2d().unwrap(),
homogens[2].to_point2d().unwrap(),
homogens[3].to_point2d().unwrap(),
];
let mut xs = [points[0].x, points[1].x, points[2].x, points[3].x];
let mut ys = [points[0].y, points[1].y, points[2].y, points[3].y];
xs.sort_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal));
ys.sort_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal));
Some(WorldRect::new(
WorldPoint::new(xs[1], ys[1]),
WorldSize::new(xs[2] - xs[1], ys[2] - ys[1]),
))
}
let mut xs = [points[0].x, points[1].x, points[2].x, points[3].x];
let mut ys = [points[0].y, points[1].y, points[2].y, points[3].y];
xs.sort_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal));
ys.sort_by(|a, b| a.partial_cmp(b).unwrap_or(cmp::Ordering::Equal));
Some(WorldRect::new(
WorldPoint::new(xs[1], ys[1]),
WorldSize::new(xs[2] - xs[1], ys[2] - ys[1]),
))
}
2 changes: 1 addition & 1 deletion webrender/src/prim_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,7 +2043,7 @@ fn write_brush_segment_description(
}

if is_large || rect_clips_only {
// If there we no local clips, then we will subdivide the primitive into
// If there were no local clips, then we will subdivide the primitive into
// a uniform grid (up to 8x8 segments). This will typically result in
// a significant number of those segments either being completely clipped,
// or determined to not need a clip mask for that segment.
Expand Down
32 changes: 6 additions & 26 deletions webrender/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use api::{BorderRadius, DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePixelScale};
use api::{DevicePoint, DeviceRect, DeviceSize, LayoutPixel, LayoutPoint, LayoutRect, LayoutSize};
use api::{WorldPixel, WorldRect, WorldPoint, WorldSize};
use api::{DeviceRect, LayoutPixel, LayoutRect};
use api::{WorldPixel, WorldRect};
use euclid::{Point2D, Rect, Size2D, TypedPoint2D, TypedRect, TypedSize2D};
use euclid::{TypedTransform2D, TypedTransform3D, TypedVector2D};
use euclid::{HomogeneousVector};
Expand Down Expand Up @@ -331,15 +331,6 @@ pub trait MaxRect {
fn max_rect() -> Self;
}

impl MaxRect for LayoutRect {
fn max_rect() -> Self {
LayoutRect::new(
LayoutPoint::new(f32::MIN / 2.0, f32::MIN / 2.0),
LayoutSize::new(f32::MAX, f32::MAX),
)
}
}

impl MaxRect for DeviceIntRect {
fn max_rect() -> Self {
DeviceIntRect::new(
Expand All @@ -349,7 +340,7 @@ impl MaxRect for DeviceIntRect {
}
}

impl MaxRect for DeviceRect {
impl<U> MaxRect for TypedRect<f32, U> {
fn max_rect() -> Self {
// Having an unlimited bounding box is fine up until we try
// to cast it to `i32`, where we get `-2147483648` for any
Expand All @@ -359,20 +350,9 @@ impl MaxRect for DeviceRect {
// with explanation left as an exercise for the reader.
const MAX_COORD: f32 = 1.0e9;

DeviceRect::new(
DevicePoint::new(-MAX_COORD, -MAX_COORD),
DeviceSize::new(2.0 * MAX_COORD, 2.0 * MAX_COORD),
)
}
}

impl MaxRect for WorldRect {
fn max_rect() -> Self {
const MAX_COORD: f32 = 1.0e9;

WorldRect::new(
WorldPoint::new(-MAX_COORD, -MAX_COORD),
WorldSize::new(2.0 * MAX_COORD, 2.0 * MAX_COORD),
TypedRect::new(
TypedPoint2D::new(-MAX_COORD, -MAX_COORD),
TypedSize2D::new(2.0 * MAX_COORD, 2.0 * MAX_COORD),
)
}
}
Expand Down

0 comments on commit fc4b78f

Please sign in to comment.