source: trunk/src/ddraw/OS2PALETTE.CPP@ 210

Last change on this file since 210 was 210, checked in by hugh, 26 years ago

DX 6 Version of ddraw rel files

File size: 6.7 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <memory.h>
5#define INITGUID
6#include "os2palette.h"
7#define _OS2WIN_H
8#define FAR
9#include "misc.h"
10#include "os2palset.h"
11#include <winerror.h>
12
13//******************************************************************************
14//******************************************************************************
15OS2IDirectDrawPalette::OS2IDirectDrawPalette( OS2IDirectDraw *lpDirectDraw,
16 int palsize,
17 LPPALETTEENTRY lpColorTable,
18 DWORD dwPalFlags) :
19 Referenced(0), os2pal(NULL),
20 lastError(DD_OK), lpDraw(NULL)
21{
22 lpVtbl = &Vtbl;
23 Vtbl.AddRef = PalAddRef;
24 Vtbl.Release = PalRelease;
25 Vtbl.QueryInterface = PalQueryInterface;
26 Vtbl.GetCaps = PalGetCaps;
27 Vtbl.GetEntries = PalGetEntries;
28 Vtbl.Initialize = PalInitialize;
29 Vtbl.SetEntries = PalSetEntries;
30
31 lpDraw = lpDirectDraw;
32 lpDraw->Vtbl.AddRef(lpDraw);
33 hDive = lpDirectDraw->GetDiveInstance();
34 dwCaps = dwPalFlags;
35
36 dwSize = palsize;
37 if(256==dwSize)
38 dwCaps |= DDPCAPS_ALLOW256;
39 dwCaps &= ~DDPCAPS_VSYNC; // No sync change
40
41 os2pal = (LPPALETTEENTRY)malloc(palsize*sizeof(PALETTEENTRY));
42 memcpy((char *)os2pal, (char *)lpColorTable, palsize*sizeof(PALETTEENTRY));
43}
44//******************************************************************************
45//******************************************************************************
46OS2IDirectDrawPalette::~OS2IDirectDrawPalette()
47{
48 if(os2pal)
49 free(os2pal);
50 lpDraw->Vtbl.Release(lpDraw);
51}
52//******************************************************************************
53//******************************************************************************
54HRESULT __stdcall PalQueryInterface(THIS This, REFIID riid, LPVOID FAR * ppvObj)
55{
56 #ifdef DEBUG
57 WriteLog("OS2IDirectDrawPalette::PalQueryInterface\n");
58 #endif
59
60 *ppvObj = NULL;
61
62 if(!IsEqualGUID(riid, IID_IDirectDrawPalette))
63//&& !IsEqualGUID(riid, IID_IUnknown))
64 return E_NOINTERFACE;
65
66 *ppvObj = This;
67
68 PalAddRef(This);
69 return(DD_OK);
70}
71//******************************************************************************
72//******************************************************************************
73ULONG __stdcall PalAddRef(THIS This)
74{
75 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
76
77 #ifdef DEBUG
78 WriteLog("OS2IDirectDrawPalette::PalAddRef %d\n", me->Referenced+1);
79 #endif
80
81 return (++me->Referenced);
82}
83//******************************************************************************
84//******************************************************************************
85ULONG __stdcall PalRelease(THIS This)
86{
87 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
88
89 #ifdef DEBUG
90 WriteLog("OS2IDirectDrawPalette::PalRelease %d\n", me->Referenced-1);
91 #endif
92
93 if(me->Referenced)
94 {
95 me->Referenced--;
96 if(me->Referenced == 0)
97 {
98 delete me;
99 return(0);
100 }
101 else
102 return (me->Referenced);
103 }
104 else
105 return(0);
106}
107//******************************************************************************
108//******************************************************************************
109HRESULT __stdcall PalGetCaps(THIS This, LPDWORD lpdwCaps)
110{
111 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
112
113 #ifdef DEBUG
114 WriteLog("OS2IDirectDrawPalette::GetCaps\n");
115 #endif
116
117 if(NULL== lpdwCaps)
118 return(DDERR_INVALIDPARAMS);
119
120 *lpdwCaps = me->dwCaps;
121
122 if(me->fAttachedToPrimary)
123 *lpdwCaps |= DDPCAPS_PRIMARYSURFACE;
124
125 return(DD_OK);
126}
127//******************************************************************************
128//******************************************************************************
129HRESULT __stdcall PalGetEntries(THIS This, DWORD dwFlags,
130 DWORD dwBase,
131 DWORD dwNumEntries,
132 LPPALETTEENTRY lpEntries)
133{
134 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
135
136 #ifdef DEBUG
137 WriteLog("OS2IDirectDrawPalette::PalGetEntries\n");
138 #endif
139
140 if( (NULL== lpEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
141 return(DDERR_INVALIDPARAMS);
142
143 memcpy( (char *)lpEntries,
144 (char *)(me->os2pal + dwBase),
145 dwNumEntries*sizeof(PALETTEENTRY));
146 return(DD_OK);
147}
148//******************************************************************************
149//******************************************************************************
150HRESULT __stdcall PalInitialize(THIS, LPDIRECTDRAW, DWORD, LPPALETTEENTRY)
151{
152 #ifdef DEBUG
153 WriteLog("OS2IDirectDrawPalette::PalInitialize\n");
154 #endif
155 return(DDERR_ALREADYINITIALIZED);
156}
157//******************************************************************************
158//******************************************************************************
159HRESULT __stdcall PalSetEntries(THIS This, DWORD dwFlags,
160 DWORD dwBase,
161 DWORD dwNumEntries,
162 LPPALETTEENTRY lpNewEntries)
163{
164 OS2IDirectDrawPalette *me = (OS2IDirectDrawPalette *)This;
165
166 #ifdef DEBUG
167 WriteLog("OS2IDirectDrawPalette::PalSetEntries\n");
168 #endif
169 if( (NULL== lpNewEntries) ||(0!=dwFlags) ||(dwBase<0) ||((dwBase + dwNumEntries)>me->dwSize) )
170 return(DDERR_INVALIDPARAMS);
171 memcpy((char *)(me->os2pal + dwBase),
172 (char *)lpNewEntries,
173 dwNumEntries*sizeof(PALETTEENTRY));
174
175 if(me->fAttachedToPrimary)
176 me->SetPhysPalette();
177
178 return(DD_OK);
179}
180//******************************************************************************
181//******************************************************************************
182void OS2IDirectDrawPalette::SetPhysPalette()
183{
184 OS2SetPhysPalette(os2pal);
185}
186//******************************************************************************
187//******************************************************************************
188void OS2IDirectDrawPalette::RestorePhysPalette()
189{
190 OS2ResetPhysPalette();
191}
192//******************************************************************************
193//******************************************************************************
194void OS2IDirectDrawPalette::SetIsPrimary(BOOL fNewVal)
195{
196 if(fNewVal==fAttachedToPrimary)
197 return;
198 fAttachedToPrimary = fNewVal;
199 if(fAttachedToPrimary)
200 SetPhysPalette();
201
202}
203//******************************************************************************
204//******************************************************************************
205
Note: See TracBrowser for help on using the repository browser.