Minimize amount of data copied to display server
This commit is contained in:
parent
5f633be205
commit
dd69db99ca
1 changed files with 17 additions and 10 deletions
27
sortix.c
27
sortix.c
|
@ -148,23 +148,25 @@ static void sortix_draw_bitmap(struct graphics_device *dev, struct bitmap *bmp,
|
||||||
{
|
{
|
||||||
struct window_data *window_data = dev->driver_data;
|
struct window_data *window_data = dev->driver_data;
|
||||||
|
|
||||||
warnx("sortix_draw_bitmap(%p, %p, %i, %i)", dev, bmp, x1, y1); //debg
|
|
||||||
size_t width = bmp->x;
|
size_t width = bmp->x;
|
||||||
size_t height = bmp->y;
|
size_t height = bmp->y;
|
||||||
|
if (!width || !height)
|
||||||
|
return;
|
||||||
|
// TODO: Overflow when multiplying
|
||||||
|
uint32_t *buffer = mem_alloc(width * height * sizeof(uint32_t));
|
||||||
|
|
||||||
for (size_t y = 0; y < height; y++) {
|
for (size_t y = 0; y < height; y++) {
|
||||||
if (window_data->fb.yres <= y1 + y) continue;
|
|
||||||
for (size_t x = 0; x < width; x++) {
|
for (size_t x = 0; x < width; x++) {
|
||||||
if (window_data->fb.xres <= x1 + x) continue;
|
|
||||||
void *pixel_data = ((unsigned char*)bmp->data) + y * bmp->skip + x * sizeof(uint32_t);
|
void *pixel_data = ((unsigned char*)bmp->data) + y * bmp->skip + x * sizeof(uint32_t);
|
||||||
uint32_t pixel;
|
uint32_t pixel;
|
||||||
memcpy(&pixel, pixel_data, sizeof(uint32_t));
|
memcpy(&pixel, pixel_data, sizeof(uint32_t));
|
||||||
// Set the alpha channel (see sortix_fill_area() for further details)
|
// Set alpha (see sortix_fill_area() for more details)
|
||||||
pixel |= 0xff000000;
|
pixel |= 0xff000000;
|
||||||
window_data->fb.buffer[(y1 + y) * window_data->fb.pitch + x + x1] = pixel;
|
buffer[y * width + x] = pixel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
display_render_window(connection, window_data->window_id, 0, 0, window_data->fb.xres, window_data->fb.yres, window_data->fb.buffer);
|
display_render_window(connection, window_data->window_id, x1, y1, width, height, buffer);
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
|
static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2, int y2, long color)
|
||||||
|
@ -173,6 +175,10 @@ static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2
|
||||||
|
|
||||||
size_t width = x2 - x1;
|
size_t width = x2 - x1;
|
||||||
size_t height = y2 - y1;
|
size_t height = y2 - y1;
|
||||||
|
if (!width || !height)
|
||||||
|
return;
|
||||||
|
// TODO: Overflow when multiplying
|
||||||
|
uint32_t *buffer = mem_alloc(width * height * sizeof(uint32_t));
|
||||||
|
|
||||||
// Links uses a pixel format where the top byte is clear
|
// Links uses a pixel format where the top byte is clear
|
||||||
// Sortix stores alpha there, so set it to 255
|
// Sortix stores alpha there, so set it to 255
|
||||||
|
@ -180,19 +186,20 @@ static void sortix_fill_area(struct graphics_device *dev, int x1, int y1, int x2
|
||||||
|
|
||||||
for (size_t y = 0; y < height; y++) {
|
for (size_t y = 0; y < height; y++) {
|
||||||
for (size_t x = 0; x < width; x++)
|
for (size_t x = 0; x < width; x++)
|
||||||
window_data->fb.buffer[(y1 + y) * window_data->fb.pitch + x + x1] = pixel;
|
buffer[y * width + x] = pixel;
|
||||||
}
|
}
|
||||||
display_render_window(connection, window_data->window_id, 0, 0, window_data->fb.xres, window_data->fb.yres, window_data->fb.buffer);
|
display_render_window(connection, window_data->window_id, x1, y1, width, height, buffer);
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortix_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
|
static void sortix_draw_hline(struct graphics_device *dev, int x1, int y, int x2, long color)
|
||||||
{
|
{
|
||||||
sortix_fill_area(dev, x1, y, x2, y, color);
|
sortix_fill_area(dev, x1, y, x2, y + 1, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortix_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
|
static void sortix_draw_vline(struct graphics_device *dev, int x, int y1, int y2, long color)
|
||||||
{
|
{
|
||||||
sortix_fill_area(dev, x, y1, x, y2, color);
|
sortix_fill_area(dev, x, y1, x + 1, y2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sortix_set_title(struct graphics_device *dev, unsigned char *title)
|
static void sortix_set_title(struct graphics_device *dev, unsigned char *title)
|
||||||
|
|
Loading…
Reference in a new issue