pipeline: Simplify layer change notifications to backend
authorRobert Bragg <robert@linux.intel.com>
Thu, 25 Nov 2010 13:19:59 +0000 (13:19 +0000)
committerRobert Bragg <robert@linux.intel.com>
Thu, 25 Nov 2010 14:41:25 +0000 (14:41 +0000)
Previously we used the layers->backend_priv[] members to determine when
to notify backends about layer changes, but it entirely up to the
backends if they want to associate private state with layers, even
though they may still be interested in layer change notifications (they
may associate layer related state with the owner pipeline).

We now make the observation that in
_cogl_pipeline_backend_layer_change_notify we should be able to assume
there can only be one backend currently associated with the layer
because we wouldn't allow changes to a layer with multiple dependants.
This means we can determine the backend to notify by looking at the
owner pipeline instead.

clutter/cogl/cogl/cogl-pipeline.c

index 1ec8647..790e8bf 100644 (file)
@@ -1494,20 +1494,18 @@ _cogl_pipeline_backend_layer_change_notify (CoglPipeline *owner,
                                             CoglPipelineLayer *layer,
                                             CoglPipelineLayerState change)
 {
-  int i;
-
-  /* NB: layers may be used by multiple pipelines which may be using
-   * different backends, therefore we determine which backends to
-   * notify based on the private state pointers for each backend...
+  /* NB: Although layers can have private state associated with them
+   * by multiple backends we know that a layer can't be *changed* if
+   * it has multiple dependants so if we reach here we know we only
+   * have a single owner and can only be associated with a single
+   * backend that needs to be notified of the layer change...
    */
-  for (i = 0; i < COGL_PIPELINE_N_BACKENDS; i++)
+  if (owner->backend != COGL_PIPELINE_BACKEND_UNDEFINED &&
+      _cogl_pipeline_backends[owner->backend]->layer_pre_change_notify)
     {
-      if (layer->backend_priv[i] &&
-          _cogl_pipeline_backends[i]->layer_pre_change_notify)
-        {
-          const CoglPipelineBackend *backend = _cogl_pipeline_backends[i];
-          backend->layer_pre_change_notify (owner, layer, change);
-        }
+      const CoglPipelineBackend *backend =
+        _cogl_pipeline_backends[owner->backend];
+      backend->layer_pre_change_notify (owner, layer, change);
     }
 }