From 23008f85744591c1c74a62a7f7c3a16d9d6afcea Mon Sep 17 00:00:00 2001 From: UK992 Date: Tue, 3 May 2016 15:03:53 +0200 Subject: [PATCH] Replace deprecated Matrix4 with Matrix4D --- src/layers.rs | 32 +++++++++++++-------------- src/rendergl.rs | 58 +++++++++++++++++++++++-------------------------- src/tiling.rs | 9 ++++---- src/util.rs | 4 ++-- 4 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/layers.rs b/src/layers.rs index 2cb648c..8589433 100644 --- a/src/layers.rs +++ b/src/layers.rs @@ -11,7 +11,7 @@ use color::Color; use geometry::{DevicePixel, LayerPixel}; use tiling::{Tile, TileGrid}; -use euclid::matrix::Matrix4; +use euclid::Matrix4D; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; use euclid::point::{Point2D, TypedPoint2D}; @@ -42,7 +42,7 @@ impl ContentAge { #[cfg_attr(feature = "plugins", derive(HeapSizeOf))] pub struct TransformState { /// Final, concatenated transform + perspective matrix for this layer - pub final_transform: Matrix4, + pub final_transform: Matrix4D, /// If this is none, the rect was clipped and is not visible at all! pub screen_rect: Option, @@ -57,7 +57,7 @@ pub struct TransformState { impl TransformState { fn new() -> TransformState { TransformState { - final_transform: Matrix4::identity(), + final_transform: Matrix4D::identity(), screen_rect: None, world_rect: Rect::zero(), has_transform: false, @@ -67,8 +67,8 @@ impl TransformState { pub struct Layer { pub children: RefCell>>>, - pub transform: RefCell, - pub perspective: RefCell, + pub transform: RefCell>, + pub perspective: RefCell>, pub tile_size: usize, pub extra_data: RefCell, tile_grid: RefCell, @@ -108,8 +108,8 @@ impl Layer { -> Layer { Layer { children: RefCell::new(vec!()), - transform: RefCell::new(Matrix4::identity()), - perspective: RefCell::new(Matrix4::identity()), + transform: RefCell::new(Matrix4D::identity()), + perspective: RefCell::new(Matrix4D::identity()), bounds: RefCell::new(bounds), tile_size: tile_size, extra_data: RefCell::new(data), @@ -182,8 +182,8 @@ impl Layer { } pub fn update_transform_state(&self, - parent_transform: &Matrix4, - parent_perspective: &Matrix4, + parent_transform: &Matrix4D, + parent_perspective: &Matrix4D, parent_origin: &Point2D) { let mut ts = self.transform_state.borrow_mut(); let rect_without_scroll = self.bounds.borrow() @@ -196,9 +196,9 @@ impl Layer { let y0 = ts.world_rect.origin.y; // Build world space transform - let local_transform = Matrix4::identity().translate(x0, y0, 0.0) - .mul(&*self.transform.borrow()) - .translate(-x0, -y0, 0.0); + let local_transform = Matrix4D::identity().translate(x0, y0, 0.0) + .mul(&*self.transform.borrow()) + .translate(-x0, -y0, 0.0); ts.final_transform = parent_perspective.mul(&local_transform).mul(&parent_transform); ts.screen_rect = project_rect_to_screen(&ts.world_rect, &ts.final_transform); @@ -208,12 +208,12 @@ impl Layer { // We should probably make the display list optimizer work with transforms! // This layer is part of a 3d context if its concatenated transform // is not identity, since 2d transforms don't get layers. - ts.has_transform = ts.final_transform != Matrix4::identity(); + ts.has_transform = ts.final_transform != Matrix4D::identity(); // Build world space perspective transform - let perspective_transform = Matrix4::identity().translate(x0, y0, 0.0) - .mul(&*self.perspective.borrow()) - .translate(-x0, -y0, 0.0); + let perspective_transform = Matrix4D::identity().translate(x0, y0, 0.0) + .mul(&*self.perspective.borrow()) + .translate(-x0, -y0, 0.0); for child in self.children().iter() { child.update_transform_state(&ts.final_transform, diff --git a/src/rendergl.rs b/src/rendergl.rs index 63cf73d..027d24e 100755 --- a/src/rendergl.rs +++ b/src/rendergl.rs @@ -16,11 +16,7 @@ use texturegl::TextureTarget::{TextureTarget2D, TextureTargetRectangle}; use tiling::Tile; use platform::surface::NativeDisplay; -use euclid::matrix::Matrix4; -use euclid::Matrix2D; -use euclid::point::Point2D; -use euclid::rect::Rect; -use euclid::size::Size2D; +use euclid::{Matrix2D, Matrix4D, Point2D, Rect, Size2D}; use libc::c_int; use gleam::gl; use gleam::gl::{GLenum, GLfloat, GLint, GLsizei, GLuint}; @@ -68,8 +64,8 @@ impl TextureVertex { const ORTHO_NEAR_PLANE: f32 = -1000000.0; const ORTHO_FAR_PLANE: f32 = 1000000.0; -fn create_ortho(scene_size: &Size2D) -> Matrix4 { - Matrix4::ortho(0.0, scene_size.width, scene_size.height, 0.0, ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE) +fn create_ortho(scene_size: &Size2D) -> Matrix4D { + Matrix4D::ortho(0.0, scene_size.width, scene_size.height, 0.0, ORTHO_NEAR_PLANE, ORTHO_FAR_PLANE) } static TEXTURE_FRAGMENT_SHADER_SOURCE: &'static str = " @@ -212,9 +208,9 @@ impl TextureProgram { fn bind_uniforms_and_attributes(&self, vertices: &[TextureVertex; 4], - transform: &Matrix4, - projection_matrix: &Matrix4, - texture_space_transform: &Matrix4, + transform: &Matrix4D, + projection_matrix: &Matrix4D, + texture_space_transform: &Matrix4D, buffers: &Buffers, opacity: f32) { gl::uniform_1i(self.sampler_uniform, 0); @@ -284,8 +280,8 @@ impl SolidColorProgram { } fn bind_uniforms_and_attributes_common(&self, - transform: &Matrix4, - projection_matrix: &Matrix4, + transform: &Matrix4D, + projection_matrix: &Matrix4D, color: &Color) { gl::uniform_matrix_4fv(self.modelview_uniform, false, &transform.to_array()); gl::uniform_matrix_4fv(self.projection_uniform, false, &projection_matrix.to_array()); @@ -298,8 +294,8 @@ impl SolidColorProgram { fn bind_uniforms_and_attributes_for_lines(&self, vertices: &[ColorVertex; 5], - transform: &Matrix4, - projection_matrix: &Matrix4, + transform: &Matrix4D, + projection_matrix: &Matrix4D, buffers: &Buffers, color: &Color) { self.bind_uniforms_and_attributes_common(transform, projection_matrix, color); @@ -311,8 +307,8 @@ impl SolidColorProgram { fn bind_uniforms_and_attributes_for_quad(&self, vertices: &[ColorVertex; 4], - transform: &Matrix4, - projection_matrix: &Matrix4, + transform: &Matrix4D, + projection_matrix: &Matrix4D, buffers: &Buffers, color: &Color) { self.bind_uniforms_and_attributes_common(transform, projection_matrix, color); @@ -521,8 +517,8 @@ impl RenderContext { fn bind_and_render_solid_quad(&self, vertices: &[ColorVertex; 4], - transform: &Matrix4, - projection: &Matrix4, + transform: &Matrix4D, + projection: &Matrix4D, color: &Color) { self.solid_color_program.enable_attribute_arrays(); gl::use_program(self.solid_color_program.program.id); @@ -538,8 +534,8 @@ impl RenderContext { fn bind_and_render_quad(&self, vertices: &[TextureVertex; 4], texture: &Texture, - transform: &Matrix4, - projection_matrix: &Matrix4, + transform: &Matrix4D, + projection_matrix: &Matrix4D, opacity: f32) { let mut texture_coordinates_need_to_be_scaled_by_size = false; let program = match texture.target { @@ -569,7 +565,7 @@ impl RenderContext { // We calculate a transformation matrix for the texture coordinates // which is useful for flipping the texture vertically or scaling the // coordinates when dealing with GL_ARB_texture_rectangle. - let mut texture_transform = Matrix4::identity(); + let mut texture_transform = Matrix4D::identity(); if texture.flip == VerticalFlip { texture_transform = texture_transform.scale(1.0, -1.0, 1.0); } @@ -599,8 +595,8 @@ impl RenderContext { pub fn bind_and_render_quad_lines(&self, vertices: &[ColorVertex; 5], - transform: &Matrix4, - projection: &Matrix4, + transform: &Matrix4D, + projection: &Matrix4D, color: &Color, line_thickness: usize) { self.solid_color_program.enable_attribute_arrays(); @@ -617,8 +613,8 @@ impl RenderContext { fn render_layer(&self, layer: Rc>, - transform: &Matrix4, - projection: &Matrix4, + transform: &Matrix4D, + projection: &Matrix4D, clip_rect: Option>, gfx_context: &NativeDisplay) { let ts = layer.transform_state.borrow(); @@ -685,7 +681,7 @@ impl RenderContext { ColorVertex::new(aabb.origin), ]; self.bind_and_render_quad_lines(&debug_vertices, - &Matrix4::identity(), + &Matrix4D::identity(), projection, &LAYER_AABB_DEBUG_BORDER_COLOR, LAYER_AABB_DEBUG_BORDER_THICKNESS); @@ -695,8 +691,8 @@ impl RenderContext { fn render_tile(&self, tile: &Tile, layer_origin: &Point2D, - transform: &Matrix4, - projection: &Matrix4, + transform: &Matrix4D, + projection: &Matrix4D, clip_rect: Option>, opacity: f32) { if tile.texture.is_zero() || !tile.bounds.is_some() { @@ -754,8 +750,8 @@ impl RenderContext { fn render_3d_context(&self, context: &RenderContext3D, - transform: &Matrix4, - projection: &Matrix4, + transform: &Matrix4D, + projection: &Matrix4D, gfx_context: &NativeDisplay) { if context.children.is_empty() { return; @@ -831,7 +827,7 @@ pub fn render_scene(root_layer: Rc>, gl::depth_func(gl::LEQUAL); // Set up the initial modelview matrix. - let transform = Matrix4::identity().scale(scene.scale.get(), scene.scale.get(), 1.0); + let transform = Matrix4D::identity().scale(scene.scale.get(), scene.scale.get(), 1.0); let projection = create_ortho(&scene.viewport.size.to_untyped()); // Build the list of render items diff --git a/src/tiling.rs b/src/tiling.rs index 77eb7b2..09ad2d1 100644 --- a/src/tiling.rs +++ b/src/tiling.rs @@ -14,8 +14,7 @@ use texturegl::Texture; use util::project_rect_to_screen; use euclid::length::Length; -use euclid::matrix::Matrix4; -use euclid::point::Point2D; +use euclid::{Matrix4D, Point2D}; use euclid::rect::{Rect, TypedRect}; use euclid::size::{Size2D, TypedSize2D}; use std::collections::HashMap; @@ -161,7 +160,7 @@ impl TileGrid { test_rect: &Rect, current_layer_size: TypedSize2D, layer_world_origin: &Point2D, - layer_transform: &Matrix4) -> bool { + layer_transform: &Matrix4D) -> bool { let tile_rect = self.get_rect_for_tile_index(*tile_index, current_layer_size); let tile_rect = tile_rect.as_f32() @@ -182,7 +181,7 @@ impl TileGrid { pub fn mark_tiles_outside_of_rect_as_unused(&mut self, rect: TypedRect, layer_world_origin: &Point2D, - layer_transform: &Matrix4, + layer_transform: &Matrix4D, current_layer_size: TypedSize2D) { let mut tile_indexes_to_take = Vec::new(); @@ -236,7 +235,7 @@ impl TileGrid { viewport: TypedRect, current_layer_size: TypedSize2D, layer_world_origin: &Point2D, - layer_transform: &Matrix4, + layer_transform: &Matrix4D, current_content_age: ContentAge) -> Vec { let mut buffer_requests = Vec::new(); diff --git a/src/util.rs b/src/util.rs index 7d43a5b..cc2f729 100644 --- a/src/util.rs +++ b/src/util.rs @@ -10,7 +10,7 @@ // Miscellaneous utilities. use std::iter::repeat; -use euclid::{Rect, Point2D, Point3D, Point4D, Matrix4, Size2D}; +use euclid::{Matrix4D, Point2D, Point3D, Point4D, Rect, Size2D}; use std::f32; const W_CLIPPING_PLANE: f32 = 0.00001; @@ -89,7 +89,7 @@ fn clip_polygon_to_near_plane(clip_space_vertices: &[Point4D; 4]) } pub fn project_rect_to_screen(rect: &Rect, - transform: &Matrix4) -> Option { + transform: &Matrix4D) -> Option { let mut result = None; let x0 = rect.min_x();