/** * cairo_os2_surface_create_for_window: * @hwnd_client_window: the window handle to bind the surface to * @width: the width of the surface * @height: the height of the surface * * Create a Cairo surface which is bound to a given window; the caller retains * ownership of the window. This is a convenience function for use with * windows that will only be updated when cairo_os2_surface_refresh_window() * is called (usually in response to a WM_PAINT message). It avoids the need * to create a persistent HPS for every window and assumes that one will be * supplied by the caller when a cairo function needs one. If it isn't, an * HPS will be created on-the-fly and released before the function which needs * it returns. * * Return value: the newly created surface * * Since: 1.10 **/ cairo_surface_t * cairo_os2_surface_create_for_window (HWND hwnd_client_window, int width, int height) { cairo_os2_surface_t *local_os2_surface; /* A window handle must be provided. */ if (!hwnd_client_window) { return _cairo_surface_create_in_error ( _cairo_error (CAIRO_STATUS_NO_MEMORY)); } /* Create the surface. */ local_os2_surface = (cairo_os2_surface_t *) cairo_os2_surface_create (0, width, height); /* If successful, save the hwnd & turn off automatic repainting. */ if (!local_os2_surface->image_surface->base.status) { local_os2_surface->hwnd_client_window = hwnd_client_window; local_os2_surface->blit_as_changes = FALSE; } return (cairo_surface_t *)local_os2_surface; }
void CairoDrawThread(void *pParam) { HWND hwndClientWindow = (HWND) pParam; HPS hpsClientWindow; SWP swpTemp; // Query HPS of HWND hpsClientWindow = WinGetPS(hwndClientWindow); WinQueryWindowPos(hwndClientWindow, &swpTemp); // Set FPU state which might have been changed by some Win* calls! // (Workaround for a PM bug) DisableFPUException(); // Initialize cairo support cairo_os2_init(); // Create cairo surface pCairoSurface = cairo_os2_surface_create(hpsClientWindow, swpTemp.cx, swpTemp.cy); // Tell the surface the HWND too, so if the application decides // that it wants to draw itself, then it will be able to turn // on blit_as_changes. cairo_os2_surface_set_hwnd(pCairoSurface, hwndClientWindow); // Make sure that the changes will be shown only // when we tell so cairo_os2_surface_set_manual_window_refresh(pCairoSurface, TRUE); // Create Cairo drawing handle for the surface pCairoHandle = cairo_create(pCairoSurface); // Do the main drawing loop as long as needed! bShutdownDrawing = 0; CairoDrawLoop(hwndClientWindow, swpTemp.cx, swpTemp.cy, pCairoSurface, pCairoHandle); // Clean up! cairo_destroy(pCairoHandle); cairo_surface_destroy(pCairoSurface); cairo_os2_fini(); WinReleasePS(hpsClientWindow); _endthread(); }
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize, gfxImageFormat aImageFormat) : mWnd(0), mSize(aSize) { #ifdef DEBUG_thebes_2 printf("gfxOS2Surface[%#x]::gfxOS2Surface(Size=%dx%d, %d)\n", (unsigned int)this, aSize.width, aSize.height, aImageFormat); #endif // in this case we don't have a window, so we create a memory presentation // space to construct the cairo surface on // create a PS, partly taken from nsOffscreenSurface::Init(), i.e. nsDrawingSurfaceOS2.cpp DEVOPENSTRUC dop = { 0, 0, 0, 0, 0 }; SIZEL sizel = { 0, 0 }; // use same page size as device mDC = DevOpenDC(0, OD_MEMORY, (PSZ)"*", 5, (PDEVOPENDATA)&dop, NULLHANDLE); NS_ASSERTION(mDC != DEV_ERROR, "Could not create memory DC"); mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on memory DC!"); // now create a bitmap of the right size BITMAPINFOHEADER2 hdr = { 0 }; hdr.cbFix = sizeof(BITMAPINFOHEADER2); hdr.cx = mSize.width; hdr.cy = mSize.height; hdr.cPlanes = 1; // find bit depth LONG lBitCount = 0; DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); hdr.cBitCount = (USHORT)lBitCount; mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap in memory!"); // set final stats & select bitmap into PS GpiSetBitmap(mPS, mBitmap); // now we can finally create the cairo surface on the in-memory PS cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); #ifdef DEBUG_thebes_2 printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); #endif // Normally, OS/2 cairo surfaces have to be forced to redraw completely // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in // full, so that is not necessary here. // manual refresh is done from nsWindow::OnPaint cairo_os2_surface_set_manual_window_refresh(surf, 1); Init(surf); }
gfxOS2Surface::gfxOS2Surface(const gfxIntSize& aSize, gfxASurface::gfxImageFormat aFormat) : mWnd(0), mDC(0), mPS(0), mSize(aSize), mSurfType(os2Image) { if (!CheckSurfaceSize(aSize)) return; cairo_surface_t *surf = cairo_os2_surface_create((cairo_format_t)aFormat, mSize.width, mSize.height); Init(surf); RecordMemoryUsed(mSize.width * mSize.height * 4 + OS2_OVERHEAD); }
gfxOS2Surface::gfxOS2Surface(HDC aDC, const gfxIntSize& aSize) : mWnd(0), mDC(aDC), mBitmap(nullptr), mSize(aSize) { #ifdef DEBUG_thebes_2 printf("gfxOS2Surface[%#x]::gfxOS2Surface(HDC=%#x, Size=%dx%d)\n", (unsigned int)this, (unsigned int)aDC, aSize.width, aSize.height); #endif SIZEL sizel = { 0, 0 }; // use same page size as device mPS = GpiCreatePS(0, mDC, &sizel, PU_PELS | GPIT_MICRO | GPIA_ASSOC); NS_ASSERTION(mPS != GPI_ERROR, "Could not create PS on print DC!"); // now create a bitmap of the right size BITMAPINFOHEADER2 hdr = { 0 }; hdr.cbFix = sizeof(BITMAPINFOHEADER2); hdr.cx = mSize.width; hdr.cy = mSize.height; hdr.cPlanes = 1; // find bit depth LONG lBitCount = 0; DevQueryCaps(mDC, CAPS_COLOR_BITCOUNT, 1, &lBitCount); hdr.cBitCount = (USHORT)lBitCount; mBitmap = GpiCreateBitmap(mPS, &hdr, 0, 0, 0); NS_ASSERTION(mBitmap != GPI_ERROR, "Could not create bitmap for printer!"); // set final stats & select bitmap into PS GpiSetBitmap(mPS, mBitmap); // now we can finally create the cairo surface on the in-memory PS cairo_surface_t *surf = cairo_os2_surface_create(mPS, mSize.width, mSize.height); #ifdef DEBUG_thebes_2 printf(" type(%#x)=%d (ID=%#x, h/w=%d/%d)\n", (unsigned int)surf, cairo_surface_get_type(surf), (unsigned int)mPS, mSize.width, mSize.height); #endif // Normally, OS/2 cairo surfaces have to be forced to redraw completely // by calling cairo_surface_mark_dirty(surf), but Mozilla paints them in // full, so that is not necessary here. Init(surf); }