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 const struct TagItem
*tstate
;
105 ULONG minwidth
= 320;
106 ULONG maxwidth
= 1600;
107 ULONG minheight
= 240;
108 ULONG maxheight
= 1200;
112 struct List
*cybermlist
= NULL
;
116 UWORD
*cmodelarray
= NULL
;
117 HIDDT_ModeID
*hiddmodes
= NULL
, *hmptr
;
118 struct TagItem querytags
[] = { { TAG_DONE
, 0UL } };
120 gfxhidd
= SDD(GfxBase
)->gfxhidd
;
122 for (tstate
= taglist
; (tag
= NextTagItem(&tstate
)); ) {
123 switch (tag
->ti_Tag
) {
124 case CYBRMREQ_MinWidth
:
125 minwidth
= (ULONG
)tag
->ti_Data
;
128 case CYBRMREQ_MaxWidth
:
129 maxwidth
= (ULONG
)tag
->ti_Data
;
132 case CYBRMREQ_MinHeight
:
133 minheight
= (ULONG
)tag
->ti_Data
;
136 case CYBRMREQ_MaxHeight
:
137 maxheight
= (ULONG
)tag
->ti_Data
;
140 case CYBRMREQ_MinDepth
:
141 mindepth
= (ULONG
)tag
->ti_Data
;
144 case CYBRMREQ_MaxDepth
:
145 maxdepth
= (ULONG
)tag
->ti_Data
;
148 case CYBRMREQ_CModelArray
:
149 cmodelarray
= (UWORD
*)tag
->ti_Data
;
153 D(bug("!!! UNKNOWN TAG PASSED TO AllocCModeListTagList\n"));
158 /* Allocate the exec list */
159 cybermlist
= AllocMem(sizeof (struct List
), MEMF_CLEAR
);
160 if (NULL
== cybermlist
)
166 /* Get all HIDD modes */
167 hiddmodes
= HIDD_Gfx_QueryModeIDs(gfxhidd
, querytags
);
168 if (NULL
== hiddmodes
)
172 for (hmptr
= hiddmodes
; *hmptr
!= vHidd_ModeID_Invalid
; hmptr
++) {
174 struct CyberModeNode
*cmnode
;
176 IPTR width
, height
, depth
;
177 OOP_Object
*sync
, *pf
;
179 if (!HIDD_Gfx_GetMode(gfxhidd
, *hmptr
, &sync
, &pf
)) {
180 /* This should never happen because HIDD_GfxWueryModeIDs() should
181 only return valid modes
183 D(bug("!!! UNABLE TO GET HIDD MODE INFO IN AllocCModeListTagList() !!!\n"));
184 D(bug("!!! THIS SHOULD *NEVER* HAPPEN !!!\n"));
188 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &width
);
189 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &height
);
191 if ( width
< minwidth
193 || height
< minheight
194 || height
> maxheight
) {
199 /* Get the pxifmt info */
200 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
202 if (depth
< mindepth
|| depth
> maxdepth
)
205 /* Check whether the gfxmode is the correct pixel format */
206 if (NULL
!= cmodelarray
) {
207 HIDDT_StdPixFmt stdpf
;
211 /* Get the gfxmode pixelf format */
212 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
214 cyberpf
= hidd2cyber_pixfmt(stdpf
, GfxBase
);
215 if (cyberpf
== (UWORD
)-1)
216 continue; /* Unknown format */
218 for (cyberpixfmts
= cmodelarray
; *cyberpixfmts
; cyberpixfmts
++) {
219 /* See if the stdpixfmt is present in the array */
220 if (*cyberpixfmts
== cyberpf
) {
224 } /* for (each supplied pixelformat in the cmodelarray) */
227 continue; /* PixFmt not wanted, just continue with next node */
229 } /* if (cmodelarray supplied in the taglist) */
231 /* Allocate a cybergfx modeinfo struct */
232 cmnode
= AllocMem(sizeof (struct CyberModeNode
), MEMF_CLEAR
);
236 cmnode
->Width
= width
;
237 cmnode
->Height
= height
;
238 cmnode
->Depth
= depth
;
239 cmnode
->DisplayTagList
= NULL
;
241 snprintf( cmnode
->ModeText
243 , "AROS: %ldx%ldx%ld"
244 , width
, height
, depth
247 /* Keep track of the node */
248 AddTail(cybermlist
, (struct Node
*)cmnode
);
250 } /* for (modeids returned from the HIDD) */
256 if (NULL
!= hiddmodes
)
257 HIDD_Gfx_ReleaseModeIDs(gfxhidd
, hiddmodes
);
259 if (NULL
!= cybermlist
)
260 driver_FreeCModeList(cybermlist
, GfxBase
);
270 ULONG
driver_BestCModeIDTagList(struct TagItem
*tags
, struct GfxBase
*GfxBase
)
272 const struct TagItem
*tstate
;
275 ULONG nominal_width
, nominal_height
, depth
;
281 nominal_height
= 600;
286 for (tstate
= tags
; (tag
= NextTagItem(&tstate
)); ) {
287 switch (tag
->ti_Tag
) {
288 case CYBRBIDTG_Depth
:
289 depth
= tag
->ti_Data
;
292 case CYBRBIDTG_NominalWidth
:
293 nominal_width
= tag
->ti_Data
;
296 case CYBRBIDTG_NominalHeight
:
297 nominal_height
= tag
->ti_Data
;
300 case CYBRBIDTG_MonitorID
:
301 monitorid
= tag
->ti_Data
;
304 case CYBRBIDTG_BoardName
:
305 boardname
= (STRPTR
)tag
->ti_Data
;
309 D(bug("!!! UNKOWN ATTR PASSED TO BestCModeIDTagList(): %x !!!\n", tag
->ti_Tag
));
314 } /* for (each tag in the taglist) */
318 /* No request for a cgfx mode */
322 /* Get the best modeid */
323 struct TagItem modetags
[] = {
324 { BIDTAG_NominalWidth
, nominal_width
},
325 { BIDTAG_NominalHeight
, nominal_height
},
326 { BIDTAG_DesiredWidth
, nominal_width
},
327 { BIDTAG_DesiredHeight
, nominal_height
},
328 { BIDTAG_Depth
, depth
},
329 { BIDTAG_MonitorID
, monitorid
},
333 modeid
= BestModeIDA(modetags
);
336 /* Use the data to select a mode */
341 ULONG
driver_GetCyberIDAttr(ULONG attribute
, ULONG id
, struct GfxBase
*GfxBase
)
343 /* First lookup the pixfmt for the ID */
345 OOP_Object
*sync
, *pf
;
346 HIDDT_ModeID hiddmode
;
348 hiddmode
= AMIGA_TO_HIDD_MODEID(id
);
352 if (HIDD_Gfx_GetMode(SDD(GfxBase
)->gfxhidd
, hiddmode
, &sync
, &pf
)) {
354 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
357 D(bug("!!! TRYING TO GET ATTR FROM NON-CGFX MODE IN GetCyberIDAttr() !!!\n"));
362 case CYBRIDATTR_PIXFMT
: {
363 HIDDT_StdPixFmt stdpf
;
365 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
367 retval
= hidd2cyber_pixfmt(stdpf
, GfxBase
);
369 D(bug("!!! NO CGFX PIXFMT IN GetCyberIDAttr() !!!\n"));
373 case CYBRIDATTR_DEPTH
:
377 case CYBRIDATTR_WIDTH
:
378 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &retval
);
381 case CYBRIDATTR_HEIGHT
:
382 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &retval
);
385 case CYBRIDATTR_BPPIX
:
386 OOP_GetAttr(pf
, aHidd_PixFmt_BytesPerPixel
, &retval
);
390 D(bug("!!! UNKONOW ATTRIBUTE IN GetCyberIDAttr(): %x !!!\n"
403 BOOL
driver_IsCyberModeID(ULONG modeid
, struct GfxBase
*GfxBase
)
405 BOOL iscyber
= FALSE
;
406 HIDDT_ModeID hiddmode
= 0;
407 OOP_Object
*sync
, *pf
;
409 hiddmode
= AMIGA_TO_HIDD_MODEID(modeid
);
411 if (HIDD_Gfx_GetMode(SDD(GfxBase
)->gfxhidd
, hiddmode
, &sync
, &pf
)) {
412 HIDDT_StdPixFmt stdpf
;
414 OOP_GetAttr(pf
, aHidd_PixFmt_StdPixFmt
, &stdpf
);
415 if (((UWORD
)-1) != hidd2cyber_pixfmt(stdpf
, GfxBase
)) {
423 HIDDT_ModeID
get_best_resolution_and_depth(struct GfxBase
*GfxBase
)
425 HIDDT_ModeID ret
= vHidd_ModeID_Invalid
;
427 HIDDT_ModeID
*modes
, *m
;
428 struct TagItem querytags
[] = { { TAG_DONE
, 0UL } };
430 gfxhidd
= SDD(GfxBase
)->gfxhidd
;
432 /* Query the gfxhidd for all modes */
433 modes
= HIDD_Gfx_QueryModeIDs(gfxhidd
, querytags
);
436 ULONG best_resolution
= 0;
437 ULONG best_depth
= 0;
439 for (m
= modes
; vHidd_ModeID_Invalid
!= *m
; m
++) {
440 OOP_Object
*sync
, *pf
;
442 HIDD_Gfx_GetMode(gfxhidd
, *m
, &sync
, &pf
);
444 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
445 if (depth
>= best_depth
) {
449 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &width
);
450 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &height
);
452 res
= width
* height
;
453 if (res
> best_resolution
) {
455 best_resolution
= res
;
463 HIDD_Gfx_ReleaseModeIDs(gfxhidd
, modes
);