Skip to main content

fre_rs/types/
display.rs

1use super::*;
2
3
4crate::class! {@Typeof
5    /// A reference to the AS3 object `flash.display.BitmapData`.
6    /// 
7    /// Some properties and methods are not yet implemented.
8    /// 
9    BitmapData
10}
11impl<'a> BitmapData<'a> {
12    /// During the closure call stack, the Flash runtime is in a restricted state
13    /// where most APIs are unavailable, and [`Sync`] is used to prevent illegal
14    /// FFI call ordering.
15    /// 
16    pub fn with <F, R> (self, f: F) -> R
17    where F: Sync + FnOnce (BitmapDataAdapter) -> R
18    {
19        let mut descriptor = MaybeUninit::<FREBitmapData2>::uninit();
20        let result = unsafe {FREAcquireBitmapData2(self.as_ptr(), descriptor.as_mut_ptr())};
21        debug_assert!(result.is_ok(), "{}", FfiError::try_from(result).unwrap());
22        let descriptor = unsafe {descriptor.assume_init()};
23        let r = f(unsafe {BitmapDataAdapter::new(self.as_ptr(), descriptor)});
24        let result = unsafe {FREReleaseBitmapData(self.as_ptr())};
25        debug_assert!(result.is_ok(), "{}", FfiError::try_from(result).unwrap());
26        r
27    }
28}
29
30
31crate::class! {
32    /// A reference to the AS3 object `flash.display.NativeWindow`.
33    /// 
34    /// Some properties and methods are not yet implemented.
35    /// 
36    NativeWindow
37}
38impl<'a> NativeWindow<'a> {
39    pub fn get_stage(self) -> Stage<'a> {
40        let object = self.get_property(crate::ucstringify!(stage)).unwrap();
41        assert!(!object.is_null());
42        unsafe {object.as_unchecked()}
43    }
44
45    /// Passes the underlying native handle to the provided closure.
46    /// 
47    /// The [`NonNullHandle`] is only valid for the duration of this closure call.
48    /// 
49    /// During the closure call stack, the Flash runtime is in a restricted state
50    /// where most APIs are unavailable, and [`Sync`] is used to prevent illegal
51    /// FFI call ordering.
52    /// 
53    pub fn with <F, R> (self, f: F) -> R
54    where F: Sync + FnOnce (NonNullHandle) -> R
55    {
56        let mut handle = MaybeUninit::<FRENativeWindow>::uninit();
57        let result = unsafe {FREAcquireNativeWindowHandle(self.as_ptr(), handle.as_mut_ptr())};
58        assert!(result.is_ok());
59        let handle = unsafe {handle.assume_init()};
60        let handle = NonNullHandle::new(handle).unwrap();
61        let r = f(handle);
62        let result = unsafe {FREReleaseNativeWindowHandle(self.as_ptr())};
63        debug_assert!(result.is_ok());
64        r
65    }
66}
67
68
69crate::class! {
70    /// A reference to the AS3 object `flash.display.Stage`.
71    /// 
72    /// Some properties and methods are not yet implemented.
73    /// 
74    Stage
75}
76impl<'a> Stage<'a> {
77
78    /// The render mode of this stage.
79    ///
80    /// Use [`Context::get_render_mode`] with [`None`] for the main/initial stage.
81    /// 
82    pub fn render_mode(self) -> RenderMode {crate::context::stack::current_context().get_render_mode(Some(self))}
83
84    #[allow(non_snake_case)]
85    pub fn get_stage3Ds(self) -> Box<[Stage3D<'a>]> {
86        let object = self.get_property(crate::ucstringify!(stage3Ds)).unwrap();
87        assert!(!object.is_null());
88        let vector: Vector = unsafe {object.as_unchecked()};
89        let stage_3ds: Box<[Stage3D]> = vector.iter()
90            .map(|stage_3d|unsafe {stage_3d.as_unchecked()})
91            .collect();
92        stage_3ds
93    }
94}
95
96
97crate::class! {
98    /// A reference to the AS3 object `flash.display.Stage3D`.
99    /// 
100    /// Some properties and methods are not yet implemented.
101    /// 
102    Stage3D
103}
104impl<'a> Stage3D<'a> {
105    #[allow(non_snake_case)]
106    pub fn get_context3D(self) -> Option<Context3D<'a>> {
107        let object = self.get_property(crate::ucstringify!(context3D)).unwrap();
108        if object.is_null() {None} else {Some(unsafe {object.as_unchecked()})}
109    }
110}
111
112
113crate::class! {
114    /// A reference to the AS3 object `flash.display3D.Context3D`.
115    /// 
116    /// Some properties and methods are not yet implemented.
117    /// 
118    Context3D
119}
120impl<'a> Context3D<'a> {
121    /// Returns the underlying native handle.
122    /// 
123    /// See [`FREGetNativeContext3DHandle`] for details.
124    /// 
125    pub fn raw (self) -> NonNullHandle {
126        let mut handle = MaybeUninit::<FREHandle>::uninit();
127        let r = unsafe {FREGetNativeContext3DHandle(self.as_ptr(), handle.as_mut_ptr())};
128        debug_assert!(r.is_ok());
129        let handle = unsafe {handle.assume_init()};
130        NonNullHandle::new(handle).unwrap()
131    }
132}
133
134
135crate::class! {
136    /// A reference to the AS3 object `air.media.MediaBuffer`.
137    /// 
138    /// Some properties and methods are not yet implemented.
139    ///
140    MediaBuffer
141}
142impl<'a> MediaBuffer<'a> {
143
144    /// [`FRESetRenderSource`]
145    /// 
146    /// Returns [`Err`] if `display_object` has an incorrect type.
147    /// 
148    pub fn render_to (self, display_object: NonNullObject<'_>) -> Result<(), FfiError> {crate::context::stack::current_context().set_render_source(self, display_object)}
149
150    /// [`FREMediaBufferLock`] [`FREMediaBufferUnlock`]
151    /// 
152    pub fn with <F, R> (self, f: F) -> R
153    where F: FnOnce (MediaBufferDataAdapter) -> R {crate::context::stack::current_context().with_media_buffer(self, f)}
154}
155