1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-14 22:03:27 +01:00

Use bpp from display mode for surfaces

This commit is contained in:
Toni Spets 2010-10-17 00:41:14 +03:00
parent 15ff8f8e2a
commit 3c257aac86
4 changed files with 114 additions and 50 deletions

51
main.c
View File

@ -18,47 +18,10 @@
#include <stdio.h>
#include "ddraw.h"
#include "main.h"
#include "palette.h"
#include "surface.h"
typedef struct
{
/* IUnknown */
HRESULT (*QueryInterface)(void *, REFIID, void **);
ULONG (*AddRef)(void *);
ULONG (*Release)(void *);
/* IDirectDraw */
HRESULT (*Compact)(void *);
HRESULT (*CreateClipper)(void *);
HRESULT (*CreatePalette)(void *, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR *, IUnknown FAR *);
HRESULT (*CreateSurface)(void *, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *);
HRESULT (*DuplicateSurface)(void *);
HRESULT (*EnumDisplayModes)(void *);
HRESULT (*EnumSurfaces)(void *);
HRESULT (*FlipToGDISurface)(void *);
HRESULT (*GetCaps)(void *, LPDDCAPS, LPDDCAPS);
HRESULT (*GetDisplayMode)(void *);
HRESULT (*GetFourCCCodes)(void *);
HRESULT (*GetGDISurface)(void *);
HRESULT (*GetMonitorFrequency)(void *);
HRESULT (*SetScanLine)(void *);
HRESULT (*GetVerticalBlankStatus)(void *);
HRESULT (*Initialize)(void *);
HRESULT (*RestoreDisplayMode)(void *);
HRESULT (*SetCooperativeLevel)(void *, HWND, DWORD);
HRESULT (*SetDisplayMode)(void *, DWORD, DWORD, DWORD, DWORD, DWORD);
HRESULT (*WaitForVerticalBlank)(void *);
} fakeDirectDraw;
typedef struct
{
fakeDirectDraw *Functions;
ULONG Ref;
} fakeDirectDrawObject;
HRESULT ddraw_GetCaps(void *This, LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDEmulCaps)
{
printf("DirectDraw::GetCaps(This=%p, lpDDDriverCaps=%p, lpDDEmulCaps=%p)\n", This, lpDDDriverCaps, lpDDEmulCaps);
@ -93,10 +56,16 @@ HRESULT ddraw_SetCooperativeLevel(void *This, HWND hWnd, DWORD dwFlags)
return DD_OK;
}
HRESULT ddraw_SetDisplayMode(void *This, DWORD width, DWORD height, DWORD bpp, DWORD refreshRate, DWORD flags)
HRESULT ddraw_SetDisplayMode(void *_This, DWORD width, DWORD height, DWORD bpp)
{
printf("DirectDraw::SetDisplayMode(This=%p, width=%d, height=%d, bpp=%d, refreshRate=%d, flags=0x%08X)\n",
This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp, (unsigned int)refreshRate, (unsigned int)flags);
fakeDirectDrawObject *This = (fakeDirectDrawObject *)_This;
printf("DirectDraw::SetDisplayMode(This=%p, width=%d, height=%d, bpp=%d)\n", This, (unsigned int)width, (unsigned int)height, (unsigned int)bpp);
This->width = width;
This->height = height;
This->bpp = bpp;
return DD_OK;
}

65
main.h Normal file
View File

@ -0,0 +1,65 @@
/*
* Copyright (c) 2010 Toni Spets <toni.spets@iki.fi>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef MAIN_H
#define MAIN_H
#include <windows.h>
#include "ddraw.h"
typedef struct
{
/* IUnknown */
HRESULT (*QueryInterface)(void *, REFIID, void **);
ULONG (*AddRef)(void *);
ULONG (*Release)(void *);
/* IDirectDraw */
HRESULT (*Compact)(void *);
HRESULT (*CreateClipper)(void *);
HRESULT (*CreatePalette)(void *, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR *, IUnknown FAR *);
HRESULT (*CreateSurface)(void *, LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *);
HRESULT (*DuplicateSurface)(void *);
HRESULT (*EnumDisplayModes)(void *);
HRESULT (*EnumSurfaces)(void *);
HRESULT (*FlipToGDISurface)(void *);
HRESULT (*GetCaps)(void *, LPDDCAPS, LPDDCAPS);
HRESULT (*GetDisplayMode)(void *);
HRESULT (*GetFourCCCodes)(void *);
HRESULT (*GetGDISurface)(void *);
HRESULT (*GetMonitorFrequency)(void *);
HRESULT (*SetScanLine)(void *);
HRESULT (*GetVerticalBlankStatus)(void *);
HRESULT (*Initialize)(void *);
HRESULT (*RestoreDisplayMode)(void *);
HRESULT (*SetCooperativeLevel)(void *, HWND, DWORD);
HRESULT (*SetDisplayMode)(void *, DWORD, DWORD, DWORD);
HRESULT (*WaitForVerticalBlank)(void *);
} fakeDirectDraw;
typedef struct
{
fakeDirectDraw *Functions;
ULONG Ref;
DWORD width;
DWORD height;
DWORD bpp;
} fakeDirectDrawObject;
#endif

