Gradients: release memory

This commit is contained in:
o9000 2016-10-04 17:57:03 +02:00
parent 1922cafa14
commit a5434a362b
12 changed files with 54 additions and 37 deletions

View file

@ -164,7 +164,7 @@ void init_battery_panel(void *p)
battery->area.has_mouse_press_effect = battery->area.has_mouse_over_effect;
if (battery_tooltip_enabled)
battery->area._get_tooltip_text = battery_get_tooltip;
init_area_gradients(&battery->area);
instantiate_area_gradients(&battery->area);
}
void battery_init_fonts()

View file

@ -196,7 +196,7 @@ void init_clock_panel(void *p)
clock->area.resize_needed = 1;
clock->area.on_screen = TRUE;
init_area_gradients(&clock->area);
instantiate_area_gradients(&clock->area);
if (time_tooltip_format) {
clock->area._get_tooltip_text = clock_get_tooltip;

View file

@ -182,7 +182,7 @@ void init_execp_panel(void *p)
execp->area.resize_needed = TRUE;
execp->area.on_screen = TRUE;
init_area_gradients(&execp->area);
instantiate_area_gradients(&execp->area);
if (!execp->backend->timer)
execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer);

View file

@ -108,7 +108,7 @@ void init_launcher_panel(void *p)
launcher->area.on_screen = TRUE;
panel_refresh = TRUE;
init_area_gradients(&launcher->area);
instantiate_area_gradients(&launcher->area);
launcher_load_themes(launcher);
launcher_load_icons(launcher);
@ -450,7 +450,7 @@ void launcher_load_icons(Launcher *launcher)
add_area(&launcherIcon->area, (Area *)launcher);
launcher->list_icons = g_slist_append(launcher->list_icons, launcherIcon);
launcher_reload_icon(launcher, launcherIcon);
init_area_gradients(&launcherIcon->area);
instantiate_area_gradients(&launcherIcon->area);
app = g_slist_next(app);
}
}

View file

@ -150,6 +150,9 @@ void cleanup_panel()
panel_window_name = NULL;
free(panels);
panels = NULL;
free_area(&panel_config.area);
if (backgrounds)
g_array_free(backgrounds, TRUE);
backgrounds = NULL;
@ -195,6 +198,7 @@ void init_panel()
panels = calloc(num_panels, sizeof(Panel));
for (int i = 0; i < num_panels; i++) {
memcpy(&panels[i], &panel_config, sizeof(Panel));
panels[i].area.gradients = g_list_copy(panel_config.area.gradients);
}
fprintf(stderr,
@ -219,7 +223,7 @@ void init_panel()
p->area._clear = panel_clear_background;
p->separator_list = NULL;
init_panel_size_and_position(p);
init_area_gradients(&p->area);
instantiate_area_gradients(&p->area);
// add children according to panel_items
for (int k = 0; k < strlen(panel_items_order); k++) {
if (panel_items_order[k] == 'L')

View file

@ -84,7 +84,7 @@ void init_separator_panel(void *p)
separator->area.on_screen = TRUE;
separator->area._resize = resize_separator;
separator->area._draw_foreground = draw_separator;
init_area_gradients(&separator->area);
instantiate_area_gradients(&separator->area);
}
}

View file

@ -123,7 +123,7 @@ void init_systray_panel(void *p)
show(&systray.area);
schedule_redraw(&systray.area);
refresh_systray = TRUE;
init_area_gradients(&systray.area);
instantiate_area_gradients(&systray.area);
}
gboolean resize_systray(void *obj)

View file

@ -595,9 +595,9 @@ void set_task_state(Task *task, TaskState state)
Task *task1 = g_ptr_array_index(task_buttons, i);
task1->current_state = state;
task1->area.bg = panels[0].g_task.background[state];
free_area_gradients(&task1->area);
task1->area.gradients = panels[0].g_task.gradient[state];
init_area_gradients(&task1->area);
free_area_gradient_instances(&task1->area);
task1->area.gradients = g_list_copy(panels[0].g_task.gradient[state]);
instantiate_area_gradients(&task1->area);
schedule_redraw(&task1->area);
if (state == TASK_ACTIVE && g_slist_find(urgent_list, task1))
del_urgent(task1);

View file

