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