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 */
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;
- if(This->palette) {
- PALETTEENTRY ent[256];
+ PALETTEENTRY *pal = NULL;
- 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;
- }
+ if(This->palette) {
+ 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;
if(This->resource.format == WINED3DFMT_P8 ||
This->resource.format == WINED3DFMT_A8P8) {
unsigned int n;
- if(This->palette) {
- PALETTEENTRY ent[256];
+ PALETTEENTRY *pal = NULL;
- 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;
- }
+ if(This->palette) {
+ 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;