View File

@ -16,6 +16,8 @@
#include <windows.h>
#include <stdio.h>
#include "main.h"
#include "surface.h"
/* from main */
@ -54,29 +56,56 @@ ULONG ddraw_surface_Release(void *_This)
return This->Ref;
}
HRESULT ddraw_CreateSurface(void *This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lpDDSurface, IUnknown FAR * unkOuter)
HRESULT ddraw_CreateSurface(void *_This, LPDDSURFACEDESC lpDDSurfaceDesc, LPDIRECTDRAWSURFACE FAR *lpDDSurface, IUnknown FAR * unkOuter)
{
fakeDirectDrawObject *This = (fakeDirectDrawObject *)_This;
printf("DirectDraw::CreateSurface(This=%p, lpDDSurfaceDesc=%p, lpDDSurface=%p, unkOuter=%p)\n", This, lpDDSurfaceDesc, lpDDSurface, unkOuter);
dump_surface_desc_flags(lpDDSurfaceDesc);
printf(" lpDDSurfaceDesc->dwHeight: %d\n", (int)lpDDSurfaceDesc->dwHeight);
printf(" lpDDSurfaceDesc->dwWidth: %d\n", (int)lpDDSurfaceDesc->dwWidth);
fakeDirectDrawSurfaceObject *Surface = (fakeDirectDrawSurfaceObject *)malloc(sizeof(fakeDirectDrawSurfaceObject));
if(lpDDSurfaceDesc->dwFlags & DDSD_CAPS)
{
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
printf(" DDSCAPS_PRIMARYSURFACE\n");
Surface->width = This->width;
Surface->height = This->height;
}
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_OFFSCREENPLAIN)
{
printf(" DDSCAPS_OFFSCREENPLAIN\n");
}
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY)
{
printf(" DDSCAPS_VIDEOMEMORY\n");
}
if(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_LOCALVIDMEM)
{
printf(" DDSCAPS_LOCALVIDMEM\n");
}
}
if( !(lpDDSurfaceDesc->dwFlags & DDSD_CAPS) || !(lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) )
{
Surface->width = lpDDSurfaceDesc->dwWidth;
Surface->height = lpDDSurfaceDesc->dwHeight;
}
Surface->Functions = &siface;
/* private stuff */
Surface->width = lpDDSurfaceDesc->dwWidth;
Surface->height = lpDDSurfaceDesc->dwHeight;
Surface->bpp = This->bpp;
Surface->surface = NULL;
if(Surface->width && Surface->height)
{
Surface->surface = malloc(Surface->width * Surface->height);
Surface->surface = malloc(Surface->width * Surface->height * Surface->bpp / 8);
}
printf(" Surface = %p\n", Surface);
printf(" Surface = %p (%dx%d@%d)\n", Surface, (int)Surface->width, (int)Surface->height, (int)Surface->bpp);
Surface->Ref = 0;
ddraw_surface_AddRef(Surface);
@ -95,7 +124,7 @@ HRESULT ddraw_surface_Blt(void *This, LPRECT lpDestRect, LPDIRECTDRAWSURFACE lpD
HRESULT ddraw_surface_GetCaps(void *_This, LPDDSCAPS lpDDSCaps)
{
printf("DirectDrawSurface::GetCaps(This=%p, lpDDSCaps=%p)\n", _This, lpDDSCaps);
lpDDSCaps->dwCaps = 0;
lpDDSCaps->dwCaps = 0x00000000l;
return DD_OK;
}

View File

@ -74,6 +74,7 @@ typedef struct
DWORD width;
DWORD height;
DWORD bpp;
void *surface;
ULONG Ref;