VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/enable.c@ 3418

Last change on this file since 3418 was 3418, checked in by vboxsync, 17 years ago

OPENGL_GETINFO as a dummy is sufficient.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.9 KB
Line 
1/******************************Module*Header*******************************\
2*
3* *******************
4* * GDI SAMPLE CODE *
5* *******************
6*
7* Module Name: enable.c
8*
9* This module contains the functions that enable and disable the
10* driver, the pdev, and the surface.
11*
12* Copyright (c) 1992-1998 Microsoft Corporation
13\**************************************************************************/
14
15#include "driver.h"
16#include "dd.h"
17
18// The driver function table with all function index/address pairs
19
20// Hook functions to track dirty rectangles and generate RDP orders.
21// NT4 functions
22DRVFN gadrvfn_nt4[] = {
23 { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0
24 { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1
25 { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2
26 { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3
27 { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4
28 { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5
29 { INDEX_DrvOffset, (PFN) DrvOffset }, // 6
30 { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8
31 { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12
32 { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13
33 { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14
34 { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15
35 { INDEX_DrvPaint, (PFN) DrvPaint }, // 17
36 { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18
37 { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19
38 { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20
39 { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22
40 { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23
41 { INDEX_DrvEscape, (PFN) DrvEscape }, // 24
42 { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29
43 { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30
44 { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31
45 { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38
46 { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40
47 { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41
48#ifdef VBOX_WITH_DDRAW
49 { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
50 { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
51 { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
52#endif
53};
54/* Experimental begin */
55BOOL APIENTRY DrvResetPDEV(
56 DHPDEV dhpdevOld,
57 DHPDEV dhpdevNew
58 )
59{
60 DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, dhpdevOld, dhpdevNew));
61 return TRUE;
62}
63
64BOOL DrvNineGrid (PVOID x1, PVOID x2, PVOID x3, PVOID x4, PVOID x5, PVOID x6, PVOID x7, PVOID x8, PVOID x9)
65{
66 DISPDBG((0, "Experimental %s: %p, %p, %p, %p, %p, %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4, x5, x6, x7, x8, x9));
67 return FALSE;
68}
69
70VOID APIENTRY DrvDestroyFont(
71 FONTOBJ *pfo)
72{
73 DISPDBG((0, "Experimental %s: %p\n", __FUNCTION__, pfo));
74}
75
76ULONG APIENTRY DrvEscape(SURFOBJ *pso, ULONG iEsc, ULONG cjIn, PVOID pvIn, ULONG cjOut, PVOID pvOut)
77{
78 DISPDBG((0, "%s: %p, %p, %p, %p, %p, %p\n", __FUNCTION__, pso, iEsc, cjIn, pvIn, cjOut, pvOut));
79
80 switch(iEsc)
81 {
82#ifdef VBOX_WITH_OPENGL
83 case OPENGL_GETINFO:
84 {
85 /* It doesn't matter that we fail here. Opengl32 will fall back to software rendering when this escape is not supported. */
86 DISPDBG((0, "OPENGL_GETINFO size %d\n", cjOut));
87 break;
88 }
89#endif
90
91 case QUERYESCSUPPORT:
92 if ( cjIn == sizeof(DWORD)
93 && pvIn)
94 {
95 DWORD nEscapeQuery = *(DWORD *)pvIn;
96
97 switch(nEscapeQuery)
98 {
99#ifdef VBOX_WITH_OPENGL
100 case OPENGL_GETINFO:
101 return 1;
102#endif
103 default:
104 DISPDBG((0, "QUERYESCSUPPORT %d unsupported\n", nEscapeQuery));
105 break;
106 }
107 }
108 else
109 DISPDBG((0, "QUERYESCSUPPORT invalid size %d\n", cjOut));
110 break;
111
112 default:
113 DISPDBG((0, "Unsupported Escape %d\n", iEsc));
114 break;
115 }
116 return 0;
117}
118
119BOOL DrvConnect (PVOID x1, PVOID x2, PVOID x3, PVOID x4)
120{
121 DISPDBG((0, "Experimental %s: %p, %p, %p, %p\n", __FUNCTION__, x1, x2, x3, x4));
122 return TRUE;
123}
124
125BOOL DrvDisconnect (PVOID x1, PVOID x2)
126{
127 DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
128 return FALSE;
129}
130
131BOOL DrvReconnect (PVOID x1, PVOID x2)
132{
133 DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
134 return FALSE;
135}
136
137BOOL DrvShadowConnect (PVOID x1, PVOID x2)
138{
139 DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
140 return FALSE;
141}
142
143BOOL DrvShadowDisconnect (PVOID x1, PVOID x2)
144{
145 DISPDBG((0, "Experimental %s: %p, %p\n", __FUNCTION__, x1, x2));
146 return FALSE;
147}
148
149
150/* Experimental end */
151
152// W2K,XP functions
153DRVFN gadrvfn_nt5[] = {
154 { INDEX_DrvEnablePDEV, (PFN) DrvEnablePDEV }, // 0 0x0
155 { INDEX_DrvCompletePDEV, (PFN) DrvCompletePDEV }, // 1 0x1
156 { INDEX_DrvDisablePDEV, (PFN) DrvDisablePDEV }, // 2 0x2
157 { INDEX_DrvEnableSurface, (PFN) DrvEnableSurface }, // 3 0x3
158 { INDEX_DrvDisableSurface, (PFN) DrvDisableSurface }, // 4 0x4
159 { INDEX_DrvAssertMode, (PFN) DrvAssertMode }, // 5 0x5
160 { INDEX_DrvDisableDriver, (PFN) DrvDisableDriver }, // 8 0x8
161 { INDEX_DrvRealizeBrush, (PFN) DrvRealizeBrush }, // 12 0xc
162 { INDEX_DrvDitherColor, (PFN) DrvDitherColor }, // 13 0xd
163 { INDEX_DrvStrokePath, (PFN) DrvStrokePath }, // 14 0xe
164 { INDEX_DrvFillPath, (PFN) DrvFillPath }, // 15 0xf
165 { INDEX_DrvPaint, (PFN) DrvPaint }, // 17 0x11
166 { INDEX_DrvBitBlt, (PFN) DrvBitBlt }, // 18 0x12
167 { INDEX_DrvCopyBits, (PFN) DrvCopyBits }, // 19 0x13
168 { INDEX_DrvStretchBlt, (PFN) DrvStretchBlt, }, // 20 0x14
169 { INDEX_DrvSetPalette, (PFN) DrvSetPalette }, // 22 0x16
170 { INDEX_DrvTextOut, (PFN) DrvTextOut }, // 23 0x17
171 { INDEX_DrvEscape, (PFN) DrvEscape }, // 24 0x18
172 { INDEX_DrvSetPointerShape, (PFN) DrvSetPointerShape }, // 29 0x1d
173 { INDEX_DrvMovePointer, (PFN) DrvMovePointer }, // 30 0x1e
174 { INDEX_DrvLineTo, (PFN) DrvLineTo }, // 31 0x1f
175 { INDEX_DrvSynchronize, (PFN) DrvSynchronize }, // 38 0x26
176 { INDEX_DrvSaveScreenBits, (PFN) DrvSaveScreenBits }, // 40 0x28
177 { INDEX_DrvGetModes, (PFN) DrvGetModes }, // 41 0x29
178#ifdef VBOX_WITH_DDRAW
179 { INDEX_DrvGetDirectDrawInfo, (PFN) DrvGetDirectDrawInfo }, // 59 0x3b
180 { INDEX_DrvEnableDirectDraw, (PFN) DrvEnableDirectDraw }, // 60 0x3c
181 { INDEX_DrvDisableDirectDraw, (PFN) DrvDisableDirectDraw }, // 61 0x3d
182 { INDEX_DrvDeriveSurface, (PFN) DrvDeriveSurface }, // 85
183#endif
184 { INDEX_DrvNotify, (PFN) DrvNotify }, // 87 0x57
185// /* Experimental. */
186// { 0x7, (PFN) DrvResetPDEV }, // 0x7
187// { 0x5b, (PFN) DrvNineGrid }, // 0x5b
188// { 0x2b, (PFN) DrvDestroyFont }, // 0x2b
189// { 0x18, (PFN) DrvEscape }, // 0x18
190// { 0x4d, (PFN) DrvConnect }, // 0x4d
191// { 0x4e, (PFN) DrvDisconnect }, // 0x4e
192// { 0x4f, (PFN) DrvReconnect }, // 0x4f
193// { 0x50, (PFN) DrvShadowConnect }, // 0x50
194// { 0x51, (PFN) DrvShadowDisconnect }, // 0x51
195
196};
197
198// Required hook bits will be set up according to DDI version
199static ULONG gflHooks = 0;
200
201#define HOOKS_BMF8BPP gflHooks
202#define HOOKS_BMF16BPP gflHooks
203#define HOOKS_BMF24BPP gflHooks
204#define HOOKS_BMF32BPP gflHooks
205
206HSEMAPHORE ghsemHwBuffer = 0;
207
208/******************************Public*Routine******************************\
209* DrvEnableDriver
210*
211* Enables the driver by retrieving the drivers function table and version.
212*
213\**************************************************************************/
214
215BOOL DrvEnableDriver(
216ULONG iEngineVersion,
217ULONG cj,
218PDRVENABLEDATA pded)
219{
220// Engine Version is passed down so future drivers can support previous
221// engine versions. A next generation driver can support both the old
222// and new engine conventions if told what version of engine it is
223// working with. For the first version the driver does nothing with it.
224
225 iEngineVersion;
226
227 DISPDBG((0, "VBoxDisp::DrvEnableDriver called. iEngine version = %08X\n", iEngineVersion));
228
229 // Set up hook flags to intercept all functions which can generate VRDP orders
230 gflHooks = HOOK_BITBLT | HOOK_TEXTOUT | HOOK_FILLPATH |
231 HOOK_COPYBITS | HOOK_STROKEPATH | HOOK_LINETO |
232 HOOK_PAINT | HOOK_STRETCHBLT | HOOK_SYNCHRONIZEACCESS;
233
234// Fill in as much as we can.
235
236 if (cj >= sizeof(DRVENABLEDATA))
237 pded->pdrvfn = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
238 gadrvfn_nt5:
239 gadrvfn_nt4;
240
241
242 if (cj >= (sizeof(ULONG) * 2))
243 pded->c = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
244 sizeof(gadrvfn_nt5) / sizeof(DRVFN):
245 sizeof(gadrvfn_nt4) / sizeof(DRVFN);
246
247// DDI version this driver was targeted for is passed back to engine.
248// Future graphic's engine may break calls down to old driver format.
249
250 if (cj >= sizeof(ULONG))
251 pded->iDriverVersion = (iEngineVersion >= DDI_DRIVER_VERSION_NT5)?
252 DDI_DRIVER_VERSION_NT5:
253 DDI_DRIVER_VERSION_NT4;
254
255 if (!ghsemHwBuffer)
256 {
257 ghsemHwBuffer = EngCreateSemaphore ();
258 }
259
260 return(TRUE);
261}
262
263/******************************Public*Routine******************************\
264* DrvDisableDriver
265*
266* Tells the driver it is being disabled. Release any resources allocated in
267* DrvEnableDriver.
268*
269\**************************************************************************/
270
271VOID DrvDisableDriver(VOID)
272{
273 DISPDBG((0, "VBoxDisp::DrvDisableDriver called.\n"));
274
275 if (ghsemHwBuffer)
276 {
277 EngDeleteSemaphore (ghsemHwBuffer);
278 ghsemHwBuffer = NULL;
279 }
280
281 return;
282}
283
284/******************************Public*Routine******************************\
285* DrvEnablePDEV
286*
287* DDI function, Enables the Physical Device.
288*
289* Return Value: device handle to pdev.
290*
291\**************************************************************************/
292
293DHPDEV DrvEnablePDEV(
294DEVMODEW *pDevmode, // Pointer to DEVMODE
295PWSTR pwszLogAddress, // Logical address
296ULONG cPatterns, // number of patterns
297HSURF *ahsurfPatterns, // return standard patterns
298ULONG cjGdiInfo, // Length of memory pointed to by pGdiInfo
299ULONG *pGdiInfo, // Pointer to GdiInfo structure
300ULONG cjDevInfo, // Length of following PDEVINFO structure
301DEVINFO *pDevInfo, // physical device information structure
302HDEV hdev, // HDEV, used for callbacks
303PWSTR pwszDeviceName, // DeviceName - not used
304HANDLE hDriver) // Handle to base driver
305{
306 GDIINFO GdiInfo;
307 DEVINFO DevInfo;
308 PPDEV ppdev = (PPDEV) NULL;
309
310 DISPDBG((0, "VBoxDisp::DrvEnablePDEV called\n"));
311
312 UNREFERENCED_PARAMETER(pwszLogAddress);
313 UNREFERENCED_PARAMETER(pwszDeviceName);
314
315 RtlZeroMemory(&DevInfo, sizeof (DEVINFO));
316 RtlZeroMemory(&GdiInfo, sizeof (GDIINFO));
317
318 // Allocate a physical device structure.
319
320 ppdev = (PPDEV) EngAllocMem(0, sizeof(PDEV), ALLOC_TAG);
321
322 if (ppdev == (PPDEV) NULL)
323 {
324 DISPDBG((0, "DISP DrvEnablePDEV failed EngAllocMem\n"));
325 return((DHPDEV) 0);
326 }
327
328 memset(ppdev, 0, sizeof(PDEV));
329
330 // Save the screen handle in the PDEV.
331
332 ppdev->hDriver = hDriver;
333
334 // Get the current screen mode information. Set up device caps and devinfo.
335
336 if (!bInitPDEV(ppdev, pDevmode, &GdiInfo, &DevInfo))
337 {
338 DISPDBG((0,"DISP DrvEnablePDEV failed\n"));
339 goto error_free;
340 }
341
342 // Initialize the cursor information.
343
344 if (!bInitPointer(ppdev, &DevInfo))
345 {
346 // Not a fatal error...
347 DISPDBG((0, "DrvEnablePDEV failed bInitPointer\n"));
348 }
349
350 // Initialize palette information.
351
352 if (!bInitPaletteInfo(ppdev, &DevInfo))
353 {
354 DISPDBG((0, "DrvEnablePDEV failed bInitPalette\n"));
355 goto error_free;
356 }
357
358// // Start a thread that will process notifications from VMMDev
359// if (!bInitNotificationThread(ppdev))
360// {
361// DISPDBG((0, "DrvEnablePDEV failed bInitNotificationThread\n"));
362// goto error_free;
363// }
364
365 // Copy the devinfo into the engine buffer.
366
367 DISPDBG((0, "VBoxDisp::DrvEnablePDEV: sizeof(DEVINFO) = %d, cjDevInfo = %d, alpha = %d\n", sizeof(DEVINFO), cjDevInfo, DevInfo.flGraphicsCaps2 & GCAPS2_ALPHACURSOR));
368
369// @todo seems to be not necessary. these bits are initialized in screen.c DevInfo.flGraphicsCaps |= GCAPS_OPAQUERECT |
370// GCAPS_DITHERONREALIZE |
371// GCAPS_PALMANAGED |
372// GCAPS_ALTERNATEFILL |
373// GCAPS_WINDINGFILL |
374// GCAPS_MONO_DITHER |
375// GCAPS_COLOR_DITHER |
376// GCAPS_ASYNCMOVE;
377//
378// DevInfo.flGraphicsCaps |= GCAPS_DITHERONREALIZE;
379
380 DevInfo.flGraphicsCaps2 |= GCAPS2_RESERVED1; /* @todo figure out what is this. */
381
382 memcpy(pDevInfo, &DevInfo, min(sizeof(DEVINFO), cjDevInfo));
383
384 // Set the pdevCaps with GdiInfo we have prepared to the list of caps for this
385 // pdev.
386
387 memcpy(pGdiInfo, &GdiInfo, min(cjGdiInfo, sizeof(GDIINFO)));
388
389 DISPDBG((0, "VBoxDisp::DrvEnablePDEV completed\n"));
390
391 return((DHPDEV) ppdev);
392
393 // Error case for failure.
394error_free:
395 EngFreeMem(ppdev);
396 return((DHPDEV) 0);
397}
398
399/******************************Public*Routine******************************\
400* DrvCompletePDEV
401*
402* Store the HPDEV, the engines handle for this PDEV, in the DHPDEV.
403*
404\**************************************************************************/
405
406VOID DrvCompletePDEV(
407DHPDEV dhpdev,
408HDEV hdev)
409{
410 DISPDBG((0, "VBoxDisp::DrvCompletePDEV called\n"));
411 ((PPDEV) dhpdev)->hdevEng = hdev;
412}
413
414/******************************Public*Routine******************************\
415* DrvDisablePDEV
416*
417* Release the resources allocated in DrvEnablePDEV. If a surface has been
418* enabled DrvDisableSurface will have already been called.
419*
420\**************************************************************************/
421
422VOID DrvDisablePDEV(
423DHPDEV dhpdev)
424{
425 DISPDBG((0, "VBoxDisp::DrvDisablePDEV called\n"));
426// vStopNotificationThread ((PPDEV) dhpdev);
427 vDisablePalette((PPDEV) dhpdev);
428
429 /* Free the driver's VBVA resources. */
430 vboxVbvaDisable ((PPDEV) dhpdev);
431
432 EngFreeMem(dhpdev);
433}
434
435/******************************Public*Routine******************************\
436* VOID DrvOffset
437*
438* DescriptionText
439*
440\**************************************************************************/
441
442BOOL DrvOffset(
443SURFOBJ* pso,
444LONG x,
445LONG y,
446FLONG flReserved)
447{
448 PDEV* ppdev = (PDEV*) pso->dhpdev;
449
450 // Add back last offset that we subtracted. I could combine the next
451 // two statements, but I thought this was more clear. It's not
452 // performance critical anyway.
453
454 ppdev->pjScreen += ((ppdev->ptlOrg.y * ppdev->lDeltaScreen) +
455 (ppdev->ptlOrg.x * ((ppdev->ulBitCount+1) >> 3)));
456
457 // Subtract out new offset
458
459 ppdev->pjScreen -= ((y * ppdev->lDeltaScreen) +
460 (x * ((ppdev->ulBitCount+1) >> 3)));
461
462 ppdev->ptlOrg.x = x;
463 ppdev->ptlOrg.y = y;
464
465 return(TRUE);
466}
467
468/******************************Public*Routine******************************\
469* DrvEnableSurface
470*
471* Enable the surface for the device. Hook the calls this driver supports.
472*
473* Return: Handle to the surface if successful, 0 for failure.
474*
475\**************************************************************************/
476
477HSURF DrvEnableSurface(
478DHPDEV dhpdev)
479{
480 PPDEV ppdev;
481 HSURF hsurf;
482 SIZEL sizl;
483 ULONG ulBitmapType;
484 FLONG flHooks;
485
486 DISPDBG((0, "DISP DrvEnableSurface called\n"));
487
488 // Create engine bitmap around frame buffer.
489
490 ppdev = (PPDEV) dhpdev;
491
492 ppdev->ptlOrg.x = 0;
493 ppdev->ptlOrg.y = 0;
494
495 if (!bInitSURF(ppdev, TRUE))
496 {
497 DISPDBG((0, "DISP DrvEnableSurface failed bInitSURF\n"));
498 return(FALSE);
499 }
500
501 DISPDBG((0, "DISP DrvEnableSurface bInitSURF success\n"));
502
503 sizl.cx = ppdev->cxScreen;
504 sizl.cy = ppdev->cyScreen;
505
506 if (ppdev->ulBitCount == 8)
507 {
508 if (!bInit256ColorPalette(ppdev)) {
509 DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
510 return(FALSE);
511 }
512 ulBitmapType = BMF_8BPP;
513 flHooks = HOOKS_BMF8BPP;
514 }
515 else if (ppdev->ulBitCount == 16)
516 {
517 ulBitmapType = BMF_16BPP;
518 flHooks = HOOKS_BMF16BPP;
519 }
520 else if (ppdev->ulBitCount == 24)
521 {
522 ulBitmapType = BMF_24BPP;
523 flHooks = HOOKS_BMF24BPP;
524 }
525 else
526 {
527 ulBitmapType = BMF_32BPP;
528 flHooks = HOOKS_BMF32BPP;
529 }
530
531 hsurf = (HSURF) EngCreateBitmap(sizl,
532 ppdev->lDeltaScreen,
533 ulBitmapType,
534 (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
535 (PVOID) (ppdev->pjScreen));
536
537 if (hsurf == (HSURF) 0)
538 {
539 DISPDBG((0, "DISP DrvEnableSurface failed EngCreateBitmap\n"));
540 goto l_Failure;
541 }
542 else
543 {
544 ppdev->hsurfScreenBitmap = hsurf;
545
546 if (!EngAssociateSurface(hsurf, ppdev->hdevEng, 0))
547 {
548 DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for ScreenBitmap.\n"));
549 goto l_Failure;
550 }
551 else
552 {
553 SURFOBJ *pso = EngLockSurface(hsurf);
554
555 ppdev->psoScreenBitmap = pso;
556
557 hsurf = (HSURF) EngCreateDeviceSurface((DHSURF)pso,
558 sizl,
559 ulBitmapType);
560
561 if (hsurf == (HSURF) 0)
562 {
563 DISPDBG((0, "DISP DrvEnableSurface failed EngCreateDeviceSurface\n"));
564 goto l_Failure;
565 }
566 else
567 {
568 ppdev->hsurfScreen = hsurf;
569
570 if (!EngAssociateSurface(hsurf, ppdev->hdevEng, flHooks))
571 {
572 DISPDBG((0, "DISP DrvEnableSurface failed EngAssociateSurface for Screen.\n"));
573 goto l_Failure;
574 }
575 else
576 {
577 ppdev->flHooks = flHooks;
578 ppdev->ulBitmapType = ulBitmapType;
579 }
580 }
581 }
582 }
583
584 return ppdev->hsurfScreen;
585
586l_Failure:
587
588 DrvDisableSurface(dhpdev);
589
590 return((HSURF)0);
591}
592
593/******************************Public*Routine******************************\
594* DrvDisableSurface
595*
596* Free resources allocated by DrvEnableSurface. Release the surface.
597*
598\**************************************************************************/
599
600VOID DrvDisableSurface(
601DHPDEV dhpdev)
602{
603 PPDEV ppdev = (PPDEV)dhpdev;
604
605 DISPDBG((0, "VBoxDisp::DrvDisableSurface called\n"));
606 if (ppdev->psoScreenBitmap)
607 {
608 EngUnlockSurface (ppdev->psoScreenBitmap);
609 ppdev->psoScreenBitmap = NULL;
610 }
611
612 if (ppdev->hsurfScreen)
613 {
614 EngDeleteSurface(ppdev->hsurfScreen);
615 ppdev->hsurfScreen = (HSURF)0;
616 }
617
618 if (ppdev->hsurfScreenBitmap)
619 {
620 EngDeleteSurface(ppdev->hsurfScreenBitmap);
621 ppdev->hsurfScreenBitmap = (HSURF)0;
622 }
623
624 vDisableSURF(ppdev);
625}
626
627/******************************Public*Routine******************************\
628* DrvAssertMode
629*
630* This asks the device to reset itself to the mode of the pdev passed in.
631*
632\**************************************************************************/
633
634BOOL DrvAssertMode(
635DHPDEV dhpdev,
636BOOL bEnable)
637{
638 PPDEV ppdev = (PPDEV) dhpdev;
639 ULONG ulReturn;
640 PBYTE pjScreen;
641
642 DISPDBG((0, "DISP DrvAssertMode called bEnable = %d\n", bEnable));
643
644 if (bEnable)
645 {
646 pjScreen = ppdev->pjScreen;
647
648 if (!bInitSURF(ppdev, FALSE))
649 {
650 DISPDBG((0, "DISP DrvAssertMode failed bInitSURF\n"));
651 return (FALSE);
652 }
653
654 if (pjScreen != ppdev->pjScreen)
655 {
656 HSURF hsurf;
657 SIZEL sizl;
658 SURFOBJ *pso;
659
660 DISPDBG((0, "DISP DrvAssertMode Screen pointer has changed!!!\n"));
661
662 sizl.cx = ppdev->cxScreen;
663 sizl.cy = ppdev->cyScreen;
664
665 hsurf = (HSURF) EngCreateBitmap(sizl,
666 ppdev->lDeltaScreen,
667 ppdev->ulBitmapType,
668 (ppdev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
669 (PVOID) (ppdev->pjScreen));
670
671 if (hsurf == (HSURF) 0)
672 {
673 DISPDBG((0, "DISP DrvAssertMode failed EngCreateBitmap\n"));
674 return FALSE;
675 }
676
677 pso = EngLockSurface(hsurf);
678
679 if (ppdev->psoScreenBitmap)
680 {
681 EngUnlockSurface (ppdev->psoScreenBitmap);
682 ppdev->psoScreenBitmap = NULL;
683 }
684
685 if (ppdev->hsurfScreenBitmap)
686 {
687 EngDeleteSurface(ppdev->hsurfScreenBitmap);
688 ppdev->hsurfScreenBitmap = (HSURF)0;
689 }
690
691 ppdev->hsurfScreenBitmap = hsurf;
692 ppdev->psoScreenBitmap = pso;
693 }
694
695 if (!EngAssociateSurface(ppdev->hsurfScreenBitmap, ppdev->hdevEng, 0))
696 {
697 DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for ScreenBitmap.\n"));
698 return FALSE;
699 }
700
701 if (!EngAssociateSurface(ppdev->hsurfScreen, ppdev->hdevEng, ppdev->flHooks))
702 {
703 DISPDBG((0, "DISP DrvAssertMode failed EngAssociateSurface for Screen.\n"));
704 return FALSE;
705 }
706
707 return TRUE;
708 }
709 else
710 {
711 //
712 // We must give up the display.
713 // Call the kernel driver to reset the device to a known state.
714 //
715
716 if (EngDeviceIoControl(ppdev->hDriver,
717 IOCTL_VIDEO_RESET_DEVICE,
718 NULL,
719 0,
720 NULL,
721 0,
722 &ulReturn))
723 {
724 DISPDBG((0, "DISP DrvAssertMode failed IOCTL\n"));
725 return FALSE;
726 }
727 else
728 {
729 return TRUE;
730 }
731 }
732}
733
734/******************************Public*Routine******************************\
735* DrvGetModes
736*
737* Returns the list of available modes for the device.
738*
739\**************************************************************************/
740
741ULONG DrvGetModes(
742HANDLE hDriver,
743ULONG cjSize,
744DEVMODEW *pdm)
745
746{
747
748 DWORD cModes;
749 DWORD cbOutputSize;
750 PVIDEO_MODE_INFORMATION pVideoModeInformation, pVideoTemp;
751 DWORD cOutputModes = cjSize / (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
752 DWORD cbModeSize;
753
754 DISPDBG((3, "DrvGetModes\n"));
755
756 cModes = getAvailableModes(hDriver,
757 (PVIDEO_MODE_INFORMATION *) &pVideoModeInformation,
758 &cbModeSize);
759
760 if (cModes == 0)
761 {
762 DISPDBG((0, "DrvGetModes failed to get mode information"));
763 return 0;
764 }
765
766 if (pdm == NULL)
767 {
768 cbOutputSize = cModes * (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
769 }
770 else
771 {
772 //
773 // Now copy the information for the supported modes back into the output
774 // buffer
775 //
776
777 cbOutputSize = 0;
778
779 pVideoTemp = pVideoModeInformation;
780
781 do
782 {
783 if (pVideoTemp->Length != 0)
784 {
785 if (cOutputModes == 0)
786 {
787 break;
788 }
789
790 //
791 // Zero the entire structure to start off with.
792 //
793
794 memset(pdm, 0, sizeof(DEVMODEW));
795
796 //
797 // Set the name of the device to the name of the DLL.
798 //
799
800 memcpy(pdm->dmDeviceName, DLL_NAME, sizeof(DLL_NAME));
801
802 pdm->dmSpecVersion = DM_SPECVERSION;
803 pdm->dmDriverVersion = DM_SPECVERSION;
804 pdm->dmSize = sizeof(DEVMODEW);
805 pdm->dmDriverExtra = DRIVER_EXTRA_SIZE;
806
807 pdm->dmBitsPerPel = pVideoTemp->NumberOfPlanes *
808 pVideoTemp->BitsPerPlane;
809 pdm->dmPelsWidth = pVideoTemp->VisScreenWidth;
810 pdm->dmPelsHeight = pVideoTemp->VisScreenHeight;
811 pdm->dmDisplayFrequency = pVideoTemp->Frequency;
812 pdm->dmDisplayFlags = 0;
813
814 pdm->dmFields = DM_BITSPERPEL |
815 DM_PELSWIDTH |
816 DM_PELSHEIGHT |
817 DM_DISPLAYFREQUENCY |
818 DM_DISPLAYFLAGS ;
819
820 //
821 // Go to the next DEVMODE entry in the buffer.
822 //
823
824 cOutputModes--;
825
826 pdm = (LPDEVMODEW) ( ((ULONG_PTR)pdm) + sizeof(DEVMODEW)
827 + DRIVER_EXTRA_SIZE);
828
829 cbOutputSize += (sizeof(DEVMODEW) + DRIVER_EXTRA_SIZE);
830
831 }
832
833 pVideoTemp = (PVIDEO_MODE_INFORMATION)
834 (((PUCHAR)pVideoTemp) + cbModeSize);
835
836 } while (--cModes);
837 }
838
839 EngFreeMem(pVideoModeInformation);
840
841 return cbOutputSize;
842
843}
844
845VOID DrvSynchronize(
846IN DHPDEV dhpdev,
847IN RECTL *prcl)
848{
849}
850
851/******************************Public*Routine******************************\
852* DrvNotify
853*
854* Called by GDI to notify us of certain "interesting" events
855*
856* DN_DEVICE_ORIGIN is used to communicate the X/Y offsets of individual monitors
857* when DualView is in effect.
858*
859\**************************************************************************/
860
861VOID DrvNotify(
862SURFOBJ *pso,
863ULONG iType,
864PVOID pvData)
865{
866 PDEV* ppdev = (PDEV*) pso->dhpdev;
867
868 DISPDBG((0, "VBoxDisp::DrvNotify called.\n"));
869
870 switch(iType)
871 {
872 case DN_DEVICE_ORIGIN:
873 ppdev->ptlDevOrg = *(PPOINTL)pvData;
874 DISPDBG((3, "DN_DEVICE_ORIGIN: %d, %d (PSO = %p, pInfo = %p)\n", ppdev->ptlDevOrg.x,
875 ppdev->ptlDevOrg.y, pso, ppdev->pInfo));
876 if (ppdev->pInfo)
877 {
878 ppdev->pInfo->screen.xOrigin = ppdev->ptlDevOrg.x;
879 ppdev->pInfo->screen.yOrigin = ppdev->ptlDevOrg.y;
880 VBoxProcessDisplayInfo(ppdev);
881 }
882 break;
883 case DN_DRAWING_BEGIN:
884 DISPDBG((3, "DN_DRAWING_BEGIN (PSO = %p)\n", pso));
885 break;
886 }
887}
888
889#ifdef VBOX_WITH_DDRAW
890//--------------------------Public Routine-------------------------------------
891//
892// HBITMAP DrvDeriveSurface
893//
894// This function derives and creates a GDI surface from the specified
895// DirectDraw surface.
896//
897// Parameters
898// pDirectDraw-----Points to a DD_DIRECTDRAW_GLOBAL structure that describes
899// the DirectDraw object.
900// pSurface--------Points to a DD_SURFACE_LOCAL structure that describes the
901// DirectDraw surface around which to wrap a GDI surface.
902//
903// Return Value
904// DrvDeriveSurface returns a handle to the created GDI surface upon success.
905// It returns NULL if the call fails or if the driver cannot accelerate GDI
906// drawing to the specified DirectDraw surface.
907//
908// Comments
909// DrvDeriveSurface allows the driver to create a GDI surface around a
910// DirectDraw video memory or AGP surface object in order to allow accelerated
911// GDI drawing to the surface. If the driver does not hook this call, all GDI
912// drawing to DirectDraw surfaces is done in software using the DIB engine.
913//
914// GDI calls DrvDeriveSurface with RGB surfaces only.
915//
916// The driver should call DrvCreateDeviceBitmap to create a GDI surface of the
917// same size and format as that of the DirectDraw surface. Space for the
918// actual pixels need not be allocated since it already exists.
919//
920//-----------------------------------------------------------------------------
921HBITMAP DrvDeriveSurface(DD_DIRECTDRAW_GLOBAL* pDirectDraw, DD_SURFACE_LOCAL* pSurface)
922{
923 PPDEV pDev = (PPDEV)pDirectDraw->dhpdev;
924 HBITMAP hbmDevice;
925 DD_SURFACE_GLOBAL* pSurfaceGlobal;
926 SIZEL sizl;
927
928 DISPDBG((0, "%s: %p\n", __FUNCTION__, pDev));
929
930 pSurfaceGlobal = pSurface->lpGbl;
931
932 //
933 // GDI should never call us for a non-RGB surface, but let's assert just
934 // to make sure they're doing their job properly.
935 //
936 AssertMsg(!(pSurfaceGlobal->ddpfSurface.dwFlags & DDPF_FOURCC), ("GDI called us with a non-RGB surface!"));
937
938#if 0
939 // The GDI driver does not accelerate surfaces in AGP memory,
940 // thus we fail the call
941
942 if (pSurface->ddsCaps.dwCaps & DDSCAPS_NONLOCALVIDMEM)
943 {
944 DISPDBG((0, "DrvDeriveSurface return NULL, surface in AGP memory"));
945 return 0;
946 }
947
948 // The GDI driver does not accelerate managed surface,
949 // thus we fail the call
950 if (pSurface->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
951 {
952 DISPDBG((0, "DrvDeriveSurface return NULL, surface is managed"));
953 return 0;
954 }
955
956 //
957 // The rest of our driver expects GDI calls to come in with the same
958 // format as the primary surface. So we'd better not wrap a device
959 // bitmap around an RGB format that the rest of our driver doesn't
960 // understand. Also, we must check to see that it is not a surface
961 // whose pitch does not match the primary surface.
962 //
963 // NOTE: Most surfaces created by this driver are allocated as 2D surfaces
964 // whose lPitch's are equal to the screen pitch. However, overlay surfaces
965 // are allocated such that there lPitch's are usually different then the
966 // screen pitch. The hardware can not accelerate drawing operations to
967 // these surfaces and thus we fail to derive these surfaces.
968 //
969 if ( (pSurfaceGlobal->ddpfSurface.dwRGBBitCount == pDev->ulBitCount) )
970 {
971 SIZEL sizel;
972 DWORD ulBitmapType, flHooks;
973
974 sizl.cx = pSurfaceGlobal->wWidth;
975 sizl.cy = pSurfaceGlobal->wHeight;
976
977 if (pDev->ulBitCount == 8)
978 {
979 if (!bInit256ColorPalette(pDev)) {
980 DISPDBG((0, "DISP DrvEnableSurface failed to init the 8bpp palette\n"));
981 return(FALSE);
982 }
983 ulBitmapType = BMF_8BPP;
984 flHooks = HOOKS_BMF8BPP;
985 }
986 else if (pDev->ulBitCount == 16)
987 {
988 ulBitmapType = BMF_16BPP;
989 flHooks = HOOKS_BMF16BPP;
990 }
991 else if (pDev->ulBitCount == 24)
992 {
993 ulBitmapType = BMF_24BPP;
994 flHooks = HOOKS_BMF24BPP;
995 }
996 else
997 {
998 ulBitmapType = BMF_32BPP;
999 flHooks = HOOKS_BMF32BPP;
1000 }
1001
1002 hbmDevice = EngCreateBitmap(sizl,
1003 pDev->lDeltaScreen,
1004 ulBitmapType,
1005 (pDev->lDeltaScreen > 0) ? BMF_TOPDOWN : 0,
1006 (PVOID) (pDev->pjScreen));
1007 if (hbmDevice)
1008 {
1009 VOID* pvScan0 = pDev->pjScreen + pSurfaceGlobal->fpVidMem;
1010
1011 //
1012 // Note that HOOK_SYNCHRONIZE must always be hooked when we
1013 // give GDI a pointer to the bitmap bits. We don't need to
1014 // do it here since HOOK_SYNCHRONIZE is always set in our
1015 // pdev->flHooks
1016 //
1017 ULONG flags = MS_NOTSYSTEMMEMORY;
1018
1019 if ( EngModifySurface((HSURF)hbmDevice,
1020 pDev->hdevEng,
1021 pDev->flHooks,
1022 flags,
1023 (DHSURF)hbmDevice,
1024 pvScan0,
1025 pSurfaceGlobal->lPitch,
1026 NULL) )
1027 {
1028 SURFOBJ* surfobj = EngLockSurface((HSURF) hbmDevice);
1029 AssertMsg(surfobj->iType == STYPE_BITMAP, ("expected STYPE_BITMAP"));
1030 surfobj->iType = STYPE_DEVBITMAP;
1031 EngUnlockSurface(surfobj);
1032
1033 DISPDBG((0, "DrvDeriveSurface return succeed"));
1034 return(hbmDevice);
1035 }
1036
1037 DISPDBG((0, "DrvDeriveSurface: EngModifySurface failed"));
1038 EngDeleteSurface((HSURF)hbmDevice);
1039 }
1040 }
1041
1042 DISPDBG((0, "DrvDeriveSurface return NULL"));
1043 DISPDBG((0, "pSurfaceGlobal->ddpfSurface.dwRGBBitCount = %d, lPitch =%ld", pSurfaceGlobal->ddpfSurface.dwRGBBitCount,pSurfaceGlobal->lPitch));
1044#endif
1045
1046 return(0);
1047}
1048#endif /* VBOX_WITH_DDRAW */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette