summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-06-13 21:02:04 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-06-13 21:02:04 +0800
commit5d2383c2fa30c374ad28feda0100d058a510bdf8 (patch)
tree22608f5bd12fe3c717dfca4d6eb98867c14a902a
parent1d2841bfff3f7508ddb563ec8b7bbb091106e4a5 (diff)
downloadcompositionkit-5d2383c2fa30c374ad28feda0100d058a510bdf8.tar.gz
compositionkit-5d2383c2fa30c374ad28feda0100d058a510bdf8.tar.bz2
Add the ability to add/remove uniforms from shaders
-rw-r--r--ckservice/ckservice-main.c236
1 files changed, 236 insertions, 0 deletions
diff --git a/ckservice/ckservice-main.c b/ckservice/ckservice-main.c
index c01b0bd..6538909 100644
--- a/ckservice/ckservice-main.c
+++ b/ckservice/ckservice-main.c
@@ -147,6 +147,26 @@ find_surface_by_id (gconstpointer a,
}
static gint
+find_attribute_by_name (gconstpointer a,
+ gconstpointer b)
+{
+ CompositionKitAttribute *cka = (CompositionKitAttribute *) a;
+ gchar *req_name = (gchar *) b;
+
+ return g_strcmp0 (cka->name, req_name);
+}
+
+static gint
+find_uniform_by_name (gconstpointer a,
+ gconstpointer b)
+{
+ CompositionKitUniform *cku = (CompositionKitUniform *) a;
+ gchar *req_name = (gchar *) b;
+
+ return g_strcmp0 (cku->name, req_name);
+}
+
+static gint
find_shader_by_name (gconstpointer a,
gconstpointer b)
{
@@ -445,6 +465,196 @@ handle_method_call (GDBusConnection *connection,
if (string)
g_free (string);
}
+ else if (g_strcmp0 (method_name, "AddUniform") == 0)
+ {
+ guint32 id;
+ gchar *shader_name;
+ gchar *uniform_name;
+ gchar *uniform_type;
+ GList *iter, *siter;
+
+ g_variant_get (parameters, "(sssi)", &uniform_name, &uniform_type, &shader_name, &id);
+
+ iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
+
+ if (iter)
+ {
+ CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
+
+ siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
+
+ if (siter)
+ {
+ CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
+ CompositionKitUniform *cku = new_uniform (uniform_name, uniform_type);
+ cksh->uniforms = g_list_append (cksh->uniforms, cku);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
+ }
+
+ if (uniform_name)
+ g_free (uniform_name);
+
+ if (uniform_type)
+ g_free (uniform_type);
+
+ if (shader_name)
+ g_free (shader_name);
+ }
+ else if (g_strcmp0 (method_name, "RemoveUniform") == 0)
+ {
+ guint32 id;
+ gchar *shader_name;
+ gchar *uniform_name;
+ GList *iter, *siter, *uiter;
+
+ g_variant_get (parameters, "(ssi)", &uniform_name, &shader_name, &id);
+
+ iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
+
+ if (iter)
+ {
+ CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
+
+ siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
+
+ if (siter)
+ {
+ CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
+
+ uiter = g_list_find_custom (cksh->uniforms, uniform_name, find_uniform_by_name);
+
+ if (uiter)
+ {
+ CompositionKitUniform *cku = (CompositionKitUniform *) uiter->data;
+ delete_uniform (cku);
+ cksh->uniforms = g_list_remove_link (cksh->uniforms, uiter);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No uniform %s shader %s for id %i\n", uniform_name, shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
+ }
+
+ if (uniform_name)
+ g_free (uniform_name);
+
+ if (shader_name)
+ g_free (shader_name);
+ }
+ else if (g_strcmp0 (method_name, "AddAttribute") == 0)
+ {
+ guint32 id;
+ gchar *shader_name;
+ gchar *attribute_name;
+ gchar *attribute_type;
+ GList *iter, *siter;
+
+ g_variant_get (parameters, "(sssi)", &attribute_name, &attribute_type, &shader_name, &id);
+
+ iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
+
+ if (iter)
+ {
+ CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
+
+ siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
+
+ if (siter)
+ {
+ CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
+ CompositionKitAttribute *cku = new_attribute (attribute_name, attribute_type);
+ cksh->attributes = g_list_append (cksh->attributes, cku);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
+ }
+
+ if (attribute_name)
+ g_free (attribute_name);
+
+ if (attribute_type)
+ g_free (attribute_type);
+
+ if (shader_name)
+ g_free (shader_name);
+ }
+ else if (g_strcmp0 (method_name, "RemoveAttribute") == 0)
+ {
+ guint32 id;
+ gchar *shader_name;
+ gchar *attribute_name;
+ GList *iter, *siter, *aiter;
+
+ g_variant_get (parameters, "(ssi)", &attribute_name, &attribute_name, &id);
+
+ iter = g_list_find_custom (service->priv->surfaces, &id, find_surface_by_id);
+
+ if (iter)
+ {
+ CompositionKitSurface *cks = (CompositionKitSurface *) iter->data;
+
+ siter = g_list_find_custom (cks->shaders, shader_name, find_shader_by_name);
+
+ if (siter)
+ {
+ CompositionKitShader *cksh = (CompositionKitShader *) siter->data;
+
+ aiter = g_list_find_custom (cksh->attributes, attribute_name, find_attribute_by_name);
+
+ if (aiter)
+ {
+ CompositionKitAttribute *cka = (CompositionKitAttribute *) aiter->data;
+ delete_attribute (cka);
+ cksh->attributes = g_list_remove_link (cksh->attributes, aiter);
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No attribute %s shader %s for id %i\n", attribute_name, shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No shader %s for id %i\n", shader_name, id);
+ }
+ }
+ else
+ {
+ g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "ID %i not valid\n", id);
+ }
+
+ if (attribute_name)
+ g_free (attribute_name);
+
+ if (shader_name)
+ g_free (shader_name);
+ }
else if (g_strcmp0 (method_name, "RemoveSurface") == 0)
{
guint32 id;
@@ -534,6 +744,32 @@ static const gchar introspection_xml[] =
" <arg type='i' name='id' direction='in'/>"
" </method>"
""
+ " <method name='AddUniform'>"
+ " <arg type='s' name='uniform_name' direction='in'/>"
+ " <arg type='s' name='uniform_type' direction='in'/>"
+ " <arg type='s' name='shader_name' direction='in'/>"
+ " <arg type='i' name='id' direction='in'/>"
+ " </method>"
+ ""
+ " <method name='AddAttribute'>"
+ " <arg type='s' name='attribute_name' direction='in'/>"
+ " <arg type='s' name='attribute_type' direction='in'/>"
+ " <arg type='s' name='shader_name' direction='in'/>"
+ " <arg type='i' name='id' direction='in'/>"
+ " </method>"
+ ""
+ " <method name='RemoveAttribute'>"
+ " <arg type='s' name='attribute_name' direction='in'/>"
+ " <arg type='s' name='attribute_name' direction='in'/> "
+ " <arg type='i' name='id' direction='in'/> "
+ " </method>"
+ ""
+ " <method name='RemoveUniform'>"
+ " <arg type='s' name='uniform_name' direction='in'/>"
+ " <arg type='s' name='shader_name' direction='in'/> "
+ " <arg type='i' name='id' direction='in'/> "
+ " </method>"
+ ""
" <method name='RemoveShader'>"
" <arg type='s' name='shader_name' direction='in'/> "
" <arg type='i' name='id' direction='in'/> "