2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
5 Desc: Cocoa Touch display HIDD for AROS
11 #include <aros/debug.h>
12 #include <aros/symbolsets.h>
14 #include <graphics/displayinfo.h>
15 #include <hidd/hidd.h>
16 #include <hidd/graphics.h>
17 #include <proto/alib.h>
18 #include <proto/exec.h>
19 #include <proto/hostlib.h>
20 #include <proto/oop.h>
21 #include <proto/utility.h>
24 #include "classbase.h"
27 /****************************************************************************************/
29 OOP_AttrBase HiddChunkyBMAttrBase
;
30 OOP_AttrBase HiddBitMapAttrBase
;
31 OOP_AttrBase HiddSyncAttrBase
;
32 OOP_AttrBase HiddPixFmtAttrBase
;
33 OOP_AttrBase HiddGfxAttrBase
;
34 OOP_AttrBase HiddAttrBase
;
36 static struct OOP_ABDescr attrbases
[] =
38 { IID_Hidd_ChunkyBM
, &HiddChunkyBMAttrBase
},
39 { IID_Hidd_BitMap
, &HiddBitMapAttrBase
},
40 { IID_Hidd_Sync
, &HiddSyncAttrBase
},
41 { IID_Hidd_PixFmt
, &HiddPixFmtAttrBase
},
42 { IID_Hidd_Gfx
, &HiddGfxAttrBase
},
43 { IID_Hidd
, &HiddAttrBase
},
47 /****************************************************************************************/
49 OOP_Object
*UIKit__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
51 struct TagItem pftags
[] =
53 /* Shifts are non-obviously calculated from the MSB, not from the LSB.
54 I. e. color value is placed in the most significant byte of the ULONG
55 before shifting (cc000000, not 000000cc) */
56 { aHidd_PixFmt_RedShift
, 24 },
57 { aHidd_PixFmt_GreenShift
, 16 },
58 { aHidd_PixFmt_BlueShift
, 8 },
59 { aHidd_PixFmt_AlphaShift
, 0 },
60 { aHidd_PixFmt_RedMask
, 0x000000FF },
61 { aHidd_PixFmt_GreenMask
, 0x0000FF00 },
62 { aHidd_PixFmt_BlueMask
, 0x00FF0000 },
63 { aHidd_PixFmt_AlphaMask
, 0x00000000 },
64 { aHidd_PixFmt_ColorModel
, vHidd_ColorModel_TrueColor
},
65 { aHidd_PixFmt_Depth
, 24 },
66 { aHidd_PixFmt_BytesPerPixel
, 4 },
67 { aHidd_PixFmt_BitsPerPixel
, 24 },
68 { aHidd_PixFmt_StdPixFmt
, vHidd_StdPixFmt_Native
},
69 { aHidd_PixFmt_BitMapType
, vHidd_BitMapType_Chunky
},
73 struct TagItem p_synctags
[] =
75 { aHidd_Sync_HDisp
, 160 },
76 { aHidd_Sync_VDisp
, 160 },
77 { aHidd_Sync_Description
, (IPTR
)"iOS: %hx%v Portrait"},
81 struct TagItem l_synctags
[] =
83 { aHidd_Sync_HDisp
, 160 },
84 { aHidd_Sync_VDisp
, 160 },
85 { aHidd_Sync_Description
, (IPTR
)"iOS: %hx%v Landscape"},
89 struct TagItem mode_tags
[] =
91 { aHidd_Gfx_PixFmtTags
, (IPTR
)pftags
},
92 { aHidd_Sync_HMin
, 112 }, /* In fact these can be even smaller, and */
93 { aHidd_Sync_VMin
, 112 }, /* maximum can be even bigger... */
94 { aHidd_Sync_HMax
, 16384 },
95 { aHidd_Sync_VMax
, 16384 },
96 { aHidd_Gfx_SyncTags
, (IPTR
)p_synctags
},
97 { aHidd_Gfx_SyncTags
, (IPTR
)l_synctags
},
101 struct TagItem mytags
[] =
103 { aHidd_Gfx_ModeTags
, (IPTR
)mode_tags
},
104 { aHidd_Name
, (IPTR
)"UIKit" },
105 { aHidd_HardwareName
, (IPTR
)"iOS Cocoa Touch"},
106 { aHidd_ProducerName
, (IPTR
)"Apple Corp." },
107 { TAG_MORE
, (IPTR
)msg
->attrList
}
109 struct pRoot_New mymsg
= { msg
->mID
, mytags
};
111 struct UIKitBase
*base
= cl
->UserData
;
113 EnterFunc(bug("UIKitGfx::New()\n"));
115 /* Create a display window. TODO: Support multuple displays. */
117 display
= base
->iface
->OpenDisplay(0);
123 D(bug("[UIKitGfx] Failed to create display window\n"));
127 if (base
->metrics
.orientation
== O_LANDSCAPE
)
129 l_synctags
[0].ti_Data
= base
->metrics
.width
;
130 l_synctags
[1].ti_Data
= base
->metrics
.height
- base
->metrics
.screenbar
;
132 p_synctags
[0].ti_Data
= base
->metrics
.height
;
133 p_synctags
[1].ti_Data
= base
->metrics
.width
- base
->metrics
.screenbar
;
137 p_synctags
[0].ti_Data
= base
->metrics
.width
;
138 p_synctags
[1].ti_Data
= base
->metrics
.height
- base
->metrics
.screenbar
;
140 l_synctags
[0].ti_Data
= base
->metrics
.height
;
141 l_synctags
[1].ti_Data
= base
->metrics
.width
- base
->metrics
.screenbar
;
144 /* Register gfxmodes */
145 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)&mymsg
);
148 struct gfx_data
*data
= OOP_INST_DATA(cl
, o
);
150 D(bug("UIKitGfx::New(): Got object from super\n"));
151 data
->display
= display
;
153 ReturnPtr("UIKitGfx::New", OOP_Object
*, o
);
156 /********** GfxHidd::Dispose() ******************************/
157 VOID
UIKit__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
159 struct UIKitBase
*base
= cl
->UserData
;
160 struct gfx_data
*data
= OOP_INST_DATA(cl
, o
);
163 base
->iface
->CloseDisplay(data
->display
);
167 D(bug("UIKitGfx::Dispose: calling super\n"));
168 OOP_DoSuperMethod(cl
, o
, msg
);
171 /****************************************************************************************/
173 OOP_Object
*UIKit__Hidd_Gfx__CreateObject(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_CreateObject
*msg
)
175 struct UIKitBase
*base
= cl
->UserData
;
176 OOP_Object
*object
= NULL
;
178 if (msg
->cl
== base
->basebm
)
181 struct pHidd_Gfx_CreateObject p
;
182 struct TagItem tags
[] =
185 {TAG_MORE
, (IPTR
)msg
->attrList
}
188 /* Here we select a class for the bitmap to create */
189 modeid
= GetTagData(aHidd_BitMap_ModeID
, vHidd_ModeID_Invalid
, msg
->attrList
);
190 if (modeid
!= vHidd_ModeID_Invalid
)
192 tags
[0].ti_Tag
= aHidd_BitMap_ClassPtr
;
193 tags
[0].ti_Data
= (IPTR
)base
->bmclass
;
195 D(bug("[UIKitGfx] ModeID: 0x%08lX, ClassPtr: 0x%p\n", modeid
, tags
[0].ti_Data
));
202 object
= OOP_DoSuperMethod(cl
, o
, &p
.mID
);
205 object
= OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
210 /****************************************************************************************/
212 VOID
UIKit__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
216 if (IS_GFX_ATTR(msg
->attrID
, idx
))
220 case aoHidd_Gfx_IsWindowed
:
221 case aoHidd_Gfx_NoFrameBuffer
:
222 *msg
->storage
= TRUE
;
225 case aoHidd_Gfx_DriverName
:
226 *msg
->storage
= (IPTR
)"CocoaTouch";
230 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
233 /****************************************************************************************/
235 ULONG
UIKit__Hidd_Gfx__ShowViewPorts(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_ShowViewPorts
*msg
)
241 /****************************************************************************************/
243 VOID
UIKit__Hidd_Gfx__CopyBox(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_CopyBox
*msg
)
248 /****************************************************************************************/
250 /* This is simple - all modes have the same properties */
251 static struct HIDD_ModeProperties mode_props
=
253 0, /* Ooops, we have no sprites */
255 COMPF_ABOVE
|COMPF_BELOW
|COMPF_LEFT
|COMPF_RIGHT
258 ULONG
UIKit__Hidd_Gfx__ModeProperties(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_ModeProperties
*msg
)
260 ULONG len
= msg
->propsLen
;
262 if (len
> sizeof(mode_props
))
263 len
= sizeof(mode_props
);
264 CopyMem(&mode_props
, msg
->props
, len
);
269 /****************************************************************************************/
271 static const char *symbols
[] =
282 static int UIKit_Init(struct UIKitBase
*base
)
286 D(bug("[UIKit] Initializing, base 0x%p\n", base
));
288 if (!OOP_ObtainAttrBases(attrbases
))
291 HostLibBase
= OpenResource("hostlib.resource");
295 base
->hostlib
= HostLib_Open("Libs/Host/uikit_hidd.dylib", NULL
);
299 base
->iface
= (struct UIKitInterface
*)HostLib_GetInterface(base
->hostlib
, symbols
, &r
);
305 D(bug("[UIKit] Failed to resolve %u symbols in native library\n", r
));
309 D(bug("[UIKit] Native library loaded successfully\n"));
313 /* Cache screen metrics. Status bar is always the same anyway. */
314 base
->iface
->GetMetrics(&base
->metrics
);
319 D(bug("[UIKit] Display %u x %u points, screenbar size %u\n", base
->metrics
.width
, base
->metrics
.height
, base
->metrics
.screenbar
));
321 base
->eventTask
= NewCreateTask(TASKTAG_PC
, EventTask
,
322 TASKTAG_NAME
, "Cocoa Touch events poll",
327 if (!base
->eventTask
)
333 /****************************************************************************************/
335 static int UIKit_Expunge(struct UIKitBase
*base
)
337 OOP_ReleaseAttrBases(attrbases
);
344 Signal(base
->eventTask
, SIGBREAKF_CTRL_C
);
345 /* FIXME: Response needed */
349 HostLib_DropInterface((void **)base
->iface
);
352 HostLib_Close(base
->hostlib
, NULL
);
357 /****************************************************************************************/
359 ADD2INITLIB(UIKit_Init
, 0);
360 ADD2EXPUNGELIB(UIKit_Expunge
, 0);