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