New attempt to get the svn revision into the AboutAROS requester.
[cake.git] / rom / graphics / bestmodeida.c
blob085b4136b12cb3924ddb695f14abae25d70611f5
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 TAGS
36 BIDTAG_ViewPort (struct ViewPort *) - Viewport for which a mode is searched. Default: NULL
37 BIDTAG_MonitorID (ULONG) - Returned ID must use this monitor
38 BIDTAG_SourceID (ULONG) - Use this ModeID instead of a ViewPort.
39 DIPFMustHave mask is made up of the
40 ((DisplayInfo->PropertyFlags of this ID & SPECIAL_FLAGS) |
41 DIPFMustHave flags).
42 Default:
43 if BIDTAG_ViewPort was passed: VPModeID(vp), else the
44 DIPFMustHave and DIPFMustNotHave are unchanged.
45 BIDTAG_Depth (UBYTE) - Minimal depth. Default:
46 if BIDTAG_ViewPort is passed: vp->RasInfo->BitMap->Depth,
47 else 1.
48 BIDTAG_NominalWidth (UWORD),
49 BIDTAG_NominalHeight (UWORD) - Aspect radio. Default:
50 if BIDTAG_SourceID: SourceID NominalDimensionInfo
51 if BIDTAG_ViewPort: vp->DWidth and vp->DHeight
52 or 640 x 200.
53 BIDTAG_DesiredWidth (UWORD) - Width. Default: DIBTAG_NominalWidth.
54 BIDTAG_DesiredHeight (UWORD) - Height. Default: BIDTAG_NominalHeight.
55 BIDTAG_RedBits (UBYTE),
56 BIDTAG_GreenBits (UBYTE),
57 BIDTAG_BlueBits (UBYTE) - Bits per gun the mode must support. Default: 4
58 BIDTAG_DIPFMustHave (ULONG) - DIPF flags the resulting mode must have
59 BIDTAG_DIPFMustNotHave (ULONG) - DIPF flags the resulting mode must not have
61 RESULT
62 ID - ID of the best mode to use, or INVALID_ID if a match
63 could not be found
65 NOTES
67 EXAMPLE
69 BUGS
71 SEE ALSO
72 graphics/modeid.h, graphics/displayinfo.h
74 INTERNALS
76 HISTORY
79 ******************************************************************************/
81 AROS_LIBFUNC_INIT
83 /* ULONG dipf_must_have = 0;
84 ULONG dipf_must_not_have = 0;
86 struct ViewPort *vp = NULL;
87 UWORD nominal_width = 640
88 , nominal_height = 200
89 , desired_width = 640
90 , desired_height = 200;
91 UBYTE depth = 1;
92 ULONG monitorid = INVALID_ID, sourceid = INVALID_ID;
93 UBYTE redbits = 4
94 , greenbits = 4
95 , bluebits = 4;
96 ULONG dipf_musthave = 0
97 , dipf_mustnothave = 0;
99 ULONG found_id = INVALID_ID;
100 HIDDT_ModeID hiddmode;
102 /* ULONG maxdepth = 0;
103 ULONG maxwidth = 0, maxheight = 0;
104 UBYTE maxrb = 0, maxgb = 0, maxbb = 0;
106 /* First try to get viewport */
107 vp = (struct ViewPort *)GetTagData(BIDTAG_ViewPort, (IPTR)NULL , TagItems);
108 monitorid = GetTagData(BIDTAG_MonitorID , monitorid , TagItems);
109 sourceid = GetTagData(BIDTAG_SourceID , sourceid , TagItems);
110 depth = GetTagData(BIDTAG_Depth , depth , TagItems);
111 nominal_width = GetTagData(BIDTAG_NominalWidth , nominal_width , TagItems);
112 nominal_height = GetTagData(BIDTAG_NominalHeight , nominal_height , TagItems);
113 desired_width = GetTagData(BIDTAG_DesiredWidth , desired_width , TagItems);
114 desired_height = GetTagData(BIDTAG_DesiredHeight , desired_height , TagItems);
115 redbits = GetTagData(BIDTAG_RedBits , redbits , TagItems);
116 greenbits = GetTagData(BIDTAG_GreenBits , greenbits , TagItems);
117 bluebits = GetTagData(BIDTAG_BlueBits , bluebits , TagItems);
118 dipf_musthave = GetTagData(BIDTAG_DIPFMustHave , dipf_musthave , TagItems);
119 dipf_mustnothave = GetTagData(BIDTAG_DIPFMustNotHave , dipf_mustnothave , TagItems);
121 if (NULL != vp)
123 /* Set some new default values */
124 nominal_width = desired_width = vp->DWidth;
125 nominal_height = desired_height = vp->DHeight;
127 if (NULL != vp->RasInfo->BitMap)
129 depth = GetBitMapAttr(vp->RasInfo->BitMap, BMA_DEPTH);
131 else
133 D(bug("!!! Passing viewport with NULL vp->RasInfo->BitMap to BestModeIDA() !!!\n"));
137 if (INVALID_ID != sourceid)
139 #warning Fix this
141 /* I do not understand what the docs state about this */
145 /* OK, now we try to search for a mode that has the supplied charateristics */
147 hiddmode = vHidd_ModeID_Invalid;
148 for (;;)
150 OOP_Object *sync, *pf;
152 IPTR redmask, greenmask, bluemask;
153 IPTR gm_depth, gm_width, gm_height;
154 ULONG found_depth, found_width, found_height;
155 hiddmode = HIDD_Gfx_NextModeID(SDD(GfxBase)->gfxhidd, hiddmode, &sync, &pf);
156 if (vHidd_ModeID_Invalid == hiddmode)
157 break;
159 OOP_GetAttr(pf, aHidd_PixFmt_RedMask, &redmask);
160 OOP_GetAttr(pf, aHidd_PixFmt_GreenMask, &greenmask);
161 OOP_GetAttr(pf, aHidd_PixFmt_BlueMask, &bluemask);
163 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &gm_depth);
164 OOP_GetAttr(sync, aHidd_Sync_HDisp, &gm_width);
165 OOP_GetAttr(sync, aHidd_Sync_VDisp, &gm_height);
167 if ( /* compute_numbits(redmask) >= redbits
168 && compute_numbits(greenmask) >= greenbits
169 && compute_numbits(bluemask) >= bluebits
171 && */gm_depth >= depth
172 && gm_width >= desired_width
173 && gm_height >= desired_height)
175 #warning Fix this
176 /* We return the first modeid that fulfill the criterias.
177 Instead we should find the mode that has:
178 - largest possible depth.
180 if (
181 (found_id == INVALID_ID) ||
183 (found_id != INVALID_ID) &&
184 (gm_depth < found_depth) &&
185 (gm_width < found_width) &&
186 (gm_height < found_height)
190 found_id = HIDD_TO_AMIGA_MODEID(hiddmode);
191 found_depth = gm_depth;
192 found_width = gm_width;
193 found_height = gm_height;
197 } /* for (each HIDD modeid) */
199 return found_id;
201 AROS_LIBFUNC_EXIT
202 } /* BestModeIDA */