home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / GimmeLib / dbufvquick.c < prev    next >
C/C++ Source or Header  |  1988-12-27  |  4KB  |  140 lines

  1. /*
  2.  *  FILE: dbufvquick.c
  3.  *  Support routines for converting a single-buffered Intuition screen
  4.  *  into a double-buffered screen and back.
  5.  *  It is faster than dbuf.c because copper lists are stored and manipulated
  6.  *  quickly by these routines.
  7.  *  It is slightly faster than dbufquick.c because copper lis pointers do not
  8.  *  need to be passed as extra parameters.
  9.  *
  10.  *  NOTE: these routines are not very forgiving with respect to moving the
  11.  *  screen around under Intuition.
  12.  *
  13.  *  Public Domain, but keep my name in it as the original author.
  14.  *  31-Aug-88    Jan Sven Trabandt   first release version
  15.  */
  16.  
  17.  
  18. #define I_AM_DBUFVQUICK
  19. #include "gimmelib/gimmefuncs.h"
  20. #include "gimmelib/minterm.h"
  21.  
  22. static struct View    *gimView = NULL;
  23. static struct cprlist    *gimShCpr = NULL;
  24. static struct cprlist    *gimLoCpr = NULL;
  25.  
  26.  
  27. short makeDBufVQuick( screen, bmptr )
  28.     struct Screen   *screen;
  29.     struct BitMap   **bmptr;
  30. {
  31.     struct BitMap   *bm;
  32.     struct cprlist  *lcpr, *scpr;
  33.  
  34. #ifdef GIMME_WIMPY
  35.     if( !screen || !bmptr ) {
  36.     return( -1 );
  37.     }
  38. #endif
  39.     if( !*bmptr ) {
  40.     *bmptr = gimmeBitMap( screen->BitMap.Depth, screen->Width,
  41.                 screen->Height );
  42.     if( !*bmptr ) {
  43.         return( -1 );
  44.     }
  45.     }
  46.  
  47.     Forbid();
  48.     bm = screen->RastPort.BitMap;        /* save main bitmap pointer */
  49.     gimView = ViewAddress();
  50.     lcpr = gimView->LOFCprList;            /* save these copper lists */
  51.     scpr = gimView->SHFCprList;
  52.     gimView->LOFCprList = NULL;
  53.     gimView->SHFCprList = NULL;
  54.     screen->ViewPort.RasInfo->BitMap = *bmptr;        /* set to back buffer */
  55.     MakeScreen( screen );
  56.     MrgCop( gimView );                         /* make new copper lists */
  57.     gimLoCpr = gimView->LOFCprList;           /* save new copper lists */
  58.     gimShCpr = gimView->SHFCprList;
  59.     gimView->LOFCprList = lcpr;            /* restore old copper lists */
  60.     gimView->SHFCprList = scpr;
  61.     screen->ViewPort.RasInfo->BitMap = bm;  /* restore main viewing buffer */
  62.     Permit();
  63.  
  64.     screen->RastPort.BitMap = *bmptr;        /* draw to back buffer */
  65.     return( 0 );
  66. } /* makeDBufVQuick */
  67.  
  68.  
  69. short unmakeDBufVQuick( screen, bmptr, bm )
  70.     struct Screen   *screen;
  71.     struct BitMap   **bmptr;
  72.     struct BitMap   *bm;
  73. {
  74.     struct BitMap   *viewbm;
  75.  
  76. #ifdef GIMME_WIMPY
  77.     if( !screen || !bmptr ) {
  78.     return( -1 );
  79.     }
  80. #endif
  81.     viewbm = screen->ViewPort.RasInfo->BitMap;
  82.     if( !(screen->Flags & CUSTOMBITMAP) && viewbm == *bmptr ) {
  83.     BltBitMap( viewbm, 0L, 0L, screen->RastPort.BitMap, 0L, 0L,
  84.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  85.             (ULONG) GIM_MINTERM_COPY, 0x0ffL, NULL );
  86.     swapDBufVQuick( screen, GIM_MINTERM_DEST );
  87.     }
  88.     if( viewbm != screen->RastPort.BitMap ) {
  89.     screen->RastPort.BitMap = viewbm;
  90.     }
  91.     if( bm ) {
  92.     getRidOfBitMap( bm );
  93.     }
  94.     if( gimLoCpr ) {
  95.     FreeCprList( gimLoCpr );
  96.     }
  97.     if( gimShCpr ) {
  98.     FreeCprList( gimShCpr );
  99.     }
  100.     return( 0 );
  101. } /* unmakeDBufVQuick */
  102.  
  103.  
  104. short swapDBufVQuick( screen, minterm )
  105.     register struct Screen  *screen;
  106.     SHORT   minterm;
  107. {
  108.     struct BitMap   *bm;
  109.     struct cprlist  *lcpr, *scpr;
  110.  
  111. #ifdef GIMME_WIMPY
  112.     if( !screen ) {
  113.     return( -1 );
  114.     }
  115. #endif
  116.     Forbid();
  117.     bm = screen->ViewPort.RasInfo->BitMap;
  118.     if( bm == screen->RastPort.BitMap ) {
  119.     Permit();
  120.     return( 0 );
  121.     }
  122.     lcpr = gimView->LOFCprList;            /* get current copper lists */
  123.     scpr = gimView->SHFCprList;
  124.     gimView->LOFCprList = gimLoCpr;           /* set other copper lists */
  125.     gimView->SHFCprList = gimShCpr;
  126.     gimLoCpr = lcpr;                /* save new other copper lists */
  127.     gimShCpr = scpr;
  128.     LoadView( gimView );
  129.  
  130.     screen->ViewPort.RasInfo->BitMap = screen->RastPort.BitMap;
  131.     screen->RastPort.BitMap = bm;
  132.     Permit();
  133.     if( minterm != GIM_MINTERM_DEST ) {
  134.     BltBitMap( screen->ViewPort.RasInfo->BitMap, 0L, 0L, bm, 0L, 0L,
  135.             (ULONG)(bm->BytesPerRow) << 3, (ULONG) bm->Rows,
  136.             (ULONG) minterm, 0x0ffL, NULL );
  137.     }
  138.     return( 0 );
  139. } /* swapDBufVQuick */
  140.