optimized draw command size
This commit is contained in:
parent
5c14ed0a9e
commit
1774c74fc2
19
demo/xlib.c
19
demo/xlib.c
@ -13,7 +13,7 @@
|
||||
|
||||
/* macros */
|
||||
#define MAX_BUFFER 64
|
||||
#define MAX_MEMORY (16 * 1024)
|
||||
#define MAX_MEMORY (8 * 1024)
|
||||
#define MAX_PANELS 4
|
||||
#define WIN_WIDTH 800
|
||||
#define WIN_HEIGHT 600
|
||||
@ -228,7 +228,8 @@ surface_scissor(XSurface *surf, float x, float y, float w, float h)
|
||||
}
|
||||
|
||||
static void
|
||||
surface_draw_line(XSurface *surf, float x0, float y0, float x1, float y1, struct gui_color col)
|
||||
surface_draw_line(XSurface *surf, gui_short x0, gui_short y0, gui_short x1,
|
||||
gui_short y1, struct gui_color col)
|
||||
{
|
||||
unsigned long c = color_from_byte(col);
|
||||
XSetForeground(surf->dpy, surf->gc, c);
|
||||
@ -236,7 +237,8 @@ surface_draw_line(XSurface *surf, float x0, float y0, float x1, float y1, struct
|
||||
}
|
||||
|
||||
static void
|
||||
surface_draw_rect(XSurface* surf, float x, float y, float w, float h, struct gui_color col)
|
||||
surface_draw_rect(XSurface* surf, gui_short x, gui_short y, gui_ushort w,
|
||||
gui_ushort h, struct gui_color col)
|
||||
{
|
||||
unsigned long c = color_from_byte(col);
|
||||
XSetForeground(surf->dpy, surf->gc, c);
|
||||
@ -244,8 +246,8 @@ surface_draw_rect(XSurface* surf, float x, float y, float w, float h, struct gui
|
||||
}
|
||||
|
||||
static void
|
||||
surface_draw_triangle(XSurface *surf, float x0, float y0, float x1, float y1,
|
||||
float x2, float y2, struct gui_color col)
|
||||
surface_draw_triangle(XSurface *surf, gui_short x0, gui_short y0, gui_short x1,
|
||||
gui_short y1, gui_short x2, gui_short y2, struct gui_color col)
|
||||
{
|
||||
XPoint pnts[3];
|
||||
unsigned long c = color_from_byte(col);
|
||||
@ -260,7 +262,8 @@ surface_draw_triangle(XSurface *surf, float x0, float y0, float x1, float y1,
|
||||
}
|
||||
|
||||
static void
|
||||
surface_draw_circle(XSurface *surf, float x, float y, float w, float h, struct gui_color col)
|
||||
surface_draw_circle(XSurface *surf, gui_short x, gui_short y, gui_ushort w,
|
||||
gui_ushort h, struct gui_color col)
|
||||
{
|
||||
unsigned long c = color_from_byte(col);
|
||||
XSetForeground(surf->dpy, surf->gc, c);
|
||||
@ -269,8 +272,8 @@ surface_draw_circle(XSurface *surf, float x, float y, float w, float h, struct g
|
||||
}
|
||||
|
||||
static void
|
||||
surface_draw_text(XSurface *surf, float x, float y, float w, float h, const char *text,
|
||||
size_t len, XFont *font, struct gui_color cbg, struct gui_color cfg)
|
||||
surface_draw_text(XSurface *surf, gui_short x, gui_short y, gui_ushort w, gui_ushort h,
|
||||
const char *text, size_t len, XFont *font, struct gui_color cbg, struct gui_color cfg)
|
||||
{
|
||||
int i, tx, ty, th, olen;
|
||||
unsigned long bg = color_from_byte(cbg);
|
||||
|
52
gui.c
52
gui.c
@ -974,10 +974,10 @@ gui_buffer_push_scissor(struct gui_command_buffer *buffer, gui_float x, gui_floa
|
||||
buffer->clip.w = w;
|
||||
buffer->clip.h = h;
|
||||
|
||||
cmd->x = x;
|
||||
cmd->y = y;
|
||||
cmd->w = w;
|
||||
cmd->h = h;
|
||||
cmd->x = (gui_short)x;
|
||||
cmd->y = (gui_short)y;
|
||||
cmd->w = (gui_ushort)w;
|
||||
cmd->h = (gui_ushort)h;
|
||||
}
|
||||
|
||||
void
|
||||
@ -996,10 +996,10 @@ gui_buffer_push_line(struct gui_command_buffer *buffer, gui_float x0, gui_float
|
||||
}
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_LINE, sizeof(*cmd));
|
||||
if (!cmd) return;
|
||||
cmd->begin[0] = x0;
|
||||
cmd->begin[1] = y0;
|
||||
cmd->end[0] = x1;
|
||||
cmd->end[1] = y1;
|
||||
cmd->begin[0] = (gui_short)x0;
|
||||
cmd->begin[1] = (gui_short)y0;
|
||||
cmd->end[0] = (gui_short)x1;
|
||||
cmd->end[1] = (gui_short)y1;
|
||||
cmd->color = c;
|
||||
}
|
||||
|
||||
@ -1019,10 +1019,10 @@ gui_buffer_push_rect(struct gui_command_buffer *buffer, gui_float x, gui_float y
|
||||
}
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_RECT, sizeof(*cmd));
|
||||
if (!cmd) return;
|
||||
cmd->x = x;
|
||||
cmd->y = y;
|
||||
cmd->w = w;
|
||||
cmd->h = h;
|
||||
cmd->x = (gui_short)x;
|
||||
cmd->y = (gui_short)y;
|
||||
cmd->w = (gui_ushort)w;
|
||||
cmd->h = (gui_ushort)h;
|
||||
cmd->color = c;
|
||||
}
|
||||
|
||||
@ -1043,10 +1043,10 @@ gui_buffer_push_circle(struct gui_command_buffer *buffer, gui_float x, gui_float
|
||||
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_CIRCLE, sizeof(*cmd));
|
||||
if (!cmd) return;
|
||||
cmd->x = x;
|
||||
cmd->y = y;
|
||||
cmd->w = w;
|
||||
cmd->h = h;
|
||||
cmd->x = (gui_short)x;
|
||||
cmd->y = (gui_short)y;
|
||||
cmd->w = (gui_ushort)w;
|
||||
cmd->h = (gui_ushort)h;
|
||||
cmd->color = c;
|
||||
}
|
||||
|
||||
@ -1068,12 +1068,12 @@ gui_buffer_push_triangle(struct gui_command_buffer *buffer, gui_float x0, gui_fl
|
||||
}
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_TRIANGLE, sizeof(*cmd));
|
||||
if (!cmd) return;
|
||||
cmd->a[0] = x0;
|
||||
cmd->a[1] = y0;
|
||||
cmd->b[0] = x1;
|
||||
cmd->b[1] = y1;
|
||||
cmd->c[0] = x2;
|
||||
cmd->c[1] = y2;
|
||||
cmd->a[0] = (gui_short)x0;
|
||||
cmd->a[1] = (gui_short)y0;
|
||||
cmd->b[0] = (gui_short)x1;
|
||||
cmd->b[1] = (gui_short)y1;
|
||||
cmd->c[0] = (gui_short)x2;
|
||||
cmd->c[1] = (gui_short)y2;
|
||||
cmd->color = c;
|
||||
}
|
||||
|
||||
@ -1095,10 +1095,10 @@ gui_buffer_push_text(struct gui_command_buffer *buffer, gui_float x, gui_float y
|
||||
}
|
||||
cmd = gui_buffer_push(buffer, GUI_COMMAND_TEXT, sizeof(*cmd) + length + 1);
|
||||
if (!cmd) return;
|
||||
cmd->x = x;
|
||||
cmd->y = y;
|
||||
cmd->w = w;
|
||||
cmd->h = h;
|
||||
cmd->x = (gui_short)x;
|
||||
cmd->y = (gui_short)y;
|
||||
cmd->w = (gui_ushort)w;
|
||||
cmd->h = (gui_ushort)h;
|
||||
cmd->bg = bg;
|
||||
cmd->fg = fg;
|
||||
cmd->font = font->userdata;
|
||||
|
28
gui.h
28
gui.h
@ -20,6 +20,7 @@ typedef int32_t gui_bool;
|
||||
typedef int16_t gui_short;
|
||||
typedef int64_t gui_long;
|
||||
typedef float gui_float;
|
||||
typedef uint16_t gui_ushort;
|
||||
typedef uint32_t gui_uint;
|
||||
typedef uint64_t gui_ulong;
|
||||
typedef uint32_t gui_flags;
|
||||
@ -33,6 +34,7 @@ typedef int gui_bool;
|
||||
typedef short gui_short;
|
||||
typedef long gui_long;
|
||||
typedef float gui_float;
|
||||
typedef unsigned short gui_ushort;
|
||||
typedef unsigned int gui_uint;
|
||||
typedef unsigned long gui_ulong;
|
||||
typedef unsigned int gui_flags;
|
||||
@ -214,43 +216,43 @@ struct gui_command {
|
||||
|
||||
struct gui_command_scissor {
|
||||
struct gui_command header;
|
||||
gui_float x, y;
|
||||
gui_float w, h;
|
||||
gui_short x, y;
|
||||
gui_ushort w, h;
|
||||
};
|
||||
|
||||
struct gui_command_line {
|
||||
struct gui_command header;
|
||||
gui_float begin[2];
|
||||
gui_float end[2];
|
||||
gui_short begin[2];
|
||||
gui_short end[2];
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_command_rect {
|
||||
struct gui_command header;
|
||||
gui_float x, y;
|
||||
gui_float w, h;
|
||||
gui_short x, y;
|
||||
gui_ushort w, h;
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_command_circle {
|
||||
struct gui_command header;
|
||||
gui_float x, y;
|
||||
gui_float w, h;
|
||||
gui_short x, y;
|
||||
gui_ushort w, h;
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_command_triangle {
|
||||
struct gui_command header;
|
||||
gui_float a[2];
|
||||
gui_float b[2];
|
||||
gui_float c[2];
|
||||
gui_short a[2];
|
||||
gui_short b[2];
|
||||
gui_short c[2];
|
||||
struct gui_color color;
|
||||
};
|
||||
|
||||
struct gui_command_text {
|
||||
struct gui_command header;
|
||||
gui_float x, y;
|
||||
gui_float w, h;
|
||||
gui_short x, y;
|
||||
gui_ushort w, h;
|
||||
gui_size length;
|
||||
struct gui_color bg;
|
||||
struct gui_color fg;
|
||||
|
Loading…
Reference in New Issue
Block a user