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