]> git.proxmox.com Git - mirror_edk2.git/blob - OptionRomPkg/Library/FrameBufferBltLib/FrameBufferBltLib.c
520fac4c63030e7181106579d959499b9eec2062
[mirror_edk2.git] / OptionRomPkg / Library / FrameBufferBltLib / FrameBufferBltLib.c
1 /** @file
2 FrameBufferBltLib - Library to perform blt operations on a frame buffer.
3
4 Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PiDxe.h"
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/BltLib.h>
13 #include <Library/DebugLib.h>
14
15 #if 0
16 #define VDEBUG DEBUG
17 #else
18 #define VDEBUG(x)
19 #endif
20
21 #define MAX_LINE_BUFFER_SIZE (SIZE_4KB * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
22
23 UINTN mBltLibColorDepth;
24 UINTN mBltLibWidthInBytes;
25 UINTN mBltLibBytesPerPixel;
26 UINTN mBltLibWidthInPixels;
27 UINTN mBltLibHeight;
28 UINT8 mBltLibLineBuffer[MAX_LINE_BUFFER_SIZE];
29 UINT8 *mBltLibFrameBuffer;
30 EFI_GRAPHICS_PIXEL_FORMAT mPixelFormat;
31 EFI_PIXEL_BITMASK mPixelBitMasks;
32 INTN mPixelShl[4]; // R-G-B-Rsvd
33 INTN mPixelShr[4]; // R-G-B-Rsvd
34
35
36 VOID
37 ConfigurePixelBitMaskFormat (
38 IN EFI_PIXEL_BITMASK *BitMask
39 )
40 {
41 UINTN Loop;
42 UINT32 *Masks;
43 UINT32 MergedMasks;
44
45 MergedMasks = 0;
46 Masks = (UINT32*) BitMask;
47 for (Loop = 0; Loop < 3; Loop++) {
48 ASSERT ((Loop == 3) || (Masks[Loop] != 0));
49 ASSERT ((MergedMasks & Masks[Loop]) == 0);
50 mPixelShl[Loop] = HighBitSet32 (Masks[Loop]) - 23 + (Loop * 8);
51 if (mPixelShl[Loop] < 0) {
52 mPixelShr[Loop] = -mPixelShl[Loop];
53 mPixelShl[Loop] = 0;
54 } else {
55 mPixelShr[Loop] = 0;
56 }
57 MergedMasks = (UINT32) (MergedMasks | Masks[Loop]);
58 DEBUG ((EFI_D_INFO, "%d: shl:%d shr:%d mask:%x\n", Loop, mPixelShl[Loop], mPixelShr[Loop], Masks[Loop]));
59 }
60 MergedMasks = (UINT32) (MergedMasks | Masks[3]);
61
62 ASSERT (MergedMasks != 0);
63 mBltLibBytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8);
64
65 DEBUG ((EFI_D_INFO, "Bytes per pixel: %d\n", mBltLibBytesPerPixel));
66
67 CopyMem (&mPixelBitMasks, BitMask, sizeof (*BitMask));
68 }
69
70
71 /**
72 Configure the FrameBufferLib instance
73
74 @param[in] FrameBuffer Pointer to the start of the frame buffer
75 @param[in] FrameBufferInfo Describes the frame buffer characteristics
76
77 @retval EFI_INVALID_PARAMETER - Invalid parameter
78 @retval EFI_UNSUPPORTED - The BltLib does not support this configuration
79 @retval EFI_SUCCESS - Blt operation success
80
81 **/
82 EFI_STATUS
83 EFIAPI
84 BltLibConfigure (
85 IN VOID *FrameBuffer,
86 IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo
87 )
88 {
89 STATIC EFI_PIXEL_BITMASK RgbPixelMasks =
90 { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
91 STATIC EFI_PIXEL_BITMASK BgrPixelMasks =
92 { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
93
94 switch (FrameBufferInfo->PixelFormat) {
95 case PixelRedGreenBlueReserved8BitPerColor:
96 ConfigurePixelBitMaskFormat (&RgbPixelMasks);
97 break;
98 case PixelBlueGreenRedReserved8BitPerColor:
99 ConfigurePixelBitMaskFormat (&BgrPixelMasks);
100 break;
101 case PixelBitMask:
102 ConfigurePixelBitMaskFormat (&(FrameBufferInfo->PixelInformation));
103 break;
104 case PixelBltOnly:
105 ASSERT (FrameBufferInfo->PixelFormat != PixelBltOnly);
106 return EFI_UNSUPPORTED;
107 default:
108 ASSERT (FALSE);
109 return EFI_INVALID_PARAMETER;
110 }
111 mPixelFormat = FrameBufferInfo->PixelFormat;
112
113 mBltLibFrameBuffer = (UINT8*) FrameBuffer;
114 mBltLibWidthInPixels = (UINTN) FrameBufferInfo->HorizontalResolution;
115 mBltLibHeight = (UINTN) FrameBufferInfo->VerticalResolution;
116 mBltLibWidthInBytes = mBltLibWidthInPixels * mBltLibBytesPerPixel;
117
118 ASSERT (mBltLibWidthInBytes < sizeof (mBltLibLineBuffer));
119
120 return EFI_SUCCESS;
121 }
122
123
124 /**
125 Performs a UEFI Graphics Output Protocol Blt operation.
126
127 @param[in,out] BltBuffer - The data to transfer to screen
128 @param[in] BltOperation - The operation to perform
129 @param[in] SourceX - The X coordinate of the source for BltOperation
130 @param[in] SourceY - The Y coordinate of the source for BltOperation
131 @param[in] DestinationX - The X coordinate of the destination for BltOperation
132 @param[in] DestinationY - The Y coordinate of the destination for BltOperation
133 @param[in] Width - The width of a rectangle in the blt rectangle in pixels
134 @param[in] Height - The height of a rectangle in the blt rectangle in pixels
135 @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
136 If a Delta of 0 is used, the entire BltBuffer will be operated on.
137 If a subrectangle of the BltBuffer is used, then Delta represents
138 the number of bytes in a row of the BltBuffer.
139
140 @retval EFI_DEVICE_ERROR - A hardware error occured
141 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
142 @retval EFI_SUCCESS - Blt operation success
143
144 **/
145 EFI_STATUS
146 EFIAPI
147 BltLibGopBlt (
148 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
149 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
150 IN UINTN SourceX,
151 IN UINTN SourceY,
152 IN UINTN DestinationX,
153 IN UINTN DestinationY,
154 IN UINTN Width,
155 IN UINTN Height,
156 IN UINTN Delta
157 )
158 {
159 switch (BltOperation) {
160 case EfiBltVideoToBltBuffer:
161 return BltLibVideoToBltBufferEx (
162 BltBuffer,
163 SourceX,
164 SourceY,
165 DestinationX,
166 DestinationY,
167 Width,
168 Height,
169 Delta
170 );
171
172 case EfiBltVideoToVideo:
173 return BltLibVideoToVideo (
174 SourceX,
175 SourceY,
176 DestinationX,
177 DestinationY,
178 Width,
179 Height
180 );
181
182 case EfiBltVideoFill:
183 return BltLibVideoFill (
184 BltBuffer,
185 DestinationX,
186 DestinationY,
187 Width,
188 Height
189 );
190
191 case EfiBltBufferToVideo:
192 return BltLibBufferToVideoEx (
193 BltBuffer,
194 SourceX,
195 SourceY,
196 DestinationX,
197 DestinationY,
198 Width,
199 Height,
200 Delta
201 );
202 default:
203 return EFI_INVALID_PARAMETER;
204 }
205 }
206
207
208 /**
209 Performs a UEFI Graphics Output Protocol Blt Video Fill.
210
211 @param[in] Color Color to fill the region with
212 @param[in] DestinationX X location to start fill operation
213 @param[in] DestinationY Y location to start fill operation
214 @param[in] Width Width (in pixels) to fill
215 @param[in] Height Height to fill
216
217 @retval EFI_DEVICE_ERROR - A hardware error occured
218 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
219 @retval EFI_SUCCESS - The sizes were returned
220
221 **/
222 EFI_STATUS
223 EFIAPI
224 BltLibVideoFill (
225 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color,
226 IN UINTN DestinationX,
227 IN UINTN DestinationY,
228 IN UINTN Width,
229 IN UINTN Height
230 )
231 {
232 UINTN DstY;
233 VOID *BltMemDst;
234 UINTN X;
235 UINT8 Uint8;
236 UINT32 Uint32;
237 UINT64 WideFill;
238 BOOLEAN UseWideFill;
239 BOOLEAN LineBufferReady;
240 UINTN Offset;
241 UINTN WidthInBytes;
242 UINTN SizeInBytes;
243
244 //
245 // BltBuffer to Video: Source is BltBuffer, destination is Video
246 //
247 if (DestinationY + Height > mBltLibHeight) {
248 DEBUG ((EFI_D_INFO, "VideoFill: Past screen (Y)\n"));
249 return EFI_INVALID_PARAMETER;
250 }
251
252 if (DestinationX + Width > mBltLibWidthInPixels) {
253 DEBUG ((EFI_D_INFO, "VideoFill: Past screen (X)\n"));
254 return EFI_INVALID_PARAMETER;
255 }
256
257 if (Width == 0 || Height == 0) {
258 DEBUG ((EFI_D_INFO, "VideoFill: Width or Height is 0\n"));
259 return EFI_INVALID_PARAMETER;
260 }
261
262 WidthInBytes = Width * mBltLibBytesPerPixel;
263
264 Uint32 = *(UINT32*) Color;
265 WideFill =
266 (UINT32) (
267 (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) |
268 (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) |
269 (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask)
270 );
271 VDEBUG ((EFI_D_INFO, "VideoFill: color=0x%x, wide-fill=0x%x\n", Uint32, WideFill));
272
273 //
274 // If the size of the pixel data evenly divides the sizeof
275 // WideFill, then a wide fill operation can be used
276 //
277 UseWideFill = TRUE;
278 if ((sizeof (WideFill) % mBltLibBytesPerPixel) == 0) {
279 for (X = mBltLibBytesPerPixel; X < sizeof (WideFill); X++) {
280 ((UINT8*)&WideFill)[X] = ((UINT8*)&WideFill)[X % mBltLibBytesPerPixel];
281 }
282 } else {
283 //
284 // If all the bytes in the pixel are the same value, then use
285 // a wide fill operation.
286 //
287 for (
288 X = 1, Uint8 = ((UINT8*)&WideFill)[0];
289 X < mBltLibBytesPerPixel;
290 X++) {
291 if (Uint8 != ((UINT8*)&WideFill)[X]) {
292 UseWideFill = FALSE;
293 break;
294 }
295 }
296 if (UseWideFill) {
297 SetMem ((VOID*) &WideFill, sizeof (WideFill), Uint8);
298 }
299 }
300
301 if (UseWideFill && (DestinationX == 0) && (Width == mBltLibWidthInPixels)) {
302 VDEBUG ((EFI_D_INFO, "VideoFill (wide, one-shot)\n"));
303 Offset = DestinationY * mBltLibWidthInPixels;
304 Offset = mBltLibBytesPerPixel * Offset;
305 BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
306 SizeInBytes = WidthInBytes * Height;
307 if (SizeInBytes >= 8) {
308 SetMem32 (BltMemDst, SizeInBytes & ~3, (UINT32) WideFill);
309 SizeInBytes = SizeInBytes & 3;
310 }
311 if (SizeInBytes > 0) {
312 SetMem (BltMemDst, SizeInBytes, (UINT8)(UINTN) WideFill);
313 }
314 } else {
315 LineBufferReady = FALSE;
316 for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {
317 Offset = (DstY * mBltLibWidthInPixels) + DestinationX;
318 Offset = mBltLibBytesPerPixel * Offset;
319 BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
320
321 if (UseWideFill && (((UINTN) BltMemDst & 7) == 0)) {
322 VDEBUG ((EFI_D_INFO, "VideoFill (wide)\n"));
323 SizeInBytes = WidthInBytes;
324 if (SizeInBytes >= 8) {
325 SetMem64 (BltMemDst, SizeInBytes & ~7, WideFill);
326 SizeInBytes = SizeInBytes & 7;
327 }
328 if (SizeInBytes > 0) {
329 CopyMem (BltMemDst, (VOID*) &WideFill, SizeInBytes);
330 }
331 } else {
332 VDEBUG ((EFI_D_INFO, "VideoFill (not wide)\n"));
333 if (!LineBufferReady) {
334 CopyMem (mBltLibLineBuffer, &WideFill, mBltLibBytesPerPixel);
335 for (X = 1; X < Width; ) {
336 CopyMem(
337 (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)),
338 mBltLibLineBuffer,
339 MIN (X, Width - X) * mBltLibBytesPerPixel
340 );
341 X = X + MIN (X, Width - X);
342 }
343 LineBufferReady = TRUE;
344 }
345 CopyMem (BltMemDst, mBltLibLineBuffer, WidthInBytes);
346 }
347 }
348 }
349
350 return EFI_SUCCESS;
351 }
352
353
354 /**
355 Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation.
356
357 @param[out] BltBuffer Output buffer for pixel color data
358 @param[in] SourceX X location within video
359 @param[in] SourceY Y location within video
360 @param[in] Width Width (in pixels)
361 @param[in] Height Height
362
363 @retval EFI_DEVICE_ERROR - A hardware error occured
364 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
365 @retval EFI_SUCCESS - The sizes were returned
366
367 **/
368 EFI_STATUS
369 EFIAPI
370 BltLibVideoToBltBuffer (
371 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
372 IN UINTN SourceX,
373 IN UINTN SourceY,
374 IN UINTN Width,
375 IN UINTN Height
376 )
377 {
378 return BltLibVideoToBltBufferEx (
379 BltBuffer,
380 SourceX,
381 SourceY,
382 0,
383 0,
384 Width,
385 Height,
386 0
387 );
388 }
389
390
391 /**
392 Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation
393 with extended parameters.
394
395 @param[out] BltBuffer Output buffer for pixel color data
396 @param[in] SourceX X location within video
397 @param[in] SourceY Y location within video
398 @param[in] DestinationX X location within BltBuffer
399 @param[in] DestinationY Y location within BltBuffer
400 @param[in] Width Width (in pixels)
401 @param[in] Height Height
402 @param[in] Delta Number of bytes in a row of BltBuffer
403
404 @retval EFI_DEVICE_ERROR - A hardware error occured
405 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
406 @retval EFI_SUCCESS - The sizes were returned
407
408 **/
409 EFI_STATUS
410 EFIAPI
411 BltLibVideoToBltBufferEx (
412 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
413 IN UINTN SourceX,
414 IN UINTN SourceY,
415 IN UINTN DestinationX,
416 IN UINTN DestinationY,
417 IN UINTN Width,
418 IN UINTN Height,
419 IN UINTN Delta
420 )
421 {
422 UINTN DstY;
423 UINTN SrcY;
424 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
425 VOID *BltMemSrc;
426 VOID *BltMemDst;
427 UINTN X;
428 UINT32 Uint32;
429 UINTN Offset;
430 UINTN WidthInBytes;
431
432 //
433 // Video to BltBuffer: Source is Video, destination is BltBuffer
434 //
435 if (SourceY + Height > mBltLibHeight) {
436 return EFI_INVALID_PARAMETER;
437 }
438
439 if (SourceX + Width > mBltLibWidthInPixels) {
440 return EFI_INVALID_PARAMETER;
441 }
442
443 if (Width == 0 || Height == 0) {
444 return EFI_INVALID_PARAMETER;
445 }
446
447 //
448 // If Delta is zero, then the entire BltBuffer is being used, so Delta
449 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
450 // the number of bytes in each row can be computed.
451 //
452 if (Delta == 0) {
453 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
454 }
455
456 WidthInBytes = Width * mBltLibBytesPerPixel;
457
458 //
459 // Video to BltBuffer: Source is Video, destination is BltBuffer
460 //
461 for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {
462
463 Offset = (SrcY * mBltLibWidthInPixels) + SourceX;
464 Offset = mBltLibBytesPerPixel * Offset;
465 BltMemSrc = (VOID *) (mBltLibFrameBuffer + Offset);
466
467 if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
468 BltMemDst =
469 (VOID *) (
470 (UINT8 *) BltBuffer +
471 (DstY * Delta) +
472 (DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
473 );
474 } else {
475 BltMemDst = (VOID *) mBltLibLineBuffer;
476 }
477
478 CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
479
480 if (mPixelFormat != PixelBlueGreenRedReserved8BitPerColor) {
481 for (X = 0; X < Width; X++) {
482 Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
483 Uint32 = *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel));
484 *(UINT32*) Blt =
485 (UINT32) (
486 (((Uint32 & mPixelBitMasks.RedMask) >> mPixelShl[0]) << mPixelShr[0]) |
487 (((Uint32 & mPixelBitMasks.GreenMask) >> mPixelShl[1]) << mPixelShr[1]) |
488 (((Uint32 & mPixelBitMasks.BlueMask) >> mPixelShl[2]) << mPixelShr[2])
489 );
490 }
491 }
492 }
493
494 return EFI_SUCCESS;
495 }
496
497
498 /**
499 Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation.
500
501 @param[in] BltBuffer Output buffer for pixel color data
502 @param[in] DestinationX X location within video
503 @param[in] DestinationY Y location within video
504 @param[in] Width Width (in pixels)
505 @param[in] Height Height
506
507 @retval EFI_DEVICE_ERROR - A hardware error occured
508 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
509 @retval EFI_SUCCESS - The sizes were returned
510
511 **/
512 EFI_STATUS
513 EFIAPI
514 BltLibBufferToVideo (
515 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
516 IN UINTN DestinationX,
517 IN UINTN DestinationY,
518 IN UINTN Width,
519 IN UINTN Height
520 )
521 {
522 return BltLibBufferToVideoEx (
523 BltBuffer,
524 0,
525 0,
526 DestinationX,
527 DestinationY,
528 Width,
529 Height,
530 0
531 );
532 }
533
534
535 /**
536 Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation
537 with extended parameters.
538
539 @param[in] BltBuffer Output buffer for pixel color data
540 @param[in] SourceX X location within BltBuffer
541 @param[in] SourceY Y location within BltBuffer
542 @param[in] DestinationX X location within video
543 @param[in] DestinationY Y location within video
544 @param[in] Width Width (in pixels)
545 @param[in] Height Height
546 @param[in] Delta Number of bytes in a row of BltBuffer
547
548 @retval EFI_DEVICE_ERROR - A hardware error occured
549 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
550 @retval EFI_SUCCESS - The sizes were returned
551
552 **/
553 EFI_STATUS
554 EFIAPI
555 BltLibBufferToVideoEx (
556 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
557 IN UINTN SourceX,
558 IN UINTN SourceY,
559 IN UINTN DestinationX,
560 IN UINTN DestinationY,
561 IN UINTN Width,
562 IN UINTN Height,
563 IN UINTN Delta
564 )
565 {
566 UINTN DstY;
567 UINTN SrcY;
568 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
569 VOID *BltMemSrc;
570 VOID *BltMemDst;
571 UINTN X;
572 UINT32 Uint32;
573 UINTN Offset;
574 UINTN WidthInBytes;
575
576 //
577 // BltBuffer to Video: Source is BltBuffer, destination is Video
578 //
579 if (DestinationY + Height > mBltLibHeight) {
580 return EFI_INVALID_PARAMETER;
581 }
582
583 if (DestinationX + Width > mBltLibWidthInPixels) {
584 return EFI_INVALID_PARAMETER;
585 }
586
587 if (Width == 0 || Height == 0) {
588 return EFI_INVALID_PARAMETER;
589 }
590
591 //
592 // If Delta is zero, then the entire BltBuffer is being used, so Delta
593 // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
594 // the number of bytes in each row can be computed.
595 //
596 if (Delta == 0) {
597 Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
598 }
599
600 WidthInBytes = Width * mBltLibBytesPerPixel;
601
602 for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
603
604 Offset = (DstY * mBltLibWidthInPixels) + DestinationX;
605 Offset = mBltLibBytesPerPixel * Offset;
606 BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
607
608 if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
609 BltMemSrc = (VOID *) ((UINT8 *) BltBuffer + (SrcY * Delta));
610 } else {
611 for (X = 0; X < Width; X++) {
612 Blt =
613 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) (
614 (UINT8 *) BltBuffer +
615 (SrcY * Delta) +
616 ((SourceX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
617 );
618 Uint32 = *(UINT32*) Blt;
619 *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)) =
620 (UINT32) (
621 (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) |
622 (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) |
623 (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask)
624 );
625 }
626 BltMemSrc = (VOID *) mBltLibLineBuffer;
627 }
628
629 CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
630 }
631
632 return EFI_SUCCESS;
633 }
634
635
636 /**
637 Performs a UEFI Graphics Output Protocol Blt Video to Video operation
638
639 @param[in] SourceX X location within video
640 @param[in] SourceY Y location within video
641 @param[in] DestinationX X location within video
642 @param[in] DestinationY Y location within video
643 @param[in] Width Width (in pixels)
644 @param[in] Height Height
645
646 @retval EFI_DEVICE_ERROR - A hardware error occured
647 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
648 @retval EFI_SUCCESS - The sizes were returned
649
650 **/
651 EFI_STATUS
652 EFIAPI
653 BltLibVideoToVideo (
654 IN UINTN SourceX,
655 IN UINTN SourceY,
656 IN UINTN DestinationX,
657 IN UINTN DestinationY,
658 IN UINTN Width,
659 IN UINTN Height
660 )
661 {
662 VOID *BltMemSrc;
663 VOID *BltMemDst;
664 UINTN Offset;
665 UINTN WidthInBytes;
666 INTN LineStride;
667
668 //
669 // Video to Video: Source is Video, destination is Video
670 //
671 if (SourceY + Height > mBltLibHeight) {
672 return EFI_INVALID_PARAMETER;
673 }
674
675 if (SourceX + Width > mBltLibWidthInPixels) {
676 return EFI_INVALID_PARAMETER;
677 }
678
679 if (DestinationY + Height > mBltLibHeight) {
680 return EFI_INVALID_PARAMETER;
681 }
682
683 if (DestinationX + Width > mBltLibWidthInPixels) {
684 return EFI_INVALID_PARAMETER;
685 }
686
687 if (Width == 0 || Height == 0) {
688 return EFI_INVALID_PARAMETER;
689 }
690
691 WidthInBytes = Width * mBltLibBytesPerPixel;
692
693 Offset = (SourceY * mBltLibWidthInPixels) + SourceX;
694 Offset = mBltLibBytesPerPixel * Offset;
695 BltMemSrc = (VOID *) (mBltLibFrameBuffer + Offset);
696
697 Offset = (DestinationY * mBltLibWidthInPixels) + DestinationX;
698 Offset = mBltLibBytesPerPixel * Offset;
699 BltMemDst = (VOID *) (mBltLibFrameBuffer + Offset);
700
701 LineStride = mBltLibWidthInBytes;
702 if ((UINTN) BltMemDst > (UINTN) BltMemSrc) {
703 LineStride = -LineStride;
704 }
705
706 while (Height > 0) {
707 CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
708
709 BltMemSrc = (VOID*) ((UINT8*) BltMemSrc + LineStride);
710 BltMemDst = (VOID*) ((UINT8*) BltMemDst + LineStride);
711 Height--;
712 }
713
714 return EFI_SUCCESS;
715 }
716
717
718 /**
719 Returns the sizes related to the video device
720
721 @param[out] Width Width (in pixels)
722 @param[out] Height Height (in pixels)
723
724 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
725 @retval EFI_SUCCESS - The sizes were returned
726
727 **/
728 EFI_STATUS
729 EFIAPI
730 BltLibGetSizes (
731 OUT UINTN *Width, OPTIONAL
732 OUT UINTN *Height OPTIONAL
733 )
734 {
735 if (Width != NULL) {
736 *Width = mBltLibWidthInPixels;
737 }
738 if (Height != NULL) {
739 *Height = mBltLibHeight;
740 }
741
742 return EFI_SUCCESS;
743 }
744