1 | /** @file
|
---|
2 | FrameBufferBltLib - Library to perform blt operations on a frame buffer.
|
---|
3 |
|
---|
4 | Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
|
---|
5 | 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 | #include <Library/BaseLib.h>
|
---|
17 | #include <Library/BaseMemoryLib.h>
|
---|
18 | #include <Library/BltLib.h>
|
---|
19 | #include <Library/DebugLib.h>
|
---|
20 |
|
---|
21 | #if 0
|
---|
22 | #define VDEBUG DEBUG
|
---|
23 | #else
|
---|
24 | #define VDEBUG(x)
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | #define MAX_LINE_BUFFER_SIZE (SIZE_4KB * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
|
---|
28 |
|
---|
29 | UINTN mBltLibColorDepth;
|
---|
30 | UINTN mBltLibWidthInBytes;
|
---|
31 | UINTN mBltLibBytesPerPixel;
|
---|
32 | UINTN mBltLibWidthInPixels;
|
---|
33 | UINTN mBltLibHeight;
|
---|
34 | UINT8 mBltLibLineBuffer[MAX_LINE_BUFFER_SIZE];
|
---|
35 | UINT8 *mBltLibFrameBuffer;
|
---|
36 | EFI_GRAPHICS_PIXEL_FORMAT mPixelFormat;
|
---|
37 | EFI_PIXEL_BITMASK mPixelBitMasks;
|
---|
38 | INTN mPixelShl[4]; // R-G-B-Rsvd
|
---|
39 | INTN mPixelShr[4]; // R-G-B-Rsvd
|
---|
40 |
|
---|
41 |
|
---|
42 | VOID
|
---|
43 | ConfigurePixelBitMaskFormat (
|
---|
44 | IN EFI_PIXEL_BITMASK *BitMask
|
---|
45 | )
|
---|
46 | {
|
---|
47 | UINTN Loop;
|
---|
48 | UINT32 *Masks;
|
---|
49 | UINT32 MergedMasks;
|
---|
50 |
|
---|
51 | MergedMasks = 0;
|
---|
52 | Masks = (UINT32*) BitMask;
|
---|
53 | for (Loop = 0; Loop < 3; Loop++) {
|
---|
54 | ASSERT ((Loop == 3) || (Masks[Loop] != 0));
|
---|
55 | ASSERT ((MergedMasks & Masks[Loop]) == 0);
|
---|
56 | mPixelShl[Loop] = HighBitSet32 (Masks[Loop]) - 23 + (Loop * 8);
|
---|
57 | if (mPixelShl[Loop] < 0) {
|
---|
58 | mPixelShr[Loop] = -mPixelShl[Loop];
|
---|
59 | mPixelShl[Loop] = 0;
|
---|
60 | } else {
|
---|
61 | mPixelShr[Loop] = 0;
|
---|
62 | }
|
---|
63 | MergedMasks = (UINT32) (MergedMasks | Masks[Loop]);
|
---|
64 | DEBUG ((EFI_D_INFO, "%d: shl:%d shr:%d mask:%x\n", Loop, mPixelShl[Loop], mPixelShr[Loop], Masks[Loop]));
|
---|
65 | }
|
---|
66 | MergedMasks = (UINT32) (MergedMasks | Masks[3]);
|
---|
67 |
|
---|
68 | ASSERT (MergedMasks != 0);
|
---|
69 | mBltLibBytesPerPixel = (UINTN) ((HighBitSet32 (MergedMasks) + 7) / 8);
|
---|
70 |
|
---|
71 | DEBUG ((EFI_D_INFO, "Bytes per pixel: %d\n", mBltLibBytesPerPixel));
|
---|
72 |
|
---|
73 | CopyMem (&mPixelBitMasks, BitMask, sizeof (*BitMask));
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | /**
|
---|
78 | Configure the FrameBufferLib instance
|
---|
79 |
|
---|
80 | @param[in] FrameBuffer Pointer to the start of the frame buffer
|
---|
81 | @param[in] FrameBufferInfo Describes the frame buffer characteristics
|
---|
82 |
|
---|
83 | @retval EFI_INVALID_PARAMETER - Invalid parameter
|
---|
84 | @retval EFI_UNSUPPORTED - The BltLib does not support this configuration
|
---|
85 | @retval EFI_SUCCESS - Blt operation success
|
---|
86 |
|
---|
87 | **/
|
---|
88 | EFI_STATUS
|
---|
89 | EFIAPI
|
---|
90 | BltLibConfigure (
|
---|
91 | IN VOID *FrameBuffer,
|
---|
92 | IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo
|
---|
93 | )
|
---|
94 | {
|
---|
95 | STATIC EFI_PIXEL_BITMASK RgbPixelMasks =
|
---|
96 | { 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 };
|
---|
97 | STATIC EFI_PIXEL_BITMASK BgrPixelMasks =
|
---|
98 | { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
|
---|
99 |
|
---|
100 | switch (FrameBufferInfo->PixelFormat) {
|
---|
101 | case PixelRedGreenBlueReserved8BitPerColor:
|
---|
102 | ConfigurePixelBitMaskFormat (&RgbPixelMasks);
|
---|
103 | break;
|
---|
104 | case PixelBlueGreenRedReserved8BitPerColor:
|
---|
105 | ConfigurePixelBitMaskFormat (&BgrPixelMasks);
|
---|
106 | break;
|
---|
107 | case PixelBitMask:
|
---|
108 | ConfigurePixelBitMaskFormat (&(FrameBufferInfo->PixelInformation));
|
---|
109 | break;
|
---|
110 | case PixelBltOnly:
|
---|
111 | ASSERT (FrameBufferInfo->PixelFormat != PixelBltOnly);
|
---|
112 | return EFI_UNSUPPORTED;
|
---|
113 | default:
|
---|
114 | ASSERT (FALSE);
|
---|
115 | return EFI_INVALID_PARAMETER;
|
---|
116 | }
|
---|
117 | mPixelFormat = FrameBufferInfo->PixelFormat;
|
---|
118 |
|
---|
119 | mBltLibFrameBuffer = (UINT8*) FrameBuffer;
|
---|
120 | mBltLibWidthInPixels = (UINTN) FrameBufferInfo->HorizontalResolution;
|
---|
121 | mBltLibHeight = (UINTN) FrameBufferInfo->VerticalResolution;
|
---|
122 | mBltLibWidthInBytes = mBltLibWidthInPixels * mBltLibBytesPerPixel;
|
---|
123 |
|
---|
124 | ASSERT (mBltLibWidthInBytes < sizeof (mBltLibLineBuffer));
|
---|
125 |
|
---|
126 | return EFI_SUCCESS;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | Performs a UEFI Graphics Output Protocol Blt operation.
|
---|
132 |
|
---|
133 | @param[in,out] BltBuffer - The data to transfer to screen
|
---|
134 | @param[in] BltOperation - The operation to perform
|
---|
135 | @param[in] SourceX - The X coordinate of the source for BltOperation
|
---|
136 | @param[in] SourceY - The Y coordinate of the source for BltOperation
|
---|
137 | @param[in] DestinationX - The X coordinate of the destination for BltOperation
|
---|
138 | @param[in] DestinationY - The Y coordinate of the destination for BltOperation
|
---|
139 | @param[in] Width - The width of a rectangle in the blt rectangle in pixels
|
---|
140 | @param[in] Height - The height of a rectangle in the blt rectangle in pixels
|
---|
141 | @param[in] Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
|
---|
142 | If a Delta of 0 is used, the entire BltBuffer will be operated on.
|
---|
143 | If a subrectangle of the BltBuffer is used, then Delta represents
|
---|
144 | the number of bytes in a row of the BltBuffer.
|
---|
145 |
|
---|
146 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
147 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
148 | @retval EFI_SUCCESS - Blt operation success
|
---|
149 |
|
---|
150 | **/
|
---|
151 | EFI_STATUS
|
---|
152 | EFIAPI
|
---|
153 | BltLibGopBlt (
|
---|
154 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
|
---|
155 | IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
|
---|
156 | IN UINTN SourceX,
|
---|
157 | IN UINTN SourceY,
|
---|
158 | IN UINTN DestinationX,
|
---|
159 | IN UINTN DestinationY,
|
---|
160 | IN UINTN Width,
|
---|
161 | IN UINTN Height,
|
---|
162 | IN UINTN Delta
|
---|
163 | )
|
---|
164 | {
|
---|
165 | switch (BltOperation) {
|
---|
166 | case EfiBltVideoToBltBuffer:
|
---|
167 | return BltLibVideoToBltBufferEx (
|
---|
168 | BltBuffer,
|
---|
169 | SourceX,
|
---|
170 | SourceY,
|
---|
171 | DestinationX,
|
---|
172 | DestinationY,
|
---|
173 | Width,
|
---|
174 | Height,
|
---|
175 | Delta
|
---|
176 | );
|
---|
177 |
|
---|
178 | case EfiBltVideoToVideo:
|
---|
179 | return BltLibVideoToVideo (
|
---|
180 | SourceX,
|
---|
181 | SourceY,
|
---|
182 | DestinationX,
|
---|
183 | DestinationY,
|
---|
184 | Width,
|
---|
185 | Height
|
---|
186 | );
|
---|
187 |
|
---|
188 | case EfiBltVideoFill:
|
---|
189 | return BltLibVideoFill (
|
---|
190 | BltBuffer,
|
---|
191 | DestinationX,
|
---|
192 | DestinationY,
|
---|
193 | Width,
|
---|
194 | Height
|
---|
195 | );
|
---|
196 |
|
---|
197 | case EfiBltBufferToVideo:
|
---|
198 | return BltLibBufferToVideoEx (
|
---|
199 | BltBuffer,
|
---|
200 | SourceX,
|
---|
201 | SourceY,
|
---|
202 | DestinationX,
|
---|
203 | DestinationY,
|
---|
204 | Width,
|
---|
205 | Height,
|
---|
206 | Delta
|
---|
207 | );
|
---|
208 | default:
|
---|
209 | return EFI_INVALID_PARAMETER;
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | /**
|
---|
215 | Performs a UEFI Graphics Output Protocol Blt Video Fill.
|
---|
216 |
|
---|
217 | @param[in] Color Color to fill the region with
|
---|
218 | @param[in] DestinationX X location to start fill operation
|
---|
219 | @param[in] DestinationY Y location to start fill operation
|
---|
220 | @param[in] Width Width (in pixels) to fill
|
---|
221 | @param[in] Height Height to fill
|
---|
222 |
|
---|
223 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
224 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
225 | @retval EFI_SUCCESS - The sizes were returned
|
---|
226 |
|
---|
227 | **/
|
---|
228 | EFI_STATUS
|
---|
229 | EFIAPI
|
---|
230 | BltLibVideoFill (
|
---|
231 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Color,
|
---|
232 | IN UINTN DestinationX,
|
---|
233 | IN UINTN DestinationY,
|
---|
234 | IN UINTN Width,
|
---|
235 | IN UINTN Height
|
---|
236 | )
|
---|
237 | {
|
---|
238 | UINTN DstY;
|
---|
239 | VOID *BltMemSrc;
|
---|
240 | VOID *BltMemDst;
|
---|
241 | UINTN X;
|
---|
242 | UINT8 Uint8;
|
---|
243 | UINT32 Uint32;
|
---|
244 | UINT64 WideFill;
|
---|
245 | BOOLEAN UseWideFill;
|
---|
246 | BOOLEAN LineBufferReady;
|
---|
247 | UINTN Offset;
|
---|
248 | UINTN WidthInBytes;
|
---|
249 | UINTN SizeInBytes;
|
---|
250 |
|
---|
251 | //
|
---|
252 | // BltBuffer to Video: Source is BltBuffer, destination is Video
|
---|
253 | //
|
---|
254 | if (DestinationY + Height > mBltLibHeight) {
|
---|
255 | DEBUG ((EFI_D_INFO, "VideoFill: Past screen (Y)\n"));
|
---|
256 | return EFI_INVALID_PARAMETER;
|
---|
257 | }
|
---|
258 |
|
---|
259 | if (DestinationX + Width > mBltLibWidthInPixels) {
|
---|
260 | DEBUG ((EFI_D_INFO, "VideoFill: Past screen (X)\n"));
|
---|
261 | return EFI_INVALID_PARAMETER;
|
---|
262 | }
|
---|
263 |
|
---|
264 | if (Width == 0 || Height == 0) {
|
---|
265 | DEBUG ((EFI_D_INFO, "VideoFill: Width or Height is 0\n"));
|
---|
266 | return EFI_INVALID_PARAMETER;
|
---|
267 | }
|
---|
268 |
|
---|
269 | WidthInBytes = Width * mBltLibBytesPerPixel;
|
---|
270 |
|
---|
271 | Uint32 = *(UINT32*) Color;
|
---|
272 | WideFill =
|
---|
273 | (UINT32) (
|
---|
274 | (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) |
|
---|
275 | (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) |
|
---|
276 | (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask)
|
---|
277 | );
|
---|
278 | VDEBUG ((EFI_D_INFO, "VideoFill: color=0x%x, wide-fill=0x%x\n", Uint32, WideFill));
|
---|
279 |
|
---|
280 | //
|
---|
281 | // If the size of the pixel data evenly divides the sizeof
|
---|
282 | // WideFill, then a wide fill operation can be used
|
---|
283 | //
|
---|
284 | UseWideFill = TRUE;
|
---|
285 | if ((sizeof (WideFill) % mBltLibBytesPerPixel) == 0) {
|
---|
286 | for (X = mBltLibBytesPerPixel; X < sizeof (WideFill); X++) {
|
---|
287 | ((UINT8*)&WideFill)[X] = ((UINT8*)&WideFill)[X % mBltLibBytesPerPixel];
|
---|
288 | }
|
---|
289 | } else {
|
---|
290 | //
|
---|
291 | // If all the bytes in the pixel are the same value, then use
|
---|
292 | // a wide fill operation.
|
---|
293 | //
|
---|
294 | for (
|
---|
295 | X = 1, Uint8 = ((UINT8*)&WideFill)[0];
|
---|
296 | X < mBltLibBytesPerPixel;
|
---|
297 | X++) {
|
---|
298 | if (Uint8 != ((UINT8*)&WideFill)[X]) {
|
---|
299 | UseWideFill = FALSE;
|
---|
300 | break;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | if (UseWideFill) {
|
---|
304 | SetMem ((VOID*) &WideFill, sizeof (WideFill), Uint8);
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | if (UseWideFill && (DestinationX == 0) && (Width == mBltLibWidthInPixels)) {
|
---|
309 | VDEBUG ((EFI_D_INFO, "VideoFill (wide, one-shot)\n"));
|
---|
310 | Offset = DestinationY * mBltLibWidthInPixels;
|
---|
311 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
312 | BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
|
---|
313 | SizeInBytes = WidthInBytes * Height;
|
---|
314 | if (SizeInBytes >= 8) {
|
---|
315 | SetMem32 (BltMemDst, SizeInBytes & ~3, (UINT32) WideFill);
|
---|
316 | SizeInBytes = SizeInBytes & 3;
|
---|
317 | }
|
---|
318 | if (SizeInBytes > 0) {
|
---|
319 | SetMem (BltMemDst, SizeInBytes, (UINT8)(UINTN) WideFill);
|
---|
320 | }
|
---|
321 | } else {
|
---|
322 | LineBufferReady = FALSE;
|
---|
323 | for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {
|
---|
324 | Offset = (DstY * mBltLibWidthInPixels) + DestinationX;
|
---|
325 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
326 | BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
|
---|
327 |
|
---|
328 | if (UseWideFill && (((UINTN) BltMemDst & 7) == 0)) {
|
---|
329 | VDEBUG ((EFI_D_INFO, "VideoFill (wide)\n"));
|
---|
330 | SizeInBytes = WidthInBytes;
|
---|
331 | if (SizeInBytes >= 8) {
|
---|
332 | SetMem64 (BltMemDst, SizeInBytes & ~7, WideFill);
|
---|
333 | SizeInBytes = SizeInBytes & 7;
|
---|
334 | }
|
---|
335 | if (SizeInBytes > 0) {
|
---|
336 | CopyMem (BltMemDst, (VOID*) &WideFill, SizeInBytes);
|
---|
337 | }
|
---|
338 | } else {
|
---|
339 | VDEBUG ((EFI_D_INFO, "VideoFill (not wide)\n"));
|
---|
340 | if (!LineBufferReady) {
|
---|
341 | CopyMem (mBltLibLineBuffer, &WideFill, mBltLibBytesPerPixel);
|
---|
342 | for (X = 1; X < Width; ) {
|
---|
343 | CopyMem(
|
---|
344 | (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)),
|
---|
345 | mBltLibLineBuffer,
|
---|
346 | MIN (X, Width - X) * mBltLibBytesPerPixel
|
---|
347 | );
|
---|
348 | X = X + MIN (X, Width - X);
|
---|
349 | }
|
---|
350 | BltMemSrc = (VOID *) mBltLibLineBuffer;
|
---|
351 | LineBufferReady = TRUE;
|
---|
352 | }
|
---|
353 | CopyMem (BltMemDst, mBltLibLineBuffer, WidthInBytes);
|
---|
354 | }
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | return EFI_SUCCESS;
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | /**
|
---|
363 | Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation.
|
---|
364 |
|
---|
365 | @param[out] BltBuffer Output buffer for pixel color data
|
---|
366 | @param[in] SourceX X location within video
|
---|
367 | @param[in] SourceY Y location within video
|
---|
368 | @param[in] Width Width (in pixels)
|
---|
369 | @param[in] Height Height
|
---|
370 |
|
---|
371 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
372 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
373 | @retval EFI_SUCCESS - The sizes were returned
|
---|
374 |
|
---|
375 | **/
|
---|
376 | EFI_STATUS
|
---|
377 | EFIAPI
|
---|
378 | BltLibVideoToBltBuffer (
|
---|
379 | OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
|
---|
380 | IN UINTN SourceX,
|
---|
381 | IN UINTN SourceY,
|
---|
382 | IN UINTN Width,
|
---|
383 | IN UINTN Height
|
---|
384 | )
|
---|
385 | {
|
---|
386 | return BltLibVideoToBltBufferEx (
|
---|
387 | BltBuffer,
|
---|
388 | SourceX,
|
---|
389 | SourceY,
|
---|
390 | 0,
|
---|
391 | 0,
|
---|
392 | Width,
|
---|
393 | Height,
|
---|
394 | 0
|
---|
395 | );
|
---|
396 | }
|
---|
397 |
|
---|
398 |
|
---|
399 | /**
|
---|
400 | Performs a UEFI Graphics Output Protocol Blt Video to Buffer operation
|
---|
401 | with extended parameters.
|
---|
402 |
|
---|
403 | @param[out] BltBuffer Output buffer for pixel color data
|
---|
404 | @param[in] SourceX X location within video
|
---|
405 | @param[in] SourceY Y location within video
|
---|
406 | @param[in] DestinationX X location within BltBuffer
|
---|
407 | @param[in] DestinationY Y location within BltBuffer
|
---|
408 | @param[in] Width Width (in pixels)
|
---|
409 | @param[in] Height Height
|
---|
410 | @param[in] Delta Number of bytes in a row of BltBuffer
|
---|
411 |
|
---|
412 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
413 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
414 | @retval EFI_SUCCESS - The sizes were returned
|
---|
415 |
|
---|
416 | **/
|
---|
417 | EFI_STATUS
|
---|
418 | EFIAPI
|
---|
419 | BltLibVideoToBltBufferEx (
|
---|
420 | OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
|
---|
421 | IN UINTN SourceX,
|
---|
422 | IN UINTN SourceY,
|
---|
423 | IN UINTN DestinationX,
|
---|
424 | IN UINTN DestinationY,
|
---|
425 | IN UINTN Width,
|
---|
426 | IN UINTN Height,
|
---|
427 | IN UINTN Delta
|
---|
428 | )
|
---|
429 | {
|
---|
430 | UINTN DstY;
|
---|
431 | UINTN SrcY;
|
---|
432 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
|
---|
433 | VOID *BltMemSrc;
|
---|
434 | VOID *BltMemDst;
|
---|
435 | UINTN X;
|
---|
436 | UINT32 Uint32;
|
---|
437 | UINTN Offset;
|
---|
438 | UINTN WidthInBytes;
|
---|
439 |
|
---|
440 | //
|
---|
441 | // Video to BltBuffer: Source is Video, destination is BltBuffer
|
---|
442 | //
|
---|
443 | if (SourceY + Height > mBltLibHeight) {
|
---|
444 | return EFI_INVALID_PARAMETER;
|
---|
445 | }
|
---|
446 |
|
---|
447 | if (SourceX + Width > mBltLibWidthInPixels) {
|
---|
448 | return EFI_INVALID_PARAMETER;
|
---|
449 | }
|
---|
450 |
|
---|
451 | if (Width == 0 || Height == 0) {
|
---|
452 | return EFI_INVALID_PARAMETER;
|
---|
453 | }
|
---|
454 |
|
---|
455 | //
|
---|
456 | // If Delta is zero, then the entire BltBuffer is being used, so Delta
|
---|
457 | // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
|
---|
458 | // the number of bytes in each row can be computed.
|
---|
459 | //
|
---|
460 | if (Delta == 0) {
|
---|
461 | Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
|
---|
462 | }
|
---|
463 |
|
---|
464 | WidthInBytes = Width * mBltLibBytesPerPixel;
|
---|
465 |
|
---|
466 | //
|
---|
467 | // Video to BltBuffer: Source is Video, destination is BltBuffer
|
---|
468 | //
|
---|
469 | for (SrcY = SourceY, DstY = DestinationY; DstY < (Height + DestinationY); SrcY++, DstY++) {
|
---|
470 |
|
---|
471 | Offset = (SrcY * mBltLibWidthInPixels) + SourceX;
|
---|
472 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
473 | BltMemSrc = (VOID *) (mBltLibFrameBuffer + Offset);
|
---|
474 |
|
---|
475 | if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
|
---|
476 | BltMemDst =
|
---|
477 | (VOID *) (
|
---|
478 | (UINT8 *) BltBuffer +
|
---|
479 | (DstY * Delta) +
|
---|
480 | (DestinationX * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
|
---|
481 | );
|
---|
482 | } else {
|
---|
483 | BltMemDst = (VOID *) mBltLibLineBuffer;
|
---|
484 | }
|
---|
485 |
|
---|
486 | CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
|
---|
487 |
|
---|
488 | if (mPixelFormat != PixelBlueGreenRedReserved8BitPerColor) {
|
---|
489 | for (X = 0; X < Width; X++) {
|
---|
490 | Blt = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) ((UINT8 *) BltBuffer + (DstY * Delta) + (DestinationX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
|
---|
491 | Uint32 = *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel));
|
---|
492 | *(UINT32*) Blt =
|
---|
493 | (UINT32) (
|
---|
494 | (((Uint32 & mPixelBitMasks.RedMask) >> mPixelShl[0]) << mPixelShr[0]) |
|
---|
495 | (((Uint32 & mPixelBitMasks.GreenMask) >> mPixelShl[1]) << mPixelShr[1]) |
|
---|
496 | (((Uint32 & mPixelBitMasks.BlueMask) >> mPixelShl[2]) << mPixelShr[2])
|
---|
497 | );
|
---|
498 | }
|
---|
499 | }
|
---|
500 | }
|
---|
501 |
|
---|
502 | return EFI_SUCCESS;
|
---|
503 | }
|
---|
504 |
|
---|
505 |
|
---|
506 | /**
|
---|
507 | Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation.
|
---|
508 |
|
---|
509 | @param[in] BltBuffer Output buffer for pixel color data
|
---|
510 | @param[in] DestinationX X location within video
|
---|
511 | @param[in] DestinationY Y location within video
|
---|
512 | @param[in] Width Width (in pixels)
|
---|
513 | @param[in] Height Height
|
---|
514 |
|
---|
515 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
516 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
517 | @retval EFI_SUCCESS - The sizes were returned
|
---|
518 |
|
---|
519 | **/
|
---|
520 | EFI_STATUS
|
---|
521 | EFIAPI
|
---|
522 | BltLibBufferToVideo (
|
---|
523 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
|
---|
524 | IN UINTN DestinationX,
|
---|
525 | IN UINTN DestinationY,
|
---|
526 | IN UINTN Width,
|
---|
527 | IN UINTN Height
|
---|
528 | )
|
---|
529 | {
|
---|
530 | return BltLibBufferToVideoEx (
|
---|
531 | BltBuffer,
|
---|
532 | 0,
|
---|
533 | 0,
|
---|
534 | DestinationX,
|
---|
535 | DestinationY,
|
---|
536 | Width,
|
---|
537 | Height,
|
---|
538 | 0
|
---|
539 | );
|
---|
540 | }
|
---|
541 |
|
---|
542 |
|
---|
543 | /**
|
---|
544 | Performs a UEFI Graphics Output Protocol Blt Buffer to Video operation
|
---|
545 | with extended parameters.
|
---|
546 |
|
---|
547 | @param[in] BltBuffer Output buffer for pixel color data
|
---|
548 | @param[in] SourceX X location within BltBuffer
|
---|
549 | @param[in] SourceY Y location within BltBuffer
|
---|
550 | @param[in] DestinationX X location within video
|
---|
551 | @param[in] DestinationY Y location within video
|
---|
552 | @param[in] Width Width (in pixels)
|
---|
553 | @param[in] Height Height
|
---|
554 | @param[in] Delta Number of bytes in a row of BltBuffer
|
---|
555 |
|
---|
556 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
557 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
558 | @retval EFI_SUCCESS - The sizes were returned
|
---|
559 |
|
---|
560 | **/
|
---|
561 | EFI_STATUS
|
---|
562 | EFIAPI
|
---|
563 | BltLibBufferToVideoEx (
|
---|
564 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
|
---|
565 | IN UINTN SourceX,
|
---|
566 | IN UINTN SourceY,
|
---|
567 | IN UINTN DestinationX,
|
---|
568 | IN UINTN DestinationY,
|
---|
569 | IN UINTN Width,
|
---|
570 | IN UINTN Height,
|
---|
571 | IN UINTN Delta
|
---|
572 | )
|
---|
573 | {
|
---|
574 | UINTN DstY;
|
---|
575 | UINTN SrcY;
|
---|
576 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Blt;
|
---|
577 | VOID *BltMemSrc;
|
---|
578 | VOID *BltMemDst;
|
---|
579 | UINTN X;
|
---|
580 | UINT32 Uint32;
|
---|
581 | UINTN Offset;
|
---|
582 | UINTN WidthInBytes;
|
---|
583 |
|
---|
584 | //
|
---|
585 | // BltBuffer to Video: Source is BltBuffer, destination is Video
|
---|
586 | //
|
---|
587 | if (DestinationY + Height > mBltLibHeight) {
|
---|
588 | return EFI_INVALID_PARAMETER;
|
---|
589 | }
|
---|
590 |
|
---|
591 | if (DestinationX + Width > mBltLibWidthInPixels) {
|
---|
592 | return EFI_INVALID_PARAMETER;
|
---|
593 | }
|
---|
594 |
|
---|
595 | if (Width == 0 || Height == 0) {
|
---|
596 | return EFI_INVALID_PARAMETER;
|
---|
597 | }
|
---|
598 |
|
---|
599 | //
|
---|
600 | // If Delta is zero, then the entire BltBuffer is being used, so Delta
|
---|
601 | // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size,
|
---|
602 | // the number of bytes in each row can be computed.
|
---|
603 | //
|
---|
604 | if (Delta == 0) {
|
---|
605 | Delta = Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
|
---|
606 | }
|
---|
607 |
|
---|
608 | WidthInBytes = Width * mBltLibBytesPerPixel;
|
---|
609 |
|
---|
610 | for (SrcY = SourceY, DstY = DestinationY; SrcY < (Height + SourceY); SrcY++, DstY++) {
|
---|
611 |
|
---|
612 | Offset = (DstY * mBltLibWidthInPixels) + DestinationX;
|
---|
613 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
614 | BltMemDst = (VOID*) (mBltLibFrameBuffer + Offset);
|
---|
615 |
|
---|
616 | if (mPixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
|
---|
617 | BltMemSrc = (VOID *) ((UINT8 *) BltBuffer + (SrcY * Delta));
|
---|
618 | } else {
|
---|
619 | for (X = 0; X < Width; X++) {
|
---|
620 | Blt =
|
---|
621 | (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *) (
|
---|
622 | (UINT8 *) BltBuffer +
|
---|
623 | (SrcY * Delta) +
|
---|
624 | ((SourceX + X) * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL))
|
---|
625 | );
|
---|
626 | Uint32 = *(UINT32*) Blt;
|
---|
627 | *(UINT32*) (mBltLibLineBuffer + (X * mBltLibBytesPerPixel)) =
|
---|
628 | (UINT32) (
|
---|
629 | (((Uint32 << mPixelShl[0]) >> mPixelShr[0]) & mPixelBitMasks.RedMask) |
|
---|
630 | (((Uint32 << mPixelShl[1]) >> mPixelShr[1]) & mPixelBitMasks.GreenMask) |
|
---|
631 | (((Uint32 << mPixelShl[2]) >> mPixelShr[2]) & mPixelBitMasks.BlueMask)
|
---|
632 | );
|
---|
633 | }
|
---|
634 | BltMemSrc = (VOID *) mBltLibLineBuffer;
|
---|
635 | }
|
---|
636 |
|
---|
637 | CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
|
---|
638 | }
|
---|
639 |
|
---|
640 | return EFI_SUCCESS;
|
---|
641 | }
|
---|
642 |
|
---|
643 |
|
---|
644 | /**
|
---|
645 | Performs a UEFI Graphics Output Protocol Blt Video to Video operation
|
---|
646 |
|
---|
647 | @param[in] SourceX X location within video
|
---|
648 | @param[in] SourceY Y location within video
|
---|
649 | @param[in] DestinationX X location within video
|
---|
650 | @param[in] DestinationY Y location within video
|
---|
651 | @param[in] Width Width (in pixels)
|
---|
652 | @param[in] Height Height
|
---|
653 |
|
---|
654 | @retval EFI_DEVICE_ERROR - A hardware error occured
|
---|
655 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
656 | @retval EFI_SUCCESS - The sizes were returned
|
---|
657 |
|
---|
658 | **/
|
---|
659 | EFI_STATUS
|
---|
660 | EFIAPI
|
---|
661 | BltLibVideoToVideo (
|
---|
662 | IN UINTN SourceX,
|
---|
663 | IN UINTN SourceY,
|
---|
664 | IN UINTN DestinationX,
|
---|
665 | IN UINTN DestinationY,
|
---|
666 | IN UINTN Width,
|
---|
667 | IN UINTN Height
|
---|
668 | )
|
---|
669 | {
|
---|
670 | VOID *BltMemSrc;
|
---|
671 | VOID *BltMemDst;
|
---|
672 | UINTN Offset;
|
---|
673 | UINTN WidthInBytes;
|
---|
674 | INTN LineStride;
|
---|
675 |
|
---|
676 | //
|
---|
677 | // Video to Video: Source is Video, destination is Video
|
---|
678 | //
|
---|
679 | if (SourceY + Height > mBltLibHeight) {
|
---|
680 | return EFI_INVALID_PARAMETER;
|
---|
681 | }
|
---|
682 |
|
---|
683 | if (SourceX + Width > mBltLibWidthInPixels) {
|
---|
684 | return EFI_INVALID_PARAMETER;
|
---|
685 | }
|
---|
686 |
|
---|
687 | if (DestinationY + Height > mBltLibHeight) {
|
---|
688 | return EFI_INVALID_PARAMETER;
|
---|
689 | }
|
---|
690 |
|
---|
691 | if (DestinationX + Width > mBltLibWidthInPixels) {
|
---|
692 | return EFI_INVALID_PARAMETER;
|
---|
693 | }
|
---|
694 |
|
---|
695 | if (Width == 0 || Height == 0) {
|
---|
696 | return EFI_INVALID_PARAMETER;
|
---|
697 | }
|
---|
698 |
|
---|
699 | WidthInBytes = Width * mBltLibBytesPerPixel;
|
---|
700 |
|
---|
701 | Offset = (SourceY * mBltLibWidthInPixels) + SourceX;
|
---|
702 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
703 | BltMemSrc = (VOID *) (mBltLibFrameBuffer + Offset);
|
---|
704 |
|
---|
705 | Offset = (DestinationY * mBltLibWidthInPixels) + DestinationX;
|
---|
706 | Offset = mBltLibBytesPerPixel * Offset;
|
---|
707 | BltMemDst = (VOID *) (mBltLibFrameBuffer + Offset);
|
---|
708 |
|
---|
709 | LineStride = mBltLibWidthInBytes;
|
---|
710 | if ((UINTN) BltMemDst > (UINTN) BltMemSrc) {
|
---|
711 | LineStride = -LineStride;
|
---|
712 | }
|
---|
713 |
|
---|
714 | while (Height > 0) {
|
---|
715 | CopyMem (BltMemDst, BltMemSrc, WidthInBytes);
|
---|
716 |
|
---|
717 | BltMemSrc = (VOID*) ((UINT8*) BltMemSrc + LineStride);
|
---|
718 | BltMemDst = (VOID*) ((UINT8*) BltMemDst + LineStride);
|
---|
719 | Height--;
|
---|
720 | }
|
---|
721 |
|
---|
722 | return EFI_SUCCESS;
|
---|
723 | }
|
---|
724 |
|
---|
725 |
|
---|
726 | /**
|
---|
727 | Returns the sizes related to the video device
|
---|
728 |
|
---|
729 | @param[out] Width Width (in pixels)
|
---|
730 | @param[out] Height Height (in pixels)
|
---|
731 |
|
---|
732 | @retval EFI_INVALID_PARAMETER - Invalid parameter passed in
|
---|
733 | @retval EFI_SUCCESS - The sizes were returned
|
---|
734 |
|
---|
735 | **/
|
---|
736 | EFI_STATUS
|
---|
737 | EFIAPI
|
---|
738 | BltLibGetSizes (
|
---|
739 | OUT UINTN *Width, OPTIONAL
|
---|
740 | OUT UINTN *Height OPTIONAL
|
---|
741 | )
|
---|
742 | {
|
---|
743 | if (Width != NULL) {
|
---|
744 | *Width = mBltLibWidthInPixels;
|
---|
745 | }
|
---|
746 | if (Height != NULL) {
|
---|
747 | *Height = mBltLibHeight;
|
---|
748 | }
|
---|
749 |
|
---|
750 | return EFI_SUCCESS;
|
---|
751 | }
|
---|
752 |
|
---|