1 /*
2  * COPYRIGHT:            See COPYING in the top level directory
3  * PROJECT:              ReactOS DirectX
4  * FILE:                 dll/directx/ddraw/Surface/callbacks_surf_hel.c
5  * PURPOSE:              HEL Callbacks For Surface APIs
6  * PROGRAMMER:           Magnus Olsen
7  *
8  */
9 
10 #include "rosdraw.h"
11 
HelDdSurfAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA lpDestroySurface)12 DWORD CALLBACK HelDdSurfAddAttachedSurface(LPDDHAL_ADDATTACHEDSURFACEDATA lpDestroySurface)
13 {
14     DX_STUB;
15 }
16 
HelDdSurfBlt(LPDDHAL_BLTDATA lpBltData)17 DWORD CALLBACK HelDdSurfBlt(LPDDHAL_BLTDATA lpBltData)
18 {
19     DX_WINDBG_trace();
20 
21     if (lpBltData->dwFlags & DDBLT_COLORFILL)
22     {
23         HBRUSH hbr = CreateSolidBrush(lpBltData->bltFX.dwFillColor );
24         FillRect( (HDC)lpBltData->lpDDDestSurface->lpSurfMore->lpDD_lcl->hDC,
25                   (CONST RECT *)&lpBltData->rDest,
26                   hbr);
27         DeleteObject(hbr);
28         lpBltData->ddRVal = DD_OK;
29     }
30     else if (lpBltData->dwFlags & DDBLT_ROP)
31     {
32         BitBlt( (HDC)lpBltData->lpDDDestSurface->lpSurfMore->lpDD_lcl->hDC,
33                 lpBltData->rDest.top,
34                 lpBltData->rDest.left,
35                 lpBltData->rDest.right,
36                 lpBltData->rDest.bottom,
37                 (HDC)lpBltData->lpDDSrcSurface->lpSurfMore->lpDD_lcl->hDC,
38                 lpBltData->rSrc.top,
39                 lpBltData->rSrc.right,
40                 lpBltData->bltFX.dwROP);
41                 lpBltData->ddRVal = DD_OK;
42     }
43     return DDHAL_DRIVER_HANDLED;
44 }
45 
HelDdSurfDestroySurface(LPDDHAL_DESTROYSURFACEDATA lpDestroySurfaceData)46 DWORD CALLBACK HelDdSurfDestroySurface(LPDDHAL_DESTROYSURFACEDATA lpDestroySurfaceData)
47 {
48     DX_STUB;
49 }
50 
HelDdSurfFlip(LPDDHAL_FLIPDATA lpFlipData)51 DWORD CALLBACK HelDdSurfFlip(LPDDHAL_FLIPDATA lpFlipData)
52 {
53     DX_STUB;
54 }
55 
HelDdSurfGetBltStatus(LPDDHAL_GETBLTSTATUSDATA lpGetBltStatusData)56 DWORD CALLBACK HelDdSurfGetBltStatus(LPDDHAL_GETBLTSTATUSDATA lpGetBltStatusData)
57 {
58     DX_STUB;
59 }
60 
HelDdSurfGetFlipStatus(LPDDHAL_GETFLIPSTATUSDATA lpGetFlipStatusData)61 DWORD CALLBACK HelDdSurfGetFlipStatus(LPDDHAL_GETFLIPSTATUSDATA lpGetFlipStatusData)
62 {
63     DX_STUB;
64 }
65 
HelDdSurfLock(LPDDHAL_LOCKDATA lpLockData)66 DWORD CALLBACK HelDdSurfLock(LPDDHAL_LOCKDATA lpLockData)
67 {
68 
69     HDC hDC;
70     HBITMAP hImage = NULL;
71 
72     LONG cbBuffer = 0;
73     LPDWORD pixels = NULL;
74 
75     HDC hMemDC = NULL;
76     HBITMAP hDCBmp = NULL;
77     BITMAP bm = {0};
78 
79     DX_WINDBG_trace();
80 
81     /* ToDo tell ddraw internal this surface is locked */
82     /* ToDo add support for dwFlags */
83 
84 
85     /* Get our hdc for the active window */
86     hDC = GetDC((HWND)lpLockData->lpDDSurface->lpSurfMore->lpDD_lcl->hFocusWnd);
87 
88     if (hDC != NULL)
89     {
90         /* Create a memory bitmap to store a copy of current hdc surface */
91 
92         if (!lpLockData->bHasRect)
93         {
94             hImage = CreateCompatibleBitmap (hDC, lpLockData->lpDDSurface->lpGbl->wWidth, lpLockData->lpDDSurface->lpGbl->wHeight);
95         }
96         else
97         {
98             hImage = CreateCompatibleBitmap (hDC, lpLockData->rArea.right, lpLockData->rArea.bottom);
99         }
100 
101         /* Create a memory hdc so we can draw on our current memory bitmap */
102         hMemDC = CreateCompatibleDC(hDC);
103 
104         if (hMemDC != NULL)
105         {
106             /* Select our memory bitmap to our memory hdc */
107             hDCBmp = (HBITMAP) SelectObject (hMemDC, hImage);
108 
109             /* Get our memory bitmap information */
110             GetObject(hImage, sizeof(BITMAP), &bm);
111 
112             if (!lpLockData->bHasRect)
113             {
114                 BitBlt (hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY);
115             }
116             else
117             {
118                 BitBlt (hMemDC, lpLockData->rArea.top, lpLockData->rArea.left, lpLockData->rArea.right, lpLockData->rArea.bottom, hDC, 0, 0, SRCCOPY);
119             }
120 
121             SelectObject (hMemDC, hDCBmp);
122 
123             /* Allocate memory buffer for the bitmap pixel data  */
124             cbBuffer = bm.bmWidthBytes * bm.bmHeight ;
125             pixels = (PDWORD) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbBuffer );
126 
127             if (pixels != NULL)
128             {
129                 /* Get the bitmap bits */
130                 GetBitmapBits(hImage,cbBuffer,pixels);
131 
132                 /* Fixme HACK - check which member stores the HEL bitmap buffer */
133                 lpLockData->lpDDSurface->lpSurfMore->lpDDRAWReserved2 = pixels;
134 
135                 /* Setup return value */
136                 lpLockData->ddRVal = DD_OK;
137                 lpLockData->lpSurfData = pixels;
138             }
139         }
140     }
141 
142 
143     /* Free the pixels buffer if we fail */
144     if ( (pixels != NULL) &&
145          (lpLockData->ddRVal != DD_OK) )
146     {
147         HeapFree(GetProcessHeap(), 0, pixels );
148     }
149 
150     /* Cleanup after us */
151     if (hImage != NULL)
152     {
153         DeleteObject (hImage);
154     }
155 
156     if (hMemDC != NULL)
157     {
158         DeleteDC (hMemDC);
159     }
160 
161     return DDHAL_DRIVER_HANDLED;
162 }
163 
HelDdSurfreserved4(DWORD * lpPtr)164 DWORD CALLBACK HelDdSurfreserved4(DWORD *lpPtr)
165 {
166     /* This api is not documented by MS, keep it stubbed */
167     DX_STUB;
168 }
169 
HelDdSurfSetClipList(LPDDHAL_SETCLIPLISTDATA lpSetClipListData)170 DWORD CALLBACK HelDdSurfSetClipList(LPDDHAL_SETCLIPLISTDATA lpSetClipListData)
171 {
172     DX_STUB;
173 }
174 
HelDdSurfSetColorKey(LPDDHAL_SETCOLORKEYDATA lpSetColorKeyData)175 DWORD CALLBACK HelDdSurfSetColorKey(LPDDHAL_SETCOLORKEYDATA lpSetColorKeyData)
176 {
177     DX_STUB;
178 }
179 
HelDdSurfSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA lpSetOverlayPositionData)180 DWORD CALLBACK HelDdSurfSetOverlayPosition(LPDDHAL_SETOVERLAYPOSITIONDATA lpSetOverlayPositionData)
181 {
182     DX_STUB;
183 }
184 
HelDdSurfSetPalette(LPDDHAL_SETPALETTEDATA lpSetPaletteData)185 DWORD CALLBACK HelDdSurfSetPalette(LPDDHAL_SETPALETTEDATA lpSetPaletteData)
186 {
187     DX_STUB;
188 }
189 
HelDdSurfUnlock(LPDDHAL_UNLOCKDATA lpUnLockData)190 DWORD CALLBACK HelDdSurfUnlock(LPDDHAL_UNLOCKDATA lpUnLockData)
191 {
192     HDC hDC;
193     HBITMAP hImage = NULL;
194 
195     HDC hMemDC = NULL;
196     HBITMAP hDCBmp = NULL;
197     BITMAP bm = {0};
198 
199     DX_WINDBG_trace();
200 
201     /* Get our hdc for the active window */
202     hDC = GetDC((HWND)lpUnLockData->lpDDSurface->lpSurfMore->lpDD_lcl->hFocusWnd);
203 
204     if (hDC != NULL)
205     {
206         /* Create a memory bitmap to store a copy of current hdc surface */
207 
208         /* fixme the rcarea are not store in the struct yet so the data will look corrupted */
209         hImage = CreateCompatibleBitmap (hDC, lpUnLockData->lpDDSurface->lpGbl->wWidth, lpUnLockData->lpDDSurface->lpGbl->wHeight);
210 
211         /* Create a memory hdc so we can draw on our current memory bitmap */
212         hMemDC = CreateCompatibleDC(hDC);
213 
214         if (hMemDC != NULL)
215         {
216             /* Select our memory bitmap to our memory hdc */
217             hDCBmp = (HBITMAP) SelectObject (hMemDC, hImage);
218 
219             /* Get our memory bitmap information */
220             GetObject(hImage, sizeof(BITMAP), &bm);
221 
222             SetBitmapBits(hImage,bm.bmWidthBytes * bm.bmHeight, lpUnLockData->lpDDSurface->lpSurfMore->lpDDRAWReserved2);
223 
224             BitBlt (hDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
225 
226             SelectObject (hMemDC, hDCBmp);
227 
228             /* Setup return value */
229              lpUnLockData->ddRVal = DD_OK;
230         }
231     }
232 
233     /* Cleanup after us */
234     if (hImage != NULL)
235     {
236         DeleteObject (hImage);
237     }
238 
239     if (hMemDC != NULL)
240     {
241         DeleteDC (hMemDC);
242     }
243 
244     if (lpUnLockData->lpDDSurface->lpSurfMore->lpDDRAWReserved2 != NULL)
245     {
246         HeapFree(GetProcessHeap(), 0, lpUnLockData->lpDDSurface->lpSurfMore->lpDDRAWReserved2 );
247     }
248 
249     return DDHAL_DRIVER_HANDLED;
250 }
251 
HelDdSurfUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA lpUpDateOverLayData)252 DWORD CALLBACK HelDdSurfUpdateOverlay(LPDDHAL_UPDATEOVERLAYDATA lpUpDateOverLayData)
253 {
254     DX_STUB;
255 }
256 
257