Skip to main content

fre_sys/
ffi.rs

1//! 
2//! Rust bindings for the C API declared in `<AIR-SDK>/include/FlashRuntimeExtensions.h`.
3//! 
4
5#![allow(non_snake_case)]
6
7use super::markers::*;
8use super::types::*;
9
10// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Initialization ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
11
12///
13/// Defines the signature for native calls that can be invoked via an
14/// instance of the AS `ExtensionContext` class.
15///
16/// @return    The return value corresponds to the return value
17///            from the AS `ExtensionContext` class `call()` method. It defaults to
18///            [`FREResult::FRE_INVALID_OBJECT`], which is reported as `null` in AS. 
19///
20pub type FREFunction = unsafe extern "C" fn (
21    ctx: FREContext,
22    functionData: FREData,
23    argc: uint32_t,
24    argv: *const FREObject,
25) -> FREObject;
26
27/// See [`FREFunction`].
28#[repr(C)]
29#[derive(Debug)]
30pub struct FRENamedFunction {
31    pub name: FREStr,
32    pub functionData: FREData,
33    pub function: FREFunction,
34}
35
36///
37/// Defines the signature for the initializer that is called each time
38/// a new AS `ExtensionContext` object is created.
39///
40/// @param `extData` The extension client data provided to the [`FREInitializer`] function as `extDataToSet`.
41///
42/// @param `ctxType` Pointer to the contextType string (UTF8) as provided to the AS `createExtensionContext` call.
43///
44/// @param `ctx` The [`FREContext`] being initialized.
45///
46/// @param `numFunctionsToSet` The number of elements in the `functionsToSet` array.
47///
48/// @param `functionsToSet` A pointer to an array of [`FRENamedFunction`] elements.
49///
50pub type FREContextInitializer = unsafe extern "C" fn (
51    extData: FREData,
52    ctxType: FREStr,
53    ctx: FREContext,
54    numFunctionsToSet: *mut uint32_t,
55    functionsToSet: *mut *const FRENamedFunction,
56);
57
58///
59/// Defines the signature for the finalizer that is called each time
60/// an `ExtensionContext` instance is disposed.
61///
62pub type FREContextFinalizer = Option<unsafe extern "C" fn (
63    ctx: FREContext
64)>;
65
66///
67/// The initialization function provided by each extension must conform
68/// to the following signature.
69///
70/// @param `extDataToSet` Provided for the extension to store per-extension instance data. 
71///            For example, if the extension creates
72///            globals per-instance, it can store a pointer to them here.
73///
74/// @param `ctxInitializerToSet` Must be set to a pointer to a function
75///            of type [`FREContextInitializer`]. Will be invoked whenever
76///            the ActionScript code creates a new context for this extension.
77///
78/// @param `ctxFinalizerToSet` Must be set to a pointer to a function
79///            of type [`FREContextFinalizer`].
80///
81pub type FREInitializer = unsafe extern "C" fn (
82    extDataToSet: *mut FREData,
83    ctxInitializerToSet: *mut FREContextInitializer,
84    ctxFinalizerToSet: *mut FREContextFinalizer,
85);
86
87///
88/// Called iff the extension is unloaded from the process. Extensions
89/// are not guaranteed to be unloaded; the runtime process may exit without
90/// doing so.
91///
92pub type FREFinalizer = Option<unsafe extern "C" fn (
93    extData: FREData,
94)>;
95
96// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Result Codes ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
97
98/// 
99/// These values must not be changed.
100///
101/// <https://help.adobe.com/en_US/air/extensions/WSb464b1207c184b14-2c95362d12937e5c13e-7ff8.html>
102#[derive(Debug, Clone, Copy, PartialEq, Eq)]
103#[repr(transparent)]
104pub struct FREResult(pub int32_t);
105impl FREResult {
106    pub const FRE_OK: Self                      = Self(0);
107    pub const FRE_NO_SUCH_NAME: Self            = Self(1);
108    pub const FRE_INVALID_OBJECT: Self          = Self(2);
109    pub const FRE_TYPE_MISMATCH: Self           = Self(3);
110    pub const FRE_ACTIONSCRIPT_ERROR: Self      = Self(4);
111    pub const FRE_INVALID_ARGUMENT: Self        = Self(5);
112    pub const FRE_READ_ONLY: Self               = Self(6);
113    pub const FRE_WRONG_THREAD: Self            = Self(7);
114    pub const FRE_ILLEGAL_STATE: Self           = Self(8);
115    pub const FRE_INSUFFICIENT_MEMORY: Self     = Self(9);
116    pub fn is_ok(self) -> bool {self == Self::FRE_OK}
117    pub fn is_err(self) -> bool {self != Self::FRE_OK}
118}
119impl std::fmt::Display for FREResult {
120    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
121}
122impl std::fmt::UpperHex for FREResult {
123    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
124}
125
126// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Context Data ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
127
128unsafe extern "C" {
129///
130/// @returns [`FREResult::FRE_OK`]
131///          [`FREResult::FRE_WRONG_THREAD`]
132///          [`FREResult::FRE_INVALID_ARGUMENT`] If `nativeData` is null.
133///
134pub fn FREGetContextNativeData(ctx: FREContext, nativeData: *mut FREData) -> FREResult;
135
136///
137/// @returns [`FREResult::FRE_OK`]
138///          [`FREResult::FRE_INVALID_ARGUMENT`]
139///          [`FREResult::FRE_WRONG_THREAD`]
140///
141pub fn FRESetContextNativeData(ctx: FREContext, nativeData: FREData) -> FREResult;
142
143///
144/// @returns [`FREResult::FRE_OK`]
145///          [`FREResult::FRE_WRONG_THREAD`]
146///          [`FREResult::FRE_INVALID_ARGUMENT`] If `actionScriptData` is null.
147///
148pub fn FREGetContextActionScriptData(ctx: FREContext, actionScriptData: *mut FREObject) -> FREResult;
149
150///
151/// @returns [`FREResult::FRE_OK`]
152///          [`FREResult::FRE_WRONG_THREAD`]
153/// 
154pub fn FRESetContextActionScriptData(ctx: FREContext, actionScriptData: FREObject) -> FREResult;
155}
156
157// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Primitive Types ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
158
159/// 
160/// These values must not be changed.
161///
162#[derive(Debug, Clone, Copy, PartialEq, Eq)]
163#[repr(transparent)]
164pub struct FREObjectType(pub int32_t);
165impl FREObjectType {
166    pub const FRE_TYPE_OBJECT: Self             = Self(0);
167    pub const FRE_TYPE_NUMBER: Self             = Self(1);
168    pub const FRE_TYPE_STRING: Self             = Self(2);
169    pub const FRE_TYPE_BYTEARRAY: Self          = Self(3);
170    pub const FRE_TYPE_ARRAY: Self              = Self(4);
171    pub const FRE_TYPE_VECTOR: Self             = Self(5);
172    pub const FRE_TYPE_BITMAPDATA: Self         = Self(6);
173    pub const FRE_TYPE_BOOLEAN: Self            = Self(7);
174    pub const FRE_TYPE_NULL: Self               = Self(8);
175    pub fn is_null(self) -> bool {self == Self::FRE_TYPE_NULL}
176}
177impl std::fmt::Display for FREObjectType {
178    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
179}
180impl std::fmt::UpperHex for FREObjectType {
181    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
182}
183
184unsafe extern "C" {
185///
186/// @returns [`FREResult::FRE_OK`]
187///          [`FREResult::FRE_INVALID_OBJECT`]
188///          [`FREResult::FRE_WRONG_THREAD`]
189///          [`FREResult::FRE_INVALID_ARGUMENT`] If `objectType` is null.
190///
191pub fn FREGetObjectType(object: FREObject, objectType: *mut FREObjectType) -> FREResult;
192
193///
194/// @returns [`FREResult::FRE_OK`]
195///          [`FREResult::FRE_TYPE_MISMATCH`]
196///          [`FREResult::FRE_INVALID_OBJECT`]
197///          [`FREResult::FRE_INVALID_ARGUMENT`]
198///          [`FREResult::FRE_WRONG_THREAD`]
199///
200pub fn FREGetObjectAsInt32(object: FREObject, value: *mut int32_t) -> FREResult;
201
202/// 
203/// Ses [`FREGetObjectAsInt32`].
204/// 
205pub fn FREGetObjectAsUint32(object: FREObject, value: *mut uint32_t) -> FREResult;
206
207/// 
208/// Ses [`FREGetObjectAsInt32`].
209/// 
210pub fn FREGetObjectAsDouble(object: FREObject, value: *mut double) -> FREResult;
211
212/// 
213/// Ses [`FREGetObjectAsInt32`].
214/// 
215pub fn FREGetObjectAsBool(object: FREObject, value: *mut FREBoolean) -> FREResult;
216
217///
218/// @returns [`FREResult::FRE_OK`]
219///          [`FREResult::FRE_INVALID_ARGUMENT`]
220///          [`FREResult::FRE_WRONG_THREAD`]
221/// 
222pub fn FRENewObjectFromInt32(value: int32_t, object: *mut FREObject) -> FREResult;
223
224/// 
225/// Ses [`FRENewObjectFromInt32`].
226/// 
227pub fn FRENewObjectFromUint32(value: uint32_t, object: *mut FREObject) -> FREResult;
228
229/// 
230/// Ses [`FRENewObjectFromInt32`].
231/// 
232pub fn FRENewObjectFromDouble(value: double, object: *mut FREObject) -> FREResult;
233/// 
234/// Ses [`FRENewObjectFromInt32`].
235/// 
236pub fn FRENewObjectFromBool(value: FREBoolean, object: *mut FREObject) -> FREResult;
237
238///
239/// Retrieves a string representation of the object referred to by
240/// the given object. The referenced string is immutable and valid 
241/// only for duration of the call to a registered function. If the 
242/// caller wishes to keep the the string, they must keep a copy of it.
243///
244/// @param `object` The string to be retrieved.
245///
246/// @param `length` The size, in bytes, of the string. Includes the
247///               null terminator. **(AIR-SDK-51.1.3.1) DOES NOT INCLUDE A NUL-TERMINATOR IN PRACTICE.**
248///
249/// @param `value`  A pointer to a possibly temporary copy of the string.
250///
251/// @return  [`FREResult::FRE_OK`]
252///          [`FREResult::FRE_TYPE_MISMATCH`]
253///          [`FREResult::FRE_INVALID_OBJECT`]
254///          [`FREResult::FRE_INVALID_ARGUMENT`]
255///          [`FREResult::FRE_WRONG_THREAD`]
256///
257pub fn FREGetObjectAsUTF8(object: FREObject, length: *mut uint32_t, value: *mut FREStr) -> FREResult;
258
259///
260/// Creates a new `String` object that contains a copy of the specified
261/// string.
262///
263/// @param `length` The length, in bytes, of the original string. Must include
264///               the null terminator.
265///
266/// @param `value`  A pointer to the original string.
267///
268/// @param `object` Receives a reference to the new string object.
269/// 
270/// @return  [`FREResult::FRE_OK`]
271///          [`FREResult::FRE_INVALID_ARGUMENT`]
272///          [`FREResult::FRE_WRONG_THREAD`]
273///
274pub fn FRENewObjectFromUTF8(length: uint32_t, value: FREStr, object: *mut FREObject) -> FREResult;
275
276// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Utility methods ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
277
278///
279/// Outputs a trace to the ActionScript debugger
280///
281/// @param `strTrace` A null-terminated string to output to the debugger.
282///
283/// @returns [`FREResult::FRE_OK`]
284///          [`FREResult::FRE_INVALID_ARGUMENT`] if `strTrace` is null
285///          [`FREResult::FRE_WRONG_THREAD`]
286///
287pub fn FRETrace(ctx: FREContext, strTrace: FREStr) -> FREResult;
288}
289
290#[derive(Debug, Clone, Copy, PartialEq, Eq)]
291#[repr(transparent)]
292pub struct FRERenderMode(pub int32_t);
293impl FRERenderMode {
294    pub const FRE_RENDERMODE_UNKNOWN: Self              = Self(0);
295    pub const FRE_RENDERMODE_NONE: Self                 = Self(1);
296    pub const FRE_RENDERMODE_CPU: Self                  = Self(2);
297    pub const FRE_RENDERMODE_DIRECT_OGLES: Self         = Self(3);
298    pub const FRE_RENDERMODE_DIRECT_OGL: Self           = Self(4);
299    pub const FRE_RENDERMODE_DIRECT_D3D9: Self          = Self(5);
300    pub const FRE_RENDERMODE_DIRECT_D3D10: Self         = Self(6);
301    pub const FRE_RENDERMODE_DIRECT_D3D11: Self         = Self(7);
302    pub const FRE_RENDERMODE_SOFTWARE_GDI: Self         = Self(8);
303    pub const FRE_RENDERMODE_GPU_OGLES: Self            = Self(9);
304}
305impl std::fmt::Display for FRERenderMode {
306    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
307}
308impl std::fmt::UpperHex for FRERenderMode {
309    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {self.0.fmt(f)}
310}
311
312unsafe extern "C" {
313///
314/// Returns the current render mode and mechanism for AIR
315///
316/// @param `stage` The AS3 `Stage` object for which to return the render mode. If this parameter
317///              is passed as NULL, the function will use the main/initial stage.
318///
319/// @param `pRenderMode` A pointer to a byte that will be populated with one
320///                    of the render modes from the [`FRERenderMode`] enumeration.
321///
322/// @returns [`FREResult::FRE_OK`]
323///          [`FREResult::FRE_INVALID_ARGUMENT`] if `pRenderMode` is null
324///          [`FREResult::FRE_INVALID_OBJECT`] if `stage` is non-null but not a `Stage` object
325///          [`FREResult::FRE_WRONG_THREAD`]
326///
327pub fn FREGetRenderMode(ctx: FREContext, stage: FREObject, pRenderMode: *mut uint8_t) -> FREResult;
328
329///
330/// Sets a `MediaBuffer` object as the rendering source for a `DisplayObject`.
331///
332/// @param `source` The AS3 `MediaBuffer` object that will be used to render into the display object.
333///
334/// @param `target` The AS3 `DisplayObject` object that will render the contents from the `MediaBuffer`.
335///
336/// @returns [`FREResult::FRE_OK`]
337///          [`FREResult::FRE_INVALID_ARGUMENT`] if either element is null
338///          [`FREResult::FRE_INVALID_OBJECT`] if the objects are incorrect types
339///          [`FREResult::FRE_WRONG_THREAD`]
340///
341pub fn FRESetRenderSource(ctx: FREContext, source: FREObject, target: FREObject) -> FREResult;
342
343///
344/// Locks a `MediaBuffer` bitmap and returns information about the data storage.
345///
346/// Note that for every call to [`FREMediaBufferLock`], a corresponding call to [`FREMediaBufferUnlock`] must be made.
347/// Ideally this would be as swift as possible, as locking a media buffer would impact rendering of any bitmap
348/// it contains. The unlock must be called prior to returning from the ANE function call though.
349///
350/// @param `ctx` The [`FREContext`] for the native extension instance.
351/// @param `mediaBuffer` The AS3 `MediaBuffer` object for which the image data is requested.
352/// @param `pData` Pointer to a byte pointer that will be set to the internal image data.
353/// @param `pWidth` Pointer to a value that will be set to the width of the image data.
354/// @param `pHeight` Pointer to a value that will be set to the height of the image data.
355/// @param `pStride` Pointer to a value that will be set to the stride i.e. number of bytes between the start of each row on the image.
356/// @param `pFormat` Pointer to a value that will be set to a format value (for future usage: currently images are ARGB format).
357///
358/// @returns [`FREResult::FRE_OK`]
359///          [`FREResult::FRE_INVALID_ARGUMENT`] if any parameter is null
360///          [`FREResult::FRE_INVALID_OBJECT`] if the `MediaBuffer` objects has an incorrect type
361///          [`FREResult::FRE_WRONG_THREAD`] if called from the wrong thread; at some point this function will be updated to allow multi-thread calling
362///
363pub fn FREMediaBufferLock(
364    ctx: FREContext,
365    mediaBuffer: FREObject,
366    pData: *mut FREBytes,
367    pWidth: *mut uint32_t,
368    pHeight: *mut uint32_t,
369    pStride: *mut uint32_t,
370    pFormat: *mut uint32_t,
371) -> FREResult;
372
373///
374/// Unlocks a `MediaBuffer` bitmap.
375///
376/// Currently the `bUpdate` parameter is ignored: changes to the data provided by the [`FREMediaBufferLock`] function will
377/// always have an impact on the rendered bitmap. This parameter is provided to allow for future flexibility.
378///
379/// @param `ctx` The [`FREContext`] for the native extension instance.
380/// @param `mediaBuffer` The AS3 `MediaBuffer` object for which the image data is released.
381/// @param `bUpdate` Whether to use the updated data for rendering. Note that this parameter may not have any effect.
382///
383/// @returns [`FREResult::FRE_OK`]
384///          [`FREResult::FRE_INVALID_ARGUMENT`] if the `ctx` or `mediaBuffer` parameter is null
385///          [`FREResult::FRE_INVALID_OBJECT`] if the `MediaBuffer` objects has an incorrect type
386///          [`FREResult::FRE_WRONG_THREAD`] if called from the wrong thread; at some point this function will be updated to allow multi-thread calling
387///
388pub fn FREMediaBufferUnlock(ctx: FREContext, mediaBuffer: FREObject, bUpdate: uint32_t) -> FREResult;
389
390// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Object Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
391
392///
393/// @param `className` UTF8-encoded name of the class being constructed.
394///
395/// @param `thrownException` A pointer to a handle that can receive the handle of any ActionScript 
396///            `Error` thrown during execution. May be null if the caller does not
397///            want to receive this handle. If not null and no error occurs, is set an
398///            invalid handle value.
399///
400/// @return  [`FREResult::FRE_OK`]
401///          [`FREResult::FRE_TYPE_MISMATCH`]
402///          [`FREResult::FRE_INVALID_OBJECT`]
403///          [`FREResult::FRE_INVALID_ARGUMENT`]
404///          [`FREResult::FRE_ACTIONSCRIPT_ERROR`] If an ActionScript exception results from calling this method.
405///              In this case, `thrownException` will be set to the handle of the thrown value. 
406///          [`FREResult::FRE_ILLEGAL_STATE`] If a `ByteArray` or `BitmapData` has been acquired and not yet released.
407///          [`FREResult::FRE_NO_SUCH_NAME`]
408///          [`FREResult::FRE_WRONG_THREAD`]
409///
410pub fn FRENewObject(
411    className: FREStr,
412    argc: uint32_t,
413    argv: *mut FREObject,
414    object: *mut FREObject,
415    thrownException: *mut FREObject,
416) -> FREResult;
417
418///
419/// @param `propertyName` UTF8-encoded name of the property being fetched.
420///
421/// @param `thrownException` A pointer to a handle that can receive the handle of any ActionScript 
422///            `Error` thrown during getting the property. May be null if the caller does not
423///            want to receive this handle. If not null and no error occurs, is set an
424///            invalid handle value.
425///
426/// @return  [`FREResult::FRE_OK`]
427///          [`FREResult::FRE_TYPE_MISMATCH`]
428///          [`FREResult::FRE_INVALID_OBJECT`]
429///          [`FREResult::FRE_INVALID_ARGUMENT`]
430///          [`FREResult::FRE_ACTIONSCRIPT_ERROR`] If an ActionScript exception results from getting this property.
431///              In this case, `thrownException` will be set to the handle of the thrown value. 
432///          [`FREResult::FRE_NO_SUCH_NAME`] If the named property doesn't exist, or if the reference is ambiguous
433///              because the property exists in more than one namespace.
434///          [`FREResult::FRE_ILLEGAL_STATE`] If a `ByteArray` or `BitmapData` has been acquired and not yet released.
435///          [`FREResult::FRE_WRONG_THREAD`]
436///
437pub fn FREGetObjectProperty(
438    object: FREObject,
439    propertyName: FREStr,
440    propertyValue: *mut FREObject,
441    thrownException: *mut FREObject,
442) -> FREResult;
443
444///
445/// @param `propertyName` UTF8-encoded name of the property being set.
446///
447/// @param `thrownException` A pointer to a handle that can receive the handle of any ActionScript 
448///            `Error` thrown during method execution. May be null if the caller does not
449///            want to receive this handle. If not null and no error occurs, is set an
450///            invalid handle value.
451///
452/// @return  [`FREResult::FRE_OK`]
453///          [`FREResult::FRE_TYPE_MISMATCH`]
454///          [`FREResult::FRE_INVALID_OBJECT`]
455///          [`FREResult::FRE_INVALID_ARGUMENT`]
456///          [`FREResult::FRE_ACTIONSCRIPT_ERROR`] If an ActionScript exception results from getting this property.
457///              In this case, `thrownException` will be set to the handle of the thrown value. 
458///          [`FREResult::FRE_NO_SUCH_NAME`] If the named property doesn't exist, or if the reference is ambiguous
459///              because the property exists in more than one namespace.
460///          [`FREResult::FRE_ILLEGAL_STATE`] If a `ByteArray` or `BitmapData` has been acquired and not yet released.
461///          [`FREResult::FRE_READ_ONLY`]
462///          [`FREResult::FRE_WRONG_THREAD`]
463///
464pub fn FRESetObjectProperty(
465    object: FREObject,
466    propertyName: FREStr,
467    propertyValue: FREObject,
468    thrownException: *mut FREObject,
469) -> FREResult;
470
471///
472/// @param `methodName` UTF8-encoded null-terminated name of the method being invoked.
473///
474/// @param `thrownException` A pointer to a handle that can receive the handle of any ActionScript 
475///            `Error` thrown during method execution. May be null if the caller does not
476///            want to receive this handle. If not null and no error occurs, is set an
477///            invalid handle value.
478///
479/// @return  [`FREResult::FRE_OK`]
480///          [`FREResult::FRE_TYPE_MISMATCH`]
481///          [`FREResult::FRE_INVALID_OBJECT`]
482///          [`FREResult::FRE_INVALID_ARGUMENT`]
483///          [`FREResult::FRE_ACTIONSCRIPT_ERROR`] If an ActionScript exception results from calling this method.
484///              In this case, `thrownException` will be set to the handle of the thrown value. 
485///          [`FREResult::FRE_NO_SUCH_NAME`] If the named method doesn't exist, or if the reference is ambiguous
486///              because the method exists in more than one namespace.
487///          [`FREResult::FRE_ILLEGAL_STATE`] If a `ByteArray` or `BitmapData` has been acquired and not yet released.
488///          [`FREResult::FRE_WRONG_THREAD`]
489///
490pub fn FRECallObjectMethod(
491    object: FREObject,
492    methodName: FREStr,
493    argc: uint32_t,
494    argv: *mut FREObject,
495    result: *mut FREObject,
496    thrownException: *mut FREObject,
497) -> FREResult;
498}
499
500// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BitmapData Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
501
502#[derive(Debug, Default)]
503#[repr(C)]
504pub struct FREBitmapData {
505    /// width of the `BitmapData` bitmap
506    pub width: uint32_t,
507    /// height of the `BitmapData` bitmap
508    pub height: uint32_t,
509    /// if non-zero, pixel format is ARGB32, otherwise pixel format is _RGB32, host endianness
510    pub hasAlpha: FREBoolean,
511    /// pixel color values are premultiplied with alpha if non-zero, un-multiplied if zero
512    pub isPremultiplied: FREBoolean,
513    /// line stride in number of 32 bit values, typically the same as `width`
514    pub lineStride32: uint32_t,
515    /// pointer to the first 32-bit pixel of the bitmap data
516    pub bits32: *mut uint32_t,
517}
518
519#[derive(Debug, Default)]
520#[repr(C)]
521pub struct FREBitmapData2 {
522    /// width of the `BitmapData` bitmap
523    pub width: uint32_t,
524    /// height of the `BitmapData` bitmap
525    pub height: uint32_t,
526    /// if non-zero, pixel format is ARGB32, otherwise pixel format is _RGB32, host endianness
527    pub hasAlpha: FREBoolean,
528    /// pixel color values are premultiplied with alpha if non-zero, un-multiplied if zero
529    pub isPremultiplied: FREBoolean,
530    /// line stride in number of 32 bit values, typically the same as `width`
531    pub lineStride32: uint32_t,
532    /// if non-zero, last row of pixels starts at bits32, otherwise, first row of pixels starts at bits32.
533    pub isInvertedY: FREBoolean,
534    /// pointer to the first 32-bit pixel of the bitmap data
535    pub bits32: *mut uint32_t,
536}
537
538unsafe extern "C" {
539///
540/// Referenced data is valid only for duration of the call
541/// to a registered function.
542///
543/// @return  [`FREResult::FRE_OK`]
544///          [`FREResult::FRE_TYPE_MISMATCH`]
545///          [`FREResult::FRE_INVALID_OBJECT`]
546///          [`FREResult::FRE_INVALID_ARGUMENT`]
547///          [`FREResult::FRE_WRONG_THREAD`]
548///          [`FREResult::FRE_ILLEGAL_STATE`]
549///
550pub fn FREAcquireBitmapData(
551    object: FREObject,
552    descriptorToSet: *mut FREBitmapData,
553) -> FREResult;
554
555///
556/// Referenced data is valid only for duration of the call
557/// to a registered function.
558///
559/// Use of this API requires that the extension and application must be packaged for 
560/// the 3.1 namespace or later.
561///
562/// @return  [`FREResult::FRE_OK`]
563///          [`FREResult::FRE_TYPE_MISMATCH`]
564///          [`FREResult::FRE_INVALID_OBJECT`]
565///          [`FREResult::FRE_INVALID_ARGUMENT`]
566///          [`FREResult::FRE_WRONG_THREAD`]
567///          [`FREResult::FRE_ILLEGAL_STATE`]
568///
569pub fn FREAcquireBitmapData2(
570    object: FREObject,
571    descriptorToSet: *mut FREBitmapData2
572) -> FREResult;
573
574///
575/// `BitmapData` must be acquired to call this. Clients must invalidate any region
576/// they modify in order to notify AIR of the changes. Only invalidated regions
577/// are redrawn.
578///
579/// @return  [`FREResult::FRE_OK`]
580///          [`FREResult::FRE_INVALID_OBJECT`]
581///          [`FREResult::FRE_WRONG_THREAD`]
582///          [`FREResult::FRE_ILLEGAL_STATE`]
583///          [`FREResult::FRE_TYPE_MISMATCH`]
584///
585pub fn FREInvalidateBitmapDataRect(
586    object: FREObject,
587    x: uint32_t,
588    y: uint32_t,
589    width: uint32_t,
590    height: uint32_t,
591) -> FREResult;
592
593///
594/// Release data that has been acquired with an earlier call to [`FREAcquireBitmapData`] or [`FREAcquireBitmapData2`]
595///
596/// @return  [`FREResult::FRE_OK`]
597///          [`FREResult::FRE_WRONG_THREAD`]
598///          [`FREResult::FRE_ILLEGAL_STATE`]
599///          [`FREResult::FRE_TYPE_MISMATCH`]
600///
601pub fn FREReleaseBitmapData(object: FREObject) -> FREResult;
602}
603
604// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ByteArray Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
605
606#[derive(Debug)]
607#[repr(C)]
608pub struct FREByteArray {
609    pub length: uint32_t,
610    pub bytes: FREBytes,
611}
612
613unsafe extern "C" {
614///
615/// Creates a new byte array using optional input information (`length` and optional `byte`)
616///
617/// @return  [`FREResult::FRE_OK`]
618///          [`FREResult::FRE_INVALID_ARGUMENT`]
619///          [`FREResult::FRE_WRONG_THREAD`]
620///          [`FREResult::FRE_ILLEGAL_STATE`]
621///
622pub fn FRENewByteArray(
623    byteArrayData: *mut FREByteArray,
624    handle: *mut FREObject,
625) -> FREResult;
626
627///
628/// Referenced data is valid only for duration of the call
629/// to a registered function.
630///
631/// @return  [`FREResult::FRE_OK`]
632///          [`FREResult::FRE_TYPE_MISMATCH`]
633///          [`FREResult::FRE_INVALID_OBJECT`]
634///          [`FREResult::FRE_INVALID_ARGUMENT`]
635///          [`FREResult::FRE_WRONG_THREAD`]
636///          [`FREResult::FRE_ILLEGAL_STATE`]
637///
638pub fn FREAcquireByteArray(
639    object: FREObject,
640    byteArrayToSet: *mut FREByteArray,
641) -> FREResult;
642
643///
644/// @return  [`FREResult::FRE_OK`]
645///          [`FREResult::FRE_INVALID_OBJECT`]
646///          [`FREResult::FRE_ILLEGAL_STATE`]
647///          [`FREResult::FRE_WRONG_THREAD`]
648///
649pub fn FREReleaseByteArray(object: FREObject) -> FREResult;
650
651// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Array and Vector Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
652
653///
654/// @return  [`FREResult::FRE_OK`]
655///          [`FREResult::FRE_INVALID_OBJECT`]
656///          [`FREResult::FRE_INVALID_ARGUMENT`]
657///          [`FREResult::FRE_ILLEGAL_STATE`]
658///          [`FREResult::FRE_TYPE_MISMATCH`]
659///          [`FREResult::FRE_WRONG_THREAD`]
660///
661pub fn FREGetArrayLength(
662    arrayOrVector: FREObject,
663    length: *mut uint32_t,
664) -> FREResult;
665
666///
667/// @return  [`FREResult::FRE_OK`]
668///          [`FREResult::FRE_INVALID_OBJECT`]
669///          [`FREResult::FRE_TYPE_MISMATCH`]
670///          [`FREResult::FRE_ILLEGAL_STATE`]
671///          [`FREResult::FRE_INVALID_ARGUMENT`] If `length` is greater than 2^32.
672///          [`FREResult::FRE_READ_ONLY`]   If the handle refers to a `Vector`
673///              of fixed size.
674///          [`FREResult::FRE_WRONG_THREAD`]
675///          [`FREResult::FRE_INSUFFICIENT_MEMORY`]
676///
677pub fn FRESetArrayLength(
678    arrayOrVector: FREObject,
679    length: uint32_t,
680) -> FREResult;
681
682///
683/// If an `Array` is sparse and an element that isn't defined is requested, the
684/// return value will be FRE_OK but the handle value will be invalid.
685///
686/// @return  [`FREResult::FRE_OK`]
687///          [`FREResult::FRE_ILLEGAL_STATE`]
688///          [`FREResult::FRE_INVALID_ARGUMENT`] If the handle refers to a vector and the index is
689///              greater than the size of the array.
690///          [`FREResult::FRE_INVALID_OBJECT`]
691///          [`FREResult::FRE_TYPE_MISMATCH`]
692///          [`FREResult::FRE_WRONG_THREAD`]
693///
694pub fn FREGetArrayElementAt(
695    arrayOrVector: FREObject,
696    index: uint32_t,
697    value: *mut FREObject,
698) -> FREResult;
699
700///
701///
702/// @return  [`FREResult::FRE_OK`]
703///          [`FREResult::FRE_INVALID_OBJECT`]
704///          [`FREResult::FRE_ILLEGAL_STATE`]
705///          [`FREResult::FRE_TYPE_MISMATCH`] If an attempt to made to set a value in a `Vector`
706///              when the type of the value doesn't match the `Vector`'s item type.
707///          [`FREResult::FRE_WRONG_THREAD`]
708///
709pub fn FRESetArrayElementAt(
710    arrayOrVector: FREObject,
711    index: uint32_t,
712    value: FREObject,
713) -> FREResult;
714
715// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ NativeWindow Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
716
717///
718/// Referenced handle is valid only for duration of the call
719/// to a registered function.
720///
721/// @return  [`FREResult::FRE_OK`]
722///          [`FREResult::FRE_TYPE_MISMATCH`]
723///          [`FREResult::FRE_INVALID_OBJECT`]
724///          [`FREResult::FRE_INVALID_ARGUMENT`]
725///          [`FREResult::FRE_WRONG_THREAD`]
726///          [`FREResult::FRE_ILLEGAL_STATE`]
727///
728pub fn FREAcquireNativeWindowHandle(
729    nativeWindow: FREObject,
730    handle: *mut FRENativeWindow,
731) -> FREResult;
732
733///
734/// @return  [`FREResult::FRE_OK`]
735///          [`FREResult::FRE_INVALID_OBJECT`]
736///          [`FREResult::FRE_ILLEGAL_STATE`]
737///          [`FREResult::FRE_WRONG_THREAD`]
738///
739pub fn FREReleaseNativeWindowHandle(nativeWindow: FREObject) -> FREResult;
740
741///
742/// Access the native context type for a `Context3D` object. The type depends on the
743/// render mode: currently this is only valid for OpenGL ES rendering and will return
744/// an `EGLContext` object. This object should be valid until the `Context3D` object is
745/// disposed, or the device/application loses the graphics context.
746///
747/// **Example usage in C :**
748/// ```c
749/// EGLContext airContext = EGL_NO_CONTEXT;
750/// if ( (FRE_OK == FREGetNativeContext3DHandle(args[0], (void**)&airContext)) && (airContext != EGL_NO_CONTEXT) )
751/// // ... do something with the handle ...
752/// ```
753///
754/// @return  [`FREResult::FRE_OK`]
755///          [`FREResult::FRE_TYPE_MISMATCH`]
756///          [`FREResult::FRE_INVALID_OBJECT`]
757///          [`FREResult::FRE_INVALID_ARGUMENT`]
758///          [`FREResult::FRE_WRONG_THREAD`]
759///          [`FREResult::FRE_ILLEGAL_STATE`]
760///
761pub fn FREGetNativeContext3DHandle(
762    context3D: FREObject,
763    handle: *mut FREHandle,
764) -> FREResult;
765
766// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Extension Context Access ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
767
768///
769/// Get the [`FREContext`] object associated with any `ExtensionContext` object. Note that
770/// the [`FREContext`] object may become invalid based on what happens with the other `ExtensionContext`,
771/// so this value should not be cached between function calls.
772///
773/// @param `objExtensionContext` The `ExtensionContext` (ActionScript object) for which the [`FREContext`] handle is required.
774///
775/// @param `pContext` The [`FREContext`] (C handle) associated with the given `ExtensionContext`.
776///
777/// @return  [`FREResult::FRE_OK`]
778///          [`FREResult::FRE_TYPE_MISMATCH`]
779///          [`FREResult::FRE_INVALID_OBJECT`]
780///          [`FREResult::FRE_INVALID_ARGUMENT`]
781///          [`FREResult::FRE_WRONG_THREAD`]
782///          [`FREResult::FRE_ILLEGAL_STATE`]
783///
784pub fn FREGetFREContextFromExtensionContext(
785    objExtensionContext: FREObject,
786    pContext: *mut FREContext,
787) -> FREResult;
788
789// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Callbacks ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
790
791///
792/// Causes a `StatusEvent` to be dispatched from the associated
793/// `ExtensionContext` object.
794///
795/// Dispatch happens asynchronously, even if this is called during
796/// a call to a registered function.
797///
798/// The ActionScript portion of this extension can listen for that event
799/// and, upon receipt, query the native portion for details of the event
800/// that occurred.
801///
802/// This call is thread-safe and may be invoked from any thread. The string
803/// values are copied before the call returns.
804///
805/// @return  [`FREResult::FRE_OK`] In all circumstances, as the referenced object cannot
806///              necessarily be checked for validity on the invoking thread.
807///              However, no event will be dispatched if the object is
808///              invalid or not an `EventDispatcher`.
809///          [`FREResult::FRE_INVALID_ARGUMENT`] If code or level is NULL
810///
811pub fn FREDispatchStatusEventAsync(
812    ctx: FREContext,
813    code: FREStr,
814    level: FREStr,
815) -> FREResult;
816}