Important: The information in this document is obsolete and should not be used for new development.
NewGWorld
Use theNewGWorldfunction to create an offscreen graphics world.
FUNCTION NewGWorld (VAR offscreenGWorld: GWorldPtr; pixelDepth: Integer; boundsRect: Rect; cTable: CTabHandle; aGDevice: GDHandle; flags: GWorldFlags): QDErr;
offscreenGWorld- A pointer to the offscreen graphics world created by this routine.
pixelDepth- The pixel depth of the offscreen world; possible depths are 1, 2, 4, 8, 16, and 32 bits per pixel. If you specify 0 in this parameter, you get the default behavior for the
NewGWorldfunction--that is, it uses the pixel depth of the screen with the greatest pixel depth from among all screens whose boundary rectangles intersect the rectangle that you specify in theboundsRectparameter. If you specify 0 in this parameter,NewGWorldalso uses theGDevicerecord from this device instead of creating a newGDevicerecord for the offscreen world. If you useNewGWorldon a computer that supports only basic QuickDraw, you may specify only 0 or 1 in this parameter.boundsRect- The boundary rectangle and port rectangle for the offscreen pixel map. This becomes the boundary rectangle for the
GDevicerecord, ifNewGWorldcreates one. If you specify 0 in thepixelDepthparameter,NewGWorldinterprets the boundaries in global coordinates that it uses to determine which screens intersect the rectangle. (NewGWorldthen uses the pixel depth, color table, andGDevicerecord from the screen with the greatest pixel depth from among all screens whose boundary rectangles intersect this rectangle.) Typically, your application supplies this parameter with the port rectangle for the onscreen window into which your application will copy the pixel image from this offscreen world.cTable- A handle to a
ColorTablerecord. If you passNILin this parameter,NewGWorlduses the default color table for the pixel depth that you specify in thepixelDepthparameter. If you set thepixelDepthparameter to 0,NewGWorldignores thecTableparameter and instead copies and uses the color table of the graphics device with the greatest pixel depth among all graphics devices whose boundary rectangles intersect the rectangle that you specify in theboundsRectparameter. If you useNewGWorldon a computer that supports only basic QuickDraw, you may specify onlyNILin this parameter.aGDevice- A handle to a
GDevicerecord that is used only when you specify thenoNewDeviceflag in theflagsparameter, in which caseNewGWorldattaches thisGDevicerecord to the new offscreen graphics world. If you set thepixelDepthparameter to 0, or if you do not set thenoNewDeviceflag,NewGWorldignores theaGDeviceparameter, so you should set it toNIL. If you set thepixelDepthparameter to 0,NewGWorlduses theGDevicerecord for the graphics device with the greatest pixel depth among all graphics devices whose boundary rectangles intersect the rectangle that you specify in theboundsRectparameter. You should passNILin this parameter if the computer supports only basic QuickDraw. Generally, your application should never createGDevicerecords for offscreen graphics worlds.flags- Options available to your application. You can set a combination of the flags
pixPurge,noNewDevice,useTempMem, andkeepLocal. If you don't wish to use any of these flags, pass the empty set ([ ]) in your Pascal code or 0 in your C code in this parameter, in which case you get the default behavior forNewGWorld--that is, it creates an offscreen graphics world where the base address for the offscreen pixel image is unpurgeable, it uses an existingGDevicerecord (if you pass 0 in thedepthparameter) or creates a newGDevicerecord, it uses memory in your application heap, and it allows graphics accelerators to cache the offscreen pixel image. The available flags are described here:TYPE GWorldFlags = SET OF ( {flags for only NewGWorld are listed here} pixPurge, {make base address for offscreen pixel } { image purgeable} noNewDevice, {do not create an offscreen GDevice } { record} useTempMem, {create base address for offscreen pixel } { image in temporary memory} keepLocal, {keep offscreen pixel image in main } { memory where it cannot be cached to } { a graphics accelerator card} );DESCRIPTION
TheNewGWorldfunction creates an offscreen graphics world with the pixel depth you specify in thepixelDepthparameter, the boundary rectangle you specify in theboundsRectparameter, the color table you specify in thecTableparameter, and the options you specify in theflagsparameter. TheNewGWorldfunction returns a pointer to the new offscreen graphics world in theoffscreenGWorldparameter. You use this pointer when referring to this new offscreen world in other routines described in this chapter.Typically, you pass 0 in the
pixelDepthparameter, a window's port rectangle in theboundsRectparameter,NILin thecTableandaGDeviceparameters, and--in theflagsparameter--an empty set ([ ]) for Pascal code or 0 for C code. This provides your application with the default behavior ofNewGWorld, and it supports computers running basic QuickDraw. This also allows QuickDraw to optimize theCopyBits,CopyMask, andCopyDeepMaskprocedures when your application copies the image in an offscreen graphics world into an onscreen graphics port.The
NewGWorldfunction allocates memory for an offscreen graphics port and its pixel map. On computers that support only basic QuickDraw,NewGWorldcreates a 1-bit pixel map that your application can manipulate using other relevant routines described in this chapter. Your application can copy this 1-bit pixel map into basic graphics ports.Unless you specify 0 in the
pixelDepthparameter--or pass thenoNewDeviceflag in theflagsparameter and supply aGDevicerecord in theaGDeviceparameter--NewGWorldalso allocates a new offscreenGDevicerecord.When creating an image, your application can use the
NewGWorldfunction to create an offscreen graphics world that is optimized for an image's characteristics--for example, its best pixel depth. After creating the image, your application can then use theCopyBits,CopyMask, orCopyDeepMaskprocedure to copy that image to an onscreen graphics port. Color QuickDraw automatically renders the image at the best available pixel depth for the screen. Creating an image in an offscreen graphics port and then copying it to the screen in this way prevents the visual choppiness that would otherwise occur if your application were to build a complex image directly onscreen.The
NewGWorldfunction initializes the offscreen graphics port by calling theOpenCPortfunction. TheNewGWorldfunction sets the offscreen graphics port's visible region to a rectangular region coincident with its boundary rectangle. TheNewGWorldfunction generates an inverse table with the Color Manager procedureMakeITable, unless one of theGDevicerecords for the screens has the same color table as theGDevicerecord for the offscreen world, in which caseNewGWorlduses the inverse table from thatGDevicerecord.The address of the offscreen pixel image is not directly accessible from the
PixMaprecord for the offscreen graphics world. However, you can use theGetPixBaseAddrfunction (described on page 6-38) to get a pointer to the beginning of the offscreen pixel image.For purposes of estimating memory use, you can compute the size of the offscreen pixel image by using this formula:
rowBytes * (boundsRect.bottom - boundsRect.top)In theflagsparameter, you can specify several options that are defined by theGWorldFlagsdata type. If you don't wish to use any of these options, pass an empty set ([ ]) in theflagsparameter for Pascal code or pass 0 here for C code.
As its function result,
- If you specify the
pixPurgeflag,NewGWorldstores the offscreen pixel image in a purgeable block of memory. In this case, before drawing to or from the offscreen pixel image, your application should call theLockPixelsfunction (described on page 6-32) and ensure that it returnsTRUE. IfLockPixelsreturnsFALSE, the memory for the pixel image has been purged, and your application should either callUpdateGWorldto reallocate it and then reconstruct the pixel image, or draw directly in a window instead of preparing the image in an offscreen graphics world. Never draw to or copy from an offscreen pixel image that has been purged without reallocating its memory and then reconstructing it.- If you specify the
noNewDeviceflag,NewGWorlddoes not create a new offscreenGDevicerecord. Instead, it uses theGDevicerecord that you specify in theaGDeviceparameter--and its associated pixel depth and color table--to create the offscreen graphics world. (If you set thepixelDepthparameter to 0,NewGWorlduses theGDevicerecord for the screen with the greatest pixel depth among all screens whose boundary rectangles intersect the rectangle that you specify in theboundsRectparameter--even if you specify thenoNewDeviceflag.) TheNewGWorldfunction keeps a reference to theGDevicerecord for the offscreen graphics world, and theSetGWorldprocedure (described on page 6-28) uses that record to set the current graphics device.- If you set the
useTempMemflag,NewGWorldcreates the base address for an offscreen pixel image in temporary memory. You generally would not use this flag, because you should use temporary memory only for fleeting purposes and only with theAllowPurgePixelsprocedure (described on page 6-34).- If you specify the
keepLocalflag, your offscreen pixel image is kept in Macintosh main memory and is not cached to a graphics accelerator card. Use this flag carefully, as it negates the advantages provided by any graphics acceleration card that might be present.
NewGWorldreturns one of three result codes.SPECIAL CONSIDERATIONS
If you supply a handle to aColorTablerecord in thecTableparameter,NewGWorldmakes a copy of the record and stores its handle in the offscreenPixMaprecord. It is your application's responsibility to make sure that theColorTablerecord you specify in thecTableparameter is valid for the offscreen graphics port's pixel depth.If when using
NewGWorldyou specify a pixel depth, color table, orGDevicerecord that differs from those used by the window into which you copy your offscreen image, theCopyBits,CopyMask, andCopyDeepMaskprocedures require extra time to complete.To use a custom color table in an offscreen graphics world, you need to create the associated offscreen
GDevicerecord, because Color QuickDraw needs its inverse table.The
NewGWorldfunction may move or purge memory blocks in the application heap. Your application should not call this function at interrupt time.ASSEMBLY-LANGUAGE INFORMATION
The trap macro and routine selector for theNewGWorldfunction are
Trap macro Selector _QDExtensions $00160000 RESULT CODES
noErr 0 No error paramErr -50 Illegal parameter cDepthErr -157 Invalid pixel depth SEE ALSO
Listing 6-1 on page 6-5 and Listing 6-2 on page 6-10 illustrate how to useNewGWorldto create offscreen graphics worlds.If your application needs to change the pixel depth, boundary rectangle, or color table for an offscreen graphics world, use the
UpdateGWorldfunction, described on page 6-23.