ReactOS  0.4.14-dev-376-gaedba84
createpalette.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS DirectX
4  * FILE: dll/directx/ddraw/Palette/createpalette.c
5  * PURPOSE: IDirectDrawPalette Creation
6  * PROGRAMMER: Jérôme Gardou
7  *
8  */
9 #include "rosdraw.h"
10 
12 {
13  DWORD ret = 0;
14  if(dwFlags & DDPCAPS_4BIT)
16  if(dwFlags & DDPCAPS_8BIT)
24  if(dwFlags & DDPCAPS_1BIT)
26  if(dwFlags & DDPCAPS_2BIT)
28 
29  return ret;
30 }
31 
32 HRESULT
34  LPPALETTEENTRY palent, LPDIRECTDRAWPALETTE* ppPalette, LPUNKNOWN pUnkOuter)
35 {
36  DDHAL_CREATEPALETTEDATA mDdCreatePalette = { 0 };
37 
38  LPDDRAWI_DDRAWPALETTE_INT ThisPalInt = NULL;
39  LPDDRAWI_DDRAWPALETTE_LCL ThisPalLcl = NULL;
40  LPDDRAWI_DDRAWPALETTE_GBL ThisPalGbl = NULL;
41 
42  HRESULT ret;
43 
44  if(pUnkOuter)
45  {
46  return CLASS_E_NOAGGREGATION;
47  }
48 
49  if(!(pDDraw->lpLcl->dwLocalFlags & DDRAWILCL_SETCOOPCALLED))
50  {
52  }
53 
54 
55  if (pDDraw->lpLcl->dwProcessId != GetCurrentProcessId() )
56  {
57  return DDERR_INVALIDOBJECT;
58  }
59 
60  /* Allocate the palette interface and needed members */
61  DxHeapMemAlloc(ThisPalInt, sizeof( DDRAWI_DDRAWPALETTE_INT ) );
62  if( ThisPalInt == NULL )
63  {
65  goto cleanup;
66  }
67 
68  DxHeapMemAlloc(ThisPalLcl, sizeof( DDRAWI_DDRAWPALETTE_LCL ) );
69  if( ThisPalLcl == NULL )
70  {
72  goto cleanup;
73  }
74 
75  DxHeapMemAlloc(ThisPalGbl, sizeof( DDRAWI_DDRAWPALETTE_GBL ) );
76  if( ThisPalGbl == NULL )
77  {
79  goto cleanup;
80  }
81 
82  /*Some initial setup*/
83 
84  ThisPalInt->lpLcl = ThisPalLcl;
85  ThisPalLcl->lpGbl = ThisPalGbl;
86 
87  ThisPalLcl->lpDD_lcl = ThisPalGbl->lpDD_lcl = pDDraw->lpLcl;
88  ThisPalGbl->dwFlags = ConvertPCapsFlags(dwFlags);
89 
90  ThisPalInt->lpVtbl = (PVOID)&DirectDrawPalette_Vtable;
91  ThisPalGbl->dwProcessId = GetCurrentProcessId();
92 
93  mDdCreatePalette.lpDD = pDDraw->lpLcl->lpGbl;
94  mDdCreatePalette.lpDDPalette = ThisPalGbl;
95  if(pDDraw->lpLcl->lpGbl->lpDDCBtmp->HALDD.dwFlags & DDHAL_CB32_CREATEPALETTE) {
96  mDdCreatePalette.CreatePalette = pDDraw->lpLcl->lpGbl->lpDDCBtmp->HALDD.CreatePalette;
97  DX_STUB_str("Using HAL CreatePalette\n");
98  }
99  else {
100  mDdCreatePalette.CreatePalette = pDDraw->lpLcl->lpGbl->lpDDCBtmp->HELDD.CreatePalette;
101  DX_STUB_str("Using HEL CreatePalette\n");
102  }
103  mDdCreatePalette.ddRVal = DDERR_GENERIC;
104  mDdCreatePalette.lpColorTable = palent;
105 
106  if (mDdCreatePalette.CreatePalette(&mDdCreatePalette) == DDHAL_DRIVER_NOTHANDLED)
107  {
108  DX_STUB_str("mDdCreateSurface failed with DDHAL_DRIVER_NOTHANDLED.");
110  goto cleanup;
111  }
112 
113  if (mDdCreatePalette.ddRVal != DD_OK)
114  {
115  DX_STUB_str("mDdCreateSurface failed.");
116  ret = mDdCreatePalette.ddRVal;
117  goto cleanup;
118  }
119 
120  *ppPalette = (LPDIRECTDRAWPALETTE)ThisPalInt;
121  ThisPalInt->lpLink = pDDraw->lpLcl->lpGbl->palList;
122  pDDraw->lpLcl->lpGbl->palList = ThisPalInt;
123  ThisPalInt->lpLcl->dwReserved1 = (ULONG_PTR)pDDraw;
124  IDirectDrawPalette_AddRef(*ppPalette);
125 
126  return DD_OK;
127 
128 cleanup:
129  if(ThisPalInt) DxHeapMemFree(ThisPalInt);
130  if(ThisPalLcl) DxHeapMemFree(ThisPalLcl);
131  if(ThisPalGbl) DxHeapMemFree(ThisPalGbl);
132 
133  return ret;
134 }
#define DDRAWIPAL_ALPHA
Definition: ddrawi.h:1574
#define DDPCAPS_4BIT
Definition: ddraw.h:453
#define DDRAWIPAL_256
Definition: ddrawi.h:1561
LPDDRAWI_DIRECTDRAW_LCL lpDD_lcl
Definition: ddrawi.h:1651
LPDDRAWI_DIRECTDRAW_LCL lpLcl
Definition: ddrawi.h:1148
#define DDPCAPS_2BIT
Definition: ddraw.h:461
#define DDHAL_DRIVER_NOTHANDLED
Definition: ddrawi.h:320
#define DDPCAPS_8BIT
Definition: ddraw.h:455
#define DX_STUB_str(x)
Definition: rosdraw.h:254
#define DDERR_NOTINITIALIZED
Definition: ddraw.h:185
LPDDRAWI_DDRAWPALETTE_INT lpLink
Definition: ddrawi.h:1541
#define DDERR_OUTOFMEMORY
Definition: ddraw.h:111
#define DxHeapMemFree(p)
Definition: rosdraw.h:120
#define DDERR_NOCOOPERATIVELEVELSET
Definition: ddraw.h:89
#define DDPCAPS_8BITENTRIES
Definition: ddraw.h:454
LPDDRAWI_DDRAWPALETTE_LCL lpLcl
Definition: ddrawi.h:1540
#define DDHAL_CB32_CREATEPALETTE
Definition: ddrawi.h:659
#define DDPCAPS_ALLOW256
Definition: ddraw.h:458
#define DD_OK
Definition: ddraw.h:186
#define DDERR_INVALIDOBJECT
Definition: ddraw.h:78
#define DDRAWIPAL_STORED_8INDEX
Definition: ddrawi.h:1573
static LPUNKNOWN
Definition: ndr_ole.c:49
#define DDRAWIPAL_16
Definition: ddrawi.h:1562
smooth NULL
Definition: ftsmooth.c:416
DWORD ConvertPCapsFlags(DWORD dwFlags)
Definition: createpalette.c:11
void * PVOID
Definition: retypes.h:9
#define DDERR_GENERIC
Definition: ddraw.h:72
LPDDRAWI_DDRAWPALETTE_GBL lpDDPalette
Definition: ddrawi.h:793
LPPALETTEENTRY lpColorTable
Definition: ddrawi.h:794
LONG HRESULT
Definition: typedefs.h:77
#define DxHeapMemAlloc(p, m)
Definition: rosdraw.h:113
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DDRAWIPAL_2
Definition: ddrawi.h:1572
int ret
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define DDRAWIPAL_4
Definition: ddrawi.h:1571
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
#define DDPCAPS_1BIT
Definition: ddraw.h:460
LPDDRAWI_DIRECTDRAW_LCL lpDD_lcl
Definition: ddrawi.h:1548
LPDDRAWI_DDRAWPALETTE_GBL lpGbl
Definition: ddrawi.h:1643
#define DDPCAPS_ALPHA
Definition: ddraw.h:462
LPDDHAL_CREATEPALETTE CreatePalette
Definition: ddrawi.h:796
#define ULONG_PTR
Definition: config.h:101
char * cleanup(char *str)
Definition: wpickclick.c:99
HRESULT Internal_CreatePalette(LPDDRAWI_DIRECTDRAW_INT pDDraw, DWORD dwFlags, LPPALETTEENTRY palent, LPDIRECTDRAWPALETTE *ppPalette, LPUNKNOWN pUnkOuter)
Definition: createpalette.c:33
#define DDRAWIPAL_ALLOW256
Definition: ddrawi.h:1570
const IDirectDrawPaletteVtbl DirectDrawPalette_Vtable
Definition: palette.c:147
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
struct IDirectDrawPalette * LPDIRECTDRAWPALETTE
Definition: ddraw.h:720
#define DDRAWILCL_SETCOOPCALLED
Definition: ddrawi.h:1196
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:792