2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 #include <proto/exec.h>
8 #include <proto/arossupport.h>
9 #include <proto/utility.h>
10 #include <proto/graphics.h>
12 #include <exec/lists.h>
13 #include <exec/memory.h>
15 #include <graphics/displayinfo.h>
16 #include <graphics/monitor.h>
18 #include <cybergraphx/cybergraphics.h>
22 #include <hidd/graphics.h>
27 #include "graphics_intern.h"
28 #include "graphics_internal.h"
29 #include "gfxfuncsupport.h"
33 #include <aros/debug.h>
35 HIDDT_ModeID
get_hiddmode_for_amigamodeid(ULONG modeid
, struct GfxBase
*GfxBase
)
37 return AMIGA_TO_HIDD_MODEID(modeid
);
40 VOID
destroy_dispinfo_db(APTR dispinfo_db
, struct GfxBase
*GfxBase
)
42 struct displayinfo_db
*db
;
44 db
= (struct displayinfo_db
*)dispinfo_db
;
46 ObtainSemaphore(&db
->sema
);
48 if (NULL
!= db
->mspecs
) {
49 FreeMem(db
->mspecs
, sizeof (struct MonitorSpec
) * db
->num_mspecs
);
54 ReleaseSemaphore(&db
->sema
);
56 FreeMem(db
, sizeof (*db
));
60 APTR
build_dispinfo_db(struct GfxBase
*GfxBase
)
62 struct displayinfo_db
*db
;
65 db
= AllocMem(sizeof (struct displayinfo_db
), MEMF_PUBLIC
| MEMF_CLEAR
);
68 InitSemaphore(&db
->sema
);
70 /* Get the number of possible modes in the gfxhidd */
71 OOP_GetAttr(SDD(GfxBase
)->gfxhidd
, aHidd_Gfx_NumSyncs
, &numsyncs
);
73 db
->num_mspecs
= numsyncs
;
75 /* Allocate a table to hold all the monitorspecs */
76 db
->mspecs
= AllocMem(sizeof (struct MonitorSpec
) * db
->num_mspecs
, MEMF_PUBLIC
| MEMF_CLEAR
);
77 if (NULL
!= db
->mspecs
) {
80 destroy_dispinfo_db(db
, GfxBase
);
86 #warning Implement Display mode attributes in the below function
88 VOID
driver_FreeCModeList(struct List
*modeList
, struct GfxBase
*GfxBase
)
90 struct CyberModeNode
*node
, *safe
;
92 ForeachNodeSafe(modeList
, node
, safe
) {
93 Remove((struct Node
*)node
);
94 FreeMem(node
, sizeof (struct CyberModeNode
));
97 FreeMem(modeList
, sizeof (struct List
));
100 APTR
driver_AllocCModeListTagList(struct TagItem
*taglist
, struct GfxBase
*GfxBase
)
102 struct TagItem
*tag
, *tstate
;
104 ULONG minwidth
= 320;
105 ULONG maxwidth
= 1600;
106 ULONG minheight
= 240;
107 ULONG maxheight
= 1200;
111 struct List
*cybermlist
= NULL
;
115 UWORD
*cmodelarray
= NULL
;
116 HIDDT_ModeID
*hiddmodes
= NULL
, *hmptr
;
117 struct TagItem querytags
[] = { { TAG_DONE
, 0UL } };
119 gfxhidd
= SDD(GfxBase
)->gfxhidd
;
121 for (tstate
= taglist
; (tag
= NextTagItem(&tstate
)); ) {
122 switch (tag
->ti_Tag
) {
123 case CYBRMREQ_MinWidth
:
124 minwidth
= (ULONG
)tag
->ti_Data
;
127 case CYBRMREQ_MaxWidth
:
128 maxwidth
= (ULONG
)tag
->ti_Data
;
131 case CYBRMREQ_MinHeight
:
132 minheight
= (ULONG
)tag
->ti_Data
;
135 case CYBRMREQ_MaxHeight
:
136 maxheight
= (ULONG
)tag
->ti_Data
;
139 case CYBRMREQ_MinDepth
:
140 mindepth
= (ULONG
)tag
->ti_Data
;
143 case CYBRMREQ_MaxDepth
:
144 maxdepth
= (ULONG
)tag
->ti_Data
;
147 case CYBRMREQ_CModelArray
:
148 cmodelarray
= (UWORD
*)tag
->ti_Data
;
152 D(bug("!!! UNKNOWN TAG PASSED TO AllocCModeListTagList\n"));
157 /* Allocate the exec list */
158 cybermlist
= AllocMem(sizeof (struct List
), MEMF_CLEAR
);
159 if (NULL
== cybermlist
)
165 /* Get all HIDD modes */
166 hiddmodes
= HIDD_Gfx_QueryModeIDs(gfxhidd
, querytags
);
167 if (NULL
== hiddmodes
)
171 for (hmptr
= hiddmodes
; *hmptr
!= vHidd_ModeID_Invalid
; hmptr
++) {
173 struct CyberModeNode
*cmnode
;
175 IPTR width
, height
, depth
;
176 OOP_Object
*sync
, *pf
;
178 if (!HIDD_Gfx_GetMode(gfxhidd
, *hmptr
, &sync
, &pf
)) {
179 /* This should never happen because HIDD_GfxWueryModeIDs() should
180 only return valid modes
182 D(bug("!!! UNABLE TO GET HIDD MODE INFO IN AllocCModeListTagList() !!!\n"));
183 D(bug("!!! THIS SHOULD *NEVER* HAPPEN !!!\n"));
187 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &width
);
188 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &height
);
190 if ( width
< minwidth
192 || height
< minheight
193 || height
> maxheight
) {
198 /* Get the pxifmt info */
199 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
201 if (depth
< mindepth
|| depth
> maxdepth
)
204 /* Check whether the gfxmode is the correct pixel format */
205 if (NULL
!= cmodelarray
) {
206 HIDDT_StdPixFmt stdpf
;
210 /* Get the gfxmode pixelf format */
211 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
213 cyberpf
= hidd2cyber_pixfmt(stdpf
, GfxBase
);
214 if (cyberpf
== (UWORD
)-1)
215 continue; /* Unknown format */
217 for (cyberpixfmts
= cmodelarray
; *cyberpixfmts
; cyberpixfmts
++) {
218 /* See if the stdpixfmt is present in the array */
219 if (*cyberpixfmts
== cyberpf
) {
223 } /* for (each supplied pixelformat in the cmodelarray) */
226 continue; /* PixFmt not wanted, just continue with next node */
228 } /* if (cmodelarray supplied in the taglist) */
230 /* Allocate a cybergfx modeinfo struct */
231 cmnode
= AllocMem(sizeof (struct CyberModeNode
), MEMF_CLEAR
);
235 cmnode
->Width
= width
;
236 cmnode
->Height
= height
;
237 cmnode
->Depth
= depth
;
238 cmnode
->DisplayTagList
= NULL
;
240 snprintf( cmnode
->ModeText
242 , "AROS: %ldx%ldx%ld"
243 , width
, height
, depth
246 /* Keep track of the node */
247 AddTail(cybermlist
, (struct Node
*)cmnode
);
249 } /* for (modeids returned from the HIDD) */
255 if (NULL
!= hiddmodes
)
256 HIDD_Gfx_ReleaseModeIDs(gfxhidd
, hiddmodes
);
258 if (NULL
!= cybermlist
)
259 driver_FreeCModeList(cybermlist
, GfxBase
);
269 ULONG
driver_BestCModeIDTagList(struct TagItem
*tags
, struct GfxBase
*GfxBase
)
271 struct TagItem
*tag
, *tstate
;
273 ULONG nominal_width
, nominal_height
, depth
;
279 nominal_height
= 600;
284 for (tstate
= tags
; (tag
= NextTagItem(&tstate
)); ) {
285 switch (tag
->ti_Tag
) {
286 case CYBRBIDTG_Depth
:
287 depth
= tag
->ti_Data
;
290 case CYBRBIDTG_NominalWidth
:
291 nominal_width
= tag
->ti_Data
;
294 case CYBRBIDTG_NominalHeight
:
295 nominal_height
= tag
->ti_Data
;
298 case CYBRBIDTG_MonitorID
:
299 monitorid
= tag
->ti_Data
;
302 case CYBRBIDTG_BoardName
:
303 boardname
= (STRPTR
)tag
->ti_Data
;
307 D(bug("!!! UNKOWN ATTR PASSED TO BestCModeIDTagList(): %x !!!\n", tag
->ti_Tag
));
312 } /* for (each tag in the taglist) */
316 /* No request for a cgfx mode */
320 /* Get the best modeid */
321 struct TagItem modetags
[] = {
322 { BIDTAG_NominalWidth
, nominal_width
},
323 { BIDTAG_NominalHeight
, nominal_height
},
324 { BIDTAG_DesiredWidth
, nominal_width
},
325 { BIDTAG_DesiredHeight
, nominal_height
},
326 { BIDTAG_Depth
, depth
},
327 { BIDTAG_MonitorID
, monitorid
},
331 modeid
= BestModeIDA(modetags
);
334 /* Use the data to select a mode */
339 ULONG
driver_GetCyberIDAttr(ULONG attribute
, ULONG id
, struct GfxBase
*GfxBase
)
341 /* First lookup the pixfmt for the ID */
343 OOP_Object
*sync
, *pf
;
344 HIDDT_ModeID hiddmode
;
346 hiddmode
= AMIGA_TO_HIDD_MODEID(id
);
350 if (HIDD_Gfx_GetMode(SDD(GfxBase
)->gfxhidd
, hiddmode
, &sync
, &pf
)) {
352 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
355 D(bug("!!! TRYING TO GET ATTR FROM NON-CGFX MODE IN GetCyberIDAttr() !!!\n"));
360 case CYBRIDATTR_PIXFMT
: {
361 HIDDT_StdPixFmt stdpf
;
363 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
365 retval
= hidd2cyber_pixfmt(stdpf
, GfxBase
);
367 D(bug("!!! NO CGFX PIXFMT IN GetCyberIDAttr() !!!\n"));
371 case CYBRIDATTR_DEPTH
:
375 case CYBRIDATTR_WIDTH
:
376 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &retval
);
379 case CYBRIDATTR_HEIGHT
:
380 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &retval
);
383 case CYBRIDATTR_BPPIX
:
384 OOP_GetAttr(pf
, aHidd_PixFmt_BytesPerPixel
, &retval
);
388 D(bug("!!! UNKONOW ATTRIBUTE IN GetCyberIDAttr(): %x !!!\n"
401 BOOL
driver_IsCyberModeID(ULONG modeid
, struct GfxBase
*GfxBase
)
403 BOOL iscyber
= FALSE
;
404 HIDDT_ModeID hiddmode
= 0;
405 OOP_Object
*sync
, *pf
;
407 hiddmode
= AMIGA_TO_HIDD_MODEID(modeid
);
409 if (HIDD_Gfx_GetMode(SDD(GfxBase
)->gfxhidd
, hiddmode
, &sync
, &pf
)) {
410 HIDDT_StdPixFmt stdpf
;
412 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
413 if (((UWORD
)-1) != hidd2cyber_pixfmt(stdpf
, GfxBase
)) {
421 HIDDT_ModeID
get_best_resolution_and_depth(struct GfxBase
*GfxBase
)
423 HIDDT_ModeID ret
= vHidd_ModeID_Invalid
;
425 HIDDT_ModeID
*modes
, *m
;
426 struct TagItem querytags
[] = { { TAG_DONE
, 0UL } };
428 gfxhidd
= SDD(GfxBase
)->gfxhidd
;
430 /* Query the gfxhidd for all modes */
431 modes
= HIDD_Gfx_QueryModeIDs(gfxhidd
, querytags
);
434 ULONG best_resolution
= 0;
435 ULONG best_depth
= 0;
437 for (m
= modes
; vHidd_ModeID_Invalid
!= *m
; m
++) {
438 OOP_Object
*sync
, *pf
;
440 HIDD_Gfx_GetMode(gfxhidd
, *m
, &sync
, &pf
);
442 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
443 if (depth
>= best_depth
) {
447 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &width
);
448 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &height
);
450 res
= width
* height
;
451 if (res
> best_resolution
) {
453 best_resolution
= res
;
461 HIDD_Gfx_ReleaseModeIDs(gfxhidd
, modes
);