Important: The information in this document is obsolete and should not be used for new development.
NewGWorld
Use theNewGWorld
function 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
NewGWorld
function--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 theboundsRect
parameter. If you specify 0 in this parameter,NewGWorld
also uses theGDevice
record from this device instead of creating a newGDevice
record for the offscreen world. If you useNewGWorld
on 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
GDevice
record, ifNewGWorld
creates one. If you specify 0 in thepixelDepth
parameter,NewGWorld
interprets the boundaries in global coordinates that it uses to determine which screens intersect the rectangle. (NewGWorld
then uses the pixel depth, color table, andGDevice
record 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
ColorTable
record. If you passNIL
in this parameter,NewGWorld
uses the default color table for the pixel depth that you specify in thepixelDepth
parameter. If you set thepixelDepth
parameter to 0,NewGWorld
ignores thecTable
parameter 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 theboundsRect
parameter. If you useNewGWorld
on a computer that supports only basic QuickDraw, you may specify onlyNIL
in this parameter.aGDevice
- A handle to a
GDevice
record that is used only when you specify thenoNewDevice
flag in theflags
parameter, in which caseNewGWorld
attaches thisGDevice
record to the new offscreen graphics world. If you set thepixelDepth
parameter to 0, or if you do not set thenoNewDevice
flag,NewGWorld
ignores theaGDevice
parameter, so you should set it toNIL
. If you set thepixelDepth
parameter to 0,NewGWorld
uses theGDevice
record for the graphics device with the greatest pixel depth among all graphics devices whose boundary rectangles intersect the rectangle that you specify in theboundsRect
parameter. You should passNIL
in this parameter if the computer supports only basic QuickDraw. Generally, your application should never createGDevice
records 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 existingGDevice
record (if you pass 0 in thedepth
parameter) or creates a newGDevice
record, 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
TheNewGWorld
function creates an offscreen graphics world with the pixel depth you specify in thepixelDepth
parameter, the boundary rectangle you specify in theboundsRect
parameter, the color table you specify in thecTable
parameter, and the options you specify in theflags
parameter. TheNewGWorld
function returns a pointer to the new offscreen graphics world in theoffscreenGWorld
parameter. You use this pointer when referring to this new offscreen world in other routines described in this chapter.Typically, you pass 0 in the
pixelDepth
parameter, a window's port rectangle in theboundsRect
parameter,NIL
in thecTable
andaGDevice
parameters, and--in theflags
parameter--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
, andCopyDeepMask
procedures when your application copies the image in an offscreen graphics world into an onscreen graphics port.The
NewGWorld
function allocates memory for an offscreen graphics port and its pixel map. On computers that support only basic QuickDraw,NewGWorld
creates 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
pixelDepth
parameter--or pass thenoNewDevice
flag in theflags
parameter and supply aGDevice
record in theaGDevice
parameter--NewGWorld
also allocates a new offscreenGDevice
record.When creating an image, your application can use the
NewGWorld
function 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
, orCopyDeepMask
procedure 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
NewGWorld
function initializes the offscreen graphics port by calling theOpenCPort
function. TheNewGWorld
function sets the offscreen graphics port's visible region to a rectangular region coincident with its boundary rectangle. TheNewGWorld
function generates an inverse table with the Color Manager procedureMakeITable
, unless one of theGDevice
records for the screens has the same color table as theGDevice
record for the offscreen world, in which caseNewGWorld
uses the inverse table from thatGDevice
record.The address of the offscreen pixel image is not directly accessible from the
PixMap
record for the offscreen graphics world. However, you can use theGetPixBaseAddr
function (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 theflags
parameter, you can specify several options that are defined by theGWorldFlags
data type. If you don't wish to use any of these options, pass an empty set ([ ]) in theflags
parameter for Pascal code or pass 0 here for C code.
As its function result,
- If you specify the
pixPurge
flag,NewGWorld
stores 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 theLockPixels
function (described on page 6-32) and ensure that it returnsTRUE
. IfLockPixels
returnsFALSE
, the memory for the pixel image has been purged, and your application should either callUpdateGWorld
to 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
noNewDevice
flag,NewGWorld
does not create a new offscreenGDevice
record. Instead, it uses theGDevice
record that you specify in theaGDevice
parameter--and its associated pixel depth and color table--to create the offscreen graphics world. (If you set thepixelDepth
parameter to 0,NewGWorld
uses theGDevice
record for the screen with the greatest pixel depth among all screens whose boundary rectangles intersect the rectangle that you specify in theboundsRect
parameter--even if you specify thenoNewDevice
flag.) TheNewGWorld
function keeps a reference to theGDevice
record for the offscreen graphics world, and theSetGWorld
procedure (described on page 6-28) uses that record to set the current graphics device.- If you set the
useTempMem
flag,NewGWorld
creates 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 theAllowPurgePixels
procedure (described on page 6-34).- If you specify the
keepLocal
flag, 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.
NewGWorld
returns one of three result codes.SPECIAL CONSIDERATIONS
If you supply a handle to aColorTable
record in thecTable
parameter,NewGWorld
makes a copy of the record and stores its handle in the offscreenPixMap
record. It is your application's responsibility to make sure that theColorTable
record you specify in thecTable
parameter is valid for the offscreen graphics port's pixel depth.If when using
NewGWorld
you specify a pixel depth, color table, orGDevice
record that differs from those used by the window into which you copy your offscreen image, theCopyBits
,CopyMask
, andCopyDeepMask
procedures require extra time to complete.To use a custom color table in an offscreen graphics world, you need to create the associated offscreen
GDevice
record, because Color QuickDraw needs its inverse table.The
NewGWorld
function 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 theNewGWorld
function 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 useNewGWorld
to 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
UpdateGWorld
function, described on page 6-23.