bitmaps.c

Go to the documentation of this file.
00001 
00002 /*  $Id: bitmaps.c 1206 2006-04-05 23:21:19Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 /*
00029 bitmaps.c -- routines which manage off-screen bitmaps.  In order to use these routines
00030 the program must call "initbitmaps" before calling anything.
00031 
00032 initbitmaps takes a boolean.  if false, then all subsequent calls to bitmap routines do
00033 nothing but return.
00034 */
00035 
00036 #include "frontier.h"
00037 #include "standard.h"
00038 
00039 #include <land.h>
00040 #include "mac.h"
00041 #include "quickdraw.h"
00042 #include "font.h"
00043 #include "bitmaps.h"
00044 #include "shellhooks.h"
00045 
00046 
00047 #define qd32trap 0xAB03
00048 /*
00049 0xAB1D
00050 */
00051 #define unimptrap 0xA89F
00052 
00053 
00054 
00055 static boolean flbitmapsenabled = false; /*turned on by initbitmaps*/
00056 
00057 static boolean flbitmapopen = false; /*is one open right now?*/
00058 
00059 //Code change by Timothy Paustian Saturday, April 29, 2000 10:35:03 PM
00060 //Changed to Opaque call for Carbon
00061 //I am getting rid of savedbitmap and using psavedport to do the stuff
00062 static BitMap offscreenbitmap;
00063 
00064 static Handle bitmapbasehandle;
00065 
00066 static boolean flhas32bitqd = false; /*32-bit quickdraw implemented?*/
00067 
00068 static CGrafPtr psavedport;
00069 
00070 static GWorldPtr poffscreenworld;
00071 
00072 static GDHandle hsavedgd;
00073 
00074 static Rect offscreenrect;
00075 
00076 
00077 
00078 static boolean openworld (Rect r, WindowPtr w) {
00079     
00080     /*
00081     2.1b13 dmb: set the noNewDeviceBit and useTempMemBit for NewGWorld 
00082     too; in 2.1, we're never actually calling UpdateGWorld anymore
00083     
00084     3.0.2b1 dmb: was using useTempMemBit instead of useTempMem
00085     
00086     3.0.2 dmb: don't set the noNewDeviceBit, because the ROM can leak memory
00087     */
00088     
00089     short fontnum, fontsize, fontstyle;
00090     PenState pen;
00091     Rect            portRect;
00092     
00093     GetGWorld (&psavedport, &hsavedgd);
00094     
00095 //  assert (w == (WindowPtr) psavedport);
00096     
00097     offscreenrect = r;
00098     
00099     localtoglobalrect (w, &r);
00100     //Code change by Timothy Paustian Friday, May 19, 2000 1:12:47 PM
00101     //If we get an empty rect, then just return. This prevents a paramErr
00102     //from update or NewGWorld
00103     if(EmptyRect(&r))
00104         return false;
00105     if (poffscreenworld != nil) {
00106         
00107         //Code change by Timothy Paustian Friday, May 19, 2000 12:44:38 PM
00108         //I think we don't want to use temp memory for this.
00109         //I checked this a bit and it fails when an empty rect is brought in
00110         //lets try checking for this first above
00111         if (UpdateGWorld (&poffscreenworld, 0, &r, nil, nil, 0) & gwFlagErr)
00112             return (false);
00113         }
00114     else {
00115         //Code change by Timothy Paustian Friday, May 19, 2000 12:44:38 PM
00116         //I think we don't want to use temp memory for this.
00117         if (NewGWorld (&poffscreenworld, 0, &r, nil, nil, 0) != noErr)
00118             return (false);
00119         }
00120     
00121     getfontsizestyle (&fontnum, &fontsize, &fontstyle);
00122     
00123     GetPenState (&pen);
00124     
00125     SetGWorld (poffscreenworld, nil);
00126     //Code change by Timothy Paustian Saturday, April 29, 2000 10:02:33 PM
00127     //Changed to Opaque call for Carbon
00128     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00129     //LockPortBits(poffscreenworld);
00130     //watch out for this one. I think it is working.
00131     {
00132     PixMapHandle    portPixMap = GetPortPixMap(poffscreenworld);
00133     LockPixels (portPixMap);
00134     }
00135     #else
00136     //old code
00137     LockPixels (poffscreenworld->portPixMap);
00138     #endif
00139     setfontsizestyle (fontnum, fontsize, fontstyle);
00140     
00141     SetPenState (&pen);
00142     
00143     SetOrigin (offscreenrect.left, offscreenrect.top);
00144     //Code change by Timothy Paustian Saturday, April 29, 2000 10:06:50 PM
00145     //Changed to Opaque call for Carbon
00146     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00147     GetPortBounds(poffscreenworld, &portRect);
00148     ClipRect (&portRect);
00149     #else
00150     //old code
00151     #pragma unused(portRect)
00152     ClipRect (&poffscreenworld->portRect); /*recommended by Apple DTS*/
00153     #endif
00154     /*
00155     CopyBits (&((GrafPtr) w)->portBits, &((GrafPtr) poffscreenworld)->portBits,
00156         &offscreenrect, &poffscreenworld->portRect, srcCopy, nil);
00157     
00158     EraseRect (&poffscreenworld->portRect);
00159     */
00160     
00161     return (true);
00162     } /*openworld*/
00163 
00164 
00165 static void closeworld (WindowPtr w) {
00166 #pragma unused(w)
00167 
00168     /*
00169     2/8/91 dmb: experiments show that we get better performance tossing 
00170     the gworld every time that we do using updategworld on the same one.
00171     */
00172     Rect    portRect;
00173     SetGWorld (psavedport, hsavedgd);
00174     //Code change by Timothy Paustian Saturday, April 29, 2000 10:12:08 PM
00175     //Changed to Opaque call for Carbon
00176     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00177     GetPortBounds(poffscreenworld, &portRect);
00178     CopyBits (GetPortBitMapForCopyBits(poffscreenworld), GetPortBitMapForCopyBits(psavedport),
00179         &portRect, &offscreenrect, srcCopy, nil);
00180     #else
00181     //old code
00182     #pragma unused(portRect)
00183     CopyBits (&((GrafPtr) poffscreenworld)->portBits, &((GrafPtr) psavedport)->portBits,
00184         &poffscreenworld->portRect, &offscreenrect, srcCopy, nil);
00185     #endif
00186     
00187     DisposeGWorld (poffscreenworld);
00188     
00189     poffscreenworld = nil;
00190     
00191     /*
00192     UnlockPixels (poffscreenworld->portPixMap);
00193     */
00194     } /*closeworld*/
00195 
00196 
00197 static void initworld (void) {
00198     
00199     poffscreenworld = nil;
00200     } /*initworld*/
00201 
00202 
00203 static boolean openmono (Rect r, WindowPtr w) {
00204 #pragma unused(w)
00205 
00206     register short nrowbytes;
00207     register long nboxbytes;
00208     register long sizehandle;
00209     
00210     nrowbytes = (r.right - r.left + 7) / 8;
00211     
00212     if (odd (nrowbytes)) 
00213         nrowbytes++;
00214     
00215     nboxbytes = (r.bottom - r.top) * nrowbytes;
00216     
00217     SetHandleSize (bitmapbasehandle, nboxbytes);
00218     
00219     sizehandle = GetHandleSize (bitmapbasehandle);
00220     
00221     if (sizehandle < nboxbytes) {
00222     
00223         SetHandleSize (bitmapbasehandle, 10L);
00224         
00225         return (false);
00226         }
00227     
00228     HLock (bitmapbasehandle);
00229     
00230     offscreenbitmap.baseAddr = *bitmapbasehandle;
00231     
00232     offscreenbitmap.rowBytes = nrowbytes;
00233     
00234     offscreenbitmap.bounds = r;
00235     
00236     //Code change by Timothy Paustian Saturday, April 29, 2000 10:16:24 PM
00237     //Changed to Opaque call for Carbon
00238     //we no longer need savedbitmap
00239     //old code
00240     //savedbitmap = (*w).portBits;
00241     
00242     SetPortBits (&offscreenbitmap);
00243     
00244     return (true);
00245     } /*openmono*/
00246 
00247 
00248 static void closemono (WindowPtr w) {
00249 //Code change by Timothy Paustian Tuesday, May 16, 2000 10:06:53 PM
00250 //Changed to Opaque call for Carbon
00251 //don't need to worry about this one because it only gets called when 32bit quickdraw is not
00252 //present. These machines won't run Mac OS X anyway.
00253 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00254 //a signal to show that this was called, it should not be
00255 assert(false);
00256 #else
00257     SetPortBits (psavedport);
00258     
00259     CopyBits (
00260         &offscreenbitmap, &((GrafPtr) w)->portBits, &offscreenbitmap.bounds, 
00261     
00262         &offscreenbitmap.bounds, srcCopy, nil);
00263     //#endif
00264     
00265     HUnlock (bitmapbasehandle);
00266     
00267     offscreenbitmap.baseAddr = 0;
00268  #endif 
00269     /*
00270     SetHandleSize (bitmapbasehandle, 10L);
00271     */
00272     } /*closemono*/
00273 
00274 
00275 static void initmono (void) {
00276     
00277     bitmapbasehandle = NewHandle (10L); 
00278         
00279     offscreenbitmap.baseAddr = 0;
00280         
00281     offscreenbitmap.rowBytes = 2;
00282         
00283     SetRect (&offscreenbitmap.bounds, 0, 0, 0, 0);
00284     } /*initmono*/
00285 
00286 
00287 boolean openbitmap (Rect r, WindowPtr w) {
00288     
00289     boolean fl;
00290     
00291     if (flbitmapopen)
00292         return (false); /*can't nest offscreens*/
00293     
00294     if (!flbitmapsenabled) /*application doesn't want any bitmaps*/
00295         return (false);
00296     
00297     flbitmapopen = true; /*set now so growzone won't mess with handle*/
00298     
00299     if (flhas32bitqd)
00300         fl = openworld (r, w);
00301     else
00302         fl = openmono (r, w);
00303     
00304     if (!fl) {
00305     
00306         flbitmapopen = false; /*well, it didn't work out*/
00307     
00308         return (false);
00309         }
00310     
00311     return (true);
00312     } /*openbitmap*/
00313 
00314 
00315 boolean openbitmapcopy (Rect r, WindowPtr w) {
00316     
00317     //Code change by Timothy Paustian Saturday, April 29, 2000 10:45:30 PM
00318     //Changed to Opaque call for Carbon
00319     
00320     if (!openbitmap (r, w))
00321         return (false);
00322     
00323     if (flhas32bitqd)
00324     {
00325         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00326         assert(false); //this never gets called in the latest version
00327         #else
00328         //old code
00329         CopyBits (&((GrafPtr) w)->portBits, &((GrafPtr) poffscreenworld)->portBits,
00330                 &r, &poffscreenworld->portRect, srcCopy, nil);
00331         #endif
00332     }
00333     else
00334     {   
00335         
00336         #if ACCESSOR_CALLS_ARE_FUNCTIONS == 0
00337         //old code
00338         CopyBits (&((GrafPtr) psavedport)->portBits, &offscreenbitmap, &r, &r, srcCopy, nil);
00339         #endif
00340         
00341     }
00342     return (true);
00343     } /*openbitmapcopy*/
00344 
00345 
00346 void closebitmap (WindowPtr w) {
00347     
00348     if (flbitmapsenabled && flbitmapopen) {
00349         
00350         flbitmapopen = false;
00351         
00352         if (flhas32bitqd)
00353             closeworld (w);
00354         else
00355             closemono (w);
00356         }
00357     } /*closebitmap*/
00358 
00359 //Code change by Timothy Paustian Sunday, May 7, 2000 10:59:28 PM
00360 //Changed to Opaque call for Carbon
00361 //this is really old and it should be removed
00362 static boolean trapimplemented (short trapnum) {
00363     
00364     //Code change by Timothy Paustian Sunday, May 7, 2000 10:56:54 PM
00365     //Changed to Opaque call for Carbon
00366     #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1
00367     #pragma unused(trapnum)
00368     //always return false for traps since this not allowed in carbon
00369     //This really is not needed but what the heck
00370     return false;
00371     #else
00372     return (NGetTrapAddress (trapnum, ToolTrap) != NGetTrapAddress (unimptrap, ToolTrap));
00373     #endif
00374     } /*trapimplemented*/
00375 
00376 
00377 static boolean flushbitmap (long *ctbytesneeded) {
00378     
00379     if (!flbitmapopen && (*ctbytesneeded > 0)) {
00380         
00381         *ctbytesneeded -= GetHandleSize (bitmapbasehandle);
00382         
00383         SetHandleSize (bitmapbasehandle, 0L);
00384         }
00385     
00386     return (true);
00387     } /*flushbitmap*/
00388 
00389 
00390 void initbitmaps (boolean fl) {
00391     
00392     /*
00393     2/11/91 dmb: got the gWorld routines to work properly, bypassing the 
00394     GetGWorldPixMap access routine which seemed to be returning the high 
00395     word only of the pixmaphandle.  however, performance was about three 
00396     times slower than using bitmaps, so flhas32bitqd is wired off here.  
00397     to support color, restore the assignments using Gestalt/SysEnvirons, 
00398     and create color windows in newshellwindow ().
00399     
00400     12/4/91 dmb: added flushbitmap memoryhook
00401     */
00402     
00403     long qdversion;
00404     
00405     flbitmapsenabled = fl;
00406     
00407     if (flbitmapsenabled) {
00408         
00409         if (Gestalt (gestaltQuickdrawVersion, &qdversion) == noErr)
00410             flhas32bitqd = qdversion >= gestalt32BitQD;
00411         else
00412 //Code change by Timothy Paustian Sunday, May 7, 2000 10:59:15 PM
00413 //Changed to Opaque call for Carbon
00414 //this looks like really old code for pre system 7 and we should be able to remove it now.
00415             flhas32bitqd = gHasColorQD && trapimplemented (qd32trap);
00416         
00417         if (flhas32bitqd)
00418             initworld ();
00419         else
00420             initmono ();
00421         
00422         shellpushmemoryhook (&flushbitmap);
00423         }
00424     } /*initbitmaps*/
00425 
00426 
00427 

Generated on Wed May 31 18:19:44 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6