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

Fixed inner rectangle computation for transformed clips #2189

Merged
merged 2 commits into from Dec 8, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Proper inner rectangle for the clips

  • Loading branch information
kvark committed Dec 6, 2017
commit 47a70ddc0aaf07e3769b67da0f1b445d5ffb7b42
@@ -10,7 +10,7 @@ use freelist::{FreeList, FreeListHandle, WeakFreeListHandle};
use gpu_cache::{GpuCache, GpuCacheHandle, ToGpuBlocks};
use prim_store::{ClipData, ImageMaskData};
use resource_cache::ResourceCache;
use util::{MaxRect, calculate_screen_bounding_rect, extract_inner_rect_safe};
use util::{MaxRect, calculate_screen_inner_rect, calculate_screen_bounding_rect, extract_inner_rect_safe};

pub type ClipStore = FreeList<ClipSources>;
pub type ClipSourcesHandle = FreeListHandle<ClipSources>;
@@ -252,7 +252,7 @@ impl ClipSources {
device_pixel_ratio: f32,
) -> (DeviceIntRect, Option<DeviceIntRect>) {
let screen_inner_rect =
calculate_screen_bounding_rect(transform, &self.local_inner_rect, device_pixel_ratio);
calculate_screen_inner_rect(transform, &self.local_inner_rect, device_pixel_ratio);
let screen_outer_rect = self.local_outer_rect.map(|outer_rect|
calculate_screen_bounding_rect(transform, &outer_rect, device_pixel_ratio)
);
@@ -4,11 +4,11 @@

use api::{BorderRadius, DeviceIntPoint, DeviceIntRect, DeviceIntSize, DevicePoint, DeviceRect};
use api::{DeviceSize, LayerPoint, LayerRect, LayerSize, LayerToWorldTransform, WorldRect};
use euclid::{Point2D, Rect, Size2D, TypedPoint2D, TypedRect, TypedSize2D, TypedTransform2D};
use euclid::TypedTransform3D;
use euclid::{Point2D, Rect, ScaleFactor, Size2D, TypedPoint2D, TypedRect, TypedSize2D};
use euclid::{TypedTransform2D, TypedTransform3D};
use num_traits::Zero;
use std::i32;
use std::f32;
use std::{i32, f32};
use std::cmp::Ordering;

// Matches the definition of SK_ScalarNearlyZero in Skia.
const NEARLY_ZERO: f32 = 1.0 / 4096.0;
@@ -143,20 +143,52 @@ pub fn calculate_screen_bounding_rect(
rect: &LayerRect,
device_pixel_ratio: f32
) -> DeviceIntRect {
let rect = WorldRect::from_points(&[
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()),
]) * device_pixel_ratio;
];

let scale = ScaleFactor::new(device_pixel_ratio);
let rect: DeviceRect = WorldRect::from_points(&points) * scale;

let max_rect = DeviceRect::max_rect();
rect
.round_out()
.intersection(&max_rect)
.unwrap_or(max_rect)
.to_i32()
}

pub fn calculate_screen_inner_rect(
transform: &LayerToWorldTransform,
rect: &LayerRect,
device_pixel_ratio: f32
) -> DeviceIntRect {
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()),
];
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(Ordering::Equal));
ys.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal));

let rect = DeviceRect::new(
DevicePoint::new(rect.origin.x, rect.origin.y),
DeviceSize::new(rect.size.width, rect.size.height),
);
DevicePoint::new(xs[1], ys[1]),
DeviceSize::new(xs[2] - xs[1], ys[2] - ys[1]),
) * device_pixel_ratio;

let max_rect = DeviceRect::max_rect();
rect.round_out().intersection(&max_rect).unwrap_or(max_rect).to_i32()
rect
.intersection(&max_rect)
.unwrap_or(max_rect)
.round_in()
.to_i32()
}

pub fn _subtract_rect<U>(
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.