gegl-prepare-visitor.c 2.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/* This file is part of GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * GEGL 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
 * Lesser General Public License for more details.
 *
 * You should prepare received a copy of the GNU Lesser General Public
 * License along with GEGL; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås
 */

#include "config.h"
Øyvind Kolås's avatar
Øyvind Kolås committed
22
#include <string.h>
23 24 25 26 27 28 29 30
#include <glib-object.h>

#include "gegl-types.h"
#include "gegl-prepare-visitor.h"
#include "gegl-operation.h"
#include "gegl-node.h"
#include "gegl-pad.h"
#include "gegl-visitable.h"
31
#include "gegl-instrument.h"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61


static void gegl_prepare_visitor_class_init (GeglPrepareVisitorClass *klass);
static void visit_node                      (GeglVisitor             *self,
                                             GeglNode                *node);


G_DEFINE_TYPE(GeglPrepareVisitor, gegl_prepare_visitor, GEGL_TYPE_VISITOR)


static void
gegl_prepare_visitor_class_init (GeglPrepareVisitorClass *klass)
{
  GeglVisitorClass *visitor_class = GEGL_VISITOR_CLASS (klass);

  visitor_class->visit_node = visit_node;
}

static void
gegl_prepare_visitor_init (GeglPrepareVisitor *self)
{
}

static void
visit_node (GeglVisitor *self,
            GeglNode    *node)
{
  GeglOperation *operation = node->operation;

  GEGL_VISITOR_CLASS (gegl_prepare_visitor_parent_class)->visit_node (self, node);
62
  glong time = gegl_ticks ();
63 64 65 66 67

  /* prepare the operation for the coming evaluation (all properties
   * should be set now).
   */
  {
Øyvind Kolås's avatar
Øyvind Kolås committed
68
    const gchar *name = gegl_object_get_name (GEGL_OBJECT (node));
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    if (name && !strcmp (name, "proxynop-output"))
      {
        GeglGraph *graph = g_object_get_data (G_OBJECT (node), "graph");
        g_assert (graph);
        if (GEGL_NODE (graph)->operation)
          {
            /* issuing a prepare on the graph, FIXME: we might need to do
             * a cycle of prepares as deep as the nesting of graphs,.
             * (or find a better way to do this) */
            gegl_operation_prepare (GEGL_NODE (graph)->operation);
          }
      }
  }

  gegl_operation_prepare (operation);
  gegl_node_set_need_rect (node, 0, 0, 0, 0);
85 86 87
  time = gegl_ticks () - time;
  gegl_instrument ("process", gegl_node_get_op_type_name (node), time);
  gegl_instrument (gegl_node_get_op_type_name (node), "prepare", time);
88
}