Update the address of the Free Software Foundation.
[wine] / dlls / ddraw / palette_hal.c
1 /*      DirectDrawPalette HAL driver
2  *
3  * Copyright 2001 TransGaming Technologies Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21 #include "winerror.h"
22 #include "wine/debug.h"
23
24 #include <assert.h>
25 #include <string.h>
26
27 #include "ddraw_private.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
30
31 static const IDirectDrawPaletteVtbl DDRAW_HAL_Palette_VTable;
32
33 /******************************************************************************
34  *                      IDirectDrawPalette
35  */
36 HRESULT HAL_DirectDrawPalette_Construct(IDirectDrawPaletteImpl* This,
37                                         IDirectDrawImpl* pDD, DWORD dwFlags)
38 {
39     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = pDD->local.lpGbl;
40     DDHAL_CREATEPALETTEDATA data;
41     HRESULT hr;
42
43     hr = Main_DirectDrawPalette_Construct(This, pDD, dwFlags);
44     if (FAILED(hr)) return hr;
45
46     This->final_release = HAL_DirectDrawPalette_final_release;
47     ICOM_INIT_INTERFACE(This, IDirectDrawPalette, DDRAW_HAL_Palette_VTable);
48
49     /* initialize HAL palette */
50     data.lpDD = dd_gbl;
51     data.lpDDPalette = &This->global;
52     data.lpColorTable = NULL;
53     data.ddRVal = 0;
54     data.CreatePalette = dd_gbl->lpDDCBtmp->HALDD.CreatePalette;
55     if (data.CreatePalette)
56         data.CreatePalette(&data);
57
58     return DD_OK;
59 }
60
61 HRESULT
62 HAL_DirectDrawPalette_Create(IDirectDrawImpl* pDD, DWORD dwFlags,
63                              LPDIRECTDRAWPALETTE* ppPalette,
64                              LPUNKNOWN pUnkOuter)
65 {
66     IDirectDrawPaletteImpl* This;
67     HRESULT hr;
68
69     if (pUnkOuter != NULL)
70         return CLASS_E_NOAGGREGATION; /* unchecked */
71
72     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
73     if (This == NULL) return E_OUTOFMEMORY;
74
75     hr = HAL_DirectDrawPalette_Construct(This, pDD, dwFlags);
76     if (FAILED(hr))
77         HeapFree(GetProcessHeap(), 0, This);
78     else
79         *ppPalette = ICOM_INTERFACE(This, IDirectDrawPalette);
80
81     return hr;
82 }
83
84 HRESULT WINAPI
85 HAL_DirectDrawPalette_SetEntries(LPDIRECTDRAWPALETTE iface, DWORD dwFlags,
86                                  DWORD dwStart, DWORD dwCount,
87                                  LPPALETTEENTRY palent)
88 {
89     IDirectDrawPaletteImpl *This = (IDirectDrawPaletteImpl *)iface;
90     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->local.lpDD_lcl->lpGbl;
91     DDHAL_SETENTRIESDATA data;
92
93     TRACE("(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",This,dwFlags,dwStart,dwCount,
94           palent);
95
96     data.lpDD = dd_gbl;
97     data.lpDDPalette = &This->global;
98     data.dwBase = dwStart;
99     data.dwNumEntries = dwCount;
100     data.lpEntries = palent;
101     data.ddRVal = 0;
102     data.SetEntries = dd_gbl->lpDDCBtmp->HALDDPalette.SetEntries;
103     if (data.SetEntries)
104         data.SetEntries(&data);
105
106     return Main_DirectDrawPalette_SetEntries(iface, dwFlags, dwStart, dwCount, palent);
107 }
108
109 void HAL_DirectDrawPalette_final_release(IDirectDrawPaletteImpl* This)
110 {
111     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->local.lpDD_lcl->lpGbl;
112     DDHAL_DESTROYPALETTEDATA data;
113
114     /* destroy HAL palette */
115     data.lpDD = dd_gbl;
116     data.lpDDPalette = &This->global;
117     data.ddRVal = 0;
118     data.DestroyPalette = dd_gbl->lpDDCBtmp->HALDDPalette.DestroyPalette;
119     if (data.DestroyPalette)
120         data.DestroyPalette(&data);
121
122     Main_DirectDrawPalette_final_release(This);
123 }
124
125 static const IDirectDrawPaletteVtbl DDRAW_HAL_Palette_VTable =
126 {
127     Main_DirectDrawPalette_QueryInterface,
128     Main_DirectDrawPalette_AddRef,
129     Main_DirectDrawPalette_Release,
130     Main_DirectDrawPalette_GetCaps,
131     Main_DirectDrawPalette_GetEntries,
132     Main_DirectDrawPalette_Initialize,
133     HAL_DirectDrawPalette_SetEntries
134 };