2019-06-17 22:56:36 +02:00
|
|
|
/*
|
|
|
|
* GDSII-Converter
|
|
|
|
* Copyright (C) 2019 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of GDSII-Converter.
|
|
|
|
*
|
|
|
|
* GDSII-Converter is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-10-25 21:16:31 +02:00
|
|
|
* @file gds-output-renderer.c
|
|
|
|
* @brief Base GObject class for output renderers
|
|
|
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*/
|
2019-06-17 22:56:36 +02:00
|
|
|
|
|
|
|
/** @addtogroup GdsOutputRenderer
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gds-render/output-renderers/gds-output-renderer.h>
|
2019-12-12 21:22:14 +01:00
|
|
|
#include <glib/gi18n.h>
|
2019-06-17 22:56:36 +02:00
|
|
|
|
2019-08-19 19:54:53 +02:00
|
|
|
struct renderer_params {
|
|
|
|
struct gds_cell *cell;
|
|
|
|
double scale;
|
|
|
|
};
|
|
|
|
|
2019-08-22 18:55:14 +02:00
|
|
|
struct idle_function_params {
|
|
|
|
GMutex message_lock;
|
|
|
|
char *status_message;
|
|
|
|
};
|
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
typedef struct {
|
2019-06-21 21:41:31 +02:00
|
|
|
gchar *output_file;
|
|
|
|
LayerSettings *layer_settings;
|
2019-08-19 19:54:53 +02:00
|
|
|
GMutex settings_lock;
|
|
|
|
gboolean mutex_init_status;
|
2019-08-19 20:39:25 +02:00
|
|
|
GTask *task;
|
2019-08-22 18:55:14 +02:00
|
|
|
GMainContext *main_context;
|
2019-08-19 19:54:53 +02:00
|
|
|
struct renderer_params async_params;
|
2019-08-22 18:55:14 +02:00
|
|
|
struct idle_function_params idle_function_parameters;
|
2019-06-21 21:41:31 +02:00
|
|
|
gpointer padding[11];
|
2019-06-17 22:56:36 +02:00
|
|
|
} GdsOutputRendererPrivate;
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
enum {
|
|
|
|
PROP_OUTPUT_FILE = 1,
|
|
|
|
PROP_LAYER_SETTINGS,
|
|
|
|
N_PROPERTIES
|
|
|
|
};
|
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE(GdsOutputRenderer, gds_output_renderer, G_TYPE_OBJECT)
|
|
|
|
|
2019-08-22 18:55:14 +02:00
|
|
|
enum gds_output_renderer_signal_ids {ASYNC_FINISHED = 0, ASYNC_PROGRESS_CHANGED, GDS_OUTPUT_RENDERER_SIGNAL_COUNT};
|
2019-08-19 19:54:53 +02:00
|
|
|
static guint gds_output_renderer_signals[GDS_OUTPUT_RENDERER_SIGNAL_COUNT];
|
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
static int gds_output_renderer_render_dummy(GdsOutputRenderer *renderer,
|
|
|
|
struct gds_cell *cell,
|
|
|
|
double scale)
|
|
|
|
{
|
|
|
|
(void)renderer;
|
|
|
|
(void)cell;
|
|
|
|
(void)scale;
|
|
|
|
|
2019-12-12 21:22:14 +01:00
|
|
|
g_warning(_("Output renderer does not define a render_output function!"));
|
2019-06-17 22:56:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
static void gds_output_renderer_dispose(GObject *self_obj)
|
|
|
|
{
|
|
|
|
GdsOutputRenderer *renderer = GDS_RENDER_OUTPUT_RENDERER(self_obj);
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
2019-08-19 19:54:53 +02:00
|
|
|
|
|
|
|
if (priv->mutex_init_status) {
|
|
|
|
/* Try locking the mutex, to test if it's free */
|
|
|
|
g_mutex_lock(&priv->settings_lock);
|
|
|
|
g_mutex_unlock(&priv->settings_lock);
|
|
|
|
g_mutex_clear(&priv->settings_lock);
|
2019-08-22 18:55:14 +02:00
|
|
|
|
|
|
|
g_mutex_lock(&priv->idle_function_parameters.message_lock);
|
|
|
|
g_mutex_unlock(&priv->idle_function_parameters.message_lock);
|
|
|
|
g_mutex_clear(&priv->idle_function_parameters.message_lock);
|
|
|
|
|
2019-08-19 19:54:53 +02:00
|
|
|
priv->mutex_init_status = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
g_clear_object(&priv->task);
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
if (priv->output_file)
|
|
|
|
g_free(priv->output_file);
|
|
|
|
|
2020-04-03 20:53:32 +02:00
|
|
|
if (priv->idle_function_parameters.status_message) {
|
|
|
|
g_free(priv->idle_function_parameters.status_message);
|
|
|
|
priv->idle_function_parameters.status_message = NULL;
|
|
|
|
}
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
g_clear_object(&priv->layer_settings);
|
|
|
|
|
|
|
|
/* Chain up to parent class */
|
|
|
|
G_OBJECT_CLASS(gds_output_renderer_parent_class)->dispose(self_obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gds_output_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdsOutputRenderer *self = GDS_RENDER_OUTPUT_RENDERER(obj);
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(self);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_OUTPUT_FILE:
|
|
|
|
g_value_set_string(value, priv->output_file);
|
|
|
|
break;
|
|
|
|
case PROP_LAYER_SETTINGS:
|
|
|
|
g_value_set_object(value, priv->layer_settings);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gds_output_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdsOutputRenderer *self = GDS_RENDER_OUTPUT_RENDERER(obj);
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(self);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_OUTPUT_FILE:
|
2019-08-19 19:54:53 +02:00
|
|
|
g_mutex_lock(&priv->settings_lock);
|
2019-06-21 21:41:31 +02:00
|
|
|
if (priv->output_file)
|
|
|
|
g_free(priv->output_file);
|
|
|
|
priv->output_file = g_strdup(g_value_get_string(value));
|
2019-08-19 19:54:53 +02:00
|
|
|
g_mutex_unlock(&priv->settings_lock);
|
2019-06-21 21:41:31 +02:00
|
|
|
break;
|
|
|
|
case PROP_LAYER_SETTINGS:
|
2019-08-19 19:54:53 +02:00
|
|
|
g_mutex_lock(&priv->settings_lock);
|
2019-06-21 21:41:31 +02:00
|
|
|
g_clear_object(&priv->layer_settings);
|
|
|
|
priv->layer_settings = g_value_get_object(value);
|
|
|
|
g_object_ref(priv->layer_settings);
|
2019-08-19 19:54:53 +02:00
|
|
|
g_mutex_unlock(&priv->settings_lock);
|
2019-06-21 21:41:31 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GParamSpec *gds_output_renderer_properties[N_PROPERTIES] = {NULL};
|
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
static void gds_output_renderer_class_init(GdsOutputRendererClass *klass)
|
|
|
|
{
|
2019-06-21 21:41:31 +02:00
|
|
|
GObjectClass *oclass = G_OBJECT_CLASS(klass);
|
2019-08-22 18:55:14 +02:00
|
|
|
GType progress_changed_param_types[1] = {G_TYPE_POINTER};
|
2019-06-21 21:41:31 +02:00
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
klass->render_output = gds_output_renderer_render_dummy;
|
2019-06-21 21:41:31 +02:00
|
|
|
|
|
|
|
oclass->dispose = gds_output_renderer_dispose;
|
|
|
|
oclass->set_property = gds_output_renderer_set_property;
|
|
|
|
oclass->get_property = gds_output_renderer_get_property;
|
|
|
|
|
|
|
|
/* Setup properties */
|
|
|
|
gds_output_renderer_properties[PROP_OUTPUT_FILE] =
|
2019-12-12 21:22:14 +01:00
|
|
|
g_param_spec_string(N_("output-file"), N_("output file"), N_("Output file for renderer"),
|
2019-06-21 21:41:31 +02:00
|
|
|
NULL, G_PARAM_READWRITE);
|
|
|
|
gds_output_renderer_properties[PROP_LAYER_SETTINGS] =
|
2019-12-12 21:22:14 +01:00
|
|
|
g_param_spec_object(N_("layer-settings"), N_("Layer Settings object"),
|
|
|
|
N_("Object containing the layer rendering information"),
|
2019-06-21 21:41:31 +02:00
|
|
|
GDS_RENDER_TYPE_LAYER_SETTINGS, G_PARAM_READWRITE);
|
|
|
|
g_object_class_install_properties(oclass, N_PROPERTIES, gds_output_renderer_properties);
|
2019-08-19 19:54:53 +02:00
|
|
|
|
|
|
|
/* Setup output signals */
|
2019-08-19 20:39:25 +02:00
|
|
|
gds_output_renderer_signals[ASYNC_FINISHED] =
|
2019-12-12 21:22:14 +01:00
|
|
|
g_signal_newv(N_("async-finished"), GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
2019-08-19 20:39:25 +02:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
0,
|
|
|
|
NULL);
|
2019-08-22 18:55:14 +02:00
|
|
|
gds_output_renderer_signals[ASYNC_PROGRESS_CHANGED] =
|
2019-12-12 21:22:14 +01:00
|
|
|
g_signal_newv(N_("progress-changed"), GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
2019-08-19 19:54:53 +02:00
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE,
|
2019-08-22 18:55:14 +02:00
|
|
|
1,
|
|
|
|
progress_changed_param_types);
|
2019-06-17 22:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void gds_output_renderer_init(GdsOutputRenderer *self)
|
|
|
|
{
|
2019-06-21 21:41:31 +02:00
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(self);
|
2019-06-17 22:56:36 +02:00
|
|
|
|
2019-08-19 19:54:53 +02:00
|
|
|
priv->layer_settings = NULL;
|
2019-06-21 21:41:31 +02:00
|
|
|
priv->output_file = NULL;
|
2019-08-19 20:39:25 +02:00
|
|
|
priv->task = NULL;
|
2019-08-19 19:54:53 +02:00
|
|
|
priv->mutex_init_status = TRUE;
|
2019-08-22 18:55:14 +02:00
|
|
|
priv->main_context = NULL;
|
|
|
|
priv->idle_function_parameters.status_message = NULL;
|
2019-08-19 19:54:53 +02:00
|
|
|
g_mutex_init(&priv->settings_lock);
|
2019-08-22 18:55:14 +02:00
|
|
|
g_mutex_init(&priv->idle_function_parameters.message_lock);
|
2019-06-17 22:56:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
GdsOutputRenderer *gds_output_renderer_new()
|
|
|
|
{
|
|
|
|
return GDS_RENDER_OUTPUT_RENDERER(g_object_new(GDS_RENDER_TYPE_OUTPUT_RENDERER, NULL));
|
|
|
|
}
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
GdsOutputRenderer *gds_output_renderer_new_with_props(const char *output_file, LayerSettings *layer_settings)
|
|
|
|
{
|
|
|
|
return GDS_RENDER_OUTPUT_RENDERER(g_object_new(GDS_RENDER_TYPE_OUTPUT_RENDERER,
|
2019-12-12 21:22:14 +01:00
|
|
|
N_("layer-settings"), layer_settings,
|
|
|
|
N_("output-file"), output_file,
|
2019-06-21 21:41:31 +02:00
|
|
|
NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
void gds_output_renderer_set_output_file(GdsOutputRenderer *renderer, const gchar *file_name)
|
|
|
|
{
|
|
|
|
g_return_if_fail(GDS_RENDER_IS_OUTPUT_RENDERER(renderer));
|
|
|
|
|
|
|
|
/* Check if the filename is actually filled */
|
|
|
|
if (!file_name || !file_name[0])
|
|
|
|
return;
|
2019-12-12 21:22:14 +01:00
|
|
|
g_object_set(renderer, N_("output-file"), file_name, NULL);
|
2019-06-21 21:41:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *gds_output_renderer_get_output_file(GdsOutputRenderer *renderer)
|
|
|
|
{
|
|
|
|
const char *file = NULL;
|
|
|
|
|
2019-12-12 21:22:14 +01:00
|
|
|
g_object_get(renderer, N_("output-file"), &file, NULL);
|
2019-06-21 21:41:31 +02:00
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2019-08-19 19:54:53 +02:00
|
|
|
LayerSettings *gds_output_renderer_get_and_ref_layer_settings(GdsOutputRenderer *renderer)
|
2019-06-21 21:41:31 +02:00
|
|
|
{
|
|
|
|
LayerSettings *ret = NULL;
|
2019-08-19 19:54:53 +02:00
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
|
|
|
|
|
|
|
/* Acquire settings lock */
|
|
|
|
g_mutex_lock(&priv->settings_lock);
|
2019-06-21 21:41:31 +02:00
|
|
|
|
2019-08-23 21:40:21 +02:00
|
|
|
/* This function seems to already reference the LayerSettings object */
|
2019-12-12 21:22:14 +01:00
|
|
|
g_object_get(renderer, N_("layer-settings"), &ret, NULL);
|
2019-08-19 19:54:53 +02:00
|
|
|
|
|
|
|
/* It is now safe to clear the lock */
|
|
|
|
g_mutex_unlock(&priv->settings_lock);
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gds_output_renderer_set_layer_settings(GdsOutputRenderer *renderer, LayerSettings *settings)
|
|
|
|
{
|
|
|
|
g_return_if_fail(GDS_RENDER_IS_LAYER_SETTINGS(settings));
|
|
|
|
|
2019-12-12 21:22:14 +01:00
|
|
|
g_object_set(renderer, N_("layer-settings"), settings, NULL);
|
2019-06-21 21:41:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int gds_output_renderer_render_output(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
|
2019-06-17 22:56:36 +02:00
|
|
|
{
|
2019-08-19 19:54:53 +02:00
|
|
|
int ret;
|
2019-06-17 22:56:36 +02:00
|
|
|
GdsOutputRendererClass *klass;
|
2019-06-21 21:41:31 +02:00
|
|
|
GdsOutputRendererPrivate *priv = gds_output_renderer_get_instance_private(renderer);
|
2019-06-17 22:56:36 +02:00
|
|
|
|
|
|
|
if (GDS_RENDER_IS_OUTPUT_RENDERER(renderer) == FALSE) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_error(_("Output Renderer not valid."));
|
2019-06-17 22:56:36 +02:00
|
|
|
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-06-21 21:41:31 +02:00
|
|
|
if (!priv->output_file || !priv->output_file[0]) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_error(_("No/invalid output file set."));
|
2019-06-21 21:41:31 +02:00
|
|
|
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->layer_settings) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_error(_("No layer specification supplied."));
|
2019-06-21 21:41:31 +02:00
|
|
|
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cell) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_error(_("Output renderer called without cell to render."));
|
2019-06-17 22:56:36 +02:00
|
|
|
return GDS_OUTPUT_RENDERER_PARAM_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass = GDS_RENDER_OUTPUT_RENDERER_GET_CLASS(renderer);
|
|
|
|
if (klass->render_output == NULL) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_critical(_("Output Renderer: Rendering function broken. This is a bug."));
|
2019-06-17 22:56:36 +02:00
|
|
|
return GDS_OUTPUT_RENDERER_GEN_ERR;
|
|
|
|
}
|
|
|
|
|
2019-08-19 19:54:53 +02:00
|
|
|
ret = klass->render_output(renderer, cell, scale);
|
|
|
|
|
|
|
|
return ret;
|
2019-06-17 22:56:36 +02:00
|
|
|
}
|
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
static void gds_output_renderer_async_wrapper(GTask *task,
|
|
|
|
gpointer source_object,
|
|
|
|
gpointer task_data,
|
|
|
|
GCancellable *cancellable)
|
2019-08-19 19:54:53 +02:00
|
|
|
{
|
|
|
|
GdsOutputRenderer *renderer;
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
int ret;
|
2019-08-26 20:01:32 +02:00
|
|
|
(void)task_data;
|
|
|
|
(void)cancellable;
|
2019-08-19 19:54:53 +02:00
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
renderer = GDS_RENDER_OUTPUT_RENDERER(source_object);
|
2019-08-19 19:54:53 +02:00
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
2019-08-19 20:39:25 +02:00
|
|
|
if (!priv) {
|
|
|
|
ret = -1000;
|
|
|
|
goto ret_from_task;
|
|
|
|
}
|
2019-10-25 21:16:31 +02:00
|
|
|
if (!priv->mutex_init_status) {
|
2019-08-19 20:39:25 +02:00
|
|
|
ret = -1001;
|
|
|
|
goto ret_from_task;
|
|
|
|
}
|
2019-08-19 19:54:53 +02:00
|
|
|
|
|
|
|
ret = gds_output_renderer_render_output(renderer, priv->async_params.cell, priv->async_params.scale);
|
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
ret_from_task:
|
|
|
|
g_task_return_int(task, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gds_output_renderer_async_finished(GObject *src_obj, GAsyncResult *res, gpointer user_data)
|
|
|
|
{
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
(void)user_data;
|
|
|
|
(void)res; /* Will hopefully be destroyed later */
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(GDS_RENDER_OUTPUT_RENDERER(src_obj));
|
|
|
|
|
2019-08-22 18:55:14 +02:00
|
|
|
priv->main_context = NULL;
|
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
g_signal_emit(src_obj, gds_output_renderer_signals[ASYNC_FINISHED], 0);
|
|
|
|
g_clear_object(&priv->task);
|
2019-08-22 18:55:14 +02:00
|
|
|
|
|
|
|
/* Clear reference set in gds_output_renderer_render_output_async() */
|
|
|
|
g_object_unref(src_obj);
|
2019-08-19 19:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int gds_output_renderer_render_output_async(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
|
|
|
|
{
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
2019-08-19 20:39:25 +02:00
|
|
|
if (priv->task) {
|
2019-12-12 21:22:14 +01:00
|
|
|
g_warning(_("Renderer already started asynchronously"));
|
2019-08-19 20:39:25 +02:00
|
|
|
return -2000;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->task = g_task_new(renderer, NULL, gds_output_renderer_async_finished, NULL);
|
2019-11-19 01:33:44 +01:00
|
|
|
|
|
|
|
/* This function is not available on current debian distros. */
|
|
|
|
/* g_task_set_name(priv->task, "Rendering Thread"); */
|
2019-08-23 21:50:16 +02:00
|
|
|
|
2019-08-19 20:39:25 +02:00
|
|
|
g_mutex_lock(&priv->settings_lock);
|
|
|
|
priv->async_params.cell = cell;
|
|
|
|
priv->async_params.scale = scale;
|
2019-08-22 18:55:14 +02:00
|
|
|
priv->main_context = g_main_context_default();
|
2019-08-19 20:39:25 +02:00
|
|
|
g_mutex_unlock(&priv->settings_lock);
|
|
|
|
|
2019-08-22 18:55:14 +02:00
|
|
|
/* Self reference. This could end up being nasty... */
|
|
|
|
g_object_ref(renderer);
|
|
|
|
|
|
|
|
/* Do the magic */
|
2019-08-19 20:39:25 +02:00
|
|
|
g_task_run_in_thread(priv->task, gds_output_renderer_async_wrapper);
|
2019-08-19 19:54:53 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-06-17 22:56:36 +02:00
|
|
|
|
2019-08-22 18:55:14 +02:00
|
|
|
static gboolean idle_event_processor_callback(gpointer user_data)
|
|
|
|
{
|
|
|
|
GdsOutputRenderer *renderer;
|
|
|
|
GdsOutputRendererPrivate *priv;
|
|
|
|
char *status_message;
|
|
|
|
|
|
|
|
/* If the rendering is finished before the mainloop gets to this point
|
|
|
|
* the renderer is already disposed. Catch this!
|
|
|
|
*/
|
|
|
|
if (!GDS_RENDER_IS_OUTPUT_RENDERER(user_data))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
renderer = GDS_RENDER_OUTPUT_RENDERER(user_data);
|
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
|
|
|
|
|
|
|
if (g_mutex_trylock(&priv->idle_function_parameters.message_lock)) {
|
2019-08-24 13:45:16 +02:00
|
|
|
status_message = priv->idle_function_parameters.status_message;
|
2019-08-22 18:55:14 +02:00
|
|
|
g_signal_emit(renderer, gds_output_renderer_signals[ASYNC_PROGRESS_CHANGED], 0, status_message);
|
|
|
|
g_free(priv->idle_function_parameters.status_message);
|
|
|
|
priv->idle_function_parameters.status_message = NULL;
|
|
|
|
g_mutex_unlock(&priv->idle_function_parameters.message_lock);
|
|
|
|
} else {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:44:30 +02:00
|
|
|
void gds_output_renderer_update_async_progress(GdsOutputRenderer *renderer, const char *status)
|
2019-08-22 18:55:14 +02:00
|
|
|
{
|
|
|
|
GSource *idle_event_processor;
|
|
|
|
GdsOutputRendererPrivate *priv;
|
2019-08-22 19:31:47 +02:00
|
|
|
gboolean skip_source = FALSE;
|
2019-08-22 18:55:14 +02:00
|
|
|
|
|
|
|
g_return_if_fail(GDS_RENDER_IS_OUTPUT_RENDERER(renderer));
|
|
|
|
if (!status)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv = gds_output_renderer_get_instance_private(renderer);
|
|
|
|
|
|
|
|
/* If rendering is not async */
|
|
|
|
if (!priv->main_context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_mutex_lock(&priv->idle_function_parameters.message_lock);
|
2019-08-22 19:31:47 +02:00
|
|
|
if (priv->idle_function_parameters.status_message) {
|
2019-08-22 18:55:14 +02:00
|
|
|
g_free(priv->idle_function_parameters.status_message);
|
|
|
|
|
2019-08-22 19:31:47 +02:00
|
|
|
/* Skip adding new idle source because there's already an active one */
|
|
|
|
skip_source = TRUE;
|
|
|
|
}
|
2019-08-22 18:55:14 +02:00
|
|
|
priv->idle_function_parameters.status_message = g_strdup(status);
|
|
|
|
g_mutex_unlock(&priv->idle_function_parameters.message_lock);
|
|
|
|
|
2019-08-22 19:31:47 +02:00
|
|
|
if (!skip_source) {
|
|
|
|
idle_event_processor = g_idle_source_new();
|
|
|
|
g_source_set_callback(idle_event_processor, idle_event_processor_callback, (gpointer)renderer, NULL);
|
|
|
|
g_source_attach(idle_event_processor, priv->main_context);
|
|
|
|
}
|
2019-08-22 18:55:14 +02:00
|
|
|
}
|
|
|
|
|
2019-06-17 22:56:36 +02:00
|
|
|
/** @} */
|