2 * ReactOS Generic Framebuffer acclations display driver
4 * Copyright (C) 2004 Filip Navara
5 * Copyright (C) 2007 Magnus Olsen
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "framebufacc.h"
25 InitSurface(PPDEV ppdev
,
28 VIDEO_MEMORY VideoMemory
;
29 VIDEO_MEMORY_INFORMATION VideoMemoryInfo
;
30 ULONG returnedDataLength
;
31 ULONG RemappingNeeded
= 0;
32 ULONG PointerMaxWidth
= 0;
33 ULONG PointerMaxHeight
= 0;
36 * Set video mode of our adapter.
39 if (EngDeviceIoControl(ppdev
->hDriver
,
40 IOCTL_VIDEO_SET_CURRENT_MODE
,
50 /* Check if mapping is need it */
51 if ((!bForcemapping
) &&
59 * Map the framebuffer into our memory.
62 VideoMemory
.RequestedVirtualAddress
= NULL
;
63 if (EngDeviceIoControl(ppdev
->hDriver
, IOCTL_VIDEO_MAP_VIDEO_MEMORY
,
64 &VideoMemory
, sizeof(VIDEO_MEMORY
),
65 &VideoMemoryInfo
, sizeof(VIDEO_MEMORY_INFORMATION
),
72 * Save the real video memory
74 ppdev
->pRealVideoMem
= VideoMemoryInfo
.FrameBufferBase
;
75 ppdev
->VideoMemSize
= VideoMemoryInfo
.VideoRamLength
;
81 * We maby should only ask max 8MB as cached ?, think of the video ram length is 256MB
84 ppdev
->pVideoMemCache
= NULL
;
85 #ifdef EXPERIMENTAL_ACC_SUPPORT
87 ppdev
->pVideoMemCache
= EngAllocMem(0, (ULONG
)VideoMemoryInfo
.VideoRamLength
, ALLOC_TAG
);
88 if (ppdev
->pVideoMemCache
== NULL
)
90 /* cached off for no avail system memory */
91 ppdev
->ScreenPtr
= VideoMemoryInfo
.FrameBufferBase
;
97 /* cached on, system memory is avail */
98 ppdev
->ScreenPtr
= ppdev
->pRealVideoMem
;
101 /* hw mouse pointer support */
102 PointerMaxHeight
= ppdev
->PointerCapabilities
.MaxHeight
;
103 PointerMaxWidth
= ppdev
->PointerCapabilities
.MaxWidth
* sizeof(ULONG
);
104 if (ppdev
->PointerCapabilities
.Flags
& VIDEO_MODE_COLOR_POINTER
)
106 PointerMaxWidth
= (ppdev
->PointerCapabilities
.MaxWidth
+ 7) / 8;
109 ppdev
->PointerAttributesSize
= sizeof(VIDEO_POINTER_ATTRIBUTES
) + ((sizeof(UCHAR
) * PointerMaxWidth
* PointerMaxHeight
) << 1);
111 ppdev
->pPointerAttributes
= EngAllocMem(0, ppdev
->PointerAttributesSize
, ALLOC_TAG
);
113 if (ppdev
->pPointerAttributes
!= NULL
)
115 ppdev
->pPointerAttributes
->Flags
= ppdev
->PointerCapabilities
.Flags
;
116 ppdev
->pPointerAttributes
->WidthInBytes
= PointerMaxWidth
;
117 ppdev
->pPointerAttributes
->Width
= ppdev
->PointerCapabilities
.MaxWidth
;
118 ppdev
->pPointerAttributes
->Height
= PointerMaxHeight
;
119 ppdev
->pPointerAttributes
->Column
= 0;
120 ppdev
->pPointerAttributes
->Row
= 0;
121 ppdev
->pPointerAttributes
->Enable
= 0;
125 /* no hw mouse was avail */
126 ppdev
->PointerAttributesSize
= 0;
135 * Create engine bitmap around frame buffer and set the video mode requested
136 * when PDEV was initialized.
146 PPDEV ppdev
= (PPDEV
)dhpdev
;
152 /* Setup surface and force the mapping */
153 if (!InitSurface(ppdev
, TRUE
))
158 /* Rest the desktop vitual position */
159 ppdev
->ScreenOffsetXY
.x
= 0;
160 ppdev
->ScreenOffsetXY
.y
= 0;
163 switch (ppdev
->BitsPerPixel
)
166 IntSetPalette(dhpdev
, ppdev
->PaletteEntries
, 0, 256);
167 BitmapType
= BMF_8BPP
;
171 BitmapType
= BMF_16BPP
;
175 BitmapType
= BMF_24BPP
;
179 BitmapType
= BMF_32BPP
;
186 ppdev
->iDitherFormat
= BitmapType
;
188 ScreenSize
.cx
= ppdev
->ScreenWidth
;
189 ScreenSize
.cy
= ppdev
->ScreenHeight
;
191 hSurface
= (HSURF
)EngCreateBitmap(ScreenSize
, ppdev
->ScreenDelta
, BitmapType
,
192 (ppdev
->ScreenDelta
> 0) ? BMF_TOPDOWN
: 0,
194 if (hSurface
== NULL
)
199 /* Which api we hooking to */
200 ppdev
->dwHooks
= HOOK_BITBLT
| HOOK_COPYBITS
| HOOK_FILLPATH
| HOOK_TEXTOUT
| HOOK_STROKEPATH
| HOOK_LINETO
;
203 * Associate the surface with our device.
207 if (!EngAssociateSurface(hSurface
, ppdev
->hDevEng
, ppdev
->dwHooks
))
209 EngDeleteSurface(hSurface
);
213 ppdev
->hSurfEng
= hSurface
;
221 * Used by GDI to notify a driver that the surface created by DrvEnableSurface
222 * for the current device is no longer needed.
233 VIDEO_MEMORY VideoMemory
;
234 PPDEV ppdev
= (PPDEV
)dhpdev
;
236 EngDeleteSurface(ppdev
->hSurfEng
);
237 ppdev
->hSurfEng
= NULL
;
240 /* Free the video memory cache */
241 if (ppdev
->pVideoMemCache
)
243 EngFreeMem(ppdev
->pVideoMemCache
);
247 * Unmap the framebuffer.
250 VideoMemory
.RequestedVirtualAddress
= ppdev
->pRealVideoMem
;
251 EngDeviceIoControl(((PPDEV
)dhpdev
)->hDriver
, IOCTL_VIDEO_UNMAP_VIDEO_MEMORY
,
252 &VideoMemory
, sizeof(VIDEO_MEMORY
), NULL
, 0, &ulTemp
);
254 ppdev
->pRealVideoMem
= NULL
;
255 ppdev
->pVideoMemCache
= NULL
;
262 * Sets the mode of the specified physical device to either the mode specified
263 * when the PDEV was initialized or to the default mode of the hardware.
274 PPDEV ppdev
= (PPDEV
)dhpdev
;
276 BOOLEAN Result
= TRUE
;
280 PVOID pRealVideoMem
= ppdev
->pRealVideoMem
;
282 /* Setup surface and remapping if it need it */
283 if (!InitSurface(ppdev
, FALSE
))
289 /* Check if we got same surface or not */
290 if (pRealVideoMem
!= ppdev
->pRealVideoMem
)
292 PVOID pVideoMem
= NULL
;
294 if (ppdev
->pVideoMemCache
== NULL
)
296 pVideoMem
= ppdev
->pRealVideoMem
;
300 pVideoMem
= ppdev
->pVideoMemCache
;
303 Result
= !EngModifySurface(ppdev
->hSurfEng
, ppdev
->hDevEng
,
304 ppdev
->dwHooks
| HOOK_SYNCHRONIZE
,
305 0, (DHSURF
)ppdev
, pVideoMem
,
306 ppdev
->ScreenDelta
, NULL
);
309 /* if the pRealVideoMem == ppdev->pRealVideoMem are
310 * the Result is then TRUE
318 * Call the miniport driver to reset the device to a known state.
321 Result
= !EngDeviceIoControl(ppdev
->hDriver
, IOCTL_VIDEO_RESET_DEVICE
,
322 NULL
, 0, NULL
, 0, &ulTemp
);