FrameBufferBltLib.c 24 KB

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