From 73c96cf34ce2a52e0b8ff5a60d1d4fe52ba89402 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Fri, 20 Dec 2013 21:57:48 -0700 Subject: [PATCH] Upgrade to latest Rust. --- layers.rs | 16 ++++++++-------- lib.rs | 2 +- platform/android/surface.rs | 28 +++++++++------------------- platform/linux/surface.rs | 15 ++------------- platform/macos/surface.rs | 8 ++------ rendergl.rs | 2 +- scene.rs | 2 +- texturegl.rs | 6 +++--- util.rs | 4 ++-- 9 files changed, 29 insertions(+), 54 deletions(-) diff --git a/layers.rs b/layers.rs index 9d90163..2d5ec23 100644 --- a/layers.rs +++ b/layers.rs @@ -25,7 +25,7 @@ pub enum Layer { } impl Layer { - pub fn with_common(&self, f: &fn(&mut CommonLayer) -> T) -> T { + pub fn with_common(&self, f: |&mut CommonLayer| -> T) -> T { match *self { ContainerLayerKind(container_layer) => f(&mut container_layer.common), TextureLayerKind(texture_layer) => f(&mut texture_layer.common), @@ -113,7 +113,7 @@ impl ContainerLayer { assert!(first_child_common.prev_sibling.is_none()); first_child_common.prev_sibling = Some(new_child); new_child_common.next_sibling = Some(first_child); - }) + }); } } @@ -123,7 +123,7 @@ impl ContainerLayer { None => self.last_child = Some(new_child), Some(_) => {} } - }) + }); } /// Adds a child to the end of the list. @@ -143,7 +143,7 @@ impl ContainerLayer { assert!(last_child_common.next_sibling.is_none()); last_child_common.next_sibling = Some(new_child); new_child_common.prev_sibling = Some(last_child); - }) + }); } } @@ -153,7 +153,7 @@ impl ContainerLayer { None => self.first_child = Some(new_child), Some(_) => {} } - }) + }); } pub fn remove_child(@mut self, child: Layer) { @@ -173,7 +173,7 @@ impl ContainerLayer { Some(ref sibling) => { sibling.with_common(|sibling_common| { sibling_common.prev_sibling = child_common.prev_sibling; - }) + }); } } match child_common.prev_sibling { @@ -183,10 +183,10 @@ impl ContainerLayer { Some(ref sibling) => { sibling.with_common(|sibling_common| { sibling_common.next_sibling = child_common.next_sibling; - }) + }); } } - }) + }); } } diff --git a/lib.rs b/lib.rs index ab67bb3..f7cffb7 100755 --- a/lib.rs +++ b/lib.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[link(name = "layers", vers = "0.1")]; +#[crate_id = "github.com/mozilla-servo/rust-layers#layers:0.1"]; #[feature(managed_boxes)]; diff --git a/platform/android/surface.rs b/platform/android/surface.rs index a7f8916..17c3d39 100644 --- a/platform/android/surface.rs +++ b/platform/android/surface.rs @@ -13,15 +13,14 @@ use platform::surface::NativeSurfaceMethods; use texturegl::Texture; use geom::size::Size2D; -use opengles::gl2::{egl_image_target_texture2d_oes, TEXTURE_2D, GLsizei, GLint, glTexImage2D, BGRA, UNSIGNED_BYTE}; +use opengles::gl2::{egl_image_target_texture2d_oes, TEXTURE_2D, glTexImage2D, BGRA, UNSIGNED_BYTE}; use egl::egl::EGLDisplay; -use egl::eglext::{EGLImageKHR, CreateImageKHR, DestroyImageKHR}; +use egl::eglext::{EGLImageKHR, DestroyImageKHR}; use std::cast; use std::ptr; use std::util; use std::vec; use std::libc::c_void; -use std::vec::bytes; /// FIXME(Aydin Kim) :Currently, native surface is consist of 2 types of hybrid image buffer. EGLImageKHR is used to GPU rendering and vector is used to CPU rendering. EGL extension seems not provide simple way to accessing its bitmap directly. In the future, we need to find out the way to integrate them. @@ -34,18 +33,14 @@ pub struct NativePaintingGraphicsContext{ } impl NativePaintingGraphicsContext { - #[fixed_stack_segment] pub fn from_metadata(metadata: &NativeGraphicsMetadata) -> NativePaintingGraphicsContext { - unsafe { - NativePaintingGraphicsContext { - display : metadata.display, - } - } + NativePaintingGraphicsContext { + display : metadata.display, + } } } impl Drop for NativePaintingGraphicsContext { - #[fixed_stack_segment] fn drop(&mut self) {} } @@ -68,7 +63,6 @@ pub struct NativeSurface { } impl NativeSurface { - #[fixed_stack_segment] pub fn from_image_khr(image_khr: EGLImageKHR) -> NativeSurface { let mut _image: Option = None; if image_khr != ptr::null() { @@ -84,8 +78,7 @@ impl NativeSurface { impl NativeSurfaceMethods for NativeSurface { /// This may only be called on the case of CPU rendering. - #[fixed_stack_segment] - fn new(native_context: &NativePaintingGraphicsContext, size: Size2D, stride: i32) -> NativeSurface { + fn new(_native_context: &NativePaintingGraphicsContext, size: Size2D, _stride: i32) -> NativeSurface { unsafe { let len = size.width * size.height * 4; let bitmap = vec::from_elem::(len as uint, 0); @@ -99,9 +92,8 @@ impl NativeSurfaceMethods for NativeSurface { } /// This may only be called on the compositor side. - #[fixed_stack_segment] fn bind_to_texture(&self, - native_context: &NativeCompositingGraphicsContext, + _native_context: &NativeCompositingGraphicsContext, texture: &Texture, _size: Size2D) { let _bound = texture.bind(); @@ -124,12 +116,11 @@ impl NativeSurfaceMethods for NativeSurface { } /// This may only be called on the painting side. - #[fixed_stack_segment] - fn upload(&self, graphics_context: &NativePaintingGraphicsContext, data: &[u8]) { + fn upload(&self, _graphics_context: &NativePaintingGraphicsContext, data: &[u8]) { unsafe { if self.bitmap != ptr::null() { let dest:&mut [u8] = cast::transmute((self.bitmap, data.len())); - bytes::copy_memory(dest, data, data.len()); + dest.copy_memory(data); } else { debug!("Cannot upload the buffer(CPU rendering), there is no bitmap"); @@ -144,7 +135,6 @@ impl NativeSurfaceMethods for NativeSurface { } } -#[fixed_stack_segment] fn destroy(&mut self, graphics_context: &NativePaintingGraphicsContext) { match self.image { None => {}, diff --git a/platform/linux/surface.rs b/platform/linux/surface.rs index 8881f88..231625a 100644 --- a/platform/linux/surface.rs +++ b/platform/linux/surface.rs @@ -39,12 +39,11 @@ pub struct NativePaintingGraphicsContext { } impl NativePaintingGraphicsContext { - #[fixed_stack_segment] pub fn from_metadata(metadata: &NativeGraphicsMetadata) -> NativePaintingGraphicsContext { unsafe { - let display = do metadata.display.with_c_str |c_str| { + let display = metadata.display.with_c_str(|c_str| { XOpenDisplay(c_str) - }; + }); if display.is_null() { fail!("XOpenDisplay() failed!"); @@ -64,7 +63,6 @@ impl NativePaintingGraphicsContext { } impl Drop for NativePaintingGraphicsContext { - #[fixed_stack_segment] fn drop(&mut self) { unsafe { let _ = XCloseDisplay(self.display); @@ -91,7 +89,6 @@ impl NativeCompositingGraphicsContext { /// Chooses the compositor visual info using the same algorithm that the compositor uses. /// /// FIXME(pcwalton): It would be more robust to actually have the compositor pass the visual. - #[fixed_stack_segment] fn compositor_visual_info(display: *Display) -> *XVisualInfo { unsafe { let glx_display: *glx::Display = cast::transmute(display); @@ -104,7 +101,6 @@ impl NativeCompositingGraphicsContext { /// Creates a native graphics context from the given X display connection. This uses GLX. Only /// the compositor is allowed to call this. - #[fixed_stack_segment] pub fn from_display(display: *Display) -> NativeCompositingGraphicsContext { unsafe { // FIXME(pcwalton): It would be more robust to actually have the compositor pass the @@ -167,7 +163,6 @@ pub struct NativeGraphicsMetadata { impl NativeGraphicsMetadata { /// Creates graphics metadata from a metadata descriptor. - #[fixed_stack_segment] pub fn from_descriptor(descriptor: &NativeGraphicsMetadataDescriptor) -> NativeGraphicsMetadata { NativeGraphicsMetadata { @@ -184,7 +179,6 @@ pub struct NativeGraphicsMetadataDescriptor { impl NativeGraphicsMetadataDescriptor { /// Creates a metadata descriptor from metadata. - #[fixed_stack_segment] pub fn from_metadata(metadata: NativeGraphicsMetadata) -> NativeGraphicsMetadataDescriptor { NativeGraphicsMetadataDescriptor { display: metadata.display.to_str() @@ -217,7 +211,6 @@ impl Drop for NativeSurface { } impl NativeSurface { - #[fixed_stack_segment] pub fn from_pixmap(pixmap: Pixmap) -> NativeSurface { NativeSurface { pixmap: pixmap, @@ -227,7 +220,6 @@ impl NativeSurface { } impl NativeSurfaceMethods for NativeSurface { - #[fixed_stack_segment] fn new(native_context: &NativePaintingGraphicsContext, size: Size2D, stride: i32) -> NativeSurface { unsafe { @@ -246,7 +238,6 @@ impl NativeSurfaceMethods for NativeSurface { } /// This may only be called on the compositor side. - #[fixed_stack_segment] fn bind_to_texture(&self, native_context: &NativeCompositingGraphicsContext, texture: &Texture, @@ -282,7 +273,6 @@ impl NativeSurfaceMethods for NativeSurface { } /// This may only be called on the painting side. - #[fixed_stack_segment] fn upload(&self, graphics_context: &NativePaintingGraphicsContext, data: &[u8]) { unsafe { // Ensure that we're running on the render task. Take the display. @@ -339,7 +329,6 @@ impl NativeSurfaceMethods for NativeSurface { self.pixmap as int } - #[fixed_stack_segment] fn destroy(&mut self, graphics_context: &NativePaintingGraphicsContext) { unsafe { assert!(self.pixmap != 0); diff --git a/platform/macos/surface.rs b/platform/macos/surface.rs index d7f7991..671bf9f 100644 --- a/platform/macos/surface.rs +++ b/platform/macos/surface.rs @@ -24,7 +24,6 @@ use opengles::cgl::{CGLChoosePixelFormat, CGLDescribePixelFormat, CGLPixelFormat use opengles::cgl::{CGLPixelFormatObj, CORE_BOOLEAN_ATTRIBUTES, CORE_INTEGER_ATTRIBUTES}; use opengles::cgl::{kCGLNoError}; use opengles::gl2::GLint; -use std::cell::Cell; use std::hashmap::HashMap; use std::local_data; use std::ptr; @@ -48,7 +47,6 @@ impl NativeGraphicsMetadata { } } - #[fixed_stack_segment] pub fn from_descriptor(descriptor: &NativeGraphicsMetadataDescriptor) -> NativeGraphicsMetadata { unsafe { @@ -86,7 +84,6 @@ pub struct NativeGraphicsMetadataDescriptor { } impl NativeGraphicsMetadataDescriptor { - #[fixed_stack_segment] pub fn from_metadata(metadata: NativeGraphicsMetadata) -> NativeGraphicsMetadataDescriptor { unsafe { let mut descriptor = NativeGraphicsMetadataDescriptor { @@ -148,18 +145,17 @@ pub struct NativeSurface { } impl NativeSurface { - #[fixed_stack_segment] pub fn from_io_surface(io_surface: IOSurface) -> NativeSurface { // Take the surface by ID (so that we can send it cross-process) and consume its reference. let id = io_surface.get_id(); - let io_surface_cell = Cell::new(io_surface); + let mut io_surface = Some(io_surface); local_data::modify(io_surface_repository, |opt_repository| { let mut repository = match opt_repository { None => HashMap::new(), Some(repository) => repository, }; - repository.insert(id, io_surface_cell.take()); + repository.insert(id, io_surface.take().unwrap()); Some(repository) }); diff --git a/rendergl.rs b/rendergl.rs index c6ecd16..9db6269 100755 --- a/rendergl.rs +++ b/rendergl.rs @@ -275,7 +275,7 @@ pub fn bind_and_render_quad(render_context: RenderContext, Some(program) => {program.id}, None => {fail!("There is no shader program for texture 2D");} }, - TextureTargetRectangle(*) => match render_context.program_rectangle { + TextureTargetRectangle(..) => match render_context.program_rectangle { Some(program) => {program.id}, None => {fail!("There is no shader program for texture rectangle");} }, diff --git a/scene.rs b/scene.rs index a900070..772d464 100755 --- a/scene.rs +++ b/scene.rs @@ -35,7 +35,7 @@ pub fn Scene(root: Layer, size: Size2D, transform: Matrix4) -> Scene { impl Scene { // FIXME: Workaround for cross-crate bug regarding mutability of class fields - fn set_transform(&mut self, new_transform: Matrix4) { + pub fn set_transform(&mut self, new_transform: Matrix4) { self.transform = new_transform; } } diff --git a/texturegl.rs b/texturegl.rs index 4eeb7cb..8326711 100644 --- a/texturegl.rs +++ b/texturegl.rs @@ -19,11 +19,11 @@ use opengles::gl2; use std::num::Zero; /// Image data used when uploading to a texture. -pub struct TextureImageData<'self> { +pub struct TextureImageData<'a> { size: Size2D, stride: uint, format: Format, - data: &'self [u8], + data: &'a [u8], } /// The texture target. @@ -38,7 +38,7 @@ impl TextureTarget { fn as_gl_target(self) -> GLenum { match self { TextureTarget2D => TEXTURE_2D, - TextureTargetRectangle(*) => TEXTURE_RECTANGLE_ARB, + TextureTargetRectangle(_) => TEXTURE_RECTANGLE_ARB, } } } diff --git a/util.rs b/util.rs index 74bf688..62e2b89 100644 --- a/util.rs +++ b/util.rs @@ -9,11 +9,11 @@ // Miscellaneous utilities. -use std::vec::from_fn; +use std::vec; pub fn convert_rgb32_to_rgb24(buffer: ~[u8]) -> ~[u8] { let mut i = 0; - from_fn(buffer.len() * 3 / 4, |j| { + vec::from_fn(buffer.len() * 3 / 4, |j| { match j % 3 { 0 => { buffer[i + 2]