From 96a2c65707913331d94d3782680490e5900f6597 Mon Sep 17 00:00:00 2001 From: Jack Moffitt Date: Wed, 23 Jul 2014 12:41:49 -0600 Subject: [PATCH] Upgrade Rust. --- lib.rs | 7 +- platform/linux.rs | 172 +++++++++++++++++++++++----------------------- platform/macos.rs | 16 ++--- 3 files changed, 98 insertions(+), 97 deletions(-) diff --git a/lib.rs b/lib.rs index 410acce..c9627b7 100644 --- a/lib.rs +++ b/lib.rs @@ -7,13 +7,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![crate_id = "github.com/mozilla-servo/sharegl#0.1"] -#![crate_type = "lib"] -#![crate_type = "dylib"] +#![crate_name = "sharegl"] #![crate_type = "rlib"] #![feature(phase)] +#![allow(non_snake_case_functions)] + + extern crate geom; extern crate libc; #[phase(plugin, link)] diff --git a/platform/linux.rs b/platform/linux.rs index 13f2c8f..d8dab8a 100644 --- a/platform/linux.rs +++ b/platform/linux.rs @@ -10,7 +10,7 @@ use context::GraphicsContextMethods; use libc::{c_char, c_int, c_long, c_uint, c_ulong, c_void}; -use std::ptr::null; +use std::ptr; use sync::Arc; // Constants. @@ -21,7 +21,7 @@ static GLX_GREEN_SIZE: c_int = 9; static GLX_BLUE_SIZE: c_int = 10;*/ static GLX_DEPTH_SIZE: c_int = 12; -static ATTRIBUTES: [c_int, ..4] = [ +static mut ATTRIBUTES: [c_int, ..4] = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, 0, @@ -38,130 +38,130 @@ struct Visual; // Sadly we need to copy some of this definition in here because the Xlib macros need to access it. struct Display { - ext_data: *XExtData, - private1: *_XPrivate, - fd: c_int, - private2: c_int, - proto_major_version: c_int, - proto_minor_version: c_int, - vendor: *c_char, - private3: XID, - private4: XID, - private5: XID, - private6: c_int, - resource_alloc: *c_void, - byte_order: c_int, - bitmap_unit: c_int, - bitmap_pad: c_int, - bitmap_bit_order: c_int, - nformats: c_int, - pixmap_format: *ScreenFormat, - private8: c_int, - release: c_int, - private9: *_XPrivate, - private10: *_XPrivate, - qlen: c_int, - last_request_read: c_ulong, - request: c_ulong, - private11: XPointer, - private12: XPointer, - private13: XPointer, - private14: XPointer, - max_request_size: c_uint, - db: *_XrmHashBucketRec, - private15: *c_void, - display_name: *c_char, + _ext_data: *mut XExtData, + _private1: *mut _XPrivate, + _fd: c_int, + _private2: c_int, + _proto_major_version: c_int, + _proto_minor_version: c_int, + _vendor: *mut c_char, + _private3: XID, + _private4: XID, + _private5: XID, + _private6: c_int, + _resource_alloc: *mut c_void, + _byte_order: c_int, + _bitmap_unit: c_int, + _bitmap_pad: c_int, + _bitmap_bit_order: c_int, + _nformats: c_int, + _pixmap_format: *mut ScreenFormat, + _private8: c_int, + _release: c_int, + _private9: *mut _XPrivate, + _private10: *mut _XPrivate, + _qlen: c_int, + _last_request_read: c_ulong, + _request: c_ulong, + _private11: XPointer, + _private12: XPointer, + _private13: XPointer, + _private14: XPointer, + _max_request_size: c_uint, + _db: *mut _XrmHashBucketRec, + _private15: *mut c_void, + _display_name: *mut c_char, // FIXME(pcwalton): These are needed for some reason... - pad: *c_void, - pad1: *c_void, + _pad: *mut c_void, + _pad1: *mut c_void, default_screen: c_int, - nscreens: c_int, - screens: *Screen, + _nscreens: c_int, + screens: *mut Screen, } struct Screen { - ext_data: *XExtData, - display: *Display, + _ext_data: *mut XExtData, + _display: *mut Display, root: Window, - width: c_int, - height: c_int, - mwidth: c_int, - mheight: c_int, - ndepths: c_int, - depths: *Depth, - root_depth: c_int, - root_visual: *Visual, - default_gc: GC, - cmap: Colormap, - white_pixel: c_ulong, - black_pixel: c_ulong, - max_maps: c_int, - min_maps: c_int, - backing_store: c_int, - save_unders: Bool, - root_input_mask: c_long, - pad: *c_void, + _width: c_int, + _height: c_int, + _mwidth: c_int, + _mheight: c_int, + _ndepths: c_int, + _depths: *mut Depth, + _root_depth: c_int, + _root_visual: *mut Visual, + _default_gc: GC, + _cmap: Colormap, + _white_pixel: c_ulong, + _black_pixel: c_ulong, + _max_maps: c_int, + _min_maps: c_int, + _backing_store: c_int, + _save_unders: Bool, + _root_input_mask: c_long, + _pad: *mut c_void, } struct ScreenFormat; struct XExtData; struct XVisualInfo { - visual: *Visual, - visualid: VisualID, - screen: c_int, - depth: c_int, - class: c_int, - red_mask: c_ulong, - green_mask: c_ulong, - blue_mask: c_ulong, - colormap_size: c_int, - bits_per_rgb: c_int, + _visual: *mut Visual, + _visualid: VisualID, + _screen: c_int, + _depth: c_int, + _class: c_int, + _red_mask: c_ulong, + _green_mask: c_ulong, + _blue_mask: c_ulong, + _colormap_size: c_int, + _bits_per_rgb: c_int, } type Bool = c_int; type Colormap = XID; type Drawable = c_uint; // compatible with Window -type GC = *c_void; -pub type GLXContext = *GLXContextOpaque; +type GC = *mut c_void; +pub type GLXContext = *mut GLXContextOpaque; type GLXDrawable = c_uint; // compatible with GLXPixmap type GLXPixmap = c_uint; // compatible with GLXDrawable type Pixmap = c_uint; type VisualID = c_ulong; type Window = c_uint; // compatible with Drawable type XID = c_uint; -type XPointer = *c_void; +type XPointer = *mut c_void; #[link(name = "X11")] #[link(name = "GL")] extern { - fn XOpenDisplay(n: c_int) -> *Display; - fn XCreatePixmap(display: *Display, d: Drawable, width: c_uint, height: c_uint, depth: c_uint) + fn XOpenDisplay(n: c_int) -> *mut Display; + fn XCreatePixmap(display: *mut Display, d: Drawable, width: c_uint, height: c_uint, depth: c_uint) -> Pixmap; - fn glXChooseVisual(dpy: *Display, screen: c_int, attribList: *c_int) -> *XVisualInfo; - fn glXCreateContext(dpy: *Display, vis: *XVisualInfo, shareList: GLXContext, direct: Bool) + fn glXChooseVisual(dpy: *mut Display, screen: c_int, attribList: *mut c_int) -> *mut XVisualInfo; + fn glXCreateContext(dpy: *mut Display, vis: *mut XVisualInfo, shareList: GLXContext, direct: Bool) -> GLXContext; - fn glXCreateGLXPixmap(dpy: *Display, vis: *XVisualInfo, pixmap: Pixmap) -> GLXPixmap; - fn glXMakeContextCurrent(dpy: *Display, draw: GLXDrawable, read: GLXDrawable, ctx: GLXContext) + fn glXCreateGLXPixmap(dpy: *mut Display, vis: *mut XVisualInfo, pixmap: Pixmap) -> GLXPixmap; + fn glXMakeContextCurrent(dpy: *mut Display, draw: GLXDrawable, read: GLXDrawable, ctx: GLXContext) -> Bool; } // X11 macros -fn DefaultScreen(dpy: *Display) -> c_int { +fn DefaultScreen(dpy: *mut Display) -> c_int { unsafe { (*dpy).default_screen } } -fn RootWindow(dpy: *Display, scr: c_int) -> Window { +fn RootWindow(dpy: *mut Display, scr: c_int) -> Window { unsafe { (*ScreenOfDisplay(dpy, scr)).root } } -fn ScreenOfDisplay(dpy: *Display, scr: c_int) -> *Screen { +fn ScreenOfDisplay(dpy: *mut Display, scr: c_int) -> *mut Screen { unsafe { (&(*dpy).screens).offset(scr as int) } @@ -171,7 +171,7 @@ fn ScreenOfDisplay(dpy: *Display, scr: c_int) -> *Screen { /// Linux-specific interface to 3D graphics contexts. pub struct GraphicsContext { - display: *Display, + display: *mut Display, pixmap: GLXPixmap, context: Arc, } @@ -183,14 +183,14 @@ impl GraphicsContext { unsafe { let context = match share_context { - None => glXCreateContext(display, visual, null(), 1), + None => glXCreateContext(display, visual, ptr::mut_null(), 1), Some(share_context) => { let native_share_context = share_context.native(); glXCreateContext(display, visual, *native_share_context, 1) } }; - assert!(context != null()); + assert!(context != ptr::mut_null()); GraphicsContext { display: display, @@ -200,13 +200,13 @@ impl GraphicsContext { } } - fn create_display_visual_and_pixmap() -> (*Display, *XVisualInfo, GLXPixmap) { + fn create_display_visual_and_pixmap() -> (*mut Display, *mut XVisualInfo, GLXPixmap) { unsafe { // Get a connection. let display = XOpenDisplay(0); // Get an appropriate visual. - let visual = glXChooseVisual(display, DefaultScreen(display), &ATTRIBUTES[0]); + let visual = glXChooseVisual(display, DefaultScreen(display), &mut ATTRIBUTES[0]); // Create the pixmap. let root_window = RootWindow(display, DefaultScreen(display)); diff --git a/platform/macos.rs b/platform/macos.rs index 6325755..499ca4d 100644 --- a/platform/macos.rs +++ b/platform/macos.rs @@ -38,7 +38,7 @@ impl GraphicsContext { unsafe { // Choose a pixel format. let attributes = [ kCGLPFADoubleBuffer, kCGLPFACompliant, 0 ]; - let mut pixel_format = ptr::null(); + let mut pixel_format = ptr::mut_null(); let mut pixel_format_count = 1; let gl_error = CGLChoosePixelFormat(mem::transmute(&attributes[0]), &mut pixel_format, @@ -46,12 +46,12 @@ impl GraphicsContext { assert!(gl_error == kCGLNoError); // Create the context. - let cgl_context = ptr::null(); + let mut cgl_context = ptr::mut_null(); let gl_error = match share_context { - None => CGLCreateContext(pixel_format, ptr::null(), &cgl_context), + None => CGLCreateContext(pixel_format, ptr::mut_null(), &mut cgl_context), Some(ref share_context) => { let native = share_context.native(); - CGLCreateContext(pixel_format, *native, &cgl_context) + CGLCreateContext(pixel_format, *native, &mut cgl_context) } }; assert!(gl_error == kCGLNoError); @@ -101,8 +101,8 @@ impl Clone for GraphicsContext { pub struct Context { surface: IOSurface, - framebuffer: GLuint, - texture: GLuint + _framebuffer: GLuint, + _texture: GLuint // FIXME: Needs drop. } @@ -208,8 +208,8 @@ impl ShareContext for Context { Context { surface: surface, - framebuffer: framebuffer, - texture: texture + _framebuffer: framebuffer, + _texture: texture } }