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

Use strongly typed geometry - Part 1 #568

Merged
merged 1 commit into from Nov 22, 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

Add more strongly typed geometry.

This commit introduces new units for stacking-context-local, scroll root and world coordinate systems and converts a large amount of the webrender internals from untyped geometry to these units.
  • Loading branch information
nical committed Nov 21, 2016
commit c1618f7184ae3c1b3044276378d4e7e5004e39a9
@@ -9,7 +9,7 @@ use euclid::{Matrix4D, Point2D, Size2D, Rect};
use internal_types::{ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE, TextureSampler};
use internal_types::{DebugFontVertex, DebugColorVertex, RenderTargetMode, PackedColor};
use std::f32;
use webrender_traits::{ColorF, ImageFormat};
use webrender_traits::{ColorF, ImageFormat, DeviceUintSize};

pub struct DebugRenderer {
font_vertices: Vec<DebugFontVertex>,
@@ -160,7 +160,7 @@ impl DebugRenderer {

pub fn render(&mut self,
device: &mut Device,
viewport_size: &Size2D<u32>) {
viewport_size: &DeviceUintSize) {
device.disable_depth();
device.set_blend(true);
device.set_blend_mode_alpha();

Large diffs are not rendered by default.

@@ -4,7 +4,7 @@

use app_units::Au;
use device::TextureFilter;
use euclid::{Size2D, TypedRect, TypedPoint2D, TypedSize2D, Length, UnknownUnit};
use euclid::{Size2D, TypedPoint2D, UnknownUnit};
use fnv::FnvHasher;
use offscreen_gl_context::{NativeGLContext, NativeGLContextHandle};
use offscreen_gl_context::{GLContext, NativeGLContextMethods, GLContextDispatcher};
@@ -163,18 +163,6 @@ impl GLContextWrapper {
}
}

pub type DeviceRect = TypedRect<i32, DevicePixel>;
pub type DevicePoint = TypedPoint2D<i32, DevicePixel>;
pub type DeviceSize = TypedSize2D<i32, DevicePixel>;
pub type DeviceLength = Length<i32, DevicePixel>;

#[derive(Hash, Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct DevicePixel;

pub fn device_pixel(value: f32, device_pixel_ratio: f32) -> DeviceLength {
DeviceLength::new((value * device_pixel_ratio).round() as i32)
}

const COLOR_FLOAT_TO_FIXED: f32 = 255.0;
pub const ANGLE_FLOAT_TO_FIXED: f32 = 65535.0;

@@ -2,33 +2,34 @@
* 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/. */

use euclid::{Matrix4D, Point2D, Rect, Size2D};
use spring::{DAMPING, STIFFNESS, Spring};
use webrender_traits::{PipelineId, ScrollLayerId};
use webrender_traits::{LayerRect, LayerPoint, LayerSize};
use webrender_traits::{LayerToScrollTransform, LayerToWorldTransform};

/// Contains scroll and transform information for scrollable and root stacking contexts.
/// Contains scrolling and transform information stacking contexts.
#[derive(Clone)]
pub struct Layer {
/// Manages scrolling offset, overscroll state etc.
pub scrolling: ScrollingState,

/// Size of the content inside the scroll region (in logical pixels)
pub content_size: Size2D<f32>,
pub content_size: LayerSize,

/// Viewing rectangle
pub local_viewport_rect: Rect<f32>,
pub local_viewport_rect: LayerRect,

/// Viewing rectangle clipped against parent layer(s)
pub combined_local_viewport_rect: Rect<f32>,
pub combined_local_viewport_rect: LayerRect,

/// World transform for the viewport rect itself.
pub world_viewport_transform: Matrix4D<f32>,
pub world_viewport_transform: LayerToWorldTransform,

/// World transform for content within this layer
pub world_content_transform: Matrix4D<f32>,
pub world_content_transform: LayerToWorldTransform,

/// Transform for this layer, relative to parent layer.
pub local_transform: Matrix4D<f32>,
/// Transform for this layer, relative to parent scrollable layer.
pub local_transform: LayerToScrollTransform,

/// Pipeline that this layer belongs to
pub pipeline_id: PipelineId,
@@ -38,18 +39,18 @@ pub struct Layer {
}

impl Layer {
pub fn new(local_viewport_rect: &Rect<f32>,
content_size: Size2D<f32>,
local_transform: &Matrix4D<f32>,
pub fn new(local_viewport_rect: &LayerRect,
content_size: LayerSize,
local_transform: &LayerToScrollTransform,
pipeline_id: PipelineId)
-> Layer {
Layer {
scrolling: ScrollingState::new(),
content_size: content_size,
local_viewport_rect: *local_viewport_rect,
combined_local_viewport_rect: *local_viewport_rect,
world_viewport_transform: Matrix4D::identity(),
world_content_transform: Matrix4D::identity(),
world_viewport_transform: LayerToWorldTransform::identity(),
world_content_transform: LayerToWorldTransform::identity(),
local_transform: *local_transform,
children: Vec::new(),
pipeline_id: pipeline_id,
@@ -64,7 +65,7 @@ impl Layer {
self.scrolling = *scrolling;
}

pub fn overscroll_amount(&self) -> Size2D<f32> {
pub fn overscroll_amount(&self) -> LayerSize {
let overscroll_x = if self.scrolling.offset.x > 0.0 {
-self.scrolling.offset.x
} else if self.scrolling.offset.x < self.local_viewport_rect.size.width - self.content_size.width {
@@ -82,7 +83,7 @@ impl Layer {
0.0
};

Size2D::new(overscroll_x, overscroll_y)
LayerSize::new(overscroll_x, overscroll_y)
}

pub fn stretch_overscroll_spring(&mut self) {
@@ -103,7 +104,7 @@ impl Layer {

#[derive(Copy, Clone)]
pub struct ScrollingState {
pub offset: Point2D<f32>,
pub offset: LayerPoint,
pub spring: Spring,
pub started_bouncing_back: bool,
pub bouncing_back: bool,
@@ -112,8 +113,8 @@ pub struct ScrollingState {
impl ScrollingState {
pub fn new() -> ScrollingState {
ScrollingState {
offset: Point2D::new(0.0, 0.0),
spring: Spring::at(Point2D::new(0.0, 0.0), STIFFNESS, DAMPING),
offset: LayerPoint::zero(),
spring: Spring::at(LayerPoint::zero(), STIFFNESS, DAMPING),
started_bouncing_back: false,
bouncing_back: false,
}
@@ -2,15 +2,14 @@
* 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/. */

use euclid::{Rect, Matrix4D};
use gpu_store::{GpuStore, GpuStoreAddress};
use internal_types::{DeviceRect, DeviceSize};
use prim_store::{ClipData, GpuBlock32, PrimitiveClipSource, PrimitiveStore};
use prim_store::{CLIP_DATA_GPU_SIZE, MASK_DATA_GPU_SIZE};
use std::i32;
use tiling::StackingContextIndex;
use util::{rect_from_points_f, TransformedRect};
use webrender_traits::{AuxiliaryLists, BorderRadius, ComplexClipRegion, ImageMask};
use webrender_traits::{DeviceIntRect, DeviceIntSize, LayerRect, LayerToWorldTransform};

const MAX_COORD: f32 = 1.0e+16;
pub const OPAQUE_TASK_INDEX: i32 = i32::MAX;
@@ -50,10 +49,10 @@ pub struct MaskCacheInfo {
// ResourceCache allocates/load the actual data
// will be simplified after the TextureCache upgrade
pub image: Option<ImageMask>,
pub local_rect: Option<Rect<f32>>,
pub local_inner: Option<Rect<f32>>,
pub inner_rect: DeviceRect,
pub outer_rect: DeviceRect,
pub local_rect: Option<LayerRect>,
pub local_inner: Option<LayerRect>,
pub inner_rect: DeviceIntRect,
pub outer_rect: DeviceIntRect,
}

impl MaskCacheInfo {
@@ -92,8 +91,8 @@ impl MaskCacheInfo {
image: image,
local_rect: None,
local_inner: None,
inner_rect: DeviceRect::zero(),
outer_rect: DeviceRect::zero(),
inner_rect: DeviceIntRect::zero(),
outer_rect: DeviceIntRect::zero(),
})
} else {
None
@@ -102,13 +101,14 @@ impl MaskCacheInfo {

pub fn update(&mut self,
source: &PrimitiveClipSource,
transform: &Matrix4D<f32>,
transform: &LayerToWorldTransform,
clip_store: &mut GpuStore<GpuBlock32>,
device_pixel_ratio: f32,
aux_lists: &AuxiliaryLists) {

if self.local_rect.is_none() {
let (mut local_rect, mut local_inner);
let mut local_rect;
let mut local_inner: Option<LayerRect>;
match source {
&PrimitiveClipSource::NoClip => unreachable!(),
&PrimitiveClipSource::Complex(rect, radius) => {
@@ -117,15 +117,15 @@ impl MaskCacheInfo {
PrimitiveStore::populate_clip_data(slice, data);
debug_assert_eq!(self.key.clip_range.item_count, 1);
local_rect = Some(rect);
local_inner = ComplexClipRegion::new(rect,
local_inner = ComplexClipRegion::new(rect.to_untyped(),
BorderRadius::uniform(radius))
.get_inner_rect();
.get_inner_rect().map(|r|{ LayerRect::from_untyped(&r) });
}
&PrimitiveClipSource::Region(ref region) => {
local_rect = Some(rect_from_points_f(-MAX_COORD, -MAX_COORD, MAX_COORD, MAX_COORD));
local_rect = Some(LayerRect::from_untyped(&rect_from_points_f(-MAX_COORD, -MAX_COORD, MAX_COORD, MAX_COORD)));
local_inner = match region.image_mask {
Some(ref mask) if !mask.repeat => {
local_rect = local_rect.and_then(|r| r.intersection(&mask.rect));
local_rect = local_rect.and_then(|r| r.intersection(&LayerRect::from_untyped(&mask.rect)));
None
},
Some(_) => None,
@@ -137,13 +137,13 @@ impl MaskCacheInfo {
for (clip, chunk) in clips.iter().zip(slice.chunks_mut(CLIP_DATA_GPU_SIZE)) {
let data = ClipData::from_clip_region(clip);
PrimitiveStore::populate_clip_data(chunk, data);
local_rect = local_rect.and_then(|r| r.intersection(&clip.rect));
local_rect = local_rect.and_then(|r| r.intersection(&LayerRect::from_untyped(&clip.rect)));
local_inner = local_inner.and_then(|r| clip.get_inner_rect()
.and_then(|ref inner| r.intersection(inner)));
.and_then(|ref inner| r.intersection(&LayerRect::from_untyped(&inner))));
}
}
};
self.local_rect = Some(local_rect.unwrap_or(Rect::zero()));
self.local_rect = Some(local_rect.unwrap_or(LayerRect::zero()));
self.local_inner = local_inner;
}

@@ -158,7 +158,7 @@ impl MaskCacheInfo {
device_pixel_ratio);
transformed.inner_rect
} else {
DeviceRect::new(self.outer_rect.origin, DeviceSize::zero())
DeviceIntRect::new(self.outer_rect.origin, DeviceIntSize::zero())
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.