home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!caen!uakari.primate.wisc.edu!ames!agate!rsoft!mindlink!a347
- From: John_Miller@mindlink.bc.ca (John Miller)
- Newsgroups: comp.sys.mac.programmer
- Subject: LockPixels and dereferenced PixMapHandles
- Message-ID: <14278@mindlink.bc.ca>
- Date: 14 Aug 92 00:59:06 GMT
- Distribution: world
- Organization: MIND LINK! - British Columbia, Canada
- Lines: 63
-
- In various portions of code on the developer CD, it seems to be
- assumed that once LockPixels() is called, it's safe to dereference
- the PixMapHandle when calling CopyBits. Here's one example
- from the file
- "Dev.CD June 92:
- Periodicals:
- develop:develop 10 code:
- GWorld Drawing:
- GWorld Routines:
- CalcDeltasFast.c"
-
- > srcPixMap = GetGWorldPixMap ( src );
- > dstPixMap = GetGWorldPixMap ( dst );
- >
- > if ( LockPixels ( srcPixMap ) && LockPixels( dstPixMap) )
- > { /* lock the pixmaps */
- > GetGWorld(&oldGW,&oldGD);
- > SetGWorld(dst,nil);
- > CopyBits( (BitMap*)*srcPixMap, (BitMap*)*dstPixMap,
- > &(**srcPixMap).bounds, &(**dstPixMap).bounds,
- > srcCopy, 0L );
-
- But from my reading of Inside Mac, LockPixels() only locks the
- memory used to hold the pixels, not the PixMapHandle itself.
- And when I check this in MacsBug, sure enough, the
- PixMapHandle is not locked by LockPixels() or unlocked by
- UnlockPIxels().
-
- If I had picked up this code on the street, I would simply
- assume it was buggy, but seeing as I find this in various
- fragments of Apple code, I'm wondering if I am missing
- something.
-
- Two questions:
-
- 1) Should the PixMapHandle be locked before dereferencing
- it to pass to CopyBits, or am I missing some piece of
- Mac programming forklore that guarantees that CopyBits
- will extract all the required information from parameters
- before it causes any memory shuffling?
-
- 2) Assuming that I would have to lock the PixMapHandle
- before using in the above example: is it considered valid
- to copy the PixMap structure contents to a local PixMap
- variable and pass the address of the variable to CopyBits,
- or does CopyBits assume that the address it is passed can
- be traced back to a PixMapHandle? Right now, my
- offscreen utility routines are calling MoveHHi(pixmap)
- and HLock(pixmap) after calling LockPixels(), but I would
- like to avoid the potential expense of MoveHHi and
- the potential memory fragmentation if I lock the handle
- without calling MoveHHi.
-
- (Seeing as the current CopyBits won't use the application
- heap for any image buffers, I suppose I could lock
- the PixMapHandle only before CopyBits -- thus avoiding
- fragmentation for other calls such as DrawPicture --
- but I would prefer an approach that would continue
- to work well if CopyBits' implementation details
- change.)
-
- John Miller
- Symplex Systems
-