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

Replace deprecated Matrix4 with Matrix4D #235

Merged
merged 1 commit into from
May 4, 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
32 changes: 16 additions & 16 deletions src/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<f32>,

/// If this is none, the rect was clipped and is not visible at all!
pub screen_rect: Option<ScreenRect>,
Expand All @@ -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,
Expand All @@ -67,8 +67,8 @@ impl TransformState {

pub struct Layer<T> {
pub children: RefCell<Vec<Rc<Layer<T>>>>,
pub transform: RefCell<Matrix4>,
pub perspective: RefCell<Matrix4>,
pub transform: RefCell<Matrix4D<f32>>,
pub perspective: RefCell<Matrix4D<f32>>,
pub tile_size: usize,
pub extra_data: RefCell<T>,
tile_grid: RefCell<TileGrid>,
Expand Down Expand Up @@ -108,8 +108,8 @@ impl<T> Layer<T> {
-> Layer<T> {
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),
Expand Down Expand Up @@ -182,8 +182,8 @@ impl<T> Layer<T> {
}

pub fn update_transform_state(&self,
parent_transform: &Matrix4,
parent_perspective: &Matrix4,
parent_transform: &Matrix4D<f32>,
parent_perspective: &Matrix4D<f32>,
parent_origin: &Point2D<f32>) {
let mut ts = self.transform_state.borrow_mut();
let rect_without_scroll = self.bounds.borrow()
Expand All @@ -196,9 +196,9 @@ impl<T> Layer<T> {
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);
Expand All @@ -208,12 +208,12 @@ impl<T> Layer<T> {
// 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,
Expand Down
58 changes: 27 additions & 31 deletions src/rendergl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<f32>) -> 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<f32>) -> Matrix4D<f32> {
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 = "
Expand Down Expand Up @@ -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<f32>,
projection_matrix: &Matrix4D<f32>,
texture_space_transform: &Matrix4D<f32>,
buffers: &Buffers,
opacity: f32) {
gl::uniform_1i(self.sampler_uniform, 0);
Expand Down Expand Up @@ -284,8 +280,8 @@ impl SolidColorProgram {
}

fn bind_uniforms_and_attributes_common(&self,
transform: &Matrix4,
projection_matrix: &Matrix4,
transform: &Matrix4D<f32>,
projection_matrix: &Matrix4D<f32>,
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());
Expand All @@ -298,8 +294,8 @@ impl SolidColorProgram {

fn bind_uniforms_and_attributes_for_lines(&self,
vertices: &[ColorVertex; 5],
transform: &Matrix4,
projection_matrix: &Matrix4,
transform: &Matrix4D<f32>,
projection_matrix: &Matrix4D<f32>,
buffers: &Buffers,
color: &Color) {
self.bind_uniforms_and_attributes_common(transform, projection_matrix, color);
Expand All @@ -311,8 +307,8 @@ impl SolidColorProgram {

fn bind_uniforms_and_attributes_for_quad(&self,
vertices: &[ColorVertex; 4],
transform: &Matrix4,
projection_matrix: &Matrix4,
transform: &Matrix4D<f32>,
projection_matrix: &Matrix4D<f32>,
buffers: &Buffers,
color: &Color) {
self.bind_uniforms_and_attributes_common(transform, projection_matrix, color);
Expand Down Expand Up @@ -521,8 +517,8 @@ impl RenderContext {

fn bind_and_render_solid_quad(&self,
vertices: &[ColorVertex; 4],
transform: &Matrix4,
projection: &Matrix4,
transform: &Matrix4D<f32>,
projection: &Matrix4D<f32>,
color: &Color) {
self.solid_color_program.enable_attribute_arrays();
gl::use_program(self.solid_color_program.program.id);
Expand All @@ -538,8 +534,8 @@ impl RenderContext {
fn bind_and_render_quad(&self,
vertices: &[TextureVertex; 4],
texture: &Texture,
transform: &Matrix4,
projection_matrix: &Matrix4,
transform: &Matrix4D<f32>,
projection_matrix: &Matrix4D<f32>,
opacity: f32) {
let mut texture_coordinates_need_to_be_scaled_by_size = false;
let program = match texture.target {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -599,8 +595,8 @@ impl RenderContext {

pub fn bind_and_render_quad_lines(&self,
vertices: &[ColorVertex; 5],
transform: &Matrix4,
projection: &Matrix4,
transform: &Matrix4D<f32>,
projection: &Matrix4D<f32>,
color: &Color,
line_thickness: usize) {
self.solid_color_program.enable_attribute_arrays();
Expand All @@ -617,8 +613,8 @@ impl RenderContext {

fn render_layer<T>(&self,
layer: Rc<Layer<T>>,
transform: &Matrix4,
projection: &Matrix4,
transform: &Matrix4D<f32>,
projection: &Matrix4D<f32>,
clip_rect: Option<Rect<f32>>,
gfx_context: &NativeDisplay) {
let ts = layer.transform_state.borrow();
Expand Down Expand Up @@ -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);
Expand All @@ -695,8 +691,8 @@ impl RenderContext {
fn render_tile(&self,
tile: &Tile,
layer_origin: &Point2D<f32>,
transform: &Matrix4,
projection: &Matrix4,
transform: &Matrix4D<f32>,
projection: &Matrix4D<f32>,
clip_rect: Option<Rect<f32>>,
opacity: f32) {
if tile.texture.is_zero() || !tile.bounds.is_some() {
Expand Down Expand Up @@ -754,8 +750,8 @@ impl RenderContext {

fn render_3d_context<T>(&self,
context: &RenderContext3D<T>,
transform: &Matrix4,
projection: &Matrix4,
transform: &Matrix4D<f32>,
projection: &Matrix4D<f32>,
gfx_context: &NativeDisplay) {
if context.children.is_empty() {
return;
Expand Down Expand Up @@ -831,7 +827,7 @@ pub fn render_scene<T>(root_layer: Rc<Layer<T>>,
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
Expand Down
9 changes: 4 additions & 5 deletions src/tiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -161,7 +160,7 @@ impl TileGrid {
test_rect: &Rect<f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4) -> bool {
layer_transform: &Matrix4D<f32>) -> bool {
let tile_rect = self.get_rect_for_tile_index(*tile_index,
current_layer_size);
let tile_rect = tile_rect.as_f32()
Expand All @@ -182,7 +181,7 @@ impl TileGrid {
pub fn mark_tiles_outside_of_rect_as_unused(&mut self,
rect: TypedRect<DevicePixel, f32>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4,
layer_transform: &Matrix4D<f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>) {
let mut tile_indexes_to_take = Vec::new();

Expand Down Expand Up @@ -236,7 +235,7 @@ impl TileGrid {
viewport: TypedRect<DevicePixel, f32>,
current_layer_size: TypedSize2D<DevicePixel, f32>,
layer_world_origin: &Point2D<f32>,
layer_transform: &Matrix4,
layer_transform: &Matrix4D<f32>,
current_content_age: ContentAge)
-> Vec<BufferRequest> {
let mut buffer_requests = Vec::new();
Expand Down
4 changes: 2 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +89,7 @@ fn clip_polygon_to_near_plane(clip_space_vertices: &[Point4D<f32>; 4])
}

pub fn project_rect_to_screen(rect: &Rect<f32>,
transform: &Matrix4) -> Option<ScreenRect> {
transform: &Matrix4D<f32>) -> Option<ScreenRect> {
let mut result = None;

let x0 = rect.min_x();
Expand Down