r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / graphics / bestmodeida.c
blobdd6bb7687551d25572d5d0eb544f728a522f4f41
1 /*
2 Copyright © 1995-2001, 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
56 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
58 /* ULONG dipf_must_have = 0;
59 ULONG dipf_must_not_have = 0;
61 struct ViewPort *vp = NULL;
62 UWORD nominal_width = 640
63 , nominal_height = 200
64 , desired_width = 640
65 , desired_height = 200;
66 UBYTE depth = 1;
67 ULONG monitorid = INVALID_ID, sourceid = INVALID_ID;
68 UBYTE redbits = 4
69 , greenbits = 4
70 , bluebits = 4;
71 ULONG dipf_musthave = 0
72 , dipf_mustnothave = 0;
74 ULONG found_id = INVALID_ID;
75 HIDDT_ModeID hiddmode;
77 /* ULONG maxdepth = 0;
78 ULONG maxwidth = 0, maxheight = 0;
79 UBYTE maxrb = 0, maxgb = 0, maxbb = 0;
80 */
81 /* First try to get viewport */
82 vp = (struct ViewPort *)GetTagData(BIDTAG_ViewPort, (IPTR)NULL , TagItems);
83 monitorid = GetTagData(BIDTAG_MonitorID , monitorid , TagItems);
84 sourceid = GetTagData(BIDTAG_SourceID , sourceid , TagItems);
85 depth = GetTagData(BIDTAG_Depth , depth , TagItems);
86 nominal_width = GetTagData(BIDTAG_NominalWidth , nominal_width , TagItems);
87 nominal_height = GetTagData(BIDTAG_NominalHeight , nominal_height , TagItems);
88 desired_width = GetTagData(BIDTAG_DesiredWidth , desired_width , TagItems);
89 desired_height = GetTagData(BIDTAG_DesiredHeight , desired_height , TagItems);
90 redbits = GetTagData(BIDTAG_RedBits , redbits , TagItems);
91 greenbits = GetTagData(BIDTAG_GreenBits , greenbits , TagItems);
92 bluebits = GetTagData(BIDTAG_BlueBits , bluebits , TagItems);
93 dipf_musthave = GetTagData(BIDTAG_DIPFMustHave , dipf_musthave , TagItems);
94 dipf_mustnothave = GetTagData(BIDTAG_DIPFMustNotHave , dipf_mustnothave , TagItems);
96 if (NULL != vp)
98 /* Set some new default values */
99 nominal_width = desired_width = vp->DWidth;
100 nominal_height = desired_height = vp->DHeight;
102 if (NULL != vp->RasInfo->BitMap)
104 depth = GetBitMapAttr(vp->RasInfo->BitMap, BMA_DEPTH);
106 else
108 D(bug("!!! Passing viewport with NULL vp->RasInfo->BitMap to BestModeIDA() !!!\n"));
112 if (INVALID_ID != sourceid)
114 #warning Fix this
116 /* I do not understand what the docs state about this */
120 /* OK, now we try to search for a mode that has the supplied charateristics */
122 hiddmode = vHidd_ModeID_Invalid;
123 for (;;)
125 OOP_Object *sync, *pf;
127 ULONG redmask, greenmask, bluemask;
128 ULONG gm_depth, gm_width, gm_height;
129 ULONG found_depth, found_width, found_height;
130 hiddmode = HIDD_Gfx_NextModeID(SDD(GfxBase)->gfxhidd, hiddmode, &sync, &pf);
131 if (vHidd_ModeID_Invalid == hiddmode)
132 break;
134 OOP_GetAttr(pf, aHidd_PixFmt_RedMask, &redmask);
135 OOP_GetAttr(pf, aHidd_PixFmt_GreenMask, &greenmask);
136 OOP_GetAttr(pf, aHidd_PixFmt_BlueMask, &bluemask);
138 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &gm_depth);
139 OOP_GetAttr(sync, aHidd_Sync_HDisp, &gm_width);
140 OOP_GetAttr(sync, aHidd_Sync_VDisp, &gm_height);
142 if ( /* compute_numbits(redmask) >= redbits
143 && compute_numbits(greenmask) >= greenbits
144 && compute_numbits(bluemask) >= bluebits
146 && */gm_depth >= depth
147 && gm_width >= desired_width
148 && gm_height >= desired_height)
150 #warning Fix this
151 /* We return the first modeid that fulfill the criterias.
152 Instead we should find the mode that has:
153 - largest possible depth.
155 if (
156 (found_id == INVALID_ID) ||
158 (found_id != INVALID_ID) &&
159 (gm_depth < found_depth) &&
160 (gm_width < found_width) &&
161 (gm_height < found_height)
165 found_id = HIDD_TO_AMIGA_MODEID(hiddmode);
166 found_depth = gm_depth;
167 found_width = gm_width;
168 found_height = gm_height;
172 } /* for (each HIDD modeid) */
174 return found_id;
176 AROS_LIBFUNC_EXIT
177 } /* BestModeIDA */