source: abuse/tags/pd/macabuse/imlib/port/mac/RequestVideo.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 23.5 KB
Line 
1/*------------------------------------------------------------------------------
2#
3#       MacOSª Sample Code
4#       
5#       Written by: Eric Anderson
6#        AppleLink: ERIC3
7#        AOL: ERICTHREE
8#
9#       Display Manager sample code
10#
11#       RequestVideo
12#
13#       RequestVideo.c  -       C Code
14#
15#       Copyright © 1995 Apple Computer, Inc.
16#       All rights reserved.
17#
18#       5/31/95         ewa             Added RVGetCurrentVideoSetting and RVConfirmVideoRequest routines
19#                                               to make it easy to revert back to where you came from and to give
20#                                               the user a chance to confirm the new setting if the new mode was
21#                                               valid (ie: the card supports it) but not safe (the monitor may not).
22#       5/24/95         ewa             Give the kAllValidModesBit requestFlags option for safe only or all
23#                                               valid resolution timings.
24#
25#
26#
27#       Components:     PlayVideo.c                     
28#                               RequestVideo.c         
29#                               RequestVideo.h         
30#                               RequestVideo.rsrc               
31#
32#       RequestVideo demonstrates the usage of the Display Manager introduced
33#       with the PowerMacs and integrated into the system under System 7.5. With
34#       the RequestVideo sample code library, developers will be able to explore
35#       the Display Manager API by changing bit depth and screen resolution on
36#       multisync displays on built-in, NuBus, and PCI based video. Display Manager 1.0
37#       is built into the Systems included with the first PowerMacs up through System 7.5.
38#       Display Manager 2.0 is included with the release of the new PCI based PowerMacs,
39#       and will be included in post 7.5 System Software releases.
40#       
41#       It is a good idea to reset the screen(s) to the original setting before exit
42#       since the call to RVSetVideoAsScreenPrefs() may not do the right thing under
43#       Display Manager 1.0 with certain video drivers.
44#
45#       For information on the use of this sample code, please the documentation in the Read Me file
46------------------------------------------------------------------------------*/
47
48#include "RequestVideo.h"
49
50// Internal includes
51#include <Dialogs.h>
52#include <ROMDefs.h>
53#include <Devices.h>
54#include <Errors.h>
55#include <GestaltEqu.h>
56#include <Memory.h>
57#include <Palettes.h>
58#include <Slots.h>
59#include <StdIO.h>
60#include <Displays.h>
61
62#include <stdlib.h>
63
64//--------------------------------------------------------------
65//
66// Internal defines, structs, typedefs, and routine declarations
67//
68//--------------------------------------------------------------
69#define         KMonoDev                        0                                               // false (handy definitions for gdDevType settings)
70#define         kColorDev                       1                                               // true
71#define         char_Enter                      0x03                                    // for our filter proc
72#define         char_Return                     0x0D                                    //
73#define         iRevertItem                     1                                               // User buttons
74#define         iConfirmItem            2                                               //
75#define         kSecondsToConfirm       8                                               // seconds before confirm dialog is taken down
76#define         rConfirmSwtchAlrt       2735                                    // ID of alert dialog
77
78struct DepthInfo {
79        VDSwitchInfoRec                 depthSwitchInfo;                        // This is the switch mode to choose this timing/depth
80        VPBlock                                 depthVPBlock;                           // VPBlock (including size, depth and format)
81};
82typedef struct DepthInfo DepthInfo;
83
84struct ListIteratorDataRec {
85        VDTimingInfoRec                 displayModeTimingInfo;          // Contains timing flags and such
86        unsigned long                   depthBlockCount;                        // How many depths available for a particular timing
87        DepthInfo                               *depthBlocks;                           // Array of DepthInfo
88};
89typedef struct ListIteratorDataRec ListIteratorDataRec;
90
91void GetRequestTheDM1Way (              VideoRequestRecPtr requestRecPtr,
92                                                                GDHandle walkDevice);
93
94void GetRequestTheDM2Way (              VideoRequestRecPtr requestRecPtr,
95                                                                GDHandle walkDevice,
96                                                                DMDisplayModeListIteratorUPP myModeIteratorProc,
97                                                                DMListIndexType theDisplayModeCount,
98                                                                DMListType *theDisplayModeList);
99
100pascal void ModeListIterator (  void *userData,
101                                                                DMListIndexType itemIndex,
102                                                                DMDisplayModeListEntryPtr displaymodeInfo);
103
104Boolean FindBestMatch (                 VideoRequestRecPtr requestRecPtr,
105                                                                short bitDepth,
106                                                                unsigned long horizontal,
107                                                                unsigned long vertical);
108
109void GravitateMonitors (void);
110
111pascal Boolean ConfirmAlertFilter (DialogPtr dlg, EventRecord *evt, short *itemHit);
112
113Handle myHACK = 0;
114
115//--------------------------------------------------------------
116//
117// Implementation of sample code
118//
119//--------------------------------------------------------------
120OSErr RVSetVideoRequest (VideoRequestRecPtr requestRecPtr)
121{
122        GDHandle                aMonitor;
123        Boolean                 displayMgrPresent;
124        unsigned long   displayMgrVersion;
125        OSErr                   err;
126        Boolean                 isColor;
127        long                    value = 0;
128
129        Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion);
130        Gestalt(gestaltDisplayMgrAttr,&value);
131        displayMgrPresent=value&(1<<gestaltDisplayMgrPresent);
132        if (displayMgrPresent)
133        {
134                if (requestRecPtr->displayMode && requestRecPtr->depthMode)
135                {
136                        if (requestRecPtr->availBitDepth == 1)  // Based on avail bit depth,
137                                isColor = KMonoDev;                                     // set the device to a mono device, or
138                        else isColor = kColorDev;                               // set the device to a color device
139                        SetDeviceAttribute(requestRecPtr->screenDevice,gdDevType,isColor);             
140                       
141                        // see how many monitors we have, aMonitor will be nil if we have only one.
142                        aMonitor = DMGetFirstScreenDevice (dmOnlyActiveDisplays);                       // get the first guy
143                        aMonitor = DMGetNextScreenDevice ( aMonitor, dmOnlyActiveDisplays );    // get the next guy
144                       
145                        if (nil == aMonitor || displayMgrVersion >= 0x00020000)
146                        {
147                                // only call DMSetDisplayMode if we have one monitor or DM2.0 is installed
148                                // since DM1.0 does not automatically gravitate monitors and our gravitate code
149                                // is not implemented.
150                               
151                                err = DMSetDisplayMode( requestRecPtr->screenDevice,    // GDevice
152                                                requestRecPtr->displayMode,                                             // DM1.0 uses this
153                                                &requestRecPtr->depthMode,                                              // DM1.0 uses this
154                                                (unsigned long) &(requestRecPtr->switchInfo),   // DM2.0 uses this rather than displayMode/depthMode combo
155                                                myHACK);
156                                if (noErr == err)
157                                {
158                                        // Do the monitor gravitate here if we are using a version less than DM2.0
159                                        if (displayMgrVersion < 0x00020000)
160                                                GravitateMonitors ();
161                                }
162                                else if (kDMDriverNotDisplayMgrAwareErr == err)
163                                {
164                                        // DM not supported by driver, so all we can do is set the bit depth
165                                        err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor);
166                                }
167                        }
168                        else
169                        {
170                                // we have more than one monitor and DM1.0 is installed, so all we can do is set the bit depth
171                                err = SetDepth (requestRecPtr->screenDevice, requestRecPtr->depthMode, gdDevType, isColor);
172                        }
173                       
174                        return (err);   // we did try to set the request
175                }
176        }
177        return (-1);    // return a generic error
178}
179
180OSErr HackSetRequest (VideoRequestRecPtr requestRecPtr)
181{
182        DMBeginConfigureDisplays(&myHACK);
183        return RVSetVideoRequest(requestRecPtr);
184}
185
186OSErr HackRestoreRequest (VideoRequestRecPtr requestRecPtr)
187{
188        OSErr ret;
189
190        ret = RVSetVideoRequest(requestRecPtr);
191        DMEndConfigureDisplays(myHACK);
192        return ret;
193}
194
195OSErr RVGetCurrentVideoSetting (VideoRequestRecPtr requestRecPtr)
196{
197        unsigned long           displayMgrVersion;
198        OSErr                           error = paramErr;
199        CntrlParam                      pBlock;
200        VDSwitchInfoRec         switchInfo;
201        AuxDCEHandle            theDCE;
202        VDSwitchInfoRec         videoMode;             
203
204        requestRecPtr->availBitDepth                    = 0;    // init to default - you can do it if it is important to you
205        requestRecPtr->availHorizontal                  = 0;
206        requestRecPtr->availVertical                    = 0;
207        requestRecPtr->availFlags                               = 0;
208        requestRecPtr->displayMode                              = -1;
209        requestRecPtr->depthMode                                = -1;
210        requestRecPtr->switchInfo.csMode                = 0;
211        requestRecPtr->switchInfo.csData                = 0;
212        requestRecPtr->switchInfo.csPage                = 0;
213        requestRecPtr->switchInfo.csBaseAddr    = 0;
214        requestRecPtr->switchInfo.csReserved    = 0;
215       
216        Gestalt(gestaltDisplayMgrVers, (long*)&displayMgrVersion);
217        if (requestRecPtr->screenDevice)
218        {
219                if (displayMgrVersion >= 0x00020000)
220                {       // get the info the DM 2.0 way
221                        error = DMGetDisplayMode(requestRecPtr->screenDevice, &switchInfo);
222                        if (noErr == error)
223                        {
224                                requestRecPtr->depthMode                        = switchInfo.csMode;
225                                requestRecPtr->displayMode                      = switchInfo.csData;
226                                requestRecPtr->switchInfo.csMode        = switchInfo.csMode;
227                                requestRecPtr->switchInfo.csData        = switchInfo.csData;
228                        }
229                        return (error); // we (maybe) set the world back to a known setting
230                }
231                else
232                {       // get the info the DM 1.0 way
233                        videoMode.csMode = -1;          // init to bogus value
234                        videoMode.csData = -1;          // init to bogus value                 
235                        pBlock.ioNamePtr = nil;
236                        pBlock.ioCRefNum = (*(requestRecPtr->screenDevice))->gdRefNum;
237                        pBlock.csCode = cscGetCurMode;
238                        *(Ptr *)&pBlock.csParam[0] = (Ptr)&videoMode;
239                               
240                        error = PBStatusSync((ParmBlkPtr )&pBlock);     // ask the driver first....since we trust it the most
241                               
242                        if ( noErr == error && ((-1 == videoMode.csMode) || (-1 == videoMode.csData)) )
243                                error = statusErr;
244                       
245                        if (noErr != error)     // if the driver has no clue fill it videoMode by hand as a last resort
246                        {       
247                                theDCE = (AuxDCEHandle)GetDCtlEntry((*(requestRecPtr->screenDevice))->gdRefNum);
248                               
249                                if( theDCE )
250                                {
251                                        videoMode.csData = (unsigned char)(*theDCE)->dCtlSlotId;
252                                        videoMode.csMode = (*(requestRecPtr->screenDevice))->gdMode;
253                                        error = noErr;
254                                }
255                        }
256                        if (noErr == error)     // Set our data
257                        {
258                                requestRecPtr->displayMode                      = videoMode.csData;
259                                requestRecPtr->depthMode                        = videoMode.csMode;
260                                requestRecPtr->switchInfo.csMode        = videoMode.csMode;
261                                requestRecPtr->switchInfo.csData        = videoMode.csData;
262                        }
263                        return (error); // we (maybe) set the world back to a known setting
264                }
265        }
266        return (-1);
267}
268
269OSErr RVRequestVideoSetting (VideoRequestRecPtr requestRecPtr)
270{
271        Boolean                                                 displayMgrPresent;
272        short                                                   iCount = 0;                                     // just a counter of GDevices we have seen
273        DMDisplayModeListIteratorUPP    myModeIteratorProc = nil;       // for DM2.0 searches
274        SpBlock                                                 spBlock;
275        Boolean                                                 suppliedGDevice;       
276        DisplayIDType                                   theDisplayID;                           // for DM2.0 searches
277        DMListIndexType                                 theDisplayModeCount;            // for DM2.0 searches
278        DMListType                                              theDisplayModeList;                     // for DM2.0 searches
279        long                                                    value = 0;
280        GDHandle                                                walkDevice = nil;                       // for everybody
281
282        Gestalt(gestaltDisplayMgrAttr,&value);
283        displayMgrPresent=value&(1<<gestaltDisplayMgrPresent);
284        displayMgrPresent=displayMgrPresent && (SVersion(&spBlock)==noErr);     // need slot manager
285        if (displayMgrPresent)
286        {
287                // init the needed data before we start
288                if (requestRecPtr->screenDevice)                                                        // user wants a specifc device?
289                {
290                        walkDevice = requestRecPtr->screenDevice;
291                        suppliedGDevice = true;
292                }
293                else
294                {
295                        walkDevice = DMGetFirstScreenDevice (dmOnlyActiveDisplays);                     // for everybody
296                        suppliedGDevice = false;
297                }
298               
299                myModeIteratorProc = NewDMDisplayModeListIteratorProc(ModeListIterator);        // for DM2.0 searches
300       
301                // Note that we are hosed if somebody changes the gdevice list behind our backs while we are iterating....
302                // ...now do the loop if we can start
303                if( walkDevice && myModeIteratorProc) do // start the search
304                {
305                        iCount++;               // GDevice we are looking at (just a counter)
306                        if( noErr == DMGetDisplayIDByGDevice( walkDevice, &theDisplayID, false ) )      // DM1.0 does not need this, but it fits in the loop
307                        {
308                                theDisplayModeCount = 0;        // for DM2.0 searches
309                                if (noErr == DMNewDisplayModeList(theDisplayID, 0, 0, &theDisplayModeCount, &theDisplayModeList) )
310                                {
311                                        // search NuBus & PCI the new kool way through Display Manager 2.0
312                                        GetRequestTheDM2Way (requestRecPtr, walkDevice, myModeIteratorProc, theDisplayModeCount, &theDisplayModeList);
313                                        DMDisposeList(theDisplayModeList);      // now toss the lists for this gdevice and go on to the next one
314                                }
315                                else
316                                {
317                                        // search NuBus only the old disgusting way through the slot manager
318                                        GetRequestTheDM1Way (requestRecPtr, walkDevice);
319                                }
320                        }
321                } while ( !suppliedGDevice && nil != (walkDevice = DMGetNextScreenDevice ( walkDevice, dmOnlyActiveDisplays )) );       // go until no more gdevices
322                if( myModeIteratorProc )
323                        DisposeRoutineDescriptor(myModeIteratorProc);
324                return (noErr); // we were able to get the look for a match
325        }
326        return (-1);            // return a generic error
327}
328
329void GetRequestTheDM1Way (VideoRequestRecPtr requestRecPtr, GDHandle walkDevice)
330{
331        AuxDCEHandle myAuxDCEHandle;
332        unsigned long   depthMode;
333        unsigned long   displayMode;
334        OSErr                   error;
335        OSErr                   errorEndOfTimings;
336        short                   height;
337        short                   jCount = 0;
338        Boolean                 modeOk;
339        SpBlock                 spAuxBlock;
340        SpBlock                 spBlock;
341        unsigned long   switchFlags;
342        VPBlock                 *vpData;
343        short                   width;
344
345        myAuxDCEHandle = (AuxDCEHandle) GetDCtlEntry((**walkDevice).gdRefNum); 
346        spBlock.spSlot = (**myAuxDCEHandle).dCtlSlot;
347        spBlock.spID = (**myAuxDCEHandle).dCtlSlotId;
348        spBlock.spExtDev = (**myAuxDCEHandle).dCtlExtDev;
349        spBlock.spHwDev = 0;                                                            // we are going to get this pup
350        spBlock.spParamData = 1<<foneslot;                                      // this slot, enabled, and it better be here.
351        spBlock.spTBMask = 3;                                                           // don't have constants for this yet
352        errorEndOfTimings = SGetSRsrc(&spBlock);                        // get the spDrvrHW so we know the ID of this puppy. This is important
353                                                                                                                // since some video cards support more than one display, and the spDrvrHW
354                                                                                                                // ID can, and will, be used to differentiate them.
355       
356        if ( noErr == errorEndOfTimings )
357        {
358                // reinit the param block for the SGetTypeSRsrc loop, keep the spDrvrHW we just got
359                spBlock.spID = 0;                                                               // start at zero,
360                spBlock.spTBMask = 2;                                                   // 0b0010 - ignore DrvrSW - why ignore the SW side? Is it not important for video?
361                spBlock.spParamData = (1<<fall) + (1<<foneslot) + (1<<fnext);   // 0b0111 - this slot, enabled or disabled, so we even get 640x399 on Blackbird
362                spBlock.spCategory=catDisplay;
363                spBlock.spCType=typeVideo;
364                errorEndOfTimings = SGetTypeSRsrc(&spBlock);    // but only on 7.0 systems, not a problem since we require DM1.0
365               
366                // now, loop through all the timings for this GDevice
367                if ( noErr == errorEndOfTimings ) do
368                {
369                        // now, loop through all possible depth modes for this timing mode
370                        displayMode = (unsigned char)spBlock.spID;      // "timing mode, ie:resource ref number"
371                        for (jCount = firstVidMode; jCount<= sixthVidMode; jCount++)
372                        {
373                                depthMode = jCount;             // vid mode
374                                error = DMCheckDisplayMode(walkDevice,displayMode,depthMode,&switchFlags,0,&modeOk);
375       
376                                // only if the mode is safe or we override it with the kAllValidModesBit request flag
377                                if (    noErr == error &&
378                                                modeOk &&
379                                                (       switchFlags & 1<<kNoSwitchConfirmBit ||
380                                                        requestRecPtr->requestFlags & 1<<kAllValidModesBit
381                                                )
382                                        )
383                                {
384                                        // have a good displayMode/depthMode combo - now lets look inside
385                                        spAuxBlock = spBlock;                           // don't ruin the iteration spBlock!!
386                                        spAuxBlock.spID = depthMode;            // vid mode
387                                        error=SFindStruct(&spAuxBlock);         // get back a new spsPointer
388                                        if (noErr == error)                                     // keep going if no errorÉ
389                                        {
390                                                spAuxBlock.spID = 0x01;                 // mVidParams request
391                                                error=SGetBlock (&spAuxBlock);  // use the new spPointer and get back...a NewPtr'ed spResult
392                                                if (noErr == error)                             // Ékeep going if no errorÉ
393                                                {                                                               // We have data! lets have a look
394                                                        vpData = (VPBlock*)spAuxBlock.spResult;
395                                                        height = vpData->vpBounds.bottom;       // left and top are usually zero
396                                                        width = vpData->vpBounds.right;
397                                                       
398                                                        if (FindBestMatch (requestRecPtr, vpData->vpPixelSize, vpData->vpBounds.right, vpData->vpBounds.bottom))
399                                                        {
400                                                                requestRecPtr->screenDevice = walkDevice;
401                                                                requestRecPtr->availBitDepth = vpData->vpPixelSize;
402                                                                requestRecPtr->availHorizontal = vpData->vpBounds.right;
403                                                                requestRecPtr->availVertical = vpData->vpBounds.bottom;
404                                                                requestRecPtr->displayMode = displayMode;
405                                                                requestRecPtr->depthMode = depthMode;
406                                                                requestRecPtr->switchInfo.csMode = depthMode;                           // fill in for completeness
407                                                                requestRecPtr->switchInfo.csData = displayMode;
408                                                                requestRecPtr->switchInfo.csPage = 0;
409                                                                requestRecPtr->switchInfo.csBaseAddr = 0;
410                                                                requestRecPtr->switchInfo.csReserved = 0;
411                                                                if (switchFlags & 1<<kNoSwitchConfirmBit)
412                                                                        requestRecPtr->availFlags = 0;                                                  // mode safe
413                                                                else requestRecPtr->availFlags = 1<<kModeValidNotSafeBit;       // mode valid but not safe, requires user validation of mode switch
414                                                        }
415
416                                                        if (spAuxBlock.spResult) DisposePtr ((Ptr)spAuxBlock.spResult); // toss this puppy when done
417                                                }
418                                        }
419                                }
420                        }
421                        // go around again, looking for timing modes for this GDevice
422                        spBlock.spTBMask = 2;           // ignore DrvrSW
423                        spBlock.spParamData =  (1<<fall) + (1<<foneslot) + (1<<fnext);  // next resource, this slot, whether enabled or disabled
424                        errorEndOfTimings = SGetTypeSRsrc(&spBlock);    // and get the next timing mode
425                } while ( noErr == errorEndOfTimings ); // until the end of this GDevice
426        }
427
428}
429
430pascal void ModeListIterator(void *userData, DMListIndexType, DMDisplayModeListEntryPtr displaymodeInfo)
431{
432        unsigned long                   depthCount;
433        short                                   iCount;
434        ListIteratorDataRec             *myIterateData          = (ListIteratorDataRec*) userData;
435        DepthInfo                               *myDepthInfo;
436       
437        // set user data in a round about way
438        myIterateData->displayModeTimingInfo            = *displaymodeInfo->displayModeTimingInfo;
439       
440        // now get the DMDepthInfo info into memory we own
441        depthCount = displaymodeInfo->displayModeDepthBlockInfo->depthBlockCount;
442        myDepthInfo = (DepthInfo*)NewPtrClear(depthCount * sizeof(DepthInfo));
443
444        // set the info for the caller
445        myIterateData->depthBlockCount = depthCount;
446        myIterateData->depthBlocks = myDepthInfo;
447
448        // and fill out all the entries
449        if (depthCount) for (iCount=0; iCount < depthCount; iCount++)
450        {
451                myDepthInfo[iCount].depthSwitchInfo =
452                        *displaymodeInfo->displayModeDepthBlockInfo->depthVPBlock[iCount].depthSwitchInfo;
453                myDepthInfo[iCount].depthVPBlock =
454                        *displaymodeInfo->displayModeDepthBlockInfo->depthVPBlock[iCount].depthVPBlock;
455        }
456}
457
458void GetRequestTheDM2Way (      VideoRequestRecPtr requestRecPtr,
459                                                        GDHandle walkDevice,
460                                                        DMDisplayModeListIteratorUPP myModeIteratorProc,
461                                                        DMListIndexType theDisplayModeCount,
462                                                        DMListType *theDisplayModeList)
463{
464        short                                   jCount;
465        short                                   kCount;
466        ListIteratorDataRec             searchData;
467
468        searchData.depthBlocks = nil;
469        // get the mode lists for this GDevice
470        for (jCount=0; jCount<theDisplayModeCount; jCount++)            // get info on all the resolution timings
471        {
472                DMGetIndexedDisplayModeFromList(*theDisplayModeList, jCount, 0, myModeIteratorProc, &searchData);
473               
474                // for all the depths for this resolution timing (mode)...
475                if (searchData.depthBlockCount) for (kCount = 0; kCount < searchData.depthBlockCount; kCount++)
476                {
477                        // only if the mode is valid and is safe or we override it with the kAllValidModesBit request flag
478                        if      (       searchData.displayModeTimingInfo.csTimingFlags & 1<<kModeValid &&
479                                        (       searchData.displayModeTimingInfo.csTimingFlags & 1<<kModeSafe ||
480                                                requestRecPtr->requestFlags & 1<<kAllValidModesBit
481                                        )
482                                )
483                        {
484                                if (FindBestMatch (     requestRecPtr,
485                                                                        searchData.depthBlocks[kCount].depthVPBlock.vpPixelSize,
486                                                                        searchData.depthBlocks[kCount].depthVPBlock.vpBounds.right,
487                                                                        searchData.depthBlocks[kCount].depthVPBlock.vpBounds.bottom))
488                                {
489                                        requestRecPtr->screenDevice = walkDevice;
490                                        requestRecPtr->availBitDepth = searchData.depthBlocks[kCount].depthVPBlock.vpPixelSize;
491                                        requestRecPtr->availHorizontal = searchData.depthBlocks[kCount].depthVPBlock.vpBounds.right;
492                                        requestRecPtr->availVertical = searchData.depthBlocks[kCount].depthVPBlock.vpBounds.bottom;
493                                       
494                                        // now set the important info for DM to set the display
495                                        requestRecPtr->depthMode = searchData.depthBlocks[kCount].depthSwitchInfo.csMode;
496                                        requestRecPtr->displayMode = searchData.depthBlocks[kCount].depthSwitchInfo.csData;
497                                        requestRecPtr->switchInfo = searchData.depthBlocks[kCount].depthSwitchInfo;
498                                        if (searchData.displayModeTimingInfo.csTimingFlags & 1<<kModeSafe)
499                                                requestRecPtr->availFlags = 0;                                                  // mode safe
500                                        else requestRecPtr->availFlags = 1<<kModeValidNotSafeBit;       // mode valid but not safe, requires user validation of mode switch
501       
502                                }
503                        }
504
505                }
506       
507                if (searchData.depthBlocks)
508                {
509                        DisposePtr ((Ptr)searchData.depthBlocks);       // toss for this timing mode of this gdevice
510                        searchData.depthBlocks = nil;                           // init it just so we know
511                }
512        }
513}
514
515Boolean FindBestMatch (VideoRequestRecPtr requestRecPtr, short bitDepth, unsigned long horizontal, unsigned long vertical)
516{
517        // ¥¥ do the big comparison ¥¥
518        // first time only if   (no mode yet) and
519        //                                              (bounds are greater/equal or kMaximizeRes not set) and
520        //                                              (depth is less/equal or kShallowDepth not set) and
521        //                                              (request match or kAbsoluteRequest not set)
522        if      (       nil == requestRecPtr->displayMode
523                        &&
524                        (       (horizontal >= requestRecPtr->reqHorizontal &&
525                                vertical >= requestRecPtr->reqVertical)
526                                ||                                                                                                             
527                                !(requestRecPtr->requestFlags & 1<<kMaximizeResBit)     
528                        )
529                        &&
530                        (       bitDepth <= requestRecPtr->reqBitDepth ||       
531                                !(requestRecPtr->requestFlags & 1<<kShallowDepthBit)           
532                        )
533                        &&
534                        (       (horizontal == requestRecPtr->reqHorizontal && 
535                                vertical == requestRecPtr->reqVertical &&
536                                bitDepth == requestRecPtr->reqBitDepth)
537                                ||
538                                !(requestRecPtr->requestFlags & 1<<kAbsoluteRequestBit)
539                        )
540                )
541                {
542                        // go ahead and set the new values
543                        return (true);
544                }
545        else    // can we do better than last time?
546        {
547                // if   (kBitDepthPriority set and avail not equal req) and
548                //              ((depth is greater avail and depth is less/equal req) or kShallowDepth not set) and
549                //              (avail depth less reqested and new greater avail)
550                //              (request match or kAbsoluteRequest not set)
551                if      (       (       requestRecPtr->requestFlags & 1<<kBitDepthPriorityBit &&
552                                        requestRecPtr->availBitDepth != requestRecPtr->reqBitDepth
553                                )
554                                &&
555                                (       (       bitDepth > requestRecPtr->availBitDepth &&
556                                                bitDepth <= requestRecPtr->reqBitDepth
557                                        )
558                                        ||
559                                        !(requestRecPtr->requestFlags & 1<<kShallowDepthBit)   
560                                )
561                                &&
562                                (       requestRecPtr->availBitDepth < requestRecPtr->reqBitDepth &&
563                                        bitDepth > requestRecPtr->availBitDepth
564                                )
565                                &&
566                                (       (horizontal == requestRecPtr->reqHorizontal && 
567                                        vertical == requestRecPtr->reqVertical &&
568                                        bitDepth == requestRecPtr->reqBitDepth)
569                                        ||
570                                        !(requestRecPtr->requestFlags & 1<<kAbsoluteRequestBit)
571                                )
572                        )
573                {
574                        // go ahead and set the new values
575                        return (true);
576                }
577                else
578                {
579                        // match resolution: minimize Æh & Æv
580                        if      (       abs((requestRecPtr->reqHorizontal - horizontal)) <=
581                                        abs((requestRecPtr->reqHorizontal - requestRecPtr->availHorizontal)) &&
582                                        abs((requestRecPtr->reqVertical - vertical)) <=
583                                        abs((requestRecPtr->reqVertical - requestRecPtr->availVertical))
584                                )
585                        {
586                                // now we have a smaller or equal delta
587                                //      if (h or v greater/equal to request or kMaximizeRes not set)
588                                if (    (horizontal >= requestRecPtr->reqHorizontal &&
589                                                vertical >= requestRecPtr->reqVertical)
590                                                ||
591                                                !(requestRecPtr->requestFlags & 1<<kMaximizeResBit)
592                                        )
593                                {
594                                        // if   (depth is equal or kBitDepthPriority not set) and
595                                        //              (depth is less/equal or kShallowDepth not set) and
596                                        //              ([h or v not equal] or [avail depth less reqested and new greater avail] or depth equal avail) and
597                                        //              (request match or kAbsoluteRequest not set)
598                                        if      (       (       requestRecPtr->availBitDepth == bitDepth ||                     
599                                                                !(requestRecPtr->requestFlags & 1<<kBitDepthPriorityBit)
600                                                        )
601                                                        &&
602                                                        (       bitDepth <= requestRecPtr->reqBitDepth ||       
603                                                                !(requestRecPtr->requestFlags & 1<<kShallowDepthBit)           
604                                                        )
605                                                        &&
606                                                        (       (requestRecPtr->availHorizontal != horizontal ||
607                                                                requestRecPtr->availVertical != vertical)
608                                                                ||
609                                                                (requestRecPtr->availBitDepth < requestRecPtr->reqBitDepth &&
610                                                                bitDepth > requestRecPtr->availBitDepth)
611                                                                ||
612                                                                (bitDepth == requestRecPtr->reqBitDepth)
613                                                        )
614                                                        &&
615                                                        (       (horizontal == requestRecPtr->reqHorizontal && 
616                                                                vertical == requestRecPtr->reqVertical &&
617                                                                bitDepth == requestRecPtr->reqBitDepth)
618                                                                ||
619                                                                !(requestRecPtr->requestFlags & 1<<kAbsoluteRequestBit)
620                                                        )
621                                                )
622                                        {
623                                                // go ahead and set the new values
624                                                return (true);
625                                        }
626                                }
627                        }
628                }
629        }
630        return (false);
631}
632
633void GravitateMonitors (void)
634{
635        // do the magic gravitation here
636}
Note: See TracBrowser for help on using the repository browser.