<commit_before>/* ENESIM - Direct Rendering Library
 * Copyright (C) 2007-2011 <NAME>
 *
 * This library 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.1 of the License, or (at your option) any later version.
 *
 * This library 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 have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "enesim_private.h"

#include "enesim_main.h"
#include "enesim_error.h"
#include "enesim_color.h"
#include "enesim_rectangle.h"
#include "enesim_matrix.h"
#include "enesim_pool.h"
#include "enesim_buffer.h"
#include "enesim_surface.h"
#include "enesim_compositor.h"
#include "enesim_renderer.h"
#include "enesim_renderer_compound.h"

#ifdef BUILD_OPENGL
#include "Enesim_OpenGL.h"
#endif

#include "private/renderer.h"
/**
 * @todo
 * - Handle the case whenever the renderer supports the ROP itself
 * - Might be interesting to add two more functions for this renderer
 *   this functions should set/add some callbacks for pre/post setup/cleanup
 *   Basically the idea is that whenever the renderer is about to do the
 *   setup on the childs, first call the pre setup, and then after do the
 *   post setup, this is useful for cases like esvg or eon where this libraries
 *   wrap in a way a compound renderer but we have to also store the list
 *   of children added, so basically we iterate twice, one the compound itself
 *   and one the compound-wrapper
 * - Another way to optmize this is to make the setup() function of every
 *   layer thread safe, that way given that each layer does not depend on the other
 *   the setup can be done on parallel
 */
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
#define ENESIM_RENDERER_COMPOUND_MAGIC_CHECK(d) \
	do {\
		if (!EINA_MAGIC_CHECK(d, ENESIM_RENDERER_COMPOUND_MAGIC))\
			EINA_MAGIC_FAIL(d, ENESIM_RENDERER_COMPOUND_MAGIC);\
	} while(0)

typedef struct _Enesim_Renderer_Compound
{
	EINA_MAGIC
	/* properties */
	Eina_List *layers;
	/* private */
	Eina_List *visible_layers; /* FIXME maybe is time to change from lists to arrays */
	Eina_List *added;
	Eina_List *removed;

	Enesim_Renderer_Compound_Cb pre_cb;
	void *pre_data;
	Enesim_Renderer_Compound_Cb post_cb;
	void *post_data;

	Eina_Bool changed : 1;
} Enesim_Renderer_Compound;

typedef struct _Layer
{
	Enesim_Renderer *r;
	/* generated at state setup */
	Eina_Rectangle destination_boundings;
} Layer;

static inline Enesim_Renderer_Compound * _compound_get(Enesim_Renderer *r)
{
	Enesim_Renderer_Compound *thiz;

	thiz = enesim_renderer_data_get(r);
	ENESIM_RENDERER_COMPOUND_MAGIC_CHECK(thiz);

	return thiz;
}

static inline void _compound_layer_remove(Enesim_Renderer_Compound *thiz,
		Layer *l)
{
	thiz->removed = eina_list_append(thiz->removed, l);
	thiz->layers = eina_list_remove(thiz->layers, l);
	thiz->changed = EINA_TRUE;
}

