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