home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / GDInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-09  |  5.4 KB  |  153 lines  |  [TEXT/MMCC]

  1. /*
  2. GDInfo.c
  3.  
  4. GDInfo fills the user-supplied VideoInfo record with all the descriptive
  5. information that can be obtained quickly from the driver and GDevice record
  6. without disturbing the screen. Under 1-bit QuickDraw it ignores the card->device
  7. field.
  8.  
  9. GDInfoTime fills the user-supplied VideoInfo record with the results of calling
  10. most of the routines in GDTime.c. Under 1-bit QuickDraw it ignores the "card->device"
  11. argument.
  12.  
  13. HISTORY:
  14. 4/16/93    dgp set pages=1 for 1-bit qd.
  15. 4/26/93    dgp    test HasDepth before relying on it.
  16. 4/27/93    dgp    replaced HasDepth by GDHasMode.
  17. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  18.             Metrowerks CodeWarrior C.
  19. 9/5/94 dgp removed assumption in printf's that int==short.
  20. */
  21. #include "VideoToolbox.h"
  22. #include "GDInfo.h"
  23. #include <math.h>
  24.  
  25. OSErr GDInfo(VideoInfo *card)
  26. {
  27.     short pixelSize,pages,d,mode;
  28.     Rect r;
  29.     long qD;
  30.     ColorSpec cSpec;
  31.     char *s;
  32.     
  33.     Gestalt(gestaltQuickdrawVersion,&qD);
  34.     if(qD<gestalt8BitQD){
  35.         card->device=NULL;
  36.         sprintf(card->cardName,"%s","Original 1-bit QuickDraw");
  37.         sprintf(card->driverName,"%s","Original 1-bit QuickDraw");
  38.         for(d=1;d<6;d++)card->depth[d].pixelSize=0;
  39.         card->slot=0;
  40.         CopyQuickDrawGlobals();    // make sure qd is valid.
  41.         r=qd.screenBits.bounds;
  42.         card->width=r.right-r.left;
  43.         card->height=r.bottom-r.top;
  44.         card->depth[0].pixelSize=1;
  45.         card->depth[0].clutSize=2;
  46.         card->depth[0].pages=1;
  47.         card->depth[0].framesPerClutUpdate=NAN;
  48.         card->depth[0].framesPerClutUpdateHighPriority=NAN;
  49.         card->depth[0].framesPerClutUpdateQuickly=NAN;
  50.         card->depth[0].vblPerFrame=1.0;
  51.         card->d=0;
  52.         card->dacSize=1;
  53.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  54.         card->basicTested=1;
  55.         return 0;
  56.     }
  57.     if(!card->basicTested){
  58.         // This info never changes, so get it only once
  59.         for(d=0;d<6;d++){
  60.             card->depth[d].pixelSize=0;
  61.             card->depth[d].mode=0;
  62.             card->depth[d].pages=0;
  63.         }
  64.         d=0;
  65.         for(mode=0x80;mode<=0x85 && d<6;mode++){
  66.             if(GDHasMode(card->device,mode,&pixelSize,&pages)){
  67.                 card->depth[d].mode=mode;
  68.                 card->depth[d].pixelSize=pixelSize;
  69.                 card->depth[d].pages=pages;
  70.                 d++;
  71.             }
  72.         }
  73.         sprintf(card->cardName,"%s",s=GDCardName(card->device));
  74.         DisposePtr(s);
  75.         if(GDVersion(card->device)==0)sprintf(card->driverName,"%s"
  76.             ,GDNameStr(card->device));
  77.         else sprintf(card->driverName,"%s version %d"
  78.             ,GDNameStr(card->device),(int)GDVersion(card->device));
  79.         card->slot=GetDeviceSlot(card->device);
  80.         r=(**(**card->device).gdPMap).bounds;
  81.         card->width=r.right-r.left;
  82.         card->height=r.bottom-r.top;
  83.         card->dacSize=GDDacSize(card->device);        // Takes 200 µs.
  84.         card->dacMask=((1<<card->dacSize)-1)<<(16 - card->dacSize);
  85.         card->setEntriesQuickly=(GetCardType(card->device)!=0);
  86.         card->gdGetEntries=(0==GDGetEntries(card->device,0,0,&cSpec));
  87.         card->basicTested=1;
  88.     }
  89.     // d changes any time you call SetDepth, so update it every time.
  90.     for(d=0;d<6;d++)if(card->depth[d].mode==(**card->device).gdMode)card->d=d;
  91.     
  92.     // Collect information from the GDevice record
  93.     card->depth[card->d].pixelSize=(**(**card->device).gdPMap).pixelSize;
  94.     card->depth[card->d].clutSize=GDClutSize(card->device);
  95.     return 0;
  96. }
  97.  
  98. OSErr GDInfoTime(VideoInfo *card)
  99. {
  100.     int error=0;
  101.     short clutSize=0,d=card->d;
  102.     double frames,s,missingFrames,frameRate;
  103.     long qD;
  104.     printf(BLANKLINE);    
  105.     printf("%d-bit pixels: timing CopyBits . . ." "\r",(int)card->depth[d].pixelSize);
  106.     card->depth[d].movieRate=GDMovieRate(card->device,0);
  107.     printf(BLANKLINE);    
  108.     printf("%d-bit pixels: timing CopyBitsQuickly . . ." "\r",(int)card->depth[d].pixelSize);
  109.     card->depth[d].movieRateQuickly=GDMovieRate(card->device,1);
  110.     Gestalt(gestaltQuickdrawVersion,&qD);
  111.     if(qD>=gestalt8BitQD){
  112.         printf(BLANKLINE);    
  113.         printf("%d-bit pixels: timing cscSetEntries . . ." "\r",(int)card->depth[d].pixelSize);
  114.         error=GDTimeClut(card->device,GDSetEntries,clutSize,&s,&frames,&missingFrames,&frameRate);
  115.         if(error){
  116.             // Video driver won't load clut, so we can't time that, but we can still time fram rate.
  117.             frameRate=GDFrameRate(card->device);
  118.         }
  119.         card->depth[d].frameRate=frameRate;
  120.         card->depth[d].vblPerFrame=GDVBLRate(card->device)/frameRate;
  121.         card->depth[d].framesPerClutUpdate=frames;
  122.         card->depth[d].missingFramesPerClutUpdate=missingFrames;
  123.     }else{
  124.         card->depth[d].frameRate=GDFrameRate(NULL);
  125.         card->depth[d].vblPerFrame=1.0;
  126.         card->depth[d].framesPerClutUpdate=NAN;
  127.         card->depth[d].missingFramesPerClutUpdate=NAN;
  128.     }
  129.     if(qD>=gestalt8BitQD){
  130.         printf(BLANKLINE);    
  131.         printf("%d-bit pixels: timing GDSetEntriesByTypeHighPriority . . ." "\r",(int)card->depth[d].pixelSize);
  132.         error=GDTimeClut(card->device,GDSetEntriesByTypeHighPriority,clutSize,&s,&frames,&missingFrames,&frameRate);
  133.         card->depth[d].framesPerClutUpdateHighPriority=frames;
  134.         card->depth[d].missingFramesPerClutUpdateHighPriority=missingFrames;
  135.     }else{
  136.         card->depth[d].framesPerClutUpdateHighPriority=NAN;
  137.         card->depth[d].missingFramesPerClutUpdateHighPriority=NAN;
  138.     }
  139.     if(qD>=gestalt8BitQD && GetCardType(card->device)){
  140.         printf(BLANKLINE);    
  141.         printf("%d-bit pixels: timing SetEntriesQuickly . . ." "\r",(int)card->depth[d].pixelSize);
  142.         error=GDTimeClut(card->device,SetEntriesQuickly,clutSize,&s,&frames,&missingFrames,&frameRate);
  143.         card->depth[d].framesPerClutUpdateQuickly=frames;
  144.         card->depth[d].missingFramesPerClutUpdateQuickly=missingFrames;
  145.     }else{
  146.         card->depth[d].framesPerClutUpdateQuickly=NAN;
  147.         card->depth[d].missingFramesPerClutUpdateQuickly=NAN;
  148.     }
  149.     printf(BLANKLINE);    
  150.     card->timeTested=1;
  151.     card->depth[d].timeTested=1;
  152.     return error;
  153. }