OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
BlitBufferToVideo.c
Go to the documentation of this file.
1
10#include "BlitInternal.h"
11
12#include <Library/BaseLib.h>
13#include <Library/BaseMemoryLib.h>
14#include <Library/DebugLib.h>
15
16RETURN_STATUS
18 IN OC_BLIT_CONFIGURE *Configure,
19 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
20 IN UINTN SourceX,
21 IN UINTN SourceY,
22 IN UINTN DestinationX,
23 IN UINTN DestinationY,
24 IN UINTN Width,
25 IN UINTN Height,
26 IN UINTN DeltaPixels
27 )
28{
29 UINT32 *Source;
30 UINT32 *Destination;
31 UINT32 *SourceWalker;
32 UINT32 *DestinationWalker;
33 UINTN IndexX;
34 UINTN WidthInBytes;
35 UINTN PixelsPerScanLine;
36 UINT32 Uint32;
37
38 WidthInBytes = Width * BYTES_PER_PIXEL;
39 PixelsPerScanLine = Configure->PixelsPerScanLine;
40
41 Destination = (UINT32 *)Configure->FrameBuffer
42 + DestinationY * PixelsPerScanLine + DestinationX;
43 Source = (UINT32 *)BltBuffer
44 + SourceY * DeltaPixels + SourceX;
45 if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
46 while (Height > 0) {
47 CopyMem (Destination, Source, WidthInBytes);
48 Source += DeltaPixels;
49 Destination += PixelsPerScanLine;
50 Height--;
51 }
52 } else {
53 while (Height > 0) {
54 DestinationWalker = (UINT32 *)Configure->LineBuffer;
55 SourceWalker = (UINT32 *)Source;
56 for (IndexX = 0; IndexX < Width; IndexX++) {
57 Uint32 = *SourceWalker++;
58 *DestinationWalker++ =
59 (UINT32)(
60 (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) &
61 Configure->PixelMasks.RedMask) |
62 (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) &
63 Configure->PixelMasks.GreenMask) |
64 (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) &
65 Configure->PixelMasks.BlueMask)
66 );
67 }
68
69 CopyMem (Destination, Configure->LineBuffer, WidthInBytes);
70 Source += DeltaPixels;
71 Destination += PixelsPerScanLine;
72 Height--;
73 }
74 }
75
76 return EFI_SUCCESS;
77}
78
79RETURN_STATUS
81 IN OC_BLIT_CONFIGURE *Configure,
82 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
83 IN UINTN SourceX,
84 IN UINTN SourceY,
85 IN UINTN DestinationX,
86 IN UINTN DestinationY,
87 IN UINTN Width,
88 IN UINTN Height,
89 IN UINTN DeltaPixels
90 )
91{
92 UINT32 *Source;
93 UINT32 *Destination;
94 UINT32 *SourceWalker;
95 UINT32 *DestinationWalker;
96 UINTN IndexX;
97 UINTN PixelsPerScanLine;
98 UINT32 Uint32;
99
100 PixelsPerScanLine = Configure->PixelsPerScanLine;
101
102 Destination = (UINT32 *)Configure->FrameBuffer
103 + (Configure->Width - DestinationY - 1);
104 Source = (UINT32 *)BltBuffer
105 + SourceY * DeltaPixels + SourceX;
106
107 if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
108 Uint32 = ((UINT32)SourceX | (UINT32)SourceY
109 | (UINT32)DestinationX | (UINT32)DestinationY
110 | (UINT32)Width | (UINT32)Height
111 | (UINT32)DeltaPixels | (UINT32)PixelsPerScanLine) & (16 - 1);
112
113 switch (Uint32) {
114 case 0:
115 {
116 CONST UINTN BlockWidth = 16;
117 Destination += DestinationX * PixelsPerScanLine;
118 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
119 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
120 UINT32 *A = Source + Index * DeltaPixels + Index2;
121 UINT32 *B = Destination + Index2 * PixelsPerScanLine - Index;
122 //
123 // Unrolling this one is ineffecient due to loop size(?). Gets down from 160 to 90 FPS.
124 //
125 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
126 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
127 B[BlockIndex2 * PixelsPerScanLine - BlockIndex] = A[BlockIndex * DeltaPixels + BlockIndex2];
128 }
129 }
130 }
131 }
132 }
133 return EFI_SUCCESS;
134 case 8:
135 {
136 CONST UINTN BlockWidth = 8;
137 Destination += DestinationX * PixelsPerScanLine;
138 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
139 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
140 UINT32 *A = Source + Index * DeltaPixels + Index2;
141 UINT32 *B = Destination + Index2 * PixelsPerScanLine - Index;
142 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
143 #if 0 /* Old compilers cannot unroll, disable for now */
144 #pragma clang loop unroll(full)
145 #endif
146 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
147 B[BlockIndex2 * PixelsPerScanLine - BlockIndex] = A[BlockIndex * DeltaPixels + BlockIndex2];
148 }
149 }
150 }
151 }
152 }
153 return EFI_SUCCESS;
154 case 4:
155 {
156 CONST UINTN BlockWidth = 4;
157 Destination += DestinationX * PixelsPerScanLine;
158 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
159 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
160 UINT32 *A = Source + Index * DeltaPixels + Index2;
161 UINT32 *B = Destination + Index2 * PixelsPerScanLine - Index;
162 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
163 #if 0 /* Old compilers cannot unroll, disable for now */
164 #pragma clang loop unroll(full)
165 #endif
166 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
167 B[BlockIndex2 * PixelsPerScanLine - BlockIndex] = A[BlockIndex * DeltaPixels + BlockIndex2];
168 }
169 }
170 }
171 }
172 }
173 return EFI_SUCCESS;
174 case 2:
175 {
176 CONST UINTN BlockWidth = 2;
177 Destination += DestinationX * PixelsPerScanLine;
178 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
179 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
180 UINT32 *A = Source + Index * DeltaPixels + Index2;
181 UINT32 *B = Destination + Index2 * PixelsPerScanLine - Index;
182 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
183 #if 0 /* Old compilers cannot unroll, disable for now */
184 #pragma clang loop unroll(full)
185 #endif
186 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
187 B[BlockIndex2 * PixelsPerScanLine - BlockIndex] = A[BlockIndex * DeltaPixels + BlockIndex2];
188 }
189 }
190 }
191 }
192 }
193 return EFI_SUCCESS;
194 default:
195 break;
196 }
197
198 while (Height > 0) {
199 DestinationWalker = Destination;
200 SourceWalker = Source;
201 for (IndexX = DestinationX; IndexX < DestinationX + Width; IndexX++) {
202 DestinationWalker[IndexX * PixelsPerScanLine] = *SourceWalker++;
203 }
204
205 Source += DeltaPixels;
206 Destination--;
207 Height--;
208 }
209 } else {
210 while (Height > 0) {
211 DestinationWalker = Destination;
212 SourceWalker = Source;
213 for (IndexX = DestinationX; IndexX < DestinationX + Width; IndexX++) {
214 Uint32 = *SourceWalker++;
215 DestinationWalker[IndexX * PixelsPerScanLine] =
216 (UINT32)(
217 (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) &
218 Configure->PixelMasks.RedMask) |
219 (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) &
220 Configure->PixelMasks.GreenMask) |
221 (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) &
222 Configure->PixelMasks.BlueMask)
223 );
224 }
225
226 Source += DeltaPixels;
227 Destination--;
228 Height--;
229 }
230 }
231
232 return EFI_SUCCESS;
233}
234
235RETURN_STATUS
237 IN OC_BLIT_CONFIGURE *Configure,
238 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
239 IN UINTN SourceX,
240 IN UINTN SourceY,
241 IN UINTN DestinationX,
242 IN UINTN DestinationY,
243 IN UINTN Width,
244 IN UINTN Height,
245 IN UINTN DeltaPixels
246 )
247{
248 UINT32 *Source;
249 UINT32 *Destination;
250 UINT32 *SourceWalker;
251 UINT32 *DestinationWalker;
252 UINTN IndexX;
253 UINTN PixelsPerScanLine;
254 UINT32 Uint32;
255
256 PixelsPerScanLine = Configure->PixelsPerScanLine;
257
258 DestinationX = Configure->Width - DestinationX - Width;
259 DestinationY = Configure->Height - DestinationY - Height;
260
261 Destination = (UINT32 *)Configure->FrameBuffer
262 + (DestinationY + (Height - 1)) * PixelsPerScanLine + DestinationX;
263 Source = (UINT32 *)BltBuffer
264 + SourceY * DeltaPixels + SourceX;
265
266 if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
267 while (Height > 0) {
268 DestinationWalker = Destination;
269 SourceWalker = Source + (Width - 1);
270 for (IndexX = 0; IndexX < Width; IndexX++) {
271 *DestinationWalker++ = *SourceWalker--;
272 }
273
274 Source += DeltaPixels;
275 Destination -= PixelsPerScanLine;
276 Height--;
277 }
278 } else {
279 while (Height > 0) {
280 DestinationWalker = Destination;
281 SourceWalker = Source + (Width - 1);
282 for (IndexX = 0; IndexX < Width; IndexX++) {
283 Uint32 = *SourceWalker--;
284 *DestinationWalker++ =
285 (UINT32)(
286 (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) &
287 Configure->PixelMasks.RedMask) |
288 (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) &
289 Configure->PixelMasks.GreenMask) |
290 (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) &
291 Configure->PixelMasks.BlueMask)
292 );
293 }
294
295 Source += DeltaPixels;
296 Destination -= PixelsPerScanLine;
297 Height--;
298 }
299 }
300
301 return EFI_SUCCESS;
302}
303
304RETURN_STATUS
306 IN OC_BLIT_CONFIGURE *Configure,
307 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
308 IN UINTN SourceX,
309 IN UINTN SourceY,
310 IN UINTN DestinationX,
311 IN UINTN DestinationY,
312 IN UINTN Width,
313 IN UINTN Height,
314 IN UINTN DeltaPixels
315 )
316{
317 UINT32 *Source;
318 UINT32 *Destination;
319 UINT32 *SourceWalker;
320 UINT32 *DestinationWalker;
321 UINTN LastX;
322 UINTN IndexX;
323 UINTN PixelsPerScanLine;
324 UINT32 Uint32;
325
326 PixelsPerScanLine = Configure->PixelsPerScanLine;
327
328 Destination = (UINT32 *)Configure->FrameBuffer
329 + DestinationY;
330 Source = (UINT32 *)BltBuffer
331 + SourceY * DeltaPixels + SourceX;
332
333 if (Configure->PixelFormat == PixelBlueGreenRedReserved8BitPerColor) {
334 Uint32 = ((UINT32)SourceX | (UINT32)SourceY
335 | (UINT32)DestinationX | (UINT32)DestinationY
336 | (UINT32)Width | (UINT32)Height
337 | (UINT32)DeltaPixels | (UINT32)PixelsPerScanLine) & (16 - 1);
338
339 switch (Uint32) {
340 case 0:
341 {
342 CONST UINTN BlockWidth = 16;
343 Destination += (Configure->Height - DestinationX - 1) * PixelsPerScanLine;
344 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
345 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
346 UINT32 *A = Source + Index * DeltaPixels + Index2;
347 UINT32 *B = Destination - Index2 * PixelsPerScanLine + Index;
348 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
349 #if 0 /* Old compilers cannot unroll, disable for now */
350 #pragma clang loop unroll(full)
351 #endif
352 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
353 B[BlockIndex - BlockIndex2 * PixelsPerScanLine] = A[BlockIndex * DeltaPixels + BlockIndex2];
354 }
355 }
356 }
357 }
358 }
359 return EFI_SUCCESS;
360 case 8:
361 {
362 CONST UINTN BlockWidth = 8;
363 Destination += (Configure->Height - DestinationX - 1) * PixelsPerScanLine;
364 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
365 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
366 UINT32 *A = Source + Index * DeltaPixels + Index2;
367 UINT32 *B = Destination - Index2 * PixelsPerScanLine + Index;
368 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
369 #if 0 /* Old compilers cannot unroll, disable for now */
370 #pragma clang loop unroll(full)
371 #endif
372 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
373 B[BlockIndex - BlockIndex2 * PixelsPerScanLine] = A[BlockIndex * DeltaPixels + BlockIndex2];
374 }
375 }
376 }
377 }
378 }
379 return EFI_SUCCESS;
380 case 4:
381 {
382 CONST UINTN BlockWidth = 4;
383 Destination += (Configure->Height - DestinationX - 1) * PixelsPerScanLine;
384 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
385 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
386 UINT32 *A = Source + Index * DeltaPixels + Index2;
387 UINT32 *B = Destination - Index2 * PixelsPerScanLine + Index;
388 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
389 #if 0 /* Old compilers cannot unroll, disable for now */
390 #pragma clang loop unroll(full)
391 #endif
392 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
393 B[BlockIndex - BlockIndex2 * PixelsPerScanLine] = A[BlockIndex * DeltaPixels + BlockIndex2];
394 }
395 }
396 }
397 }
398 }
399 return EFI_SUCCESS;
400 case 2:
401 {
402 CONST UINTN BlockWidth = 2;
403 Destination += (Configure->Height - DestinationX - 1) * PixelsPerScanLine;
404 for (UINTN Index = 0; Index < Height; Index += BlockWidth) {
405 for (UINTN Index2 = 0; Index2 < Width; Index2 += BlockWidth) {
406 UINT32 *A = Source + Index * DeltaPixels + Index2;
407 UINT32 *B = Destination - Index2 * PixelsPerScanLine + Index;
408 for (UINTN BlockIndex = 0; BlockIndex < BlockWidth; BlockIndex++) {
409 #if 0 /* Old compilers cannot unroll, disable for now */
410 #pragma clang loop unroll(full)
411 #endif
412 for (UINTN BlockIndex2 = 0; BlockIndex2 < BlockWidth; BlockIndex2++) {
413 B[BlockIndex - BlockIndex2 * PixelsPerScanLine] = A[BlockIndex * DeltaPixels + BlockIndex2];
414 }
415 }
416 }
417 }
418 }
419 return EFI_SUCCESS;
420 default:
421 break;
422 }
423
424 while (Height > 0) {
425 DestinationWalker = Destination;
426 SourceWalker = Source;
427 LastX = Configure->Height - DestinationX - 1;
428 for (IndexX = 0; IndexX < Width; IndexX++) {
429 DestinationWalker[(LastX - IndexX) * PixelsPerScanLine] = *SourceWalker++;
430 }
431
432 Source += DeltaPixels;
433 Destination++;
434 Height--;
435 }
436 } else {
437 while (Height > 0) {
438 DestinationWalker = Destination;
439 SourceWalker = Source;
440 LastX = Configure->Height - DestinationX - 1;
441 for (IndexX = 0; IndexX < Width; IndexX++) {
442 Uint32 = *SourceWalker++;
443 DestinationWalker[(LastX - IndexX) * PixelsPerScanLine] =
444 (UINT32)(
445 (((Uint32 << Configure->PixelShl[0]) >> Configure->PixelShr[0]) &
446 Configure->PixelMasks.RedMask) |
447 (((Uint32 << Configure->PixelShl[1]) >> Configure->PixelShr[1]) &
448 Configure->PixelMasks.GreenMask) |
449 (((Uint32 << Configure->PixelShl[2]) >> Configure->PixelShr[2]) &
450 Configure->PixelMasks.BlueMask)
451 );
452 }
453
454 Source += DeltaPixels;
455 Destination--;
456 Height--;
457 }
458 }
459
460 return EFI_SUCCESS;
461}
RETURN_STATUS BlitLibBufferToVideo180(IN OC_BLIT_CONFIGURE *Configure, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN DeltaPixels)
RETURN_STATUS BlitLibBufferToVideo90(IN OC_BLIT_CONFIGURE *Configure, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN DeltaPixels)
RETURN_STATUS BlitLibBufferToVideo270(IN OC_BLIT_CONFIGURE *Configure, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN DeltaPixels)
RETURN_STATUS BlitLibBufferToVideo0(IN OC_BLIT_CONFIGURE *Configure, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN DeltaPixels)
#define BYTES_PER_PIXEL
Definition OcBlitLib.h:20
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)