Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Changes to require Euclid 0.8 #238

Merged
merged 2 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "layers"
version = "0.2.6"
version = "0.3.0"
authors = ["The Servo Project Developers"]
license = "MIT/Apache-2.0"

Expand All @@ -14,9 +14,8 @@ libc = "0.2"
rustc-serialize = "0.3.16"
log = "0.3.4"
gleam = "0.2"
euclid = ">=0.6.2, <0.8"
servo-skia = "0.20130412.8"
azure = { git = "https://github.com/servo/rust-azure" }
euclid = "0.8"
servo-skia = "0.20130412.16"

[dependencies.heapsize]
version = ">=0.2.2, <0.4"
Expand All @@ -29,7 +28,7 @@ optional = true
[target.x86_64-apple-darwin.dependencies]
core-foundation = "0.2.0"
cgl = "0.1"
io-surface = "0.2.0"
io-surface = "0.3.0"

[target.'cfg(target_os = "linux")'.dependencies]
glx = "0.1.0"
Expand Down
16 changes: 8 additions & 8 deletions src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ pub struct Layer<T> {
tile_grid: RefCell<TileGrid>,

/// The boundaries of this layer in the coordinate system of the parent layer.
pub bounds: RefCell<TypedRect<LayerPixel, f32>>,
pub bounds: RefCell<TypedRect<f32, LayerPixel>>,

/// A monotonically increasing counter that keeps track of the current content age.
pub content_age: RefCell<ContentAge>,

/// The content offset for this layer in unscaled layer pixels.
pub content_offset: RefCell<TypedPoint2D<LayerPixel, f32>>,
pub content_offset: RefCell<TypedPoint2D<f32, LayerPixel>>,

/// Whether this layer clips its children to its boundaries.
pub masks_to_bounds: RefCell<bool>,
Expand All @@ -99,7 +99,7 @@ pub struct Layer<T> {
}

impl<T> Layer<T> {
pub fn new(bounds: TypedRect<LayerPixel, f32>,
pub fn new(bounds: TypedRect<f32, LayerPixel>,
tile_size: usize,
background_color: Color,
opacity: f32,
Expand All @@ -116,7 +116,7 @@ impl<T> Layer<T> {
tile_grid: RefCell::new(TileGrid::new(tile_size)),
content_age: RefCell::new(ContentAge::new()),
masks_to_bounds: RefCell::new(false),
content_offset: RefCell::new(Point2D::zero()),
content_offset: RefCell::new(TypedPoint2D::zero()),
background_color: RefCell::new(background_color),
opacity: RefCell::new(opacity),
establishes_3d_context: establishes_3d_context,
Expand All @@ -139,9 +139,9 @@ impl<T> Layer<T> {
/// Returns buffer requests inside the given dirty rect, and simultaneously throws out tiles
/// outside the given viewport rect.
pub fn get_buffer_requests(&self,
rect_in_layer: TypedRect<LayerPixel, f32>,
viewport_in_layer: TypedRect<LayerPixel, f32>,
scale: ScaleFactor<LayerPixel, DevicePixel, f32>)
rect_in_layer: TypedRect<f32, LayerPixel>,
viewport_in_layer: TypedRect<f32, LayerPixel>,
scale: ScaleFactor<f32, LayerPixel, DevicePixel>)
-> Vec<BufferRequest> {
let mut tile_grid = self.tile_grid.borrow_mut();
tile_grid.get_buffer_requests_in_rect(rect_in_layer * scale,
Expand All @@ -153,7 +153,7 @@ impl<T> Layer<T> {
*self.content_age.borrow())
}

pub fn resize(&self, new_size: TypedSize2D<LayerPixel, f32>) {
pub fn resize(&self, new_size: TypedSize2D<f32, LayerPixel>) {
self.bounds.borrow_mut().size = new_size;
}

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#![cfg_attr(feature = "plugins", plugin(heapsize_plugin))]

extern crate azure;
extern crate euclid;
#[cfg(feature = "plugins")]
extern crate heapsize;
Expand Down
21 changes: 11 additions & 10 deletions src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use euclid::rect::{Rect, TypedRect};
use euclid::rect::TypedRect;
use euclid::scale_factor::ScaleFactor;
use euclid::size::TypedSize2D;
use euclid::point::Point2D;
use euclid::point::TypedPoint2D;
use geometry::{DevicePixel, LayerPixel};
use layers::{BufferRequest, Layer, LayerBuffer};
use std::rc::Rc;

pub struct Scene<T> {
pub root: Option<Rc<Layer<T>>>,
pub viewport: TypedRect<DevicePixel, f32>,
pub viewport: TypedRect<f32, DevicePixel>,

/// The scene scale, to allow for zooming and high-resolution painting.
pub scale: ScaleFactor<LayerPixel, DevicePixel, f32>,
pub scale: ScaleFactor<f32, LayerPixel, DevicePixel>,
}

impl<T> Scene<T> {
pub fn new(viewport: TypedRect<DevicePixel, f32>) -> Scene<T> {
pub fn new(viewport: TypedRect<f32, DevicePixel>) -> Scene<T> {
Scene {
root: None,
viewport: viewport,
Expand All @@ -34,8 +34,8 @@ impl<T> Scene<T> {

pub fn get_buffer_requests_for_layer(&mut self,
layer: Rc<Layer<T>>,
dirty_rect: TypedRect<LayerPixel, f32>,
viewport_rect: TypedRect<LayerPixel, f32>,
dirty_rect: TypedRect<f32, LayerPixel>,
viewport_rect: TypedRect<f32, LayerPixel>,
layers_and_requests: &mut Vec<(Rc<Layer<T>>,
Vec<BufferRequest>)>,
unused_buffers: &mut Vec<Box<LayerBuffer>>) {
Expand All @@ -54,7 +54,7 @@ impl<T> Scene<T> {
match layer.transform_state.borrow().screen_rect {
Some(ref screen_rect) => {
match dirty_rect.to_untyped().intersection(&screen_rect.rect) {
Some(ref child_dirty_rect) => Rect::from_untyped(child_dirty_rect),
Some(ref child_dirty_rect) => TypedRect::from_untyped(child_dirty_rect),
None => return, // The layer is entirely outside the dirty rect.
}
},
Expand Down Expand Up @@ -101,9 +101,10 @@ impl<T> Scene<T> {
self.mark_layer_contents_as_changed_recursively_for_layer(root_layer);
}

pub fn set_root_layer_size(&self, new_size: TypedSize2D<DevicePixel, f32>) {
pub fn set_root_layer_size(&self, new_size: TypedSize2D<f32, DevicePixel>) {
if let Some(ref root_layer) = self.root {
*root_layer.bounds.borrow_mut() = Rect::new(Point2D::zero(), new_size / self.scale);
*root_layer.bounds.borrow_mut() = TypedRect::new(TypedPoint2D::zero(),
new_size / self.scale);
}
}

Expand Down
43 changes: 22 additions & 21 deletions src/tiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use texturegl::Texture;
use util::project_rect_to_screen;

use euclid::length::Length;
use euclid::{Matrix4D, Point2D};
use euclid::{Matrix4D, Point2D, TypedPoint2D};
use euclid::rect::{Rect, TypedRect};
use euclid::size::{Size2D, TypedSize2D};
use std::collections::HashMap;
Expand All @@ -33,7 +33,7 @@ pub struct Tile {
pub texture: Texture,

/// The tile boundaries in the parent layer coordinates.
pub bounds: Option<TypedRect<LayerPixel,f32>>,
pub bounds: Option<TypedRect<f32, LayerPixel>>,
}

impl Tile {
Expand Down Expand Up @@ -80,7 +80,7 @@ impl Tile {
buffer.native_surface.bind_to_texture(display, &self.texture);

// Set the layer's rect.
self.bounds = Some(Rect::from_untyped(&buffer.rect));
self.bounds = Some(TypedRect::from_untyped(&buffer.rect));
}
}

Expand All @@ -104,15 +104,15 @@ pub struct TileGrid {
pub tiles: HashMap<Point2D<usize>, Tile>,

/// The size of tiles in this grid in device pixels.
tile_size: Length<DevicePixel, usize>,
tile_size: Length<usize, DevicePixel>,

// Buffers that are currently unused.
unused_buffers: Vec<Box<LayerBuffer>>,
}

pub fn rect_uint_as_rect_f32(rect: Rect<usize>) -> Rect<f32> {
Rect::new(Point2D::new(rect.origin.x as f32, rect.origin.y as f32),
Size2D::new(rect.size.width as f32, rect.size.height as f32))
TypedRect::new(Point2D::new(rect.origin.x as f32, rect.origin.y as f32),
Size2D::new(rect.size.width as f32, rect.size.height as f32))
}

impl TileGrid {
Expand All @@ -126,21 +126,22 @@ impl TileGrid {

pub fn get_rect_for_tile_index(&self,
tile_index: Point2D<usize>,
current_layer_size: TypedSize2D<DevicePixel, f32>)
-> TypedRect<DevicePixel, usize> {
current_layer_size: TypedSize2D<f32, DevicePixel>)
-> TypedRect<usize, DevicePixel> {

let origin = Point2D::new(self.tile_size.get() * tile_index.x,
self.tile_size.get() * tile_index.y);
let origin : TypedPoint2D<usize, DevicePixel> =
TypedPoint2D::new(self.tile_size.get() * tile_index.x,
self.tile_size.get() * tile_index.y);

// Don't let tiles extend beyond the layer boundaries.
let tile_size = self.tile_size.get() as f32;
let size = Size2D::new(tile_size.min(current_layer_size.width.get() - origin.x as f32),
tile_size.min(current_layer_size.height.get() - origin.y as f32));
let size = Size2D::new(tile_size.min(current_layer_size.width - origin.x as f32),
tile_size.min(current_layer_size.height - origin.y as f32));

// Round up to texture pixels.
let size = Size2D::new(size.width.ceil() as usize, size.height.ceil() as usize);
let size = TypedSize2D::new(size.width.ceil() as usize, size.height.ceil() as usize);

Rect::from_untyped(&Rect::new(origin, size))
TypedRect::new(origin, size)
}

pub fn take_unused_buffers(&mut self) -> Vec<Box<LayerBuffer>> {
Expand All @@ -158,7 +159,7 @@ impl TileGrid {
pub fn tile_intersects_rect(&self,
tile_index: &Point2D<usize>,
test_rect: &Rect<f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>,
current_layer_size: TypedSize2D<f32, DevicePixel>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4D<f32>) -> bool {
let tile_rect = self.get_rect_for_tile_index(*tile_index,
Expand All @@ -179,10 +180,10 @@ impl TileGrid {
}

pub fn mark_tiles_outside_of_rect_as_unused(&mut self,
rect: TypedRect<DevicePixel, f32>,
rect: TypedRect<f32, DevicePixel>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4D<f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>) {
current_layer_size: TypedSize2D<f32, DevicePixel>) {
let mut tile_indexes_to_take = Vec::new();

for tile_index in self.tiles.keys() {
Expand All @@ -204,7 +205,7 @@ impl TileGrid {

pub fn get_buffer_request_for_tile(&mut self,
tile_index: Point2D<usize>,
current_layer_size: TypedSize2D<DevicePixel, f32>,
current_layer_size: TypedSize2D<f32, DevicePixel>,
current_content_age: ContentAge)
-> Option<BufferRequest> {
let tile_rect = self.get_rect_for_tile_index(tile_index, current_layer_size);
Expand All @@ -231,9 +232,9 @@ impl TileGrid {
/// Returns buffer requests inside the given dirty rect, and simultaneously throws out tiles
/// outside the given viewport rect.
pub fn get_buffer_requests_in_rect(&mut self,
dirty_rect: TypedRect<DevicePixel, f32>,
viewport: TypedRect<DevicePixel, f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>,
dirty_rect: TypedRect<f32, DevicePixel>,
viewport: TypedRect<f32, DevicePixel>,
current_layer_size: TypedSize2D<f32, DevicePixel>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4D<f32>,
current_content_age: ContentAge)
Expand Down