r4722@vps: verhaegs | 2007-05-06 13:11:19 -0400
[cake.git] / rom / graphics / bestmodeida.c
blob1e1a008373007cc564262696ca5d4cb46f43d482
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function BestModeIDA()
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <graphics/modeid.h>
10 #include <hidd/graphics.h>
11 #include <proto/graphics.h>
12 #include <proto/utility.h>
13 #include <proto/oop.h>
14 #include "dispinfo.h"
15 #include "graphics_intern.h"
17 /*****************************************************************************
19 NAME */
20 #include <proto/graphics.h>
22 AROS_LH1(ULONG, BestModeIDA,
24 /* SYNOPSIS */
25 AROS_LHA(struct TagItem *, TagItems, A0),
27 /* LOCATION */
28 struct GfxBase *, GfxBase, 175, Graphics)
30 /* FUNCTION
32 INPUTS
33 TagItems - pointer to an array of TagItems
35 RESULT
36 ID - ID of the best mode to use, or INVALID_ID if a match
37 could not be found
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 graphics/modeid.h graphics/displayinfo.h
48 INTERNALS
50 HISTORY
53 ******************************************************************************/
55 AROS_LIBFUNC_INIT
57 /* ULONG dipf_must_have = 0;
58 ULONG dipf_must_not_have = 0;
60 struct ViewPort *vp = NULL;
61 UWORD nominal_width = 640
62 , nominal_height = 200
63 , desired_width = 640
64 , desired_height = 200;
65 UBYTE depth = 1;
66 ULONG monitorid = INVALID_ID, sourceid = INVALID_ID;
67 UBYTE redbits = 4
68 , greenbits = 4
69 , bluebits = 4;
70 ULONG dipf_musthave = 0
71 , dipf_mustnothave = 0;
73 ULONG found_id = INVALID_ID;
74 HIDDT_ModeID hiddmode;
76 /* ULONG maxdepth = 0;
77 ULONG maxwidth = 0, maxheight = 0;
78 UBYTE maxrb = 0, maxgb = 0, maxbb = 0;
79 */
80 /* First try to get viewport */
81 vp = (struct ViewPort *)GetTagData(BIDTAG_ViewPort, (IPTR)NULL , TagItems);
82 monitorid = GetTagData(BIDTAG_MonitorID , monitorid , TagItems);
83 sourceid = GetTagData(BIDTAG_SourceID , sourceid , TagItems);
84 depth = GetTagData(BIDTAG_Depth , depth , TagItems);
85 nominal_width = GetTagData(BIDTAG_NominalWidth , nominal_width , TagItems);
86 nominal_height = GetTagData(BIDTAG_NominalHeight , nominal_height , TagItems);
87 desired_width = GetTagData(BIDTAG_DesiredWidth , desired_width , TagItems);
88 desired_height = GetTagData(BIDTAG_DesiredHeight , desired_height , TagItems);
89 redbits = GetTagData(BIDTAG_RedBits , redbits , TagItems);
90 greenbits = GetTagData(BIDTAG_GreenBits , greenbits , TagItems);
91 bluebits = GetTagData(BIDTAG_BlueBits , bluebits , TagItems);
92 dipf_musthave = GetTagData(BIDTAG_DIPFMustHave , dipf_musthave , TagItems);
93 dipf_mustnothave = GetTagData(BIDTAG_DIPFMustNotHave , dipf_mustnothave , TagItems);
95 if (NULL != vp)
97 /* Set some new default values */
98 nominal_width = desired_width = vp->DWidth;
99 nominal_height = desired_height = vp->DHeight;
101 if (NULL != vp->RasInfo->BitMap)
103 depth = GetBitMapAttr(vp->RasInfo->BitMap, BMA_DEPTH);
105 else
107 D(bug("!!! Passing viewport with NULL vp->RasInfo->BitMap to BestModeIDA() !!!\n"));
111 if (INVALID_ID != sourceid)
113 #warning Fix this
115 /* I do not understand what the docs state about this */
119 /* OK, now we try to search for a mode that has the supplied charateristics */
121 hiddmode = vHidd_ModeID_Invalid;
122 for (;;)
124 OOP_Object *sync, *pf;
126 ULONG redmask, greenmask, bluemask;
127 ULONG gm_depth, gm_width, gm_height;
128 ULONG found_depth, found_width, found_height;
129 hiddmode = HIDD_Gfx_NextModeID(SDD(GfxBase)->gfxhidd, hiddmode, &sync, &pf);
130 if (vHidd_ModeID_Invalid == hiddmode)
131 break;
133 OOP_GetAttr(pf, aHidd_PixFmt_RedMask, &redmask);
134 OOP_GetAttr(pf, aHidd_PixFmt_GreenMask, &greenmask);
135 OOP_GetAttr(pf, aHidd_PixFmt_BlueMask, &bluemask);
137 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &gm_depth);
138 OOP_GetAttr(sync, aHidd_Sync_HDisp, &gm_width);
139 OOP_GetAttr(sync, aHidd_Sync_VDisp, &gm_height);
141 if ( /* compute_numbits(redmask) >= redbits
142 && compute_numbits(greenmask) >= greenbits
143 && compute_numbits(bluemask) >= bluebits
145 && */gm_depth >= depth
146 && gm_width >= desired_width
147 && gm_height >= desired_height)
149 #warning Fix this
150 /* We return the first modeid that fulfill the criterias.
151 Instead we should find the mode that has:
152 - largest possible depth.
154 if (
155 (found_id == INVALID_ID) ||
157 (found_id != INVALID_ID) &&
158 (gm_depth < found_depth) &&
159 (gm_width < found_width) &&
160 (gm_height < found_height)
164 found_id = HIDD_TO_AMIGA_MODEID(hiddmode);
165 found_depth = gm_depth;
166 found_width = gm_width;
167 found_height = gm_height;
171 } /* for (each HIDD modeid) */
173 return found_id;
175 AROS_LIBFUNC_EXIT
176 } /* BestModeIDA */