/********************************************************************** * dibdrv_CreateDC */ static BOOL dibdrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW *data ) { dibdrv_physdev *pdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdev) ); if (!pdev) return FALSE; clear_dib_info(&pdev->dib); clear_dib_info(&pdev->brush.dib); clear_dib_info(&pdev->pen_brush.dib); push_dc_driver( dev, &pdev->dev, &dib_driver ); return TRUE; }
/********************************************************************** * CreateCompatibleDC (MACDRV.@) */ static BOOL macdrv_CreateCompatibleDC(PHYSDEV orig, PHYSDEV *pdev) { MACDRV_PDEVICE *physDev = create_mac_physdev(); TRACE("orig %p orig->hdc %p pdev %p pdev->hdc %p\n", orig, (orig ? orig->hdc : NULL), pdev, ((pdev && *pdev) ? (*pdev)->hdc : NULL)); if (!physDev) return FALSE; push_dc_driver(pdev, &physDev->dev, &macdrv_funcs); return TRUE; }
/********************************************************************** * X11DRV_CreateCompatibleDC */ static BOOL X11DRV_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev ) { X11DRV_PDEVICE *physDev = create_x11_physdev( stock_bitmap_pixmap ); if (!physDev) return FALSE; physDev->depth = 1; SetRect( &physDev->dc_rect, 0, 0, 1, 1 ); push_dc_driver( pdev, &physDev->dev, &x11drv_funcs ); if (orig) return TRUE; /* we already went through Xrender if we have an orig device */ if (xrender_funcs && !xrender_funcs->pCreateCompatibleDC( NULL, pdev )) return FALSE; return TRUE; }
/********************************************************************** * CreateDC (MACDRV.@) */ static BOOL macdrv_CreateDC(PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW* initData) { MACDRV_PDEVICE *physDev = create_mac_physdev(); TRACE("pdev %p hdc %p driver %s device %s output %s initData %p\n", pdev, (*pdev)->hdc, debugstr_w(driver),debugstr_w(device), debugstr_w(output), initData); if (!physDev) return FALSE; push_dc_driver(pdev, &physDev->dev, &macdrv_funcs); return TRUE; }
/********************************************************************** * X11DRV_CreateDC */ static BOOL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW* initData ) { X11DRV_PDEVICE *physDev = create_x11_physdev( root_window ); if (!physDev) return FALSE; physDev->depth = default_visual.depth; physDev->color_shifts = &X11DRV_PALETTE_default_shifts; physDev->dc_rect = get_virtual_screen_rect(); OffsetRect( &physDev->dc_rect, -physDev->dc_rect.left, -physDev->dc_rect.top ); push_dc_driver( pdev, &physDev->dev, &x11drv_funcs ); if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE; return TRUE; }
static BOOL windrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW *devmode ) { struct windrv_physdev *physdev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physdev) ); if (!physdev) return FALSE; if (!dib_driver.pCreateDC( dev, NULL, NULL, NULL, NULL )) { HeapFree( GetProcessHeap(), 0, physdev ); return FALSE; } physdev->dibdrv = get_dibdrv_pdev( *dev ); push_dc_driver( dev, &physdev->dev, &window_driver ); return TRUE; }
void dibdrv_set_window_surface( DC *dc, struct window_surface *surface ) { char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )]; BITMAPINFO *info = (BITMAPINFO *)buffer; RECT rect; void *bits; PHYSDEV windev; struct windrv_physdev *physdev; struct dibdrv_physdev *dibdrv; TRACE( "%p %p\n", dc->hSelf, surface ); windev = pop_dc_driver( dc, &window_driver ); if (surface) { if (windev) push_dc_driver( &dc->physDev, windev, windev->funcs ); else { if (!window_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL )) return; windev = find_dc_driver( dc, &window_driver ); } physdev = get_windrv_physdev( windev ); window_surface_add_ref( surface ); if (physdev->surface) window_surface_release( physdev->surface ); physdev->surface = surface; dibdrv = physdev->dibdrv; bits = surface->funcs->get_info( surface, info ); init_dib_info_from_bitmapinfo( &dibdrv->dib, info, bits ); /* clip the device rect to the surface */ rect = surface->rect; offset_rect( &rect, dc->device_rect.left, dc->device_rect.top ); intersect_rect( &dc->device_rect, &dc->device_rect, &rect ); dibdrv->dib.rect = dc->vis_rect; offset_rect( &dibdrv->dib.rect, -rect.left, -rect.top ); dibdrv->bounds = surface->funcs->get_bounds( surface ); DC_InitDC( dc ); } else if (windev) { dib_driver.pDeleteDC( pop_dc_driver( dc, &dib_driver )); windev->funcs->pDeleteDC( windev ); DC_InitDC( dc ); } }
/********************************************************************** * X11DRV_CreateDC */ static BOOL X11DRV_CreateDC( PHYSDEV *pdev, LPCWSTR driver, LPCWSTR device, LPCWSTR output, const DEVMODEW* initData ) { const struct gdi_dc_funcs *glx_funcs = get_glx_driver(); X11DRV_PDEVICE *physDev = create_x11_physdev( root_window ); if (!physDev) return FALSE; physDev->depth = screen_depth; physDev->color_shifts = &X11DRV_PALETTE_default_shifts; SetRect( &physDev->dc_rect, 0, 0, virtual_screen_rect.right - virtual_screen_rect.left, virtual_screen_rect.bottom - virtual_screen_rect.top ); push_dc_driver( pdev, &physDev->dev, &x11drv_funcs ); if (xrender_funcs && !xrender_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE; if (glx_funcs && !glx_funcs->pCreateDC( pdev, driver, device, output, initData )) return FALSE; return TRUE; }
/********************************************************************** * MFDRV_AllocMetaFile */ static DC *MFDRV_AllocMetaFile(void) { DC *dc; METAFILEDRV_PDEVICE *physDev; if (!(dc = alloc_dc_ptr( OBJ_METADC ))) return NULL; physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev)); if (!physDev) { free_dc_ptr( dc ); return NULL; } if (!(physDev->mh = HeapAlloc( GetProcessHeap(), 0, sizeof(*physDev->mh) ))) { HeapFree( GetProcessHeap(), 0, physDev ); free_dc_ptr( dc ); return NULL; } push_dc_driver( &dc->physDev, &physDev->dev, &MFDRV_Funcs ); physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0])); physDev->handles_size = HANDLE_LIST_INC; physDev->cur_handles = 0; physDev->hFile = 0; physDev->mh->mtHeaderSize = sizeof(METAHEADER) / sizeof(WORD); physDev->mh->mtVersion = 0x0300; physDev->mh->mtSize = physDev->mh->mtHeaderSize; physDev->mh->mtNoObjects = 0; physDev->mh->mtMaxRecord = 0; physDev->mh->mtNoParameters = 0; SetVirtualResolution( physDev->dev.hdc, 0, 0, 0, 0); return dc; }
/********************************************************************** * CreateEnhMetaFileW (GDI32.@) */ HDC WINAPI CreateEnhMetaFileW( HDC hdc, /* [in] optional reference DC */ LPCWSTR filename, /* [in] optional filename for disk metafiles */ const RECT* rect, /* [in] optional bounding rectangle */ LPCWSTR description /* [in] optional description */ ) { static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0}; HDC ret; DC *dc; EMFDRV_PDEVICE *physDev; HANDLE hFile; DWORD size = 0, length = 0; TRACE("%s\n", debugstr_w(filename) ); if (!(dc = alloc_dc_ptr( OBJ_ENHMETADC ))) return 0; physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev)); if (!physDev) { free_dc_ptr( dc ); return 0; } if(description) { /* App name\0Title\0\0 */ length = lstrlenW(description); length += lstrlenW(description + length + 1); length += 3; length *= 2; } size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4; if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) { HeapFree( GetProcessHeap(), 0, physDev ); free_dc_ptr( dc ); return 0; } push_dc_driver( &dc->physDev, &physDev->dev, &EMFDRV_Funcs ); physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0])); physDev->handles_size = HANDLE_LIST_INC; physDev->cur_handles = 1; physDev->hFile = 0; physDev->dc_brush = 0; physDev->dc_pen = 0; physDev->screen_dc = 0; physDev->restoring = 0; if (hdc) /* if no ref, use current display */ physDev->ref_dc = hdc; else physDev->ref_dc = physDev->screen_dc = CreateDCW( displayW, NULL, NULL, NULL ); SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0); physDev->emh->iType = EMR_HEADER; physDev->emh->nSize = size; physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0; physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1; if(rect) { physDev->emh->rclFrame.left = rect->left; physDev->emh->rclFrame.top = rect->top; physDev->emh->rclFrame.right = rect->right; physDev->emh->rclFrame.bottom = rect->bottom; } else { /* Set this to {0,0 - -1,-1} and update it at the end */ physDev->emh->rclFrame.left = physDev->emh->rclFrame.top = 0; physDev->emh->rclFrame.right = physDev->emh->rclFrame.bottom = -1; } physDev->emh->dSignature = ENHMETA_SIGNATURE; physDev->emh->nVersion = 0x10000; physDev->emh->nBytes = physDev->emh->nSize; physDev->emh->nRecords = 1; physDev->emh->nHandles = 1; physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */ physDev->emh->nDescription = length / 2; physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0; physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */ /* Size in pixels */ physDev->emh->szlDevice.cx = GetDeviceCaps( physDev->ref_dc, HORZRES ); physDev->emh->szlDevice.cy = GetDeviceCaps( physDev->ref_dc, VERTRES ); /* Size in millimeters */ physDev->emh->szlMillimeters.cx = GetDeviceCaps( physDev->ref_dc, HORZSIZE ); physDev->emh->szlMillimeters.cy = GetDeviceCaps( physDev->ref_dc, VERTSIZE ); /* Size in micrometers */ physDev->emh->szlMicrometers.cx = physDev->emh->szlMillimeters.cx * 1000; physDev->emh->szlMicrometers.cy = physDev->emh->szlMillimeters.cy * 1000; memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length); if (filename) /* disk based metafile */ { if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { free_dc_ptr( dc ); return 0; } if (!WriteFile( hFile, physDev->emh, size, NULL, NULL )) { free_dc_ptr( dc ); CloseHandle( hFile ); return 0; } physDev->hFile = hFile; } TRACE("returning %p\n", physDev->dev.hdc); ret = physDev->dev.hdc; release_dc_ptr( dc ); return ret; }
/*********************************************************************** * BITMAP_SelectObject */ static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc ) { HGDIOBJ ret; BITMAPOBJ *bitmap; DC *dc; PHYSDEV physdev = NULL, old_physdev = NULL, pathdev = NULL; if (!(dc = get_dc_ptr( hdc ))) return 0; if (GetObjectType( hdc ) != OBJ_MEMDC) { ret = 0; goto done; } ret = dc->hBitmap; if (handle == dc->hBitmap) goto done; /* nothing to do */ if (!(bitmap = GDI_GetObjPtr( handle, OBJ_BITMAP ))) { ret = 0; goto done; } if (bitmap->header.selcount && (handle != GetStockObject(DEFAULT_BITMAP))) { WARN( "Bitmap already selected in another DC\n" ); GDI_ReleaseObj( handle ); ret = 0; goto done; } if (dc->physDev->funcs == &path_driver) pathdev = pop_dc_driver( &dc->physDev ); old_physdev = GET_DC_PHYSDEV( dc, pSelectBitmap ); if(old_physdev == dc->dibdrv) old_physdev = pop_dc_driver( &dc->physDev ); physdev = GET_DC_PHYSDEV( dc, pSelectBitmap ); if (bitmap->dib || physdev->funcs == &null_driver) { physdev = dc->dibdrv; if (physdev) push_dc_driver( &dc->physDev, physdev, physdev->funcs ); else { if (!dib_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL )) goto done; dc->dibdrv = physdev = dc->physDev; } } if (!BITMAP_SetOwnerDC( handle, physdev )) { GDI_ReleaseObj( handle ); ret = 0; goto done; } if (!physdev->funcs->pSelectBitmap( physdev, handle )) { GDI_ReleaseObj( handle ); ret = 0; } else { dc->hBitmap = handle; GDI_inc_ref_count( handle ); dc->dirty = 0; dc->vis_rect.left = 0; dc->vis_rect.top = 0; dc->vis_rect.right = bitmap->bitmap.bmWidth; dc->vis_rect.bottom = bitmap->bitmap.bmHeight; GDI_ReleaseObj( handle ); DC_InitDC( dc ); GDI_dec_ref_count( ret ); } done: if(!ret) { if (physdev && physdev == dc->dibdrv) pop_dc_driver( &dc->physDev ); if (old_physdev && old_physdev == dc->dibdrv) push_dc_driver( &dc->physDev, old_physdev, old_physdev->funcs ); } if (pathdev) push_dc_driver( &dc->physDev, pathdev, pathdev->funcs ); release_dc_ptr( dc ); return ret; }