~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Frontier Kernel
Frontier/Common/source/bitmaps.c

Version: ~ [ 10.0 ] ~

** Warning: Cannot open xref database.

1 2 /* $Id: bitmaps.c,v 1.3 2005/01/11 22:48:04 andreradke Exp $ */ 3 4 /****************************************************************************** 5 6 UserLand Frontier(tm) -- High performance Web content management, 7 object database, system-level and Internet scripting environment, 8 including source code editing and debugging. 9 10 Copyright (C) 1992-2004 UserLand Software, Inc. 11 12 This program is free software; you can redistribute it and/or modify 13 it under the terms of the GNU General Public License as published by 14 the Free Software Foundation; either version 2 of the License, or 15 (at your option) any later version. 16 17 This program is distributed in the hope that it will be useful, 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public License 23 along with this program; if not, write to the Free Software 24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 25 26 ******************************************************************************/ 27 28 /* 29 bitmaps.c -- routines which manage off-screen bitmaps. In order to use these routines 30 the program must call "initbitmaps" before calling anything. 31 32 initbitmaps takes a boolean. if false, then all subsequent calls to bitmap routines do 33 nothing but return. 34 */ 35 36 #include "frontier.h" 37 #include "standard.h" 38 39 #include <land.h> 40 #include "mac.h" 41 #include "quickdraw.h" 42 #include "font.h" 43 #include "bitmaps.h" 44 #include "shellhooks.h" 45 46 47 #define qd32trap 0xAB03 48 /* 49 0xAB1D 50 */ 51 #define unimptrap 0xA89F 52 53 54 55 static boolean flbitmapsenabled = false; /*turned on by initbitmaps*/ 56 57 static boolean flbitmapopen = false; /*is one open right now?*/ 58 59 //Code change by Timothy Paustian Saturday, April 29, 2000 10:35:03 PM 60 //Changed to Opaque call for Carbon 61 //I am getting rid of savedbitmap and using psavedport to do the stuff 62 static BitMap offscreenbitmap; 63 64 static Handle bitmapbasehandle; 65 66 static boolean flhas32bitqd = false; /*32-bit quickdraw implemented?*/ 67 68 static CGrafPtr psavedport; 69 70 static GWorldPtr poffscreenworld; 71 72 static GDHandle hsavedgd; 73 74 static Rect offscreenrect; 75 76 77 78 static boolean openworld (Rect r, WindowPtr w) { 79 80 /* 81 2.1b13 dmb: set the noNewDeviceBit and useTempMemBit for NewGWorld 82 too; in 2.1, we're never actually calling UpdateGWorld anymore 83 84 3.0.2b1 dmb: was using useTempMemBit instead of useTempMem 85 86 3.0.2 dmb: don't set the noNewDeviceBit, because the ROM can leak memory 87 */ 88 89 short fontnum, fontsize, fontstyle; 90 PenState pen; 91 Rect portRect; 92 93 GetGWorld (&psavedport, &hsavedgd); 94 95 // assert (w == (WindowPtr) psavedport); 96 97 offscreenrect = r; 98 99 localtoglobalrect (w, &r); 100 //Code change by Timothy Paustian Friday, May 19, 2000 1:12:47 PM 101 //If we get an empty rect, then just return. This prevents a paramErr 102 //from update or NewGWorld 103 if(EmptyRect(&r)) 104 return false; 105 if (poffscreenworld != nil) { 106 107 //Code change by Timothy Paustian Friday, May 19, 2000 12:44:38 PM 108 //I think we don't want to use temp memory for this. 109 //I checked this a bit and it fails when an empty rect is brought in 110 //lets try checking for this first above 111 if (UpdateGWorld (&poffscreenworld, 0, &r, nil, nil, 0) & gwFlagErr) 112 return (false); 113 } 114 else { 115 //Code change by Timothy Paustian Friday, May 19, 2000 12:44:38 PM 116 //I think we don't want to use temp memory for this. 117 if (NewGWorld (&poffscreenworld, 0, &r, nil, nil, 0) != noErr) 118 return (false); 119 } 120 121 getfontsizestyle (&fontnum, &fontsize, &fontstyle); 122 123 GetPenState (&pen); 124 125 SetGWorld (poffscreenworld, nil); 126 //Code change by Timothy Paustian Saturday, April 29, 2000 10:02:33 PM 127 //Changed to Opaque call for Carbon 128 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 129 //LockPortBits(poffscreenworld); 130 //watch out for this one. I think it is working. 131 { 132 PixMapHandle portPixMap = GetPortPixMap(poffscreenworld); 133 LockPixels (portPixMap); 134 } 135 #else 136 //old code 137 LockPixels (poffscreenworld->portPixMap); 138 #endif 139 setfontsizestyle (fontnum, fontsize, fontstyle); 140 141 SetPenState (&pen); 142 143 SetOrigin (offscreenrect.left, offscreenrect.top); 144 //Code change by Timothy Paustian Saturday, April 29, 2000 10:06:50 PM 145 //Changed to Opaque call for Carbon 146 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 147 GetPortBounds(poffscreenworld, &portRect); 148 ClipRect (&portRect); 149 #else 150 //old code 151 #pragma unused(portRect) 152 ClipRect (&poffscreenworld->portRect); /*recommended by Apple DTS*/ 153 #endif 154 /* 155 CopyBits (&((GrafPtr) w)->portBits, &((GrafPtr) poffscreenworld)->portBits, 156 &offscreenrect, &poffscreenworld->portRect, srcCopy, nil); 157 158 EraseRect (&poffscreenworld->portRect); 159 */ 160 161 return (true); 162 } /*openworld*/ 163 164 165 static void closeworld (WindowPtr w) { 166 167 /* 168 2/8/91 dmb: experiments show that we get better performance tossing 169 the gworld every time that we do using updategworld on the same one. 170 */ 171 Rect portRect; 172 SetGWorld (psavedport, hsavedgd); 173 //Code change by Timothy Paustian Saturday, April 29, 2000 10:12:08 PM 174 //Changed to Opaque call for Carbon 175 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 176 GetPortBounds(poffscreenworld, &portRect); 177 CopyBits (GetPortBitMapForCopyBits(poffscreenworld), GetPortBitMapForCopyBits(psavedport), 178 &portRect, &offscreenrect, srcCopy, nil); 179 #else 180 //old code 181 #pragma unused(portRect) 182 CopyBits (&((GrafPtr) poffscreenworld)->portBits, &((GrafPtr) psavedport)->portBits, 183 &poffscreenworld->portRect, &offscreenrect, srcCopy, nil); 184 #endif 185 186 DisposeGWorld (poffscreenworld); 187 188 poffscreenworld = nil; 189 190 /* 191 UnlockPixels (poffscreenworld->portPixMap); 192 */ 193 } /*closeworld*/ 194 195 196 static void initworld (void) { 197 198 poffscreenworld = nil; 199 } /*initworld*/ 200 201 202 static boolean openmono (Rect r, WindowPtr w) { 203 204 register short nrowbytes; 205 register long nboxbytes; 206 register long sizehandle; 207 208 nrowbytes = (r.right - r.left + 7) / 8; 209 210 if (odd (nrowbytes)) 211 nrowbytes++; 212 213 nboxbytes = (r.bottom - r.top) * nrowbytes; 214 215 SetHandleSize (bitmapbasehandle, nboxbytes); 216 217 sizehandle = GetHandleSize (bitmapbasehandle); 218 219 if (sizehandle < nboxbytes) { 220 221 SetHandleSize (bitmapbasehandle, 10L); 222 223 return (false); 224 } 225 226 HLock (bitmapbasehandle); 227 228 offscreenbitmap.baseAddr = *bitmapbasehandle; 229 230 offscreenbitmap.rowBytes = nrowbytes; 231 232 offscreenbitmap.bounds = r; 233 234 //Code change by Timothy Paustian Saturday, April 29, 2000 10:16:24 PM 235 //Changed to Opaque call for Carbon 236 //we no longer need savedbitmap 237 //old code 238 //savedbitmap = (*w).portBits; 239 240 SetPortBits (&offscreenbitmap); 241 242 return (true); 243 } /*openmono*/ 244 245 246 static void closemono (WindowPtr w) { 247 //Code change by Timothy Paustian Tuesday, May 16, 2000 10:06:53 PM 248 //Changed to Opaque call for Carbon 249 //don't need to worry about this one because it only gets called when 32bit quickdraw is not 250 //present. These machines won't run Mac OS X anyway. 251 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 252 //a signal to show that this was called, it should not be 253 assert(false); 254 #else 255 SetPortBits (psavedport); 256 257 CopyBits ( 258 &offscreenbitmap, &((GrafPtr) w)->portBits, &offscreenbitmap.bounds, 259 260 &offscreenbitmap.bounds, srcCopy, nil); 261 //#endif 262 263 HUnlock (bitmapbasehandle); 264 265 offscreenbitmap.baseAddr = 0; 266 #endif 267 /* 268 SetHandleSize (bitmapbasehandle, 10L); 269 */ 270 } /*closemono*/ 271 272 273 static void initmono (void) { 274 275 bitmapbasehandle = NewHandle (10L); 276 277 offscreenbitmap.baseAddr = 0; 278 279 offscreenbitmap.rowBytes = 2; 280 281 SetRect (&offscreenbitmap.bounds, 0, 0, 0, 0); 282 } /*initmono*/ 283 284 285 boolean openbitmap (Rect r, WindowPtr w) { 286 287 boolean fl; 288 289 if (flbitmapopen) 290 return (false); /*can't nest offscreens*/ 291 292 if (!flbitmapsenabled) /*application doesn't want any bitmaps*/ 293 return (false); 294 295 flbitmapopen = true; /*set now so growzone won't mess with handle*/ 296 297 if (flhas32bitqd) 298 fl = openworld (r, w); 299 else 300 fl = openmono (r, w); 301 302 if (!fl) { 303 304 flbitmapopen = false; /*well, it didn't work out*/ 305 306 return (false); 307 } 308 309 return (true); 310 } /*openbitmap*/ 311 312 313 boolean openbitmapcopy (Rect r, WindowPtr w) { 314 315 //Code change by Timothy Paustian Saturday, April 29, 2000 10:45:30 PM 316 //Changed to Opaque call for Carbon 317 318 if (!openbitmap (r, w)) 319 return (false); 320 321 if (flhas32bitqd) 322 { 323 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 324 assert(false); //this never gets called in the latest version 325 #else 326 //old code 327 CopyBits (&((GrafPtr) w)->portBits, &((GrafPtr) poffscreenworld)->portBits, 328 &r, &poffscreenworld->portRect, srcCopy, nil); 329 #endif 330 } 331 else 332 { 333 334 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 0 335 //old code 336 CopyBits (&((GrafPtr) psavedport)->portBits, &offscreenbitmap, &r, &r, srcCopy, nil); 337 #endif 338 339 } 340 return (true); 341 } /*openbitmapcopy*/ 342 343 344 void closebitmap (WindowPtr w) { 345 346 if (flbitmapsenabled && flbitmapopen) { 347 348 flbitmapopen = false; 349 350 if (flhas32bitqd) 351 closeworld (w); 352 else 353 closemono (w); 354 } 355 } /*closebitmap*/ 356 357 //Code change by Timothy Paustian Sunday, May 7, 2000 10:59:28 PM 358 //Changed to Opaque call for Carbon 359 //this is really old and it should be removed 360 static boolean trapimplemented (short trapnum) { 361 362 //Code change by Timothy Paustian Sunday, May 7, 2000 10:56:54 PM 363 //Changed to Opaque call for Carbon 364 #if ACCESSOR_CALLS_ARE_FUNCTIONS == 1 365 //always return false for traps since this not allowed in carbon 366 //This really is not needed but what the heck 367 return false; 368 #else 369 return (NGetTrapAddress (trapnum, ToolTrap) != NGetTrapAddress (unimptrap, ToolTrap)); 370 #endif 371 } /*trapimplemented*/ 372 373 374 static boolean flushbitmap (long *ctbytesneeded) { 375 376 if (!flbitmapopen && (*ctbytesneeded > 0)) { 377 378 *ctbytesneeded -= GetHandleSize (bitmapbasehandle); 379 380 SetHandleSize (bitmapbasehandle, 0L); 381 } 382 383 return (true); 384 } /*flushbitmap*/ 385 386 387 void initbitmaps (boolean fl) { 388 389 /* 390 2/11/91 dmb: got the gWorld routines to work properly, bypassing the 391 GetGWorldPixMap access routine which seemed to be returning the high 392 word only of the pixmaphandle. however, performance was about three 393 times slower than using bitmaps, so flhas32bitqd is wired off here. 394 to support color, restore the assignments using Gestalt/SysEnvirons, 395 and create color windows in newshellwindow (). 396 397 12/4/91 dmb: added flushbitmap memoryhook 398 */ 399 400 long qdversion; 401 402 flbitmapsenabled = fl; 403 404 if (flbitmapsenabled) { 405 406 if (Gestalt (gestaltQuickdrawVersion, &qdversion) == noErr) 407 flhas32bitqd = qdversion >= gestalt32BitQD; 408 else 409 //Code change by Timothy Paustian Sunday, May 7, 2000 10:59:15 PM 410 //Changed to Opaque call for Carbon 411 //this looks like really old code for pre system 7 and we should be able to remove it now. 412 flhas32bitqd = gHasColorQD && trapimplemented (qd32trap); 413 414 if (flhas32bitqd) 415 initworld (); 416 else 417 initmono (); 418 419 shellpushmemoryhook (&flushbitmap); 420 } 421 } /*initbitmaps*/ 422 423 424 425

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.