Skip to content

Remove librustrt, audio Task #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 22, 2014
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
59 changes: 3 additions & 56 deletions src/sdl2/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::c_vec::CVec;
use libc;
use libc::{c_int, size_t, c_void};
use libc::{uint8_t};
use rustrt::task::Task;

use get_error;
use rwops::RWops;
Expand Down Expand Up @@ -246,39 +245,9 @@ pub trait AudioCallback<T> {

/// The userdata as seen by the SDL callback.
struct AudioCallbackUserdata<CB> {
task: AudioCallbackTask,
callback: CB
}

/// A Task is required to use libstd from SDL's audio callback.
struct AudioCallbackTask {
/// Set to None if there was an error running a previous task.
task: Option<Box<Task>>
}

impl Drop for AudioCallbackTask {
/// Destroy the callback task.
fn drop(&mut self) {
use rustrt::local::Local;
use std::mem::replace;

// Swap out the task with None in order to own it, since drop() only
// provides a reference.
match replace(&mut self.task, None) {
Some(task) => {
// pop current task
let old_task = Local::take();

task.destroy();

// put task back
Local::put(old_task);
},
None => ()
};
}
}

/// A phantom type for retreiving the SDL_AudioFormat of a given generic type.
/// All format types are returned as native-endian.
///
Expand Down Expand Up @@ -329,25 +298,7 @@ extern "C" fn audio_callback_marshall<T: AudioFormatNum<T>, CB: AudioCallback<T>
len: len as uint / size_of::<T>()
});

// Perform a dance to move tasks around without compiler errors
let new_task = match replace(&mut cb_userdata.task.task, None) {
Some(task) => {
let n = task.run(|| {
cb_userdata.callback.callback(buf);
});

if n.is_destroyed() { None }
else { Some(n) }
},
None => {
// Last callback had an error. Fill buffer with silence.
for x in buf.iter_mut() { *x = AudioFormatNum::zero(); }

None
}
};

replace(&mut cb_userdata.task.task, new_task);
cb_userdata.callback.callback(buf);
}
}

Expand Down Expand Up @@ -377,11 +328,7 @@ impl<T: AudioFormatNum<T>, CB: AudioCallback<T>> AudioSpecDesired<T, CB> {
}

fn callback_to_userdata(callback: CB) -> Box<AudioCallbackUserdata<CB>> {
let mut task = box Task::new(None, None);
task.name = Some("SDL audio callback".into_cow());

box AudioCallbackUserdata {
task: AudioCallbackTask { task: Some(task) },
callback: callback
}
}
Expand Down Expand Up @@ -556,8 +503,8 @@ pub struct AudioCVT {
owned: bool,
}

impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT)
impl_owned_accessors!(AudioCVT, owned)
impl_raw_accessors!(AudioCVT, *mut ll::SDL_AudioCVT);
impl_owned_accessors!(AudioCVT, owned);

impl Drop for AudioCVT {
fn drop(&mut self) {
Expand Down
1 change: 0 additions & 1 deletion src/sdl2/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

extern crate libc;
extern crate collections;
extern crate rustrt;

pub use sdl::*;

Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ macro_rules! impl_raw_accessors(
}
)+
)
)
);

macro_rules! impl_owned_accessors(
($($t:ty, $owned:ident);+) => (
Expand All @@ -20,7 +20,7 @@ macro_rules! impl_owned_accessors(
}
)+
)
)
);

macro_rules! impl_raw_constructor(
($($t:ty -> $te:ident ($($r:ident:$rt:ty),+));+) => (
Expand All @@ -33,4 +33,4 @@ macro_rules! impl_raw_constructor(
}
)+
)
)
);
6 changes: 3 additions & 3 deletions src/sdl2/pixels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub struct Palette {
raw: *const ll::SDL_Palette
}

impl_raw_accessors!(Palette, *const ll::SDL_Palette)
impl_raw_accessors!(Palette, *const ll::SDL_Palette);

#[deriving(PartialEq, Clone, Copy)]
pub enum Color {
Expand Down Expand Up @@ -149,8 +149,8 @@ pub struct PixelFormat {
raw: *const ll::SDL_PixelFormat
}

impl_raw_accessors!(PixelFormat, *const ll::SDL_PixelFormat)
impl_raw_constructor!(PixelFormat -> PixelFormat (raw: *const ll::SDL_PixelFormat))
impl_raw_accessors!(PixelFormat, *const ll::SDL_PixelFormat);
impl_raw_constructor!(PixelFormat -> PixelFormat (raw: *const ll::SDL_PixelFormat));

#[deriving(Copy, Clone, PartialEq, Show, FromPrimitive)]
pub enum PixelFormatFlag {
Expand Down
4 changes: 2 additions & 2 deletions src/sdl2/rwops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ pub struct RWops {
close_on_drop: bool
}

impl_raw_accessors!(RWops, *const ll::SDL_RWops)
impl_owned_accessors!(RWops, close_on_drop)
impl_raw_accessors!(RWops, *const ll::SDL_RWops);
impl_owned_accessors!(RWops, close_on_drop);

/// A structure that provides an abstract interface to stream I/O.
impl RWops {
Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl Drop for Surface {
}
}

impl_raw_accessors!(Surface, *const ll::SDL_Surface)
impl_owned_accessors!(Surface, owned)
impl_raw_constructor!(Surface -> Surface (raw: *const ll::SDL_Surface, owned: bool))
impl_raw_accessors!(Surface, *const ll::SDL_Surface);
impl_owned_accessors!(Surface, owned);
impl_raw_constructor!(Surface -> Surface (raw: *const ll::SDL_Surface, owned: bool));

impl Surface {
pub fn new(surface_flags: SurfaceFlag, width: int, height: int, bpp: int,
Expand Down
6 changes: 3 additions & 3 deletions src/sdl2/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ pub struct Window {
impl_raw_accessors!(
GLContext, ll::SDL_GLContext;
Window, *const ll::SDL_Window
)
);

impl_owned_accessors!(
GLContext, owned;
Window, owned
)
);

impl_raw_constructor!(
Window -> Window (raw: *const ll::SDL_Window, owned: bool)
)
);

impl Drop for Window {
fn drop(&mut self) {
Expand Down