summaryrefslogtreecommitdiff
path: root/src/lib/ector/ector_renderer.c
blob: d0efab6a6cb39229a0bda4e33876755391c6e77c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <Eina.h>
#include <Ector.h>

#include "ector_private.h"

#define MY_CLASS ECTOR_RENDERER_CLASS

static void
_ector_renderer_efl_object_destructor(Eo *obj, Ector_Renderer_Data *pd)
{
   efl_destructor(efl_super(obj, MY_CLASS));

   if (pd->m) free(pd->m);
   /*FIXME: pd-> surface will try efl_xref whenever surface_set is called.
            desturctor is called from a subclass, ref and unref do not match.
            So, Add this condition temporarily.*/
   if (efl_ref_count(pd->surface) > 0)
     efl_unref(pd->surface);
}

static Efl_Object *
_ector_renderer_efl_object_finalize(Eo *obj, Ector_Renderer_Data *pd)
{
   if (!pd->surface)
     {
        CRI("surface is not set yet, go fix your code!");
        return NULL;
     }
   pd->finalized = EINA_TRUE;
   return efl_finalize(efl_super(obj, MY_CLASS));
}

static Ector_Surface *
_ector_renderer_surface_get(const Eo *obj EINA_UNUSED, Ector_Renderer_Data *pd)
{
   return pd->surface;
}

static void
_ector_renderer_surface_set(Eo *obj EINA_UNUSED, Ector_Renderer_Data *pd, Ector_Surface *s)
{
   if (pd->finalized)
     {
        CRI("surface_set can be called during object creation only!");
        return;
     }
   pd->surface = efl_xref(s, obj);
}

static void
_ector_renderer_transformation_set(Eo *obj EINA_UNUSED,
                                   Ector_Renderer_Data *pd,
                                   const Eina_Matrix3 *m)
{
   if (!m)
     {
        free(pd->m);
        pd->m = NULL;
     }
   else
     {
        if (!pd->m) pd->m = malloc(sizeof (Eina_Matrix3));
        if (!pd->m) return;
        memcpy(pd->m, m, sizeof (Eina_Matrix3));
     }
}

static const Eina_Matrix3 *
_ector_renderer_transformation_get(const Eo *obj EINA_UNUSED,
                                   Ector_Renderer_Data *pd)
{
   return pd->m;
}

static void
_ector_renderer_origin_set(Eo *obj EINA_UNUSED,
                           Ector_Renderer_Data *pd,
                           double x, double y)
{
   pd->origin.x = x;
   pd->origin.y = y;
}

static void
_ector_renderer_origin_get(const Eo *obj EINA_UNUSED,
                           Ector_Renderer_Data *pd,
                           double *x, double *y)
{
   if (x) *x = pd->origin.x;
   if (y) *y = pd->origin.y;
}

static void
_ector_renderer_visibility_set(Eo *obj EINA_UNUSED,
                               Ector_Renderer_Data *pd,
                               Eina_Bool v)
{
   pd->visibility = v;
}

static Eina_Bool
_ector_renderer_visibility_get(const Eo *obj EINA_UNUSED,
                               Ector_Renderer_Data *pd)
{
   return pd->visibility;
}

static void
_ector_renderer_color_set(Eo *obj EINA_UNUSED,
                          Ector_Renderer_Data *pd,
                          int r, int g, int b, int a)
{
   pd->color.r = r;
   pd->color.g = g;
   pd->color.b = b;
   pd->color.a = a;
}

static void
_ector_renderer_color_get(const Eo *obj EINA_UNUSED,
                          Ector_Renderer_Data *pd,
                          int *r, int *g, int *b, int *a)
{
   if (r) *r = pd->color.r;
   if (g) *g = pd->color.g;
   if (b) *b = pd->color.b;
   if (a) *a = pd->color.a;
}

static unsigned int
_ector_renderer_crc_get(const Eo *obj EINA_UNUSED,
                        Ector_Renderer_Data *pd)
{
   unsigned int crc;

   crc = eina_crc((void*) &pd->color, sizeof(pd->color), 0xffffffff, EINA_TRUE);
   crc = eina_crc((void*) &pd->origin, sizeof(pd->origin), crc, EINA_FALSE);

   if (pd->m) crc = eina_crc((void*) pd->m, sizeof(Eina_Matrix3), crc, EINA_FALSE);

   return crc;
}

static void
_ector_renderer_mask_set(Eo *obj EINA_UNUSED,
                         Ector_Renderer_Data *pd EINA_UNUSED,
                         Ector_Buffer *mask EINA_UNUSED,
                         int op EINA_UNUSED)
{
}

#include "ector_renderer.eo.c"