/third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg/Library/GopBltLib/GopBltLib.c

https://github.com/thalium/icebox · C · 455 lines · 256 code · 30 blank · 169 comment · 11 complexity · 4f0bafaf6a6571b68de3969c9ba5f441 MD5 · raw file

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