diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index 563f2961c7..53de3024f9 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -274,12 +274,19 @@ static inline uint32_t calculate_color(const struct rgb_color *rgb, * Plot a pixel in a framebuffer. This is called from tight loops. Keep it slim * and do the validation at callers' site. */ -static inline void set_pixel(struct vector *coord, uint32_t color) +static inline void set_pixel_raw(struct vector *rcoord, uint32_t color) { const int bpp = fbinfo->bits_per_pixel; const int bpl = fbinfo->bytes_per_line; - struct vector rcoord; int i; + uint8_t * const pixel = FB + rcoord->y * bpl + rcoord->x * bpp / 8; + for (i = 0; i < bpp / 8; i++) + pixel[i] = (color >> (i * 8)); +} + +static inline void set_pixel(struct vector *coord, uint32_t color) +{ + struct vector rcoord; switch (fbinfo->orientation) { case CB_FB_ORIENTATION_NORMAL: @@ -301,9 +308,7 @@ static inline void set_pixel(struct vector *coord, uint32_t color) break; } - uint8_t * const pixel = FB + rcoord.y * bpl + rcoord.x * bpp / 8; - for (i = 0; i < bpp / 8; i++) - pixel[i] = (color >> (i * 8)); + set_pixel_raw(&rcoord, color); } /* @@ -631,9 +636,9 @@ int clear_screen(const struct rgb_color *rgb) (((color >> 16) & 0xff) == (color & 0xff)))) { memset(FB, color & 0xff, fbinfo->y_resolution * bpl); } else { - for (p.y = 0; p.y < screen.size.height; p.y++) - for (p.x = 0; p.x < screen.size.width; p.x++) - set_pixel(&p, color); + for (p.y = 0; p.y < fbinfo->y_resolution; p.y++) + for (p.x = 0; p.x < fbinfo->x_resolution; p.x++) + set_pixel_raw(&p, color); } return CBGFX_SUCCESS;