void VBoxDDRAWFrameBuffer::releaseObjects() { deleteSurface (); if (mPrimarySurface) { if (mClipper) { mPrimarySurface->SetClipper (NULL); } mPrimarySurface->Release (); mPrimarySurface = NULL; } if (mClipper) { mClipper->Release(); mClipper = NULL; } if (mDDRAW) { mDDRAW->Release(); mDDRAW = NULL; } }
/** * main */ int main(int argc, char **args) { list *slices; surface *surf; /* turn on memory tracing */ putenv("MALLOC_TRACE=memtest_memtrace.txt"); mtrace(); /* read the slices from the file */ slices = readSliceContours(args[1]); if(slices == NULL) { printf("couldn't read slices from %s!\n",args[1]); return 0; } preprocessSliceContours(slices); /* builds a guess at contour correspondence */ // correspondenceMethod = HISTOGRAM; // correspondenceScope = LOCAL; buildCorrespondenceGuess(slices); /* tile the slices */ // minSliceInd = 0; // maxSliceInd = 40; surf = tileSlices(slices); deleteSliceContours(slices); fillBranchedHoles(surf); writeOFF(surf,"testmem.off"); deleteSurface(surf); return 0; }
/** * Creates a new surface in the requested format. * On success, returns @c true and assigns the created surface to mSurface * and its definition to mSurfaceDesc. On failure, returns @c false. * * If @a aPixelFormat is other than FramebufferPixelFormat_Opaque, * then the method will attempt to attach @a aVRAM directly to the created * surface. If this fails, the caller may call this method again with * @a aPixelFormat set to FramebufferPixelFormat_Opaque to try * setting up an indirect fallback buffer for the surface. This opeartion may * theoretically also fail. * * @note Deletes the existing surface before attempting to create a new one. */ bool VBoxDDRAWFrameBuffer::createSurface (ULONG aPixelFormat, uchar *aVRAM, ULONG aBitsPerPixel, ULONG aBytesPerLine, ULONG aWidth, ULONG aHeight) { deleteSurface(); DDSURFACEDESC2 sd; /* Prepare the surface description structure. */ memset (&sd, 0, sizeof (sd)); sd.dwSize = sizeof (sd); sd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT; sd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; sd.dwWidth = aWidth; sd.dwHeight = aHeight; /* Setup the desired pixel format on the surface. */ sd.ddpfPixelFormat.dwSize = sizeof (sd.ddpfPixelFormat); sd.ddpfPixelFormat.dwFlags = DDPF_RGB; if (aPixelFormat == FramebufferPixelFormat_FOURCC_RGB) { /* Try to use the guest VRAM directly */ switch (aBitsPerPixel) { case 32: sd.ddpfPixelFormat.dwRGBBitCount = 32; sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000; sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00; sd.ddpfPixelFormat.dwBBitMask = 0x000000FF; break; case 24: sd.ddpfPixelFormat.dwRGBBitCount = 24; sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000; sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00; sd.ddpfPixelFormat.dwBBitMask = 0x000000FF; break; case 16: sd.ddpfPixelFormat.dwRGBBitCount = 16; sd.ddpfPixelFormat.dwRBitMask = 0xF800; sd.ddpfPixelFormat.dwGBitMask = 0x07E0; sd.ddpfPixelFormat.dwBBitMask = 0x001F; break; default: /* we don't directly support any other color depth */ return false; } sd.lPitch = (LONG) aBytesPerLine; sd.lpSurface = aVRAM; mUsesGuestVRAM = true; mPixelFormat = FramebufferPixelFormat_FOURCC_RGB; } else if (aPixelFormat != FramebufferPixelFormat_Opaque) { /* we don't directly support any other pixel format */ return false; } else { /* for the Opaque format, we use the indirect memory buffer as a * 32 bpp surface. */ sd.ddpfPixelFormat.dwRGBBitCount = 32; sd.ddpfPixelFormat.dwRBitMask = 0x00FF0000; sd.ddpfPixelFormat.dwGBitMask = 0x0000FF00; sd.ddpfPixelFormat.dwBBitMask = 0x000000FF; sd.lPitch = sd.dwWidth * 4; /* Allocate the memory buffer for the surface */ sd.lpSurface = RTMemAlloc (sd.lPitch * sd.dwHeight); if (sd.lpSurface == NULL) { LOGDDRAW (("DDRAW: could not allocate memory for surface.\n")); return false; } mUsesGuestVRAM = false; mPixelFormat = FramebufferPixelFormat_FOURCC_RGB; } /* create the surface */ HRESULT rc = mDDRAW->CreateSurface (&sd, &mSurface, NULL); if (rc != DD_OK) { LOGDDRAW (("DDRAW: Could not create DirectDraw surface, rc=0x%08X\n", rc)); deleteSurface(); return false; } /* Initialize the surface description member. It will be used to obtain * address, bpp and bpl. */ mSurfaceDesc = sd; LOGDDRAW(("DDRAW: Created %s surface: format = %d, address = %p\n", mUsesGuestVRAM ? "GuestVRAM": "system memory", aPixelFormat, address ())); if (!mUsesGuestVRAM) { /* Clear just created surface. */ memset (address(), 0, bytesPerLine() * height()); } return true; }