Commit 2fd8cde8 authored by Christoffer Ackelman's avatar Christoffer Ackelman

GTK: Small optimization: changed the redraw timer to a timeout, if the window...

GTK: Small optimization: changed the redraw timer to a timeout, if the window has not been redrawn 40 ms after it was marked as dirty, then force a redraw.
parent 88810c12
...@@ -336,8 +336,7 @@ FlowDrawGtk::~FlowDrawGtk() ...@@ -336,8 +336,7 @@ FlowDrawGtk::~FlowDrawGtk()
{ {
closing_down = 1; closing_down = 1;
if (redraw_timer) cancel_redraw_timer();
g_source_remove(redraw_timer);
ctx->set_nodraw(); ctx->set_nodraw();
delete ctx; delete ctx;
...@@ -466,8 +465,6 @@ FlowDrawGtk::FlowDrawGtk(GtkWidget* x_toplevel, void** flow_ctx, ...@@ -466,8 +465,6 @@ FlowDrawGtk::FlowDrawGtk(GtkWidget* x_toplevel, void** flow_ctx,
flow_create_cursor(this); flow_create_cursor(this);
init_proc(toplevel, ctx, client_data); init_proc(toplevel, ctx, client_data);
redraw_timer = g_timeout_add(40, redraw_timer_cb, this);
} }
void FlowDrawGtk::init_nav(GtkWidget* nav_widget, void* flow_ctx) void FlowDrawGtk::init_nav(GtkWidget* nav_widget, void* flow_ctx)
...@@ -1298,8 +1295,22 @@ static void event_timer(FlowCtx* ctx, int time_ms) ...@@ -1298,8 +1295,22 @@ static void event_timer(FlowCtx* ctx, int time_ms)
static gboolean redraw_timer_cb(void* data) { static gboolean redraw_timer_cb(void* data) {
FlowDrawGtk* draw_ctx = (FlowDrawGtk*)data; FlowDrawGtk* draw_ctx = (FlowDrawGtk*)data;
draw_ctx->redraw_timer = 0;
draw_ctx->ctx->redraw_if_dirty(); draw_ctx->ctx->redraw_if_dirty();
return TRUE; return FALSE;
}
void FlowDrawGtk::cancel_redraw_timer()
{
if (redraw_timer) {
g_source_remove(redraw_timer);
redraw_timer = 0;
}
}
void FlowDrawGtk::start_redraw_timer()
{
redraw_timer = g_timeout_add(40, redraw_timer_cb, this);
} }
void FlowDrawGtk::set_timer(FlowCtx* ctx, int time_ms, void FlowDrawGtk::set_timer(FlowCtx* ctx, int time_ms,
......
...@@ -93,6 +93,8 @@ public: ...@@ -93,6 +93,8 @@ public:
int begin(DrawWind *wind); int begin(DrawWind *wind);
void end(); void end();
void start_redraw_timer();
void cancel_redraw_timer();
void rect(int x, int y, int width, int height, flow_eDrawType gc_type, void rect(int x, int y, int width, int height, flow_eDrawType gc_type,
int fill, int idx, int highlight = 0, int dimmed = 0); int fill, int idx, int highlight = 0, int dimmed = 0);
......
...@@ -522,6 +522,7 @@ void FlowCtx::get_borders() ...@@ -522,6 +522,7 @@ void FlowCtx::get_borders()
void FlowCtx::set_dirty() void FlowCtx::set_dirty()
{ {
is_dirty = 1; is_dirty = 1;
fdraw->start_redraw_timer();
} }
void FlowCtx::redraw_if_dirty() void FlowCtx::redraw_if_dirty()
...@@ -531,6 +532,7 @@ void FlowCtx::redraw_if_dirty() ...@@ -531,6 +532,7 @@ void FlowCtx::redraw_if_dirty()
} }
if (is_dirty) { if (is_dirty) {
is_dirty = 0; is_dirty = 0;
fdraw->cancel_redraw_timer();
fdraw->begin(mw); fdraw->begin(mw);
fdraw->clear(); fdraw->clear();
draw(0, 0, window_width, window_height); draw(0, 0, window_width, window_height);
......
...@@ -59,6 +59,8 @@ public: ...@@ -59,6 +59,8 @@ public:
virtual int begin(DrawWind* wind); virtual int begin(DrawWind* wind);
virtual void end(); virtual void end();
virtual void start_redraw_timer() {}
virtual void cancel_redraw_timer() {}
virtual void rect(int x, int y, int width, int height, flow_eDrawType gc_type, virtual void rect(int x, int y, int width, int height, flow_eDrawType gc_type,
int fill, int idx, int highlight = 0, int dimmed = 0) = 0; int fill, int idx, int highlight = 0, int dimmed = 0) = 0;
......
...@@ -533,8 +533,7 @@ GlowDrawGtk::~GlowDrawGtk() ...@@ -533,8 +533,7 @@ GlowDrawGtk::~GlowDrawGtk()
{ {
closing_down = 1; closing_down = 1;
if (redraw_timer) cancel_redraw_timer();
g_source_remove(redraw_timer);
ctx->set_nodraw(); ctx->set_nodraw();
if (ctx->type() == glow_eCtxType_Grow) if (ctx->type() == glow_eCtxType_Grow)
...@@ -622,8 +621,6 @@ GlowDrawGtk::GlowDrawGtk(GtkWidget* toplevel, void** glow_ctx, ...@@ -622,8 +621,6 @@ GlowDrawGtk::GlowDrawGtk(GtkWidget* toplevel, void** glow_ctx,
get_window_size(ctx->mw, &ctx->mw->window_width, &ctx->mw->window_height); get_window_size(ctx->mw, &ctx->mw->window_width, &ctx->mw->window_height);
create_buffer(&m_wind); create_buffer(&m_wind);
init_proc(toplevel, ctx, client_data); init_proc(toplevel, ctx, client_data);
redraw_timer = g_timeout_add(40, redraw_timer_cb, this);
} }
void GlowDrawGtk::event_handler(GdkEvent event) void GlowDrawGtk::event_handler(GdkEvent event)
...@@ -1641,8 +1638,22 @@ static void event_timer(GlowDrawGtk* draw_ctx, int time_ms) ...@@ -1641,8 +1638,22 @@ static void event_timer(GlowDrawGtk* draw_ctx, int time_ms)
static gboolean redraw_timer_cb(void* data) { static gboolean redraw_timer_cb(void* data) {
GlowDrawGtk* draw_ctx = (GlowDrawGtk*)data; GlowDrawGtk* draw_ctx = (GlowDrawGtk*)data;
draw_ctx->redraw_timer = 0;
draw_ctx->ctx->redraw_if_dirty(); draw_ctx->ctx->redraw_if_dirty();
return TRUE; return FALSE;
}
void GlowDrawGtk::cancel_redraw_timer()
{
if (redraw_timer) {
g_source_remove(redraw_timer);
redraw_timer = 0;
}
}
void GlowDrawGtk::start_redraw_timer()
{
redraw_timer = g_timeout_add(40, redraw_timer_cb, this);
} }
void GlowDrawGtk::set_timer( void GlowDrawGtk::set_timer(
......
...@@ -120,6 +120,8 @@ public: ...@@ -120,6 +120,8 @@ public:
int begin(DrawWind* wind); int begin(DrawWind* wind);
void end(bool flush = true); void end(bool flush = true);
void start_redraw_timer();
void cancel_redraw_timer();
void get_window_size(DrawWind* w, int* width, int* height); void get_window_size(DrawWind* w, int* width, int* height);
void set_window_size(DrawWind* w, int width, int height); void set_window_size(DrawWind* w, int width, int height);
......
...@@ -663,6 +663,7 @@ void GlowCtx::get_borders() ...@@ -663,6 +663,7 @@ void GlowCtx::get_borders()
void GlowCtx::set_dirty() void GlowCtx::set_dirty()
{ {
is_dirty = 1; is_dirty = 1;
gdraw->start_redraw_timer();
} }
void GlowCtx::redraw_if_dirty() void GlowCtx::redraw_if_dirty()
...@@ -672,6 +673,7 @@ void GlowCtx::redraw_if_dirty() ...@@ -672,6 +673,7 @@ void GlowCtx::redraw_if_dirty()
} }
if (is_dirty) { if (is_dirty) {
is_dirty = 0; is_dirty = 0;
gdraw->cancel_redraw_timer();
gdraw->begin(mw); gdraw->begin(mw);
gdraw->clear(); gdraw->clear();
draw(mw, 0, 0, mw->window_width, mw->window_height); draw(mw, 0, 0, mw->window_width, mw->window_height);
......
...@@ -81,6 +81,8 @@ public: ...@@ -81,6 +81,8 @@ public:
virtual int begin(DrawWind* wind) = 0; virtual int begin(DrawWind* wind) = 0;
virtual void end(bool flush = true) = 0; virtual void end(bool flush = true) = 0;
virtual void start_redraw_timer() {}
virtual void cancel_redraw_timer() {}
virtual void rect(int x, int y, int width, int height, glow_eDrawType gc_type, virtual void rect(int x, int y, int width, int height, glow_eDrawType gc_type,
int fill, int idx, int highlight = 0) = 0; int fill, int idx, int highlight = 0) = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment