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