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(); }
/** * cairo_os2_init: * * Initializes the Cairo library. This function is automatically called if * Cairo was compiled to be a DLL (however it's not a problem if it's called * multiple times). But if you link to Cairo statically, you have to call it * once to set up Cairo's internal structures and mutexes. * * Since: 1.4 **/ cairo_public void cairo_os2_init (void) { /* This may initialize some stuffs, like create mutex semaphores etc.. */ cairo_os2_initialization_count++; if (cairo_os2_initialization_count > 1) return; DisableFPUException (); #if CAIRO_HAS_FC_FONT /* Initialize FontConfig */ FcInit (); #endif CAIRO_MUTEX_INITIALIZE (); }
/** * cairo_os2_fini: * * Uninitializes the Cairo library. This function is automatically called if * Cairo was compiled to be a DLL (however it's not a problem if it's called * multiple times). But if you link to Cairo statically, you have to call it * once to shut down Cairo, to let it free all the resources it has allocated. * * Since: 1.4 **/ cairo_public void cairo_os2_fini (void) { /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */ if (cairo_os2_initialization_count <= 0) return; cairo_os2_initialization_count--; if (cairo_os2_initialization_count > 0) return; DisableFPUException (); cairo_debug_reset_static_data (); #if CAIRO_HAS_FC_FONT # if HAVE_FCFINI /* Uninitialize FontConfig */ FcFini (); # endif #endif #ifdef __WATCOMC__ /* It can happen that the libraries we use have memory leaks, * so there are still memory chunks allocated at this point. * In these cases, Watcom might still have a bigger memory chunk, * called "the heap" allocated from the OS. * As we want to minimize the memory we lose from the point of * view of the OS, we call this function to shrink that heap * as much as possible. */ _heapshrink (); #else /* GCC has a heapmin function that approximately corresponds to * what the Watcom function does */ _heapmin (); #endif }