|
| 1 | +/* |
| 2 | + * PROJECT: ReactOS Boot Video Driver |
| 3 | + * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) |
| 4 | + * PURPOSE: Definitions for framebuffer-specific DisplayController |
| 5 | + * device boot-time configuration data stored in the |
| 6 | + * \Registry\Machine\Hardware\Description ARC tree. |
| 7 | + * COPYRIGHT: Copyright 2023 Hermès Bélusca-Maïto <[email protected]> |
| 8 | + */ |
| 9 | + |
| 10 | +#pragma once |
| 11 | + |
| 12 | +#ifdef __cplusplus |
| 13 | +extern "C" { |
| 14 | +#endif |
| 15 | + |
| 16 | +/** |
| 17 | + * @brief Framebuffer-specific device data. |
| 18 | + * |
| 19 | + * Supplemental data, extends CM_VIDEO_DEVICE_DATA. |
| 20 | + * Gets appended to the standard configuration resource list. |
| 21 | + * Any optional Irql/Vector interrupt settings are specified with |
| 22 | + * a CmResourceTypeInterrupt descriptor, while any other I/O port |
| 23 | + * is specified with a CmResourceTypePort descriptor. |
| 24 | + * The framebuffer base and size are specified by the first |
| 25 | + * CmResourceTypeMemory descriptor. |
| 26 | + **/ |
| 27 | +typedef struct _CM_FRAMEBUF_DEVICE_DATA |
| 28 | +{ |
| 29 | + CM_VIDEO_DEVICE_DATA; |
| 30 | + |
| 31 | + /* NOTE: FrameBufferSize == PixelsPerScanLine x ScreenHeight x PixelElementSize */ |
| 32 | + |
| 33 | + /* Horizontal and Vertical resolution in pixels */ |
| 34 | + ULONG ScreenWidth; |
| 35 | + ULONG ScreenHeight; |
| 36 | + |
| 37 | + /* Number of pixel elements per video memory line. Related to the |
| 38 | + * number of bytes per scan-line ("Pitch", or "ScreenStride") via: |
| 39 | + * Pitch = PixelsPerScanLine * BytesPerPixel */ |
| 40 | + ULONG PixelsPerScanLine; |
| 41 | + |
| 42 | + ULONG BitsPerPixel; // == BytesPerPixel * 8 ("PixelDepth") |
| 43 | + |
| 44 | + // MEMMODEL MemoryModel; // Linear, banked, ... |
| 45 | + |
| 46 | + /* |
| 47 | + * Physical format of the pixel for BPP > 8, specified by bit-mask. |
| 48 | + * A bit being set defines those used for the given color component, |
| 49 | + * such as Red, Green, Blue, or Reserved. |
| 50 | + */ |
| 51 | + // UCHAR NumberRedBits; |
| 52 | + // UCHAR NumberGreenBits; |
| 53 | + // UCHAR NumberBlueBits; |
| 54 | + // UCHAR NumberReservedBits; |
| 55 | + struct /*FB_PIXEL_BITMASK*/ |
| 56 | + { |
| 57 | + ULONG RedMask; |
| 58 | + ULONG GreenMask; |
| 59 | + ULONG BlueMask; |
| 60 | + ULONG ReservedMask; |
| 61 | + } PixelInformation; // PixelMasks; |
| 62 | + |
| 63 | +} CM_FRAMEBUF_DEVICE_DATA, *PCM_FRAMEBUF_DEVICE_DATA; |
| 64 | + |
| 65 | + |
| 66 | +#ifdef EFI_UGA_DRAW_PROTOCOL_GUID // EFI 1.x |
| 67 | + |
| 68 | +/* NOTE: EFI UGA does not support any other format than 32-bit xRGB, and |
| 69 | + * no direct access to the underlying hardware framebuffer is offered. */ |
| 70 | +// C_ASSERT(sizeof(EFI_UGA_PIXEL) == sizeof(ULONG)); |
| 71 | + |
| 72 | +#endif // EFI |
| 73 | + |
| 74 | +// UEFI support, see efi/GraphicsOutput.h |
| 75 | +#ifdef EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID // __GRAPHICS_OUTPUT_H__ |
| 76 | + |
| 77 | +C_ASSERT(RTL_FIELD_SIZE(CM_FRAMEBUF_DEVICE_DATA, PixelInformation) == sizeof(EFI_PIXEL_BITMASK)); |
| 78 | +// C_ASSERT(sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL) == sizeof(ULONG)); |
| 79 | + |
| 80 | +/** |
| 81 | + * @brief Maps UEFI GOP pixel format to pixel masks. |
| 82 | + * @see EFI_PIXEL_BITMASK |
| 83 | + **/ |
| 84 | +static EFI_PIXEL_BITMASK EfiPixelMasks[] = |
| 85 | +{ /* Red, Green, Blue, Reserved */ |
| 86 | + {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, // PixelRedGreenBlueReserved8BitPerColor |
| 87 | + {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, // PixelBlueGreenRedReserved8BitPerColor |
| 88 | + {0, 0, 0, 0} // PixelBitMask, PixelBltOnly, ... |
| 89 | +}; |
| 90 | + |
| 91 | +// TODO: this version of the struct is temporary |
| 92 | +// REACTOS_INTERNAL_BGCONTEXT |
| 93 | +typedef struct _ROSEFI_FRAMEBUFFER_DATA |
| 94 | +{ |
| 95 | + ULONG_PTR BaseAddress; |
| 96 | + ULONG BufferSize; |
| 97 | + UINT32 ScreenWidth; |
| 98 | + UINT32 ScreenHeight; |
| 99 | + UINT32 PixelsPerScanLine; |
| 100 | + UINT32 PixelFormat; |
| 101 | +} ROSEFI_FRAMEBUFFER_DATA, *PROSEFI_FRAMEBUFFER_DATA; |
| 102 | + |
| 103 | +#endif // UEFI |
| 104 | + |
| 105 | + |
| 106 | +/** |
| 107 | + * @brief |
| 108 | + * Calculates the number of bits per pixel ("PixelDepth") for |
| 109 | + * the given pixel format, given by the pixel color masks. |
| 110 | + * |
| 111 | + * @note |
| 112 | + * The calculation is done by finding the highest bit set in |
| 113 | + * the combined pixel color masks. |
| 114 | + * |
| 115 | + * @remark |
| 116 | + * See UEFI Spec Rev.2.10 Section 12.9 "Graphics Output Protocol": |
| 117 | + * example code "GetPixelElementSize()" function. |
| 118 | + **/ |
| 119 | +FORCEINLINE |
| 120 | +ULONG |
| 121 | +PixelBitmasksToBpp( |
| 122 | + ULONG RedMask, |
| 123 | + ULONG GreenMask, |
| 124 | + ULONG BlueMask, |
| 125 | + ULONG ReservedMask) |
| 126 | +{ |
| 127 | + ULONG CompoundMask = (RedMask | GreenMask | BlueMask | ReservedMask); |
| 128 | +#if 1 |
| 129 | + ULONG ret = 0; |
| 130 | + return (_BitScanReverse(&ret, CompoundMask) ? ret : 0); |
| 131 | +#else |
| 132 | + ULONG ret = 32; // (8 * sizeof(ULONG)); |
| 133 | + while ((CompoundMask & (1 << 31)) == 0) |
| 134 | + { |
| 135 | + ret--; |
| 136 | + CompoundMask <<= 1; |
| 137 | + } |
| 138 | + return ret; |
| 139 | +#endif |
| 140 | +} |
| 141 | + |
| 142 | +#ifdef __cplusplus |
| 143 | +} |
| 144 | +#endif |
| 145 | + |
| 146 | +/* EOF */ |
0 commit comments