Yu-Ping Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/58128 )
Change subject: libpayload: cbgfx: Clear screen by memcpy ......................................................................
libpayload: cbgfx: Clear screen by memcpy
Instead of setting each pixel in the framebuffer, use memcpy() to clear screen faster. As this method should be fast enough, remove the fast path using memset().
The speed of clear_screen() on brya (x_resolution = 1920, bytes_per_line = 7680):
- Using memset(): 15ms - Setting each pixel: 25ms - Using memcpy(): 14ms
Also remove set_pixel_raw() since it's now used in only one place.
BUG=none TEST=emerge-brya libpayload TEST=Saw developer screen on brya BRANCH=none
Change-Id: I5f08fb50faab48d3db6b61ae022af3226914f72b Signed-off-by: Yu-Ping Wu yupingso@chromium.org --- M payloads/libpayload/drivers/video/graphics.c 1 file changed, 18 insertions(+), 20 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/58128/1
diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index 53de302..7f08d40 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -274,19 +274,12 @@ * 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_raw(struct vector *rcoord, uint32_t color) +static inline void set_pixel(struct vector *coord, uint32_t color) { const int bpp = fbinfo->bits_per_pixel; const int bpl = fbinfo->bytes_per_line; - 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; + int i;
switch (fbinfo->orientation) { case CB_FB_ORIENTATION_NORMAL: @@ -308,7 +301,9 @@ break; }
- set_pixel_raw(&rcoord, color); + uint8_t * const pixel = FB + rcoord.y * bpl + rcoord.x * bpp / 8; + for (i = 0; i < bpp / 8; i++) + pixel[i] = (color >> (i * 8)); }
/* @@ -625,22 +620,25 @@ if (cbgfx_init()) return CBGFX_ERROR_INIT;
- struct vector p; + int x, y, i; uint32_t color = calculate_color(rgb, 0); const int bpp = fbinfo->bits_per_pixel; const int bpl = fbinfo->bytes_per_line; + uint8_t *line = malloc(bpl);
- /* If all significant bytes in color are equal, fastpath through memset. - * We assume that for 32bpp the high byte gets ignored anyway. */ - if ((((color >> 8) & 0xff) == (color & 0xff)) && (bpp == 16 || - (((color >> 16) & 0xff) == (color & 0xff)))) { - memset(FB, color & 0xff, fbinfo->y_resolution * bpl); - } else { - 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); + if (!line) { + LOG("Failed to allocate line buffer (%u bytes)\n", bpl); + return CBGFX_ERROR_UNKNOWN; }
+ /* Set line buffer pixels, then memcpy to framebuffer */ + for (x = 0; x < fbinfo->x_resolution; x++) + for (i = 0; i < bpp / 8; i++) + line[x * bpp / 8 + i] = (color >> (i * 8)); + for (y = 0; y < fbinfo->y_resolution; y++) + memcpy(FB + y * bpl, line, bpl); + + free(line); return CBGFX_SUCCESS; }