GopBltLib.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /** @file
  2. GopBltLib - Library to perform blt using the UEFI Graphics Output Protocol.
  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 <Protocol/GraphicsOutput.h>
  8. #include <Library/BaseLib.h>
  9. #include <Library/BaseMemoryLib.h>
  10. #include <Library/BltLib.h>
  11. #include <Library/DebugLib.h>
  12. #include <Library/MemoryAllocationLib.h>
  13. #include <Library/UefiBootServicesTableLib.h>
  14. EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop = NULL;
  15. /**
  16. Configure the FrameBufferLib instance
  17. @param[in] FrameBuffer Pointer to the start of the frame buffer
  18. @param[in] FrameBufferInfo Describes the frame buffer characteristics
  19. @retval EFI_INVALID_PARAMETER - Invalid parameter
  20. @retval EFI_UNSUPPORTED - The BltLib does not support this configuration
  21. @retval EFI_SUCCESS - Blt operation success
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. BltLibConfigure (
  26. IN VOID *FrameBuffer,
  27. IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo
  28. )
  29. {
  30. EFI_STATUS Status;
  31. EFI_HANDLE *HandleBuffer;
  32. UINTN HandleCount;
  33. UINTN Index;
  34. EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
  35. Status = gBS->LocateHandleBuffer (
  36. ByProtocol,
  37. &gEfiGraphicsOutputProtocolGuid,
  38. NULL,
  39. &HandleCount,
  40. &HandleBuffer
  41. );
  42. if (!EFI_ERROR (Status)) {
  43. for (Index = 0; Index < HandleCount; Index++) {
  44. Status = gBS->HandleProtocol (
  45. HandleBuffer[Index],
  46. &gEfiGraphicsOutputProtocolGuid,
  47. (VOID*) &Gop
  48. );
  49. if (!EFI_ERROR (Status) &&
  50. (FrameBuffer == (VOID*)(UINTN) Gop->Mode->FrameBufferBase)) {
  51. mGop = Gop;
  52. FreePool (HandleBuffer);
  53. return EFI_SUCCESS;
  54. }
  55. }
  56. FreePool (HandleBuffer);
  57. }
  58. return EFI_UNSUPPORTED;
  59. }
  60. /**
  61. Performs a UEFI Graphics Output Protocol Blt operation.
  62. @param[in,out] BltBuffer - The data to transfer to screen
  63. @param[in] BltOperation - The operation to perform
  64. @param[in] SourceX - The X coordinate of the source for BltOperation
  65. @param[in] SourceY - The Y coordinate of the source for BltOperation
  66. @param[in] DestinationX - The X coordinate of the destination for BltOperation
  67. @param[in] DestinationY - The Y coordinate of the destination for BltOperation
  68. @param[in] Width - The width of a rectangle in the blt rectangle in pixels
  69. @param[in] Height - The height of a rectangle in the blt rectangle in pixels
  70. @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
  71. If a Delta of 0 is used, the entire BltBuffer will be operated on.
  72. If a subrectangle of the BltBuffer is used, then Delta represents
  73. the number of bytes in a row of the BltBuffer.
  74. @retval EFI_DEVICE_ERROR - A hardware error occured
  75. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  76. @retval EFI_SUCCESS - Blt operation success
  77. **/
  78. EFI_STATUS
  79. InternalGopBltCommon (
  80. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
  81. IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  82. IN UINTN SourceX,
  83. IN UINTN SourceY,
  84. IN UINTN DestinationX,
  85. IN UINTN DestinationY,
  86. IN UINTN Width,
  87. IN UINTN Height,
  88. IN UINTN Delta
  89. )
  90. {
  91. if (mGop == NULL) {
  92. return EFI_DEVICE_ERROR;
  93. }
  94. return mGop->Blt (
  95. mGop,
  96. BltBuffer,
  97. BltOperation,
  98. SourceX,
  99. SourceY,
  100. DestinationX,
  101. DestinationY,
  102. Width,
  103. Height,
  104. Delta
  105. );
  106. }
  107. /**
  108. Performs a UEFI Graphics Output Protocol Blt operation.
  109. @param[in,out] BltBuffer - The data to transfer to screen
  110. @param[in] BltOperation - The operation to perform
  111. @param[in] SourceX - The X coordinate of the source for BltOperation
  112. @param[in] SourceY - The Y coordinate of the source for BltOperation
  113. @param[in] DestinationX - The X coordinate of the destination for BltOperation
  114. @param[in] DestinationY - The Y coordinate of the destination for BltOperation
  115. @param[in] Width - The width of a rectangle in the blt rectangle in pixels
  116. @param[in] Height - The height of a rectangle in the blt rectangle in pixels
  117. @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
  118. If a Delta of 0 is used, the entire BltBuffer will be operated on.
  119. If a subrectangle of the BltBuffer is used, then Delta represents
  120. the number of bytes in a row of the BltBuffer.
  121. @retval EFI_DEVICE_ERROR - A hardware error occured
  122. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  123. @retval EFI_SUCCESS - Blt operation success
  124. **/
  125. EFI_STATUS
  126. EFIAPI
  127. BltLibGopBlt (
  128. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
  129. IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
  130. IN UINTN SourceX,
  131. IN UINTN SourceY,
  132. IN UINTN DestinationX,
  133. IN UINTN DestinationY,
  134. IN UINTN Width,
  135. IN UINTN Height,
  136. IN UINTN Delta
  137. )
  138. {
  139. return InternalGopBltCommon (
  140. BltBuffer,
  141. BltOperation,
  142. SourceX,
  143. SourceY,
  144. DestinationX,
  145. DestinationY,
  146. Width,
  147. Height,
  148. Delta
  149. );
  150. }
  151. /**
  152. Performs a UEFI Graphics Output Protocol Blt Video Fill.
  153. @param[in] Color Color to fill the region with
  154. @param[in] DestinationX X location to start fill operation
  155. @param[in] DestinationY Y location to start fill operation
  156. @param[in] Width Width (in pixels) to fill
  157. @param[in] Height Height to fill
  158. @retval EFI_DEVICE_ERROR - A hardware error occured
  159. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  160. @retval EFI_SUCCESS - The sizes were returned
  161. **/
  162. EFI_STATUS
  163. EFIAPI
  164. BltLibVideoFill (
  165. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color,
  166. IN UINTN DestinationX,
  167. IN UINTN DestinationY,
  168. IN UINTN Width,
  169. IN UINTN Height
  170. )
  171. {
  172. return InternalGopBltCommon (
  173. Color,
  174. EfiBltVideoFill,
  175. 0,
  176. 0,
  177. DestinationX,
  178. DestinationY,
  179. Width,
  180. Height,
  181. 0
  182. );
  183. }
  184. /**
  185. Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation.
  186. @param[out] BltBuffer Output buffer for pixel color data
  187. @param[in] SourceX X location within video
  188. @param[in] SourceY Y location within video
  189. @param[in] Width Width (in pixels)
  190. @param[in] Height Height
  191. @retval EFI_DEVICE_ERROR - A hardware error occured
  192. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  193. @retval EFI_SUCCESS - The sizes were returned
  194. **/
  195. EFI_STATUS
  196. EFIAPI
  197. BltLibVideoToBltBuffer (
  198. OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  199. IN UINTN SourceX,
  200. IN UINTN SourceY,
  201. IN UINTN Width,
  202. IN UINTN Height
  203. )
  204. {
  205. return InternalGopBltCommon (
  206. BltBuffer,
  207. EfiBltVideoToBltBuffer,
  208. SourceX,
  209. SourceY,
  210. 0,
  211. 0,
  212. Width,
  213. Height,
  214. 0
  215. );
  216. }
  217. /**
  218. Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation
  219. with extended parameters.
  220. @param[out] BltBuffer Output buffer for pixel color data
  221. @param[in] SourceX X location within video
  222. @param[in] SourceY Y location within video
  223. @param[in] DestinationX X location within BltBuffer
  224. @param[in] DestinationY Y location within BltBuffer
  225. @param[in] Width Width (in pixels)
  226. @param[in] Height Height
  227. @param[in] Delta Number of bytes in a row of BltBuffer
  228. @retval EFI_DEVICE_ERROR - A hardware error occured
  229. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  230. @retval EFI_SUCCESS - The sizes were returned
  231. **/
  232. EFI_STATUS
  233. EFIAPI
  234. BltLibVideoToBltBufferEx (
  235. OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  236. IN UINTN SourceX,
  237. IN UINTN SourceY,
  238. IN UINTN DestinationX,
  239. IN UINTN DestinationY,
  240. IN UINTN Width,
  241. IN UINTN Height,
  242. IN UINTN Delta
  243. )
  244. {
  245. return InternalGopBltCommon (
  246. BltBuffer,
  247. EfiBltVideoToBltBuffer,
  248. SourceX,
  249. SourceY,
  250. DestinationX,
  251. DestinationY,
  252. Width,
  253. Height,
  254. Delta
  255. );
  256. }
  257. /**
  258. Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation.
  259. @param[in] BltBuffer Output buffer for pixel color data
  260. @param[in] DestinationX X location within video
  261. @param[in] DestinationY Y location within video
  262. @param[in] Width Width (in pixels)
  263. @param[in] Height Height
  264. @retval EFI_DEVICE_ERROR - A hardware error occured
  265. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  266. @retval EFI_SUCCESS - The sizes were returned
  267. **/
  268. EFI_STATUS
  269. EFIAPI
  270. BltLibBufferToVideo (
  271. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  272. IN UINTN DestinationX,
  273. IN UINTN DestinationY,
  274. IN UINTN Width,
  275. IN UINTN Height
  276. )
  277. {
  278. return InternalGopBltCommon (
  279. BltBuffer,
  280. EfiBltBufferToVideo,
  281. 0,
  282. 0,
  283. DestinationX,
  284. DestinationY,
  285. Width,
  286. Height,
  287. 0
  288. );
  289. }
  290. /**
  291. Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation
  292. with extended parameters.
  293. @param[in] BltBuffer Output buffer for pixel color data
  294. @param[in] SourceX X location within BltBuffer
  295. @param[in] SourceY Y location within BltBuffer
  296. @param[in] DestinationX X location within video
  297. @param[in] DestinationY Y location within video
  298. @param[in] Width Width (in pixels)
  299. @param[in] Height Height
  300. @param[in] Delta Number of bytes in a row of BltBuffer
  301. @retval EFI_DEVICE_ERROR - A hardware error occured
  302. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  303. @retval EFI_SUCCESS - The sizes were returned
  304. **/
  305. EFI_STATUS
  306. EFIAPI
  307. BltLibBufferToVideoEx (
  308. IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
  309. IN UINTN SourceX,
  310. IN UINTN SourceY,
  311. IN UINTN DestinationX,
  312. IN UINTN DestinationY,
  313. IN UINTN Width,
  314. IN UINTN Height,
  315. IN UINTN Delta
  316. )
  317. {
  318. return InternalGopBltCommon (
  319. BltBuffer,
  320. EfiBltBufferToVideo,
  321. SourceX,
  322. SourceY,
  323. DestinationX,
  324. DestinationY,
  325. Width,
  326. Height,
  327. Delta
  328. );
  329. }
  330. /**
  331. Performs a UEFI Graphics Output Protocol Blt Video to Video operation
  332. @param[in] SourceX X location within video
  333. @param[in] SourceY Y location within video
  334. @param[in] DestinationX X location within video
  335. @param[in] DestinationY Y location within video
  336. @param[in] Width Width (in pixels)
  337. @param[in] Height Height
  338. @retval EFI_DEVICE_ERROR - A hardware error occured
  339. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  340. @retval EFI_SUCCESS - The sizes were returned
  341. **/
  342. EFI_STATUS
  343. EFIAPI
  344. BltLibVideoToVideo (
  345. IN UINTN SourceX,
  346. IN UINTN SourceY,
  347. IN UINTN DestinationX,
  348. IN UINTN DestinationY,
  349. IN UINTN Width,
  350. IN UINTN Height
  351. )
  352. {
  353. return InternalGopBltCommon (
  354. NULL,
  355. EfiBltVideoToVideo,
  356. SourceX,
  357. SourceY,
  358. DestinationX,
  359. DestinationY,
  360. Width,
  361. Height,
  362. 0
  363. );
  364. }
  365. /**
  366. Returns the sizes related to the video device
  367. @param[out] Width Width (in pixels)
  368. @param[out] Height Height (in pixels)
  369. @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
  370. @retval EFI_SUCCESS - The sizes were returned
  371. **/
  372. EFI_STATUS
  373. EFIAPI
  374. BltLibGetSizes (
  375. OUT UINTN *Width, OPTIONAL
  376. OUT UINTN *Height OPTIONAL
  377. )
  378. {
  379. ASSERT (mGop != NULL);
  380. if (Width != NULL) {
  381. *Width = mGop->Mode->Info->HorizontalResolution;
  382. }
  383. if (Height != NULL) {
  384. *Height = mGop->Mode->Info->VerticalResolution;
  385. }
  386. return EFI_SUCCESS;
  387. }