Commit 287fdde1 authored by Jeremy Soller's avatar Jeremy Soller

Update to new heap API

parent 79df020c
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
extern crate rusttype; extern crate rusttype;
use alloc::allocator::{Alloc, Layout}; use alloc::allocator::{Alloc, Layout};
use alloc::heap::Heap; use alloc::heap::Global;
use std::{cmp, slice}; use std::{cmp, slice};
use std::ptr::NonNull;
use primitive::{fast_set32, fast_set64, fast_copy}; use primitive::{fast_set32, fast_set64, fast_copy};
...@@ -42,7 +43,7 @@ impl Display { ...@@ -42,7 +43,7 @@ impl Display {
#[cfg(not(feature="rusttype"))] #[cfg(not(feature="rusttype"))]
pub fn new(width: usize, height: usize, onscreen: usize) -> Display { pub fn new(width: usize, height: usize, onscreen: usize) -> Display {
let size = width * height; let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() }; let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
unsafe { fast_set64(offscreen as *mut u64, 0, size/2) }; unsafe { fast_set64(offscreen as *mut u64, 0, size/2) };
Display { Display {
width: width, width: width,
...@@ -55,7 +56,7 @@ impl Display { ...@@ -55,7 +56,7 @@ impl Display {
#[cfg(feature="rusttype")] #[cfg(feature="rusttype")]
pub fn new(width: usize, height: usize, onscreen: usize) -> Display { pub fn new(width: usize, height: usize, onscreen: usize) -> Display {
let size = width * height; let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() }; let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
unsafe { fast_set64(offscreen as *mut u64, 0, size/2) }; unsafe { fast_set64(offscreen as *mut u64, 0, size/2) };
Display { Display {
width: width, width: width,
...@@ -74,7 +75,7 @@ impl Display { ...@@ -74,7 +75,7 @@ impl Display {
println!("Resize display to {}, {}", width, height); println!("Resize display to {}, {}", width, height);
let size = width * height; let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() }; let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
{ {
let mut old_ptr = self.offscreen.as_ptr(); let mut old_ptr = self.offscreen.as_ptr();
...@@ -107,7 +108,7 @@ impl Display { ...@@ -107,7 +108,7 @@ impl Display {
let onscreen = self.onscreen.as_mut_ptr(); let onscreen = self.onscreen.as_mut_ptr();
self.onscreen = unsafe { slice::from_raw_parts_mut(onscreen, size) }; self.onscreen = unsafe { slice::from_raw_parts_mut(onscreen, size) };
unsafe { Heap.dealloc(self.offscreen.as_mut_ptr() as *mut u8, Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) }; unsafe { Global.dealloc(NonNull::new_unchecked(self.offscreen.as_mut_ptr() as *mut u8).as_opaque(), Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
self.offscreen = unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) }; self.offscreen = unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) };
} else { } else {
println!("Display is already {}, {}", width, height); println!("Display is already {}, {}", width, height);
...@@ -276,6 +277,6 @@ impl Display { ...@@ -276,6 +277,6 @@ impl Display {
impl Drop for Display { impl Drop for Display {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { Heap.dealloc(self.offscreen.as_mut_ptr() as *mut u8, Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) }; unsafe { Global.dealloc(NonNull::new_unchecked(self.offscreen.as_mut_ptr() as *mut u8).as_opaque(), Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment