OptionRomPkg: Fix Visual Studio compiler warnings
[mirror_edk2.git] / OptionRomPkg / Library / GopBltLib / GopBltLib.c
CommitLineData
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
26EFI_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
40EFI_STATUS\r
41EFIAPI\r
42BltLibConfigure (\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
103EFI_STATUS\r
104InternalGopBltCommon (\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
4d19deac 116 if (mGop == NULL) {\r
117 return EFI_DEVICE_ERROR;\r
118 }\r
119\r
120 return mGop->Blt (\r
121 mGop,\r
122 BltBuffer,\r
123 BltOperation,\r
124 SourceX,\r
125 SourceY,\r
126 DestinationX,\r
127 DestinationY,\r
128 Width,\r
129 Height,\r
130 Delta\r
131 );\r
132}\r
133\r
134\r
135/**\r
136 Performs a UEFI Graphics Output Protocol Blt operation.\r
137\r
138 @param[in,out] BltBuffer - The data to transfer to screen\r
139 @param[in] BltOperation - The operation to perform\r
140 @param[in] SourceX - The X coordinate of the source for BltOperation\r
141 @param[in] SourceY - The Y coordinate of the source for BltOperation\r
142 @param[in] DestinationX - The X coordinate of the destination for BltOperation\r
143 @param[in] DestinationY - The Y coordinate of the destination for BltOperation\r
144 @param[in] Width - The width of a rectangle in the blt rectangle in pixels\r
145 @param[in] Height - The height of a rectangle in the blt rectangle in pixels\r
146 @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.\r
147 If a Delta of 0 is used, the entire BltBuffer will be operated on.\r
148 If a subrectangle of the BltBuffer is used, then Delta represents\r
149 the number of bytes in a row of the BltBuffer.\r
150\r
151 @retval EFI_DEVICE_ERROR - A hardware error occured\r
152 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
153 @retval EFI_SUCCESS - Blt operation success\r
154\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158BltLibGopBlt (\r
159 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL\r
160 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,\r
161 IN UINTN SourceX,\r
162 IN UINTN SourceY,\r
163 IN UINTN DestinationX,\r
164 IN UINTN DestinationY,\r
165 IN UINTN Width,\r
166 IN UINTN Height,\r
167 IN UINTN Delta\r
168 )\r
169{\r
170 return InternalGopBltCommon (\r
171 BltBuffer,\r
172 BltOperation,\r
173 SourceX,\r
174 SourceY,\r
175 DestinationX,\r
176 DestinationY,\r
177 Width,\r
178 Height,\r
179 Delta\r
180 );\r
181}\r
182\r
183\r
184/**\r
185 Performs a UEFI Graphics Output Protocol Blt Video Fill.\r
186\r
187 @param[in] Color Color to fill the region with\r
188 @param[in] DestinationX X location to start fill operation\r
189 @param[in] DestinationY Y location to start fill operation\r
190 @param[in] Width Width (in pixels) to fill\r
191 @param[in] Height Height to fill\r
192\r
193 @retval EFI_DEVICE_ERROR - A hardware error occured\r
194 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
195 @retval EFI_SUCCESS - The sizes were returned\r
196\r
197**/\r
198EFI_STATUS\r
199EFIAPI\r
200BltLibVideoFill (\r
201 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color,\r
202 IN UINTN DestinationX,\r
203 IN UINTN DestinationY,\r
204 IN UINTN Width,\r
205 IN UINTN Height\r
206 )\r
207{\r
208 return InternalGopBltCommon (\r
209 Color,\r
210 EfiBltVideoFill,\r
211 0,\r
212 0,\r
213 DestinationX,\r
214 DestinationY,\r
215 Width,\r
216 Height,\r
217 0\r
218 );\r
219}\r
220\r
221\r
222/**\r
223 Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation.\r
224\r
225 @param[out] BltBuffer Output buffer for pixel color data\r
226 @param[in] SourceX X location within video\r
227 @param[in] SourceY Y location within video\r
228 @param[in] Width Width (in pixels)\r
229 @param[in] Height Height\r
230\r
231 @retval EFI_DEVICE_ERROR - A hardware error occured\r
232 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
233 @retval EFI_SUCCESS - The sizes were returned\r
234\r
235**/\r
236EFI_STATUS\r
237EFIAPI\r
238BltLibVideoToBltBuffer (\r
239 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,\r
240 IN UINTN SourceX,\r
241 IN UINTN SourceY,\r
242 IN UINTN Width,\r
243 IN UINTN Height\r
244 )\r
245{\r
246 return InternalGopBltCommon (\r
247 BltBuffer,\r
248 EfiBltVideoToBltBuffer,\r
249 SourceX,\r
250 SourceY,\r
251 0,\r
252 0,\r
253 Width,\r
254 Height,\r
255 0\r
256 );\r
257}\r
258\r
259\r
260/**\r
261 Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation\r
262 with extended parameters.\r
263\r
264 @param[out] BltBuffer Output buffer for pixel color data\r
265 @param[in] SourceX X location within video\r
266 @param[in] SourceY Y location within video\r
267 @param[in] DestinationX X location within BltBuffer\r
268 @param[in] DestinationY Y location within BltBuffer\r
269 @param[in] Width Width (in pixels)\r
270 @param[in] Height Height\r
271 @param[in] Delta Number of bytes in a row of BltBuffer\r
272\r
273 @retval EFI_DEVICE_ERROR - A hardware error occured\r
274 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
275 @retval EFI_SUCCESS - The sizes were returned\r
276\r
277**/\r
278EFI_STATUS\r
279EFIAPI\r
280BltLibVideoToBltBufferEx (\r
281 OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,\r
282 IN UINTN SourceX,\r
283 IN UINTN SourceY,\r
284 IN UINTN DestinationX,\r
285 IN UINTN DestinationY,\r
286 IN UINTN Width,\r
287 IN UINTN Height,\r
288 IN UINTN Delta\r
289 )\r
290{\r
291 return InternalGopBltCommon (\r
292 BltBuffer,\r
293 EfiBltVideoToBltBuffer,\r
294 SourceX,\r
295 SourceY,\r
296 DestinationX,\r
297 DestinationY,\r
298 Width,\r
299 Height,\r
300 Delta\r
301 );\r
302}\r
303\r
304\r
305/**\r
306 Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation.\r
307\r
308 @param[in] BltBuffer Output buffer for pixel color data\r
309 @param[in] DestinationX X location within video\r
310 @param[in] DestinationY Y location within video\r
311 @param[in] Width Width (in pixels)\r
312 @param[in] Height Height\r
313\r
314 @retval EFI_DEVICE_ERROR - A hardware error occured\r
315 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
316 @retval EFI_SUCCESS - The sizes were returned\r
317\r
318**/\r
319EFI_STATUS\r
320EFIAPI\r
321BltLibBufferToVideo (\r
322 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,\r
323 IN UINTN DestinationX,\r
324 IN UINTN DestinationY,\r
325 IN UINTN Width,\r
326 IN UINTN Height\r
327 )\r
328{\r
329 return InternalGopBltCommon (\r
330 BltBuffer,\r
331 EfiBltBufferToVideo,\r
332 0,\r
333 0,\r
334 DestinationX,\r
335 DestinationY,\r
336 Width,\r
337 Height,\r
338 0\r
339 );\r
340}\r
341\r
342\r
343/**\r
344 Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation\r
345 with extended parameters.\r
346\r
347 @param[in] BltBuffer Output buffer for pixel color data\r
348 @param[in] SourceX X location within BltBuffer\r
349 @param[in] SourceY Y location within BltBuffer\r
350 @param[in] DestinationX X location within video\r
351 @param[in] DestinationY Y location within video\r
352 @param[in] Width Width (in pixels)\r
353 @param[in] Height Height\r
354 @param[in] Delta Number of bytes in a row of BltBuffer\r
355\r
356 @retval EFI_DEVICE_ERROR - A hardware error occured\r
357 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
358 @retval EFI_SUCCESS - The sizes were returned\r
359\r
360**/\r
361EFI_STATUS\r
362EFIAPI\r
363BltLibBufferToVideoEx (\r
364 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,\r
365 IN UINTN SourceX,\r
366 IN UINTN SourceY,\r
367 IN UINTN DestinationX,\r
368 IN UINTN DestinationY,\r
369 IN UINTN Width,\r
370 IN UINTN Height,\r
371 IN UINTN Delta\r
372 )\r
373{\r
374 return InternalGopBltCommon (\r
375 BltBuffer,\r
376 EfiBltBufferToVideo,\r
377 SourceX,\r
378 SourceY,\r
379 DestinationX,\r
380 DestinationY,\r
381 Width,\r
382 Height,\r
383 Delta\r
384 );\r
385}\r
386\r
387\r
388/**\r
389 Performs a UEFI Graphics Output Protocol Blt Video to Video operation\r
390\r
391 @param[in] SourceX X location within video\r
392 @param[in] SourceY Y location within video\r
393 @param[in] DestinationX X location within video\r
394 @param[in] DestinationY Y location within video\r
395 @param[in] Width Width (in pixels)\r
396 @param[in] Height Height\r
397\r
398 @retval EFI_DEVICE_ERROR - A hardware error occured\r
399 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
400 @retval EFI_SUCCESS - The sizes were returned\r
401\r
402**/\r
403EFI_STATUS\r
404EFIAPI\r
405BltLibVideoToVideo (\r
406 IN UINTN SourceX,\r
407 IN UINTN SourceY,\r
408 IN UINTN DestinationX,\r
409 IN UINTN DestinationY,\r
410 IN UINTN Width,\r
411 IN UINTN Height\r
412 )\r
413{\r
414 return InternalGopBltCommon (\r
415 NULL,\r
416 EfiBltVideoToVideo,\r
417 SourceX,\r
418 SourceY,\r
419 DestinationX,\r
420 DestinationY,\r
421 Width,\r
422 Height,\r
423 0\r
424 );\r
425}\r
426\r
427/**\r
428 Returns the sizes related to the video device\r
429\r
430 @param[out] Width Width (in pixels)\r
431 @param[out] Height Height (in pixels)\r
432\r
433 @retval EFI_INVALID_PARAMETER - Invalid parameter passed in\r
434 @retval EFI_SUCCESS - The sizes were returned\r
435\r
436**/\r
437EFI_STATUS\r
438EFIAPI\r
439BltLibGetSizes (\r
440 OUT UINTN *Width, OPTIONAL\r
441 OUT UINTN *Height OPTIONAL\r
442 )\r
443{\r
444 ASSERT (mGop != NULL);\r
445\r
446 if (Width != NULL) {\r
447 *Width = mGop->Mode->Info->HorizontalResolution;\r
448 }\r
449 if (Height != NULL) {\r
450 *Height = mGop->Mode->Info->VerticalResolution;\r
451 }\r
452\r
453 return EFI_SUCCESS;\r
454}\r
455\r