modeID doesn't exist anymore.
[AROS.git] / rom / graphics / getdisplayinfodata.c
blobedb1039cd886040b6ee470648fcf412c2a227cc5
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function GetDisplayInfoData()
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
12 #include <proto/graphics.h>
13 #include <graphics/displayinfo.h>
14 #include <hidd/graphics.h>
15 #include <proto/oop.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include "graphics_intern.h"
19 #include "dispinfo.h"
21 /****************************************************************************************/
23 static const ULONG size_checks[] =
25 sizeof(struct DisplayInfo),
26 sizeof(struct DimensionInfo),
27 sizeof(struct MonitorInfo),
28 sizeof(struct NameInfo),
31 #define KNOWN_IDS 4
33 static ULONG check_sizes(ULONG tagID, ULONG size);
34 static ULONG compute_numbits(HIDDT_Pixel mask);
36 #define DLONGSZ (sizeof (ULONG) * 2)
37 #define DTAG_TO_IDX(dtag) (((dtag) & 0x7FFFF000) >> 12)
39 /*****************************************************************************
41 NAME */
42 #include <proto/graphics.h>
44 AROS_LH5(ULONG, GetDisplayInfoData,
46 /* SYNOPSIS */
47 AROS_LHA(DisplayInfoHandle, handle, A0),
48 AROS_LHA(UBYTE *, buf, A1),
49 AROS_LHA(ULONG, size, D0),
50 AROS_LHA(ULONG, tagID, D1),
51 AROS_LHA(ULONG, ID, D2),
53 /* LOCATION */
54 struct GfxBase *, GfxBase, 126, Graphics)
56 /* FUNCTION
57 Fills buffer with information about displayinfo handle.
59 INPUTS
60 handle - displayinfo handle
61 buf - pointer to destination buffer
62 size - buffer size in bytes
63 tagID - data chunk type
64 DTAG_DISP (DisplayInfo)
65 DTAG_DIMS (DimensionInfo)
66 DTAG_MNTR (MonitorInfo)
67 DTAG_NAME (NameInfo)
68 ID - displayinfo identifier, optionally used if handle is NULL
70 RESULT
71 result - if positive, number of bytes actually transferred
72 if zero, no information for ID was available
74 NOTES
76 EXAMPLE
78 BUGS
80 SEE ALSO
81 FindDisplayInfo(), NextDisplayInfo(), graphics/displayinfo.h
83 INTERNALS
84 This function provides the following private parameters:
85 DimensionInfo.reserved[0] - driver user data (intuition's monitorclass object)
86 DimensionInfo.reserved[1] - pixelformat object
87 Do not rely on this in end user software! This is private to AROS and
88 subject to change at any time!
90 HISTORY
92 ******************************************************************************/
94 AROS_LIBFUNC_INIT
96 struct QueryHeader *qh;
97 ULONG structsize;
98 OOP_Object *gfxhidd, *sync, *pf;
99 HIDDT_ModeID hiddmode;
100 struct HIDD_ModeProperties HIDDProps = {0};
102 if (NULL == handle)
103 /* FindDisplayInfo() handles INVALID_ID itself */
104 handle = FindDisplayInfo(ID);
105 if (NULL == handle)
107 D(bug("!!! COULD NOT GET HANDLE IN GetDisplayInfoData()\n"));
108 return 0;
111 gfxhidd = DIH(handle)->drv->gfxhidd;
112 hiddmode = DIH(handle)->id;
114 /* Get mode info from the HIDD */
115 if (!HIDD_Gfx_GetMode(gfxhidd, hiddmode, &sync, &pf))
117 D(bug("NO VALID MODE PASSED TO GetDisplayInfoData() !!!\n"));
118 return 0;
121 D(bug("GetDisplayInfoData(handle=%d, tagID=%x)\n"
122 , (ULONG)handle, tagID));
124 /* Build the queryheader */
125 structsize = check_sizes(tagID, size);
126 if (!structsize)
127 return 0;
128 qh = AllocMem(structsize, MEMF_CLEAR);
129 if (!qh)
130 return 0;
132 /* Fill in the queryheader */
133 qh->StructID = tagID;
134 qh->DisplayID = ID;
135 qh->SkipID = TAG_SKIP;
137 qh->Length = (structsize + (DLONGSZ - 1)) / DLONGSZ;
139 switch (tagID)
141 case DTAG_DISP:
143 struct DisplayInfo *di;
144 IPTR redmask, greenmask, bluemask;
145 IPTR pixclk = 0;
147 HIDD_Gfx_ModeProperties(gfxhidd, hiddmode, &HIDDProps, sizeof(HIDDProps));
149 di = (struct DisplayInfo *)qh;
151 /* All modes returned from the HIDD are available */
152 di->NotAvailable = FALSE;
154 /* Set the propertyflags,
155 Note that we enforce some flags because we emulate these features by software */
156 di->PropertyFlags = DIPF_IS_FOREIGN | DIPF_IS_WB | DIPF_IS_SPRITES | DIPF_IS_DBUFFER | HIDDProps.DisplayInfoFlags;
158 /* Too many colors to count here. This field is really obsolete */
159 di->PaletteRange = 65535;
161 /* Compute red green and blue bits */
162 OOP_GetAttr(pf, aHidd_PixFmt_RedMask, &redmask);
163 OOP_GetAttr(pf, aHidd_PixFmt_GreenMask, &greenmask);
164 OOP_GetAttr(pf, aHidd_PixFmt_BlueMask, &bluemask);
166 di->RedBits = compute_numbits(redmask);
167 di->GreenBits = compute_numbits(greenmask);
168 di->BlueBits = compute_numbits(bluemask);
170 OOP_GetAttr(sync, aHidd_Sync_PixelClock, &pixclk);
172 /* FIXME: don't know what to put here */
173 di->Resolution.x = 22;
174 di->Resolution.y = 22;
176 if (pixclk)
177 di->PixelSpeed = 1000000000 / pixclk;
179 /* We can emulate one sprite via software, because it's necessary for mouse pointer. */
180 di->NumStdSprites = (HIDDProps.DisplayInfoFlags & DIPF_IS_SPRITES) ? HIDDProps.NumHWSprites : 1;
182 /* At the moment sprites always have the same resolution as display */
183 di->SpriteResolution = di->Resolution;
185 break;
188 case DTAG_DIMS:
190 struct DimensionInfo *di;
191 IPTR depth, width, height;
192 IPTR minwidth, minheight;
193 IPTR maxwidth, maxheight;
195 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
196 OOP_GetAttr(sync, aHidd_Sync_HDisp, &width);
197 OOP_GetAttr(sync, aHidd_Sync_VDisp, &height);
198 OOP_GetAttr(sync, aHidd_Sync_HMin, &minwidth);
199 OOP_GetAttr(sync, aHidd_Sync_VMin, &minheight);
200 OOP_GetAttr(sync, aHidd_Sync_HMax, &maxwidth);
201 OOP_GetAttr(sync, aHidd_Sync_VMax, &maxheight);
203 di = (struct DimensionInfo *)qh;
204 di->MaxDepth = depth;
206 di->MinRasterWidth = minwidth;
207 di->MinRasterHeight = minheight;
208 di->MaxRasterWidth = maxwidth;
209 di->MaxRasterHeight = maxheight;
211 di->Nominal.MinX = 0;
212 di->Nominal.MinY = 0;
213 di->Nominal.MaxX = width - 1;
214 di->Nominal.MaxY = height - 1;
216 di->MaxOScan = di->Nominal;
217 di->VideoOScan = di->Nominal;
218 di->TxtOScan = di->Nominal;
219 di->StdOScan = di->Nominal;
221 di->MaxOScan.MinX = di->Nominal.MinX;
222 di->MaxOScan.MinY = di->Nominal.MinY;
223 di->MaxOScan.MaxX = di->Nominal.MaxX;
224 di->MaxOScan.MaxY = di->Nominal.MaxY;
226 di->VideoOScan.MinX = di->Nominal.MinX;
227 di->VideoOScan.MinY = di->Nominal.MinY;
228 di->VideoOScan.MaxX = di->Nominal.MaxX;
229 di->VideoOScan.MaxY = di->Nominal.MaxY;
231 di->TxtOScan.MinX = di->Nominal.MinX;
232 di->TxtOScan.MinY = di->Nominal.MinY;
233 di->TxtOScan.MaxX = di->Nominal.MaxX;
234 di->TxtOScan.MaxY = di->Nominal.MaxY;
236 di->StdOScan.MinX = di->Nominal.MinX;
237 di->StdOScan.MinY = di->Nominal.MinY;
238 di->StdOScan.MaxX = di->Nominal.MaxX;
239 di->StdOScan.MaxY = di->Nominal.MaxY;
241 di->reserved[0] = (IPTR)DIH(handle)->drv->userdata;
242 di->reserved[1] = (IPTR)pf;
244 break;
247 case DTAG_MNTR:
249 struct MonitorInfo *mi;
251 HIDD_Gfx_ModeProperties(gfxhidd, hiddmode, &HIDDProps, sizeof(HIDDProps));
253 mi = (struct MonitorInfo *)qh;
255 OOP_GetAttr(sync, aHidd_Sync_MonitorSpec, (IPTR *)&mi->Mspc);
258 mi->ViewPosition.X = ?;
259 mi->ViewPosition.Y = ?;
260 mi->ViewResolution.X = ?;
261 mi->ViewResolution.Y = ?;
262 mi->MinRow = ?;
263 mi->MouseTicks.X = ?;
264 mi->MouseTicks.Y = ?;
265 mi->DefaultViewPosition.X = ?;
266 mi->DefaultViewPosition.Y = ?;
269 if (mi->Mspc) {
270 mi->TotalRows = mi->Mspc->total_rows;
271 mi->TotalColorClocks = mi->Mspc->total_colorclocks;
272 mi->ViewPositionRange = mi->Mspc->ms_LegalView;
275 mi->PreferredModeID = ID;
276 mi->Compatibility = HIDDProps.CompositionFlags ? MCOMPAT_SELF : MCOMPAT_NOBODY;
278 break;
281 case DTAG_NAME:
283 struct NameInfo *ni;
284 IPTR depth, stdpixfmt;
285 STRPTR sync_description;
287 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
288 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, &stdpixfmt);
290 OOP_GetAttr(sync, aHidd_Sync_Description, (IPTR *)&sync_description);
291 ni = (struct NameInfo *)qh;
293 if (sync_description && sync_description[0] &&
294 (IS_REAL_STDPIXFMT(stdpixfmt) || (stdpixfmt == vHidd_StdPixFmt_Unknown)))
296 STRPTR pixfmt_name = "";
298 switch(stdpixfmt)
300 case vHidd_StdPixFmt_RGB16:
301 case vHidd_StdPixFmt_RGB15:
302 case vHidd_StdPixFmt_RGB24:
303 pixfmt_name = "RGB";
304 break;
306 case vHidd_StdPixFmt_RGB16_LE:
307 case vHidd_StdPixFmt_RGB15_LE:
308 pixfmt_name = "RGB PC";
309 break;
311 case vHidd_StdPixFmt_BGR24:
312 case vHidd_StdPixFmt_BGR16:
313 case vHidd_StdPixFmt_BGR15:
314 pixfmt_name = "BGR";
315 break;
317 case vHidd_StdPixFmt_BGR16_LE:
318 case vHidd_StdPixFmt_BGR15_LE:
319 pixfmt_name = "BGR PC";
320 break;
322 case vHidd_StdPixFmt_ARGB32:
323 pixfmt_name = "ARGB";
324 break;
326 case vHidd_StdPixFmt_BGRA32:
327 pixfmt_name = "BGRA";
328 break;
330 case vHidd_StdPixFmt_RGBA32:
331 pixfmt_name = "RGBA";
332 break;
334 case vHidd_StdPixFmt_0RGB32:
335 pixfmt_name = "0RGB";
336 break;
338 case vHidd_StdPixFmt_BGR032:
339 pixfmt_name = "BGR0";
340 break;
342 case vHidd_StdPixFmt_RGB032:
343 pixfmt_name = "RGB0";
344 break;
348 snprintf(ni->Name, DISPLAYNAMELEN, "%s %2dbit %s",
349 sync_description, (int)depth, pixfmt_name);
351 else
353 IPTR width = 0;
354 IPTR height = 0;
356 OOP_GetAttr(sync, aHidd_Sync_HDisp, &width);
357 OOP_GetAttr(sync, aHidd_Sync_VDisp, &height);
358 snprintf(ni->Name, DISPLAYNAMELEN, "AROS: %ldx%ldx%ld", width, height, depth);
360 break;
363 default:
364 D(bug("!!! UNKNOWN tagID IN CALL TO GetDisplayInfoData() !!!\n"));
365 break;
368 D(bug("GDID: %d\n", structsize));
370 if (size > structsize)
371 size = structsize;
372 CopyMem(qh, buf, size);
373 FreeMem(qh, structsize);
374 /* NULL-terminate the name in case if it was trimmed */
375 if (tagID == DTAG_NAME)
376 buf[size - 1] = 0;
378 return size;
380 AROS_LIBFUNC_EXIT
382 } /* GetDisplayInfoData */
384 /****************************************************************************************/
386 static ULONG check_sizes(ULONG tagID, ULONG size)
388 ULONG idx;
390 idx = DTAG_TO_IDX(tagID);
392 if (idx > KNOWN_IDS)
394 D(bug("!!! INVALID tagID TO GetDisplayInfoData"));
395 return 0;
398 return size_checks[idx];
401 /****************************************************************************************/
403 static ULONG compute_numbits(HIDDT_Pixel mask)
405 ULONG i;
406 ULONG numbits = 0;
408 for (i = 0; i <= 31; i ++)
410 if (mask & (1L << i)) numbits ++;
413 return numbits;
416 /****************************************************************************************/