]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixUgaDxe/UnixUgaScreen.c
Update the copyright notice format
[mirror_edk2.git] / UnixPkg / UnixUgaDxe / UnixUgaScreen.c
1 /*++
2
3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UnixUgaScreen.c
15
16 Abstract:
17
18 This file produces the graphics abstration of UGA. It is called by
19 UnixUgaDriver.c file which deals with the EFI 1.1 driver model.
20 This file just does graphics.
21
22 --*/
23
24 #include "UnixUga.h"
25
26 EFI_UNIX_THUNK_PROTOCOL *mUnix;
27 EFI_EVENT mUgaScreenExitBootServicesEvent;
28
29 EFI_STATUS
30 UnixUgaStartWindow (
31 IN UGA_PRIVATE_DATA *Private,
32 IN UINT32 HorizontalResolution,
33 IN UINT32 VerticalResolution,
34 IN UINT32 ColorDepth,
35 IN UINT32 RefreshRate
36 );
37
38 VOID
39 EFIAPI
40 KillNtUgaThread (
41 IN EFI_EVENT Event,
42 IN VOID *Context
43 );
44
45 //
46 // UGA Protocol Member Functions
47 //
48
49 EFI_STATUS
50 EFIAPI
51 UnixUgaGetMode (
52 EFI_UGA_DRAW_PROTOCOL *This,
53 UINT32 *HorizontalResolution,
54 UINT32 *VerticalResolution,
55 UINT32 *ColorDepth,
56 UINT32 *RefreshRate
57 )
58 /*++
59
60 Routine Description:
61 Return the current video mode information.
62
63 Arguments:
64 This - Protocol instance pointer.
65 HorizontalResolution - Current video horizontal resolution in pixels
66 VerticalResolution - Current video Vertical resolution in pixels
67 ColorDepth - Current video color depth in bits per pixel
68 RefreshRate - Current video refresh rate in Hz.
69
70 Returns:
71 EFI_SUCCESS - Mode information returned.
72 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
73 EFI_INVALID_PARAMETER - One of the input args was NULL.
74
75 --*/
76 // TODO: ADD IN/OUT description here
77 {
78 UGA_PRIVATE_DATA *Private;
79
80 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
81
82 if (Private->HardwareNeedsStarting) {
83 return EFI_NOT_STARTED;
84 }
85
86 if ((HorizontalResolution == NULL) ||
87 (VerticalResolution == NULL) ||
88 (ColorDepth == NULL) ||
89 (RefreshRate == NULL)) {
90 return EFI_INVALID_PARAMETER;
91 }
92
93 *HorizontalResolution = Private->HorizontalResolution;
94 *VerticalResolution = Private->VerticalResolution;
95 *ColorDepth = Private->ColorDepth;
96 *RefreshRate = Private->RefreshRate;
97 return EFI_SUCCESS;
98 }
99
100 EFI_STATUS
101 EFIAPI
102 UnixUgaSetMode (
103 EFI_UGA_DRAW_PROTOCOL *This,
104 UINT32 HorizontalResolution,
105 UINT32 VerticalResolution,
106 UINT32 ColorDepth,
107 UINT32 RefreshRate
108 )
109 /*++
110
111 Routine Description:
112 Return the current video mode information.
113
114 Arguments:
115 This - Protocol instance pointer.
116 HorizontalResolution - Current video horizontal resolution in pixels
117 VerticalResolution - Current video Vertical resolution in pixels
118 ColorDepth - Current video color depth in bits per pixel
119 RefreshRate - Current video refresh rate in Hz.
120
121 Returns:
122 EFI_SUCCESS - Mode information returned.
123 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
124 EFI_INVALID_PARAMETER - One of the input args was NULL.
125
126 --*/
127 // TODO: EFI_DEVICE_ERROR - add return value to function comment
128 // TODO: EFI_DEVICE_ERROR - add return value to function comment
129 // TODO: ADD IN/OUT description here
130 {
131 EFI_STATUS Status;
132 UGA_PRIVATE_DATA *Private;
133 EFI_UGA_PIXEL Fill;
134
135 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
136
137 if (Private->HardwareNeedsStarting) {
138 Status = UnixUgaStartWindow (
139 Private,
140 HorizontalResolution,
141 VerticalResolution,
142 ColorDepth,
143 RefreshRate
144 );
145 if (EFI_ERROR (Status)) {
146 return EFI_DEVICE_ERROR;
147 }
148
149 Private->HardwareNeedsStarting = FALSE;
150 }
151 Status = Private->UgaIo->UgaSize(Private->UgaIo,
152 HorizontalResolution,
153 VerticalResolution);
154
155 Private->HorizontalResolution = HorizontalResolution;
156 Private->VerticalResolution = VerticalResolution;
157 Private->ColorDepth = ColorDepth;
158 Private->RefreshRate = RefreshRate;
159
160 Fill.Red = 0x7f;
161 Fill.Green = 0x7F;
162 Fill.Blue = 0x7f;
163 This->Blt (
164 This,
165 &Fill,
166 EfiUgaVideoFill,
167 0,
168 0,
169 0,
170 0,
171 HorizontalResolution,
172 VerticalResolution,
173 HorizontalResolution * sizeof (EFI_UGA_PIXEL)
174 );
175 return EFI_SUCCESS;
176 }
177
178 EFI_STATUS
179 EFIAPI
180 UnixUgaBlt (
181 IN EFI_UGA_DRAW_PROTOCOL *This,
182 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
183 IN EFI_UGA_BLT_OPERATION BltOperation,
184 IN UINTN SourceX,
185 IN UINTN SourceY,
186 IN UINTN DestinationX,
187 IN UINTN DestinationY,
188 IN UINTN Width,
189 IN UINTN Height,
190 IN UINTN Delta OPTIONAL
191 )
192 /*++
193
194 Routine Description:
195 Blt pixels from the rectangle (Width X Height) formed by the BltBuffer
196 onto the graphics screen starting a location (X, Y). (0, 0) is defined as
197 the upper left hand side of the screen. (X, Y) can be outside of the
198 current screen geometry and the BltBuffer will be cliped when it is
199 displayed. X and Y can be negative or positive. If Width or Height is
200 bigger than the current video screen the image will be clipped.
201
202 Arguments:
203 This - Protocol instance pointer.
204 X - X location on graphics screen.
205 Y - Y location on the graphics screen.
206 Width - Width of BltBuffer.
207 Height - Hight of BltBuffer
208 BltOperation - Operation to perform on BltBuffer and video memory
209 BltBuffer - Buffer containing data to blt into video buffer. This
210 buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
211 SourceX - If the BltOperation is a EfiCopyBlt this is the source
212 of the copy. For other BLT operations this argument is not
213 used.
214 SourceX - If the BltOperation is a EfiCopyBlt this is the source
215 of the copy. For other BLT operations this argument is not
216 used.
217
218 Returns:
219 EFI_SUCCESS - The palette is updated with PaletteArray.
220 EFI_INVALID_PARAMETER - BltOperation is not valid.
221 EFI_DEVICE_ERROR - A hardware error occured writting to the video
222 buffer.
223
224 --*/
225 // TODO: SourceY - add argument and description to function comment
226 // TODO: DestinationX - add argument and description to function comment
227 // TODO: DestinationY - add argument and description to function comment
228 // TODO: Delta - add argument and description to function comment
229 {
230 UGA_PRIVATE_DATA *Private;
231 EFI_TPL OriginalTPL;
232 EFI_STATUS Status;
233
234 Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
235
236 if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) {
237 return EFI_INVALID_PARAMETER;
238 }
239
240 if (Width == 0 || Height == 0) {
241 return EFI_INVALID_PARAMETER;
242 }
243 //
244 // If Delta is zero, then the entire BltBuffer is being used, so Delta
245 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
246 // the number of bytes in each row can be computed.
247 //
248 if (Delta == 0) {
249 Delta = Width * sizeof (EFI_UGA_PIXEL);
250 }
251
252 //
253 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
254 // We would not want a timer based event (Cursor, ...) to come in while we are
255 // doing this operation.
256 //
257 OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
258
259 Status = Private->UgaIo->UgaBlt (Private->UgaIo,
260 BltBuffer,
261 BltOperation,
262 SourceX, SourceY,
263 DestinationX, DestinationY,
264 Width, Height,
265 Delta);
266
267 gBS->RestoreTPL (OriginalTPL);
268
269 return Status;
270 }
271
272
273 //
274 // Construction and Destruction functions
275 //
276
277 EFI_STATUS
278 UnixUgaSupported (
279 IN EFI_UNIX_IO_PROTOCOL *UnixIo
280 )
281 /*++
282
283 Routine Description:
284
285 Arguments:
286
287 Returns:
288
289 None
290
291 --*/
292 // TODO: UnixIo - add argument and description to function comment
293 // TODO: EFI_UNSUPPORTED - add return value to function comment
294 // TODO: EFI_SUCCESS - add return value to function comment
295 {
296 //
297 // Check to see if the IO abstraction represents a device type we support.
298 //
299 // This would be replaced a check of PCI subsystem ID, etc.
300 //
301 if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixUgaGuid)) {
302 return EFI_UNSUPPORTED;
303 }
304
305 return EFI_SUCCESS;
306 }
307
308
309 EFI_STATUS
310 UnixUgaStartWindow (
311 IN UGA_PRIVATE_DATA *Private,
312 IN UINT32 HorizontalResolution,
313 IN UINT32 VerticalResolution,
314 IN UINT32 ColorDepth,
315 IN UINT32 RefreshRate
316 )
317 /*++
318
319 Routine Description:
320
321 TODO: Add function description
322
323 Arguments:
324
325 Private - TODO: add argument description
326 HorizontalResolution - TODO: add argument description
327 VerticalResolution - TODO: add argument description
328 ColorDepth - TODO: add argument description
329 RefreshRate - TODO: add argument description
330
331 Returns:
332
333 TODO: add return values
334
335 --*/
336 {
337 EFI_STATUS Status;
338
339 mUnix = Private->UnixThunk;
340
341 Private->HorizontalResolution = HorizontalResolution;
342 Private->VerticalResolution = VerticalResolution;
343
344 //
345 // Register to be notified on exit boot services so we can destroy the window.
346 //
347 Status = gBS->CreateEvent (
348 EVT_SIGNAL_EXIT_BOOT_SERVICES,
349 TPL_CALLBACK,
350 KillNtUgaThread,
351 Private,
352 &mUgaScreenExitBootServicesEvent
353 );
354
355 Status = Private->UnixThunk->UgaCreate(&Private->UgaIo, Private->WindowName);
356 return Status;
357 }
358
359 EFI_STATUS
360 UnixUgaConstructor (
361 UGA_PRIVATE_DATA *Private
362 )
363 /*++
364
365 Routine Description:
366
367 Arguments:
368
369 Returns:
370
371 None
372
373 --*/
374 // TODO: Private - add argument and description to function comment
375 // TODO: EFI_SUCCESS - add return value to function comment
376 {
377
378 Private->UgaDraw.GetMode = UnixUgaGetMode;
379 Private->UgaDraw.SetMode = UnixUgaSetMode;
380 Private->UgaDraw.Blt = UnixUgaBlt;
381
382 Private->HardwareNeedsStarting = TRUE;
383 Private->UgaIo = NULL;
384
385 UnixUgaInitializeSimpleTextInForWindow (Private);
386
387 return EFI_SUCCESS;
388 }
389
390 EFI_STATUS
391 UnixUgaDestructor (
392 UGA_PRIVATE_DATA *Private
393 )
394 /*++
395
396 Routine Description:
397
398 Arguments:
399
400 Returns:
401
402 None
403
404 --*/
405 // TODO: Private - add argument and description to function comment
406 // TODO: EFI_SUCCESS - add return value to function comment
407 {
408 if (!Private->HardwareNeedsStarting) {
409 Private->UgaIo->UgaClose(Private->UgaIo);
410 Private->UgaIo = NULL;
411 }
412
413 return EFI_SUCCESS;
414 }
415
416 VOID
417 EFIAPI
418 KillNtUgaThread (
419 IN EFI_EVENT Event,
420 IN VOID *Context
421 )
422 /*++
423
424 Routine Description:
425
426 This is the UGA screen's callback notification function for exit-boot-services.
427 All we do here is call UnixUgaDestructor().
428
429 Arguments:
430
431 Event - not used
432 Context - pointer to the Private structure.
433
434 Returns:
435
436 None.
437
438 --*/
439 {
440 EFI_STATUS Status;
441 Status = UnixUgaDestructor (Context);
442 }