The Node2D class is a helper class for display devices that allocate memory as single rectangular blocks. For these types of device, the pace of bit block transfer (blit) operations is a constant, regardless of the width of the actual surface. Many devices use the current screen width as the width of the video memory. All blit operations are assumed to have the same stride, or pitch, and pixel format as the screen.

To allocate a memory rectangle block, create an initial Node2D object using the same height and width as the memory block. Enter the width either in pixels or in bytes. Queries to allocated subrectangles of memory return the origin of the allocated memory in the same units with which the original Node2D object was created.

You must allocate subrectangles in the same units as well. Allocate subrectangles using the Alloc method of the root node. Examine the origin of the new node using the Top and Left methods of the node. Finally, free the node using the Free method. The following code example shows how the Free method is usually implemented.

// Assume there is a 640x1000-pixel line 
// block of memory starting at memBase
// to be allocated as a rectangle.
#define PIXEL_BYTES 2
#define MEM_HEIGHT 1000
extern unsigned char *memBase;

// Allocations are done in pixels.
// Create a 20x40 surface.
Node2D *pSurf1 = AllMem->Alloc( 20, 40 );

// Check that pSurf1 is not NULL.
// Create a 100x100 surface.
Node2D *pSurf2 = AllMem->Alloc( 100, 100 );

// Check that pSurf2 is not NULL.

// Create a pointer the the top left of the block of
//    memory in surf1.
unsigned char *ptr1 = memBase + strideInBytes * pSurf1->Top()
+ PIXEL_BYTES * pSurf1->Left();

// Now delete the surface(s).

You can quickly modify display drivers that use the Node2D allocator class to manage video memory allocations. Use the member functions to help save video surfaces to system memory. The following code example from the MQ200 driver in the %_WINCEROOT%\Public\Common\OAK\Drivers\Display\MQ200\Control.cpp registry key shows these member functions.

case DRVESC_RESTOREVIDEOMEM: //set video mem to sys mem
        m_p2DVideoMemory->RestoreSystemMemtoSurf((unsigned char *)m_pPrimarySurface->Buffer(),m_ulScreenStride);
        totalMemNeeded = totalVideoMemAlloc = totalVideoMemPiece = 0;
        return ESC_SUCCESS;

case DRVESC_SAVEVIDEOMEM: // copy video mem to sys mem
        m_p2DVideoMemory->SaveSurfToSystemMem((unsigned char*)m_pPrimarySurface->Buffer(), m_ulScreenStride);
        return ESC_SUCCESS;

        *(long *)pvOut = totalVideoMemUsed;
        return ESC_SUCCESS;

A display driver can use either the Node2D class or the SurfaceHeap Class. The display driver should not use both classes. The Node2D class does not support surfaces with differing bpp. The SurfaceHeap class is preferred unless you must use rectangular memory.

See Also

Display Driver Escape Codes | GPE Base Classes | GPE | GPESurf | ColorConverter | GPEVGA | Display Drivers | Display Driver Extensions | Display Driver Samples

 Last updated on Tuesday, May 18, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.