From 218e5c2c9654cf9b28d8785b9a4c210591ac943d Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Thu, 28 Oct 2021 16:00:25 +0800 Subject: [PATCH] graphics: make SetPixel() an inline instead of a function pointer graphics_Init() happens before relocation, so the function breaks once the identity mapping is removed (or flagged NX) --- graphics/graphics.c | 4 ---- graphics/graphics.h | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/graphics/graphics.c b/graphics/graphics.c index ecb2db4..11d7c7a 100644 --- a/graphics/graphics.c +++ b/graphics/graphics.c @@ -110,9 +110,7 @@ void graphics_Init() { case v: io_Printf(#v "\r\n"); switch (gop->Mode->Info->PixelFormat) { CASE(PixelRedGreenBlueReserved8BitPerColor) - graphics_SetPixel = graphics_SetPixel_RGB; CASE(PixelBlueGreenRedReserved8BitPerColor) - graphics_SetPixel = graphics_SetPixel_BGR; CASE(PixelBitMask) CASE(PixelBltOnly) CASE(PixelFormatMax) @@ -131,8 +129,6 @@ void graphics_Init() { } -graphics_SetPixel_Type *graphics_SetPixel; - void graphics_SetPixel_RGB(int posX, int posY, const HelosGraphics_Color *color) { struct { uint8_t R, G, B; diff --git a/graphics/graphics.h b/graphics/graphics.h index 4b86748..3cf10da 100644 --- a/graphics/graphics.h +++ b/graphics/graphics.h @@ -43,14 +43,18 @@ void graphics_SwapBuffer(); void graphics_Invalidate(int left, int top, int width, int height); // Invalidates a rectangular region -// graphics_SetPixel is set by Init() to match one of SetPixel_RGB/BGR according to the framebuffer format. -typedef void(graphics_SetPixel_Type)(int posX, int posY, const HelosGraphics_Color *color); -extern graphics_SetPixel_Type *graphics_SetPixel; - // graphics_SetPixel_RGB/BGR writes the given pixel to the framebuffer in RGB/BGR format. void graphics_SetPixel_RGB(int posX, int posY, const HelosGraphics_Color *color); void graphics_SetPixel_BGR(int posX, int posY, const HelosGraphics_Color *color); +// graphics_SetPixel calls one of SetPixel_RGB/BGR according to the framebuffer format. +static inline void graphics_SetPixel(int posX, int posY, const HelosGraphics_Color *color) { + if (graphics_SystemVideoMode.PixelFormat == PixelBlueGreenRedReserved8BitPerColor) + graphics_SetPixel_BGR(posX, posY, color); + else if (graphics_SystemVideoMode.PixelFormat == PixelRedGreenBlueReserved8BitPerColor) + graphics_SetPixel_RGB(posX, posY, color); +} + void graphics_FillPixel(int startX, int startY, int endX, int endY, const HelosGraphics_Color *color);