diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 2c78f099b11..2f9dc66cca8 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -1359,6 +1359,14 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) { if (This->Flags & SFLAG_LOCKED) return WINED3DERR_INVALIDCALL; + /* According to Direct3D9 docs, only these formats are supported */ + if (((IWineD3DImpl *)This->resource.wineD3DDevice->wineD3D)->dxVersion > 7) { + if (This->resource.format != WINED3DFMT_R5G6B5 && + This->resource.format != WINED3DFMT_X1R5G5B5 && + This->resource.format != WINED3DFMT_R8G8B8 && + This->resource.format != WINED3DFMT_X8R8G8B8) return WINED3DERR_INVALIDCALL; + } + memset(&lock, 0, sizeof(lock)); /* To be sure */ /* Create a DIB section if there isn't a hdc yet */ @@ -1392,29 +1400,28 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) { if(This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8) { + /* GetDC on palettized formats is unsupported in D3D9, and the method is missing in + D3D8, so this should only be used for DX <=7 surfaces (with non-device palettes) */ unsigned int n; + PALETTEENTRY *pal = NULL; + if(This->palette) { - PALETTEENTRY ent[256]; - - GetPaletteEntries(This->palette->hpal, 0, 256, ent); - for (n=0; n<256; n++) { - col[n].rgbRed = ent[n].peRed; - col[n].rgbGreen = ent[n].peGreen; - col[n].rgbBlue = ent[n].peBlue; - col[n].rgbReserved = 0; - } + pal = This->palette->palents; } else { - IWineD3DDeviceImpl *device = This->resource.wineD3DDevice; + IWineD3DSurfaceImpl *dds_primary = (IWineD3DSurfaceImpl *)This->resource.wineD3DDevice->ddraw_primary; + if (dds_primary && dds_primary->palette) + pal = dds_primary->palette->palents; + } + if (pal) { for (n=0; n<256; n++) { - col[n].rgbRed = device->palettes[device->currentPalette][n].peRed; - col[n].rgbGreen = device->palettes[device->currentPalette][n].peGreen; - col[n].rgbBlue = device->palettes[device->currentPalette][n].peBlue; + col[n].rgbRed = pal[n].peRed; + col[n].rgbGreen = pal[n].peGreen; + col[n].rgbBlue = pal[n].peBlue; col[n].rgbReserved = 0; } - + SetDIBColorTable(This->hDC, 0, 256, col); } - SetDIBColorTable(This->hDC, 0, 256, col); } *pHDC = This->hDC; diff --git a/dlls/wined3d/surface_gdi.c b/dlls/wined3d/surface_gdi.c index 183d552f746..fcbecd3d85e 100644 --- a/dlls/wined3d/surface_gdi.c +++ b/dlls/wined3d/surface_gdi.c @@ -579,28 +579,25 @@ HRESULT WINAPI IWineGDISurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) { if(This->resource.format == WINED3DFMT_P8 || This->resource.format == WINED3DFMT_A8P8) { unsigned int n; + PALETTEENTRY *pal = NULL; + if(This->palette) { - PALETTEENTRY ent[256]; - - GetPaletteEntries(This->palette->hpal, 0, 256, ent); - for (n=0; n<256; n++) { - col[n].rgbRed = ent[n].peRed; - col[n].rgbGreen = ent[n].peGreen; - col[n].rgbBlue = ent[n].peBlue; - col[n].rgbReserved = 0; - } + pal = This->palette->palents; } else { - IWineD3DDeviceImpl *device = This->resource.wineD3DDevice; + IWineD3DSurfaceImpl *dds_primary = (IWineD3DSurfaceImpl *)This->resource.wineD3DDevice->ddraw_primary; + if (dds_primary && dds_primary->palette) + pal = dds_primary->palette->palents; + } + if (pal) { for (n=0; n<256; n++) { - col[n].rgbRed = device->palettes[device->currentPalette][n].peRed; - col[n].rgbGreen = device->palettes[device->currentPalette][n].peGreen; - col[n].rgbBlue = device->palettes[device->currentPalette][n].peBlue; + col[n].rgbRed = pal[n].peRed; + col[n].rgbGreen = pal[n].peGreen; + col[n].rgbBlue = pal[n].peBlue; col[n].rgbReserved = 0; } - + SetDIBColorTable(This->hDC, 0, 256, col); } - SetDIBColorTable(This->hDC, 0, 256, col); } *pHDC = This->hDC;