static Eina_Bool _compound_state_setup(Enesim_Renderer_Compound *thiz,
		Enesim_Renderer *r,
		Enesim_Surface *s, Enesim_Error **error)
{
	Eina_List *ll;
	Layer *l;

	if (thiz->visible_layers)
	{
		eina_list_free(thiz->visible_layers);
		thiz->visible_layers = NULL;
	}
	EINA_LIST_FREE(thiz->added, l)
	{
		/* add the recently added layers to the layers to calculate */
		thiz->layers = eina_list_append(thiz->layers, l);
		printf("adding layer '%s' to layers\n", l->r->name);
	}
	/* setup every layer */
	EINA_LIST_FOREACH(thiz->layers, ll, l)
	{
		/* the position and the matrix */
		if (thiz->pre_cb)
		{
			if (!thiz->pre_cb(r, l->r, thiz->pre_data))
			{
				continue;
			}
		}
		if (!enesim_renderer_setup(l->r, s, error))
		{
			const char *name;

			enesim_renderer_name_get(l->r, &name);
			ENESIM_RENDERER_ERROR(r, error, "Child renderer %s can not setup", name);
			continue;
		}<commit_msg>printf--<commit_after>/* ENESIM - Direct Rendering Library
 * Copyright (C) 2007-2011 <NAME>
 *
 * This library 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.1 of the License, or (at your option) any later version.
 *
 * This library 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 have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "enesim_private.h"

#include "enesim_main.h"
#include "enesim_error.h"
#include "enesim_color.h"
#include "enesim_rectangle.h"
#include "enesim_matrix.h"
#include "enesim_pool.h"
#include "enesim_buffer.h"
#include "enesim_surface.h"
#include "enesim_compositor.h"
#include "enesim_renderer.h"
#include "enesim_renderer_compound.h"

#ifdef BUILD_OPENGL
#include "Enesim_OpenGL.h"
#endif

#include "private/renderer.h"
/**
 * @todo
 * - Handle the case whenever the renderer supports the ROP itself
 * - Might be interesting to add two more functions for this renderer
 *   this functions should set/add some callbacks for pre/post setup/cleanup
 *   Basically the idea is that whenever the renderer is about to do the
 *   setup on the childs, first call the pre setup, and then after do the
 *   post setup, this is useful for cases like esvg or eon where this libraries
 *   wrap in a way a compound renderer but we have to also store the list
 *   of children added, so basically we iterate twice, one the compound itself
 *   and one the compound-wrapper
 * - Another way to optmize this is to make the setup() function of every
 *   layer thread safe, that way given that each layer does not depend on the other
 *   the setup can be done on parallel
 */
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
#define ENESIM_RENDERER_COMPOUND_MAGIC_CHECK(d) \
	do {\
		if (!EINA_MAGIC_CHECK(d, ENESIM_RENDERER_COMPOUND_MAGIC))\
			EINA_MAGIC_FAIL(d, ENESIM_RENDERER_COMPOUND_MAGIC);\
	} while(0)

typedef struct _Enesim_Renderer_Compound
{
	EINA_MAGIC
	/* properties */
	Eina_List *layers;
	/* private */
	Eina_List *visible_layers; /* FIXME maybe is time to change from lists to arrays */
	Eina_List *added;
	Eina_List *removed;

	Enesim_Renderer_Compound_Cb pre_cb;
	void *pre_data;
	Enesim_Renderer_Compound_Cb post_cb;
	void *post_data;

	Eina_Bool changed : 1;
} Enesim_Renderer_Compound;

typedef struct _Layer
{
	Enesim_Renderer *r;
	/* generated at state setup */
	Eina_Rectangle destination_boundings;
} Layer;

static inline Enesim_Renderer_Compound * _compound_get(Enesim_Renderer *r)
{
	Enesim_Renderer_Compound *thiz;

	thiz = enesim_renderer_data_get(r);
	ENESIM_RENDERER_COMPOUND_MAGIC_CHECK(thiz);

	return thiz;
}

static inline void _compound_layer_remove(Enesim_Renderer_Compound *thiz,
		Layer *l)
{
	thiz->removed = eina_list_append(thiz->removed, l);
	thiz->layers = eina_list_remove(thiz->layers, l);
	thiz->changed = EINA_TRUE;
}

static Eina_Bool _compound_state_setup(Enesim_Renderer_Compound *thiz,
		Enesim_Renderer *r,
		Enesim_Surface *s, Enesim_Error **error)
{
	Eina_List *ll;
	Layer *l;

	if (thiz->visible_layers)
	{
		eina_list_free(thiz->visible_layers);
		thiz->visible_layers = NULL;
	}
	EINA_LIST_FREE(thiz->added, l)
	{
		/* add the recently added layers to the layers to calculate */
		thiz->layers = eina_list_append(thiz->layers, l);
	}
	/* setup every layer */
	EINA_LIST_FOREACH(thiz->layers, ll, l)
	{
		/* the position and the matrix */
		if (thiz->pre_cb)
		{
			if (!thiz->pre_cb(r, l->r, thiz->pre_data))
			{
				continue;
			}
		}
		if (!enesim_renderer_setup(l->r, s, error))
		{
			const char *name;

			enesim_renderer_name_get(l->r, &name);
			ENESIM_RENDERER_ERROR(r, error, "Child renderer %s can not setup", name);
			continue;
		}
{'fraction_non_alphanumeric': 0.12514565369377767, 'fraction_numerical': 0.002796550920531345, 'mean_word_length': 4.158052884615385, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3217383', 'n_tokens_mistral': 2977, 'n_tokens_neox': 2836, 'n_words': 878}