@ -116,6 +116,15 @@ void cleanup_taskbar()
urgent_list = NULL;
stop_timeout(urgent_timeout);
for (int state = 0; state < TASK_STATE_COUNT; state++) {
g_list_free(panel_config.g_task.gradient[state]);
}
for (int state = 0; state < TASKBAR_STATE_COUNT; state++) {
g_list_free(panel_config.g_taskbar.gradient[state]);
g_list_free(panel_config.g_taskbar.gradient_name[state]);
}
}
void init_taskbar()
@ -306,14 +315,14 @@ void init_taskbar_panel(void *p)
taskbar->desktop = j;
if (j == server.desktop) {
taskbar->area.bg = panel->g_taskbar.background[TASKBAR_ACTIVE];
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panel->g_taskbar.gradient[TASKBAR_ACTIVE];
init_area_gradients(&taskbar->area);
free_area_gradient_instances(&taskbar->area);
taskbar->area.gradients = g_list_copy(panel->g_taskbar.gradient[TASKBAR_ACTIVE]);
instantiate_area_gradients(&taskbar->area);
} else {
taskbar->area.bg = panel->g_taskbar.background[TASKBAR_NORMAL];
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panel->g_taskbar.gradient[TASKBAR_NORMAL];
init_area_gradients(&taskbar->area);
free_area_gradient_instances(&taskbar->area);
taskbar->area.gradients = g_list_copy(panel->g_taskbar.gradient[TASKBAR_NORMAL]);
instantiate_area_gradients(&taskbar->area);
}
}
@ -486,15 +495,15 @@ void update_all_taskbars_visibility()
void set_taskbar_state(Taskbar *taskbar, TaskbarState state)
{
taskbar->area.bg = panels[0].g_taskbar.background[state];
free_area_gradients(&taskbar->area);
taskbar->area.gradients = panels[0].g_taskbar.gradient[state];
init_area_gradients(&taskbar->area);
free_area_gradient_instances(&taskbar->area);
taskbar->area.gradients = g_list_copy(panels[0].g_taskbar.gradient[state]);
instantiate_area_gradients(&taskbar->area);
if (taskbarname_enabled) {
taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state];
free_area_gradients(&taskbar->bar_name.area);
taskbar->bar_name.area.gradients = panels[0].g_taskbar.gradient_name[state];
init_area_gradients(&taskbar->bar_name.area);
free_area_gradient_instances(&taskbar->bar_name.area);
taskbar->bar_name.area.gradients = g_list_copy(panels[0].g_taskbar.gradient_name[state]);
instantiate_area_gradients(&taskbar->bar_name.area);
}
update_taskbar_visibility(taskbar);

View file

@ -62,10 +62,10 @@ void init_taskbarname_panel(void *p)
taskbar->bar_name.area.has_mouse_press_effect = panel_config.mouse_effects;
if (j == server.desktop) {
taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_ACTIVE];
taskbar->bar_name.area.gradients = panel->g_taskbar.gradient_name[TASKBAR_ACTIVE];
taskbar->bar_name.area.gradients = g_list_copy(panel->g_taskbar.gradient_name[TASKBAR_ACTIVE]);
} else {
taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_NORMAL];
taskbar->bar_name.area.gradients = panel->g_taskbar.gradient_name[TASKBAR_NORMAL];
taskbar->bar_name.area.gradients = g_list_copy(panel->g_taskbar.gradient_name[TASKBAR_NORMAL]);
}
// use desktop number if name is missing
@ -78,7 +78,7 @@ void init_taskbarname_panel(void *p)
// append the name at the beginning of taskbar
taskbar->area.children = g_list_append(taskbar->area.children, &taskbar->bar_name);
init_area_gradients(&taskbar->bar_name.area);
instantiate_area_gradients(&taskbar->bar_name.area);
}
for (l = list; l; l = l->next)

View file

@ -536,7 +536,7 @@ void remove_area(Area *a)
Area *area = (Area *)a;
Area *parent = (Area *)area->parent;
free_area_gradients(a);
free_area_gradient_instances(a);
if (parent) {
parent->children = g_list_remove(parent->children, area);
@ -589,7 +589,11 @@ void free_area(Area *a)
if (mouse_over_area == a) {
mouse_over_area = NULL;
}
free_area_gradients(a);
free_area_gradient_instances(a);
if (debug_gradients)
fprintf(stderr, YELLOW "freeing gradient list %p" RESET "\n", (void*)a->gradients);
g_list_free(a->gradients);
a->gradients = NULL;
}
void mouse_over(Area *area, int pressed)
@ -887,7 +891,7 @@ void instantiate_gradient_point(GradientInstance *gi, ControlPoint *control)
instantiate_gradient_offsets(gi, control->offsets_r);
}
void free_gradient_point(GradientInstance *gi, ControlPoint *control)
void free_gradient_instance_point(GradientInstance *gi, ControlPoint *control)
{
free_gradient_offsets(gi, &control->offsets_x);
free_gradient_offsets(gi, &control->offsets_y);
@ -904,18 +908,18 @@ void instantiate_gradient(Area *area, GradientClass *g, GradientInstance *gi)
instantiate_gradient_point(gi, &g->to);
}
void free_gradient(GradientInstance *gi)
void free_gradient_instance(GradientInstance *gi)
{
if (gi->pattern) {
cairo_pattern_destroy(gi->pattern);
gi->pattern = NULL;
}
free_gradient_point(gi, &gi->gradient_class->from);
free_gradient_point(gi, &gi->gradient_class->to);
free_gradient_instance_point(gi, &gi->gradient_class->from);
free_gradient_instance_point(gi, &gi->gradient_class->to);
gi->gradient_class = NULL;
}
void init_area_gradients(Area *area)
void instantiate_area_gradients(Area *area)
{
g_assert_null(area->gradient_instances);
if (debug_gradients)
@ -928,13 +932,13 @@ void init_area_gradients(Area *area)
}
}
void free_area_gradients(Area *area)
void free_area_gradient_instances(Area *area)
{
if (debug_gradients)
fprintf(stderr, "Freeing gradients for area %s\n", area->name);
for (GList *l = area->gradient_instances; l; l = l->next) {
GradientInstance *gi = (GradientInstance *)l->data;
free_gradient(gi);
free_gradient_instance(gi);
}
g_list_free_full(area->gradient_instances, free);
area->gradient_instances = NULL;

View file

@ -311,8 +311,8 @@ gboolean area_is_under_mouse(void *obj, int x, int y);
// they are outside the drawing area of the button.
gboolean full_width_area_is_under_mouse(void *obj, int x, int y);
void init_area_gradients(Area *area);
void free_area_gradients(Area *area);
void instantiate_area_gradients(Area *area);
void free_area_gradient_instances(Area *area);
void area_dump_geometry(Area *area, int indent);