Added LGPL standard comment, and copyright notices where necessary.
[wine] / dlls / ddraw / dpalette / 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 #include "dpalette/main.h"
29 #include "dpalette/hal.h"
30 #include "ddraw/main.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
33
34 static ICOM_VTABLE(IDirectDrawPalette) DDRAW_HAL_Palette_VTable;
35
36 /******************************************************************************
37  *                      IDirectDrawPalette
38  */
39 HRESULT HAL_DirectDrawPalette_Construct(IDirectDrawPaletteImpl* This,
40                                         IDirectDrawImpl* pDD, DWORD dwFlags)
41 {
42     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = pDD->local.lpGbl;
43     DDHAL_CREATEPALETTEDATA data;
44     HRESULT hr;
45
46     hr = Main_DirectDrawPalette_Construct(This, pDD, dwFlags);
47     if (FAILED(hr)) return hr;
48
49     This->final_release = HAL_DirectDrawPalette_final_release;
50     ICOM_INIT_INTERFACE(This, IDirectDrawPalette, DDRAW_HAL_Palette_VTable);
51
52     /* initialize HAL palette */
53     data.lpDD = dd_gbl;
54     data.lpDDPalette = &This->global;
55     data.lpColorTable = NULL;
56     data.ddRVal = 0;
57     data.CreatePalette = dd_gbl->lpDDCBtmp->HALDD.CreatePalette;
58     if (data.CreatePalette)
59         data.CreatePalette(&data);
60
61     return DD_OK;
62 }
63
64 HRESULT
65 HAL_DirectDrawPalette_Create(IDirectDrawImpl* pDD, DWORD dwFlags,
66                              LPDIRECTDRAWPALETTE* ppPalette,
67                              LPUNKNOWN pUnkOuter)
68 {
69     IDirectDrawPaletteImpl* This;
70     HRESULT hr;
71
72     if (pUnkOuter != NULL)
73         return CLASS_E_NOAGGREGATION; /* unchecked */
74
75     This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*This));
76     if (This == NULL) return E_OUTOFMEMORY;
77
78     hr = HAL_DirectDrawPalette_Construct(This, pDD, dwFlags);
79     if (FAILED(hr))
80         HeapFree(GetProcessHeap(), 0, This);
81     else
82         *ppPalette = ICOM_INTERFACE(This, IDirectDrawPalette);
83
84     return hr;
85 }
86
87 HRESULT WINAPI
88 HAL_DirectDrawPalette_SetEntries(LPDIRECTDRAWPALETTE iface, DWORD dwFlags,
89                                  DWORD dwStart, DWORD dwCount,
90                                  LPPALETTEENTRY palent)
91 {
92     ICOM_THIS(IDirectDrawPaletteImpl,iface);
93     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->local.lpDD_lcl->lpGbl;
94     DDHAL_SETENTRIESDATA data;
95
96     TRACE("(%p)->SetEntries(%08lx,%ld,%ld,%p)\n",This,dwFlags,dwStart,dwCount,
97           palent);
98
99     data.lpDD = dd_gbl;
100     data.lpDDPalette = &This->global;
101     data.dwBase = dwStart;
102     data.dwNumEntries = dwCount;
103     data.lpEntries = palent;
104     data.ddRVal = 0;
105     data.SetEntries = dd_gbl->lpDDCBtmp->HALDDPalette.SetEntries;
106     if (data.SetEntries)
107         data.SetEntries(&data);
108
109     return Main_DirectDrawPalette_SetEntries(iface, dwFlags, dwStart, dwCount, palent);
110 }
111
112 void HAL_DirectDrawPalette_final_release(IDirectDrawPaletteImpl* This)
113 {
114     LPDDRAWI_DIRECTDRAW_GBL dd_gbl = This->local.lpDD_lcl->lpGbl;
115     DDHAL_DESTROYPALETTEDATA data;
116
117     /* destroy HAL palette */
118     data.lpDD = dd_gbl;
119     data.lpDDPalette = &This->global;
120     data.ddRVal = 0;
121     data.DestroyPalette = dd_gbl->lpDDCBtmp->HALDDPalette.DestroyPalette;
122     if (data.DestroyPalette)
123         data.DestroyPalette(&data);
124
125     Main_DirectDrawPalette_final_release(This);
126 }
127
128 static ICOM_VTABLE(IDirectDrawPalette) DDRAW_HAL_Palette_VTable =
129 {
130     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
131     Main_DirectDrawPalette_QueryInterface,
132     Main_DirectDrawPalette_AddRef,
133     Main_DirectDrawPalette_Release,
134     Main_DirectDrawPalette_GetCaps,
135     Main_DirectDrawPalette_GetEntries,
136     Main_DirectDrawPalette_Initialize,
137     HAL_DirectDrawPalette_SetEntries
138 };