]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterGraphics.c
Fix the comments to follow UEFI Spec regarding how to check an EFI_HANDLE is valid...
[mirror_edk2.git] / MdeModulePkg / Universal / Console / ConSplitterDxe / ConSplitterGraphics.c
1 /** @file
2 Support for Graphics output spliter.
3
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13
14 **/
15
16 #include "ConSplitter.h"
17
18
19 CHAR16 mCrLfString[3] = { CHAR_CARRIAGE_RETURN, CHAR_LINEFEED, CHAR_NULL };
20
21 /**
22 Returns information for an available graphics mode that the graphics device
23 and the set of active video output devices supports.
24
25 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
26 @param ModeNumber The mode number to return information on.
27 @param SizeOfInfo A pointer to the size, in bytes, of the Info buffer.
28 @param Info A pointer to callee allocated buffer that returns information about ModeNumber.
29
30 @retval EFI_SUCCESS Mode information returned.
31 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
32 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the video mode.
33 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
34 @retval EFI_OUT_OF_RESOURCES No resource available.
35
36 **/
37 EFI_STATUS
38 EFIAPI
39 ConSplitterGraphicsOutputQueryMode (
40 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
41 IN UINT32 ModeNumber,
42 OUT UINTN *SizeOfInfo,
43 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
44 )
45 {
46 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
47
48 if (This == NULL || Info == NULL || SizeOfInfo == NULL || ModeNumber >= This->Mode->MaxMode) {
49 return EFI_INVALID_PARAMETER;
50 }
51
52 //
53 // retrieve private data
54 //
55 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
56
57 *Info = AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
58 if (*Info == NULL) {
59 return EFI_OUT_OF_RESOURCES;
60 }
61
62 *SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
63
64 CopyMem (*Info, &Private->GraphicsOutputModeBuffer[ModeNumber], *SizeOfInfo);
65
66 return EFI_SUCCESS;
67 }
68
69
70 /**
71 Set the video device into the specified mode and clears the visible portions of
72 the output display to black.
73
74 @param This The EFI_GRAPHICS_OUTPUT_PROTOCOL instance.
75 @param ModeNumber Abstraction that defines the current video mode.
76
77 @retval EFI_SUCCESS The graphics mode specified by ModeNumber was selected.
78 @retval EFI_DEVICE_ERROR The device had an error and could not complete the request.
79 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
80 @retval EFI_OUT_OF_RESOURCES No resource available.
81
82 **/
83 EFI_STATUS
84 EFIAPI
85 ConSplitterGraphicsOutputSetMode (
86 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
87 IN UINT32 ModeNumber
88 )
89 {
90 EFI_STATUS Status;
91 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
92 UINTN Index;
93 EFI_STATUS ReturnStatus;
94 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode;
95 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
96 UINTN NumberIndex;
97 UINTN SizeOfInfo;
98 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
99 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
100
101 if (ModeNumber >= This->Mode->MaxMode) {
102 return EFI_UNSUPPORTED;
103 }
104
105 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
106 Mode = &Private->GraphicsOutputModeBuffer[ModeNumber];
107
108 ReturnStatus = EFI_SUCCESS;
109 //
110 // return the worst status met
111 //
112 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
113 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
114 if (GraphicsOutput != NULL) {
115 //
116 // Find corresponding ModeNumber of this GraphicsOutput instance
117 //
118 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {
119 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
120 if (EFI_ERROR (Status)) {
121 return Status;
122 }
123 if ((Info->HorizontalResolution == Mode->HorizontalResolution) && (Info->VerticalResolution == Mode->VerticalResolution)) {
124 FreePool (Info);
125 break;
126 }
127 FreePool (Info);
128 }
129
130 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);
131 if (EFI_ERROR (Status)) {
132 ReturnStatus = Status;
133 }
134 } else if (FeaturePcdGet (PcdUgaConsumeSupport)) {
135 UgaDraw = Private->TextOutList[Index].UgaDraw;
136 if (UgaDraw != NULL) {
137 Status = UgaDraw->SetMode (
138 UgaDraw,
139 Mode->HorizontalResolution,
140 Mode->VerticalResolution,
141 32,
142 60
143 );
144 if (EFI_ERROR (Status)) {
145 ReturnStatus = Status;
146 }
147 }
148 }
149 }
150
151 This->Mode->Mode = ModeNumber;
152
153 CopyMem (This->Mode->Info, &Private->GraphicsOutputModeBuffer[ModeNumber], This->Mode->SizeOfInfo);
154
155 //
156 // Information is not enough here, so the following items remain unchanged:
157 // GraphicsOutputMode->Info->Version, GraphicsOutputMode->Info->PixelFormat
158 // GraphicsOutputMode->SizeOfInfo, GraphicsOutputMode->FrameBufferBase, GraphicsOutputMode->FrameBufferSize
159 // These items will be initialized/updated when a new GOP device is added into ConsoleSplitter.
160 //
161
162 return ReturnStatus;
163 }
164
165
166
167 /**
168 The following table defines actions for BltOperations.
169
170 EfiBltVideoFill - Write data from the BltBuffer pixel (SourceX, SourceY)
171 directly to every pixel of the video display rectangle
172 (DestinationX, DestinationY)
173 (DestinationX + Width, DestinationY + Height).
174 Only one pixel will be used from the BltBuffer. Delta is NOT used.
175 EfiBltVideoToBltBuffer - Read data from the video display rectangle
176 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
177 the BltBuffer rectangle (DestinationX, DestinationY )
178 (DestinationX + Width, DestinationY + Height). If DestinationX or
179 DestinationY is not zero then Delta must be set to the length in bytes
180 of a row in the BltBuffer.
181 EfiBltBufferToVideo - Write data from the BltBuffer rectangle
182 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
183 video display rectangle (DestinationX, DestinationY)
184 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
185 not zero then Delta must be set to the length in bytes of a row in the
186 BltBuffer.
187 EfiBltVideoToVideo - Copy from the video display rectangle
188 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
189 to the video display rectangle (DestinationX, DestinationY)
190 (DestinationX + Width, DestinationY + Height).
191 The BltBuffer and Delta are not used in this mode.
192
193 @param This Protocol instance pointer.
194 @param BltBuffer Buffer containing data to blit into video buffer.
195 This buffer has a size of
196 Width*Height*sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
197 @param BltOperation Operation to perform on BlitBuffer and video
198 memory
199 @param SourceX X coordinate of source for the BltBuffer.
200 @param SourceY Y coordinate of source for the BltBuffer.
201 @param DestinationX X coordinate of destination for the BltBuffer.
202 @param DestinationY Y coordinate of destination for the BltBuffer.
203 @param Width Width of rectangle in BltBuffer in pixels.
204 @param Height Hight of rectangle in BltBuffer in pixels.
205 @param Delta OPTIONAL.
206
207 @retval EFI_SUCCESS The Blt operation completed.
208 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
209 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video
210 buffer.
211
212 **/
213 EFI_STATUS
214 EFIAPI
215 ConSplitterGraphicsOutputBlt (
216 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
217 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
218 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
219 IN UINTN SourceX,
220 IN UINTN SourceY,
221 IN UINTN DestinationX,
222 IN UINTN DestinationY,
223 IN UINTN Width,
224 IN UINTN Height,
225 IN UINTN Delta OPTIONAL
226 )
227 {
228 EFI_STATUS Status;
229 EFI_STATUS ReturnStatus;
230 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
231 UINTN Index;
232 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
233 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
234
235 if (This == NULL || ((UINTN) BltOperation) >= EfiGraphicsOutputBltOperationMax) {
236 return EFI_INVALID_PARAMETER;
237 }
238
239 Private = GRAPHICS_OUTPUT_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
240
241 ReturnStatus = EFI_SUCCESS;
242
243 //
244 // return the worst status met
245 //
246 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
247 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
248 if (GraphicsOutput != NULL) {
249 Status = GraphicsOutput->Blt (
250 GraphicsOutput,
251 BltBuffer,
252 BltOperation,
253 SourceX,
254 SourceY,
255 DestinationX,
256 DestinationY,
257 Width,
258 Height,
259 Delta
260 );
261 if (EFI_ERROR (Status)) {
262 ReturnStatus = Status;
263 } else if (BltOperation == EfiBltVideoToBltBuffer) {
264 //
265 // Only need to read the data into buffer one time
266 //
267 return EFI_SUCCESS;
268 }
269 }
270
271 UgaDraw = Private->TextOutList[Index].UgaDraw;
272 if (UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
273 Status = UgaDraw->Blt (
274 UgaDraw,
275 (EFI_UGA_PIXEL *) BltBuffer,
276 (EFI_UGA_BLT_OPERATION) BltOperation,
277 SourceX,
278 SourceY,
279 DestinationX,
280 DestinationY,
281 Width,
282 Height,
283 Delta
284 );
285 if (EFI_ERROR (Status)) {
286 ReturnStatus = Status;
287 } else if (BltOperation == EfiBltVideoToBltBuffer) {
288 //
289 // Only need to read the data into buffer one time
290 //
291 return EFI_SUCCESS;
292 }
293 }
294 }
295
296 return ReturnStatus;
297 }
298
299 /**
300 Return the current video mode information.
301
302 @param This The EFI_UGA_DRAW_PROTOCOL instance.
303 @param HorizontalResolution The size of video screen in pixels in the X dimension.
304 @param VerticalResolution The size of video screen in pixels in the Y dimension.
305 @param ColorDepth Number of bits per pixel, currently defined to be 32.
306 @param RefreshRate The refresh rate of the monitor in Hertz.
307
308 @retval EFI_SUCCESS Mode information returned.
309 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
310 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
311
312 **/
313 EFI_STATUS
314 EFIAPI
315 ConSplitterUgaDrawGetMode (
316 IN EFI_UGA_DRAW_PROTOCOL *This,
317 OUT UINT32 *HorizontalResolution,
318 OUT UINT32 *VerticalResolution,
319 OUT UINT32 *ColorDepth,
320 OUT UINT32 *RefreshRate
321 )
322 {
323 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
324
325 if ((HorizontalResolution == NULL) ||
326 (VerticalResolution == NULL) ||
327 (RefreshRate == NULL) ||
328 (ColorDepth == NULL)) {
329 return EFI_INVALID_PARAMETER;
330 }
331 //
332 // retrieve private data
333 //
334 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
335
336 *HorizontalResolution = Private->UgaHorizontalResolution;
337 *VerticalResolution = Private->UgaVerticalResolution;
338 *ColorDepth = Private->UgaColorDepth;
339 *RefreshRate = Private->UgaRefreshRate;
340
341 return EFI_SUCCESS;
342 }
343
344
345 /**
346 Set the current video mode information.
347
348 @param This The EFI_UGA_DRAW_PROTOCOL instance.
349 @param HorizontalResolution The size of video screen in pixels in the X dimension.
350 @param VerticalResolution The size of video screen in pixels in the Y dimension.
351 @param ColorDepth Number of bits per pixel, currently defined to be 32.
352 @param RefreshRate The refresh rate of the monitor in Hertz.
353
354 @retval EFI_SUCCESS Mode information returned.
355 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
356 @retval EFI_OUT_OF_RESOURCES Out of resources.
357
358 **/
359 EFI_STATUS
360 EFIAPI
361 ConSplitterUgaDrawSetMode (
362 IN EFI_UGA_DRAW_PROTOCOL *This,
363 IN UINT32 HorizontalResolution,
364 IN UINT32 VerticalResolution,
365 IN UINT32 ColorDepth,
366 IN UINT32 RefreshRate
367 )
368 {
369 EFI_STATUS Status;
370 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
371 UINTN Index;
372 EFI_STATUS ReturnStatus;
373 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
374 UINTN NumberIndex;
375 UINTN SizeOfInfo;
376 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
377 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
378
379 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
380
381 ReturnStatus = EFI_SUCCESS;
382
383 //
384 // Update the Mode data
385 //
386 Private->UgaHorizontalResolution = HorizontalResolution;
387 Private->UgaVerticalResolution = VerticalResolution;
388 Private->UgaColorDepth = ColorDepth;
389 Private->UgaRefreshRate = RefreshRate;
390
391 //
392 // return the worst status met
393 //
394 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
395
396 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
397 if (GraphicsOutput != NULL) {
398 //
399 // Find corresponding ModeNumber of this GraphicsOutput instance
400 //
401 for (NumberIndex = 0; NumberIndex < GraphicsOutput->Mode->MaxMode; NumberIndex ++) {
402 Status = GraphicsOutput->QueryMode (GraphicsOutput, (UINT32) NumberIndex, &SizeOfInfo, &Info);
403 if (EFI_ERROR (Status)) {
404 return Status;
405 }
406 if ((Info->HorizontalResolution == HorizontalResolution) && (Info->VerticalResolution == VerticalResolution)) {
407 FreePool (Info);
408 break;
409 }
410 FreePool (Info);
411 }
412
413 Status = GraphicsOutput->SetMode (GraphicsOutput, (UINT32) NumberIndex);
414 if (EFI_ERROR (Status)) {
415 ReturnStatus = Status;
416 }
417 } else if (FeaturePcdGet (PcdUgaConsumeSupport)){
418 UgaDraw = Private->TextOutList[Index].UgaDraw;
419 if (UgaDraw != NULL) {
420 Status = UgaDraw->SetMode (
421 UgaDraw,
422 HorizontalResolution,
423 VerticalResolution,
424 ColorDepth,
425 RefreshRate
426 );
427 if (EFI_ERROR (Status)) {
428 ReturnStatus = Status;
429 }
430 }
431 }
432 }
433
434 return ReturnStatus;
435 }
436
437
438 /**
439 Blt a rectangle of pixels on the graphics screen.
440
441 The following table defines actions for BltOperations.
442
443 EfiUgaVideoFill:
444 Write data from the BltBuffer pixel (SourceX, SourceY)
445 directly to every pixel of the video display rectangle
446 (DestinationX, DestinationY)
447 (DestinationX + Width, DestinationY + Height).
448 Only one pixel will be used from the BltBuffer. Delta is NOT used.
449 EfiUgaVideoToBltBuffer:
450 Read data from the video display rectangle
451 (SourceX, SourceY) (SourceX + Width, SourceY + Height) and place it in
452 the BltBuffer rectangle (DestinationX, DestinationY )
453 (DestinationX + Width, DestinationY + Height). If DestinationX or
454 DestinationY is not zero then Delta must be set to the length in bytes
455 of a row in the BltBuffer.
456 EfiUgaBltBufferToVideo:
457 Write data from the BltBuffer rectangle
458 (SourceX, SourceY) (SourceX + Width, SourceY + Height) directly to the
459 video display rectangle (DestinationX, DestinationY)
460 (DestinationX + Width, DestinationY + Height). If SourceX or SourceY is
461 not zero then Delta must be set to the length in bytes of a row in the
462 BltBuffer.
463 EfiUgaVideoToVideo:
464 Copy from the video display rectangle
465 (SourceX, SourceY) (SourceX + Width, SourceY + Height) .
466 to the video display rectangle (DestinationX, DestinationY)
467 (DestinationX + Width, DestinationY + Height).
468 The BltBuffer and Delta are not used in this mode.
469
470 @param This Protocol instance pointer.
471 @param BltBuffer Buffer containing data to blit into video buffer. This
472 buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
473 @param BltOperation Operation to perform on BlitBuffer and video memory
474 @param SourceX X coordinate of source for the BltBuffer.
475 @param SourceY Y coordinate of source for the BltBuffer.
476 @param DestinationX X coordinate of destination for the BltBuffer.
477 @param DestinationY Y coordinate of destination for the BltBuffer.
478 @param Width Width of rectangle in BltBuffer in pixels.
479 @param Height Hight of rectangle in BltBuffer in pixels.
480 @param Delta OPTIONAL
481
482 @retval EFI_SUCCESS The Blt operation completed.
483 @retval EFI_INVALID_PARAMETER BltOperation is not valid.
484 @retval EFI_DEVICE_ERROR A hardware error occured writting to the video buffer.
485
486 **/
487 EFI_STATUS
488 EFIAPI
489 ConSplitterUgaDrawBlt (
490 IN EFI_UGA_DRAW_PROTOCOL *This,
491 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
492 IN EFI_UGA_BLT_OPERATION BltOperation,
493 IN UINTN SourceX,
494 IN UINTN SourceY,
495 IN UINTN DestinationX,
496 IN UINTN DestinationY,
497 IN UINTN Width,
498 IN UINTN Height,
499 IN UINTN Delta OPTIONAL
500 )
501 {
502 EFI_STATUS Status;
503 TEXT_OUT_SPLITTER_PRIVATE_DATA *Private;
504 UINTN Index;
505 EFI_STATUS ReturnStatus;
506 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
507
508 Private = UGA_DRAW_SPLITTER_PRIVATE_DATA_FROM_THIS (This);
509
510 ReturnStatus = EFI_SUCCESS;
511 //
512 // return the worst status met
513 //
514 for (Index = 0; Index < Private->CurrentNumberOfConsoles; Index++) {
515 GraphicsOutput = Private->TextOutList[Index].GraphicsOutput;
516 if (GraphicsOutput != NULL) {
517 Status = GraphicsOutput->Blt (
518 GraphicsOutput,
519 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) BltBuffer,
520 (EFI_GRAPHICS_OUTPUT_BLT_OPERATION) BltOperation,
521 SourceX,
522 SourceY,
523 DestinationX,
524 DestinationY,
525 Width,
526 Height,
527 Delta
528 );
529 if (EFI_ERROR (Status)) {
530 ReturnStatus = Status;
531 } else if (BltOperation == EfiUgaVideoToBltBuffer) {
532 //
533 // Only need to read the data into buffer one time
534 //
535 return EFI_SUCCESS;
536 }
537 }
538
539 if (Private->TextOutList[Index].UgaDraw != NULL && FeaturePcdGet (PcdUgaConsumeSupport)) {
540 Status = Private->TextOutList[Index].UgaDraw->Blt (
541 Private->TextOutList[Index].UgaDraw,
542 BltBuffer,
543 BltOperation,
544 SourceX,
545 SourceY,
546 DestinationX,
547 DestinationY,
548 Width,
549 Height,
550 Delta
551 );
552 if (EFI_ERROR (Status)) {
553 ReturnStatus = Status;
554 } else if (BltOperation == EfiUgaVideoToBltBuffer) {
555 //
556 // Only need to read the data into buffer one time
557 //
558 return EFI_SUCCESS;
559 }
560 }
561 }
562
563 return ReturnStatus;
564 }
565
566 /**
567 Sets the output device(s) to a specified mode.
568
569 @param Private Text Out Splitter pointer.
570 @param ModeNumber The mode number to set.
571
572 **/
573 VOID
574 TextOutSetMode (
575 IN TEXT_OUT_SPLITTER_PRIVATE_DATA *Private,
576 IN UINTN ModeNumber
577 )
578 {
579 //
580 // No need to do extra check here as whether (Column, Row) is valid has
581 // been checked in ConSplitterTextOutSetCursorPosition. And (0, 0) should
582 // always be supported.
583 //
584 Private->TextOutMode.Mode = (INT32) ModeNumber;
585 Private->TextOutMode.CursorColumn = 0;
586 Private->TextOutMode.CursorRow = 0;
587 Private->TextOutMode.CursorVisible = TRUE;
588
589 return;
590 }