aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ector/software/ector_renderer_software_gradient_radial.c
blob: ee761b1ef1605b2dcd5ba4c5cbfa911684295f40 (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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <Eina.h>
#include <Ector.h>
#include <software/Ector_Software.h>

#include "ector_private.h"
#include "ector_software_private.h"

static void
_update_radial_data(Ector_Renderer_Software_Gradient_Data *gdata)
{
   update_color_table(gdata);

   gdata->radial.cx = gdata->grd->radial.x;
   gdata->radial.cy = gdata->grd->radial.y;
   gdata->radial.cradius = gdata->grd->radius;

   if (!gdata->grd->focal.x)
     gdata->radial.fx = gdata->grd->radial.x;
   else
     gdata->radial.fx = gdata->grd->focal.x;

   if (!gdata->grd->focal.y)
     gdata->radial.fy = gdata->grd->radial.y;
   else
     gdata->radial.fy = gdata->grd->focal.y;

   gdata->radial.fradius = 0;

   gdata->radial.dx = gdata->radial.cx - gdata->radial.fx;
   gdata->radial.dy = gdata->radial.cy - gdata->radial.fy;

   gdata->radial.dr = gdata->radial.cradius - gdata->radial.fradius;
   gdata->radial.sqrfr = gdata->radial.fradius * gdata->radial.fradius;

   gdata->radial.a = gdata->radial.dr * gdata->radial.dr -
                     gdata->radial.dx * gdata->radial.dx -
                     gdata->radial.dy * gdata->radial.dy;
   gdata->radial.inv2a = 1 / (2 * gdata->radial.a);

   gdata->radial.extended = (gdata->radial.fradius >= 0.00001f) || gdata->radial.a >= 0.00001f;
}


static Eina_Bool
_ector_renderer_software_gradient_radial_ector_renderer_generic_base_prepare(Eo *obj, Ector_Renderer_Software_Gradient_Data *pd)
{
   if (!pd->surface)
     {
        Eo *parent;

        eo_do(obj, parent = eo_parent_get(obj));
        if (!parent) return EINA_FALSE;
        pd->surface = eo_data_xref(parent, ECTOR_SOFTWARE_SURFACE_CLASS, obj);
     }

   _update_radial_data(pd);
   return EINA_FALSE;
}

// Clearly duplicated and should be in a common place...
static Eina_Bool
_ector_renderer_software_gradient_radial_ector_renderer_generic_base_draw(Eo *obj EINA_UNUSED,
                                                                          Ector_Renderer_Software_Gradient_Data *pd EINA_UNUSED,
                                                                          Ector_Rop op EINA_UNUSED, Eina_Array *clips EINA_UNUSED,
                                                                          unsigned int mul_col EINA_UNUSED)
{
   return EINA_TRUE;
}

// Clearly duplicated and should be in a common place...
static Eina_Bool
_ector_renderer_software_gradient_radial_ector_renderer_software_base_fill(Eo *obj EINA_UNUSED, Ector_Renderer_Software_Gradient_Data *pd)
{
   ector_software_rasterizer_radial_gradient_set(pd->surface->software, pd);
   return EINA_TRUE;
}

Eo *
_ector_renderer_software_gradient_radial_eo_base_constructor(Eo *obj,
                                                             Ector_Renderer_Software_Gradient_Data *pd)
{
   obj = eo_super_eo_constructor( ECTOR_RENDERER_SOFTWARE_GRADIENT_RADIAL_CLASS, obj);
   pd->gd  = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_MIXIN, obj);
   pd->gld = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_RADIAL_MIXIN, obj);

   return obj;
}

void
_ector_renderer_software_gradient_radial_eo_base_destructor(Eo *obj,
                                                            Ector_Renderer_Software_Gradient_Data *pd)
{
   Eo *parent;

   destroy_color_table(pd);

   eo_do(obj, parent = eo_parent_get(obj));
   eo_data_xunref(parent, pd->surface, obj);

   eo_data_xunref(obj, pd->gd, obj);
   eo_data_xunref(obj, pd->gld, obj);

   eo_super_eo_destructor(ECTOR_RENDERER_SOFTWARE_GRADIENT_RADIAL_CLASS, obj);
}

void
_ector_renderer_software_gradient_radial_efl_gfx_gradient_base_stop_set(Eo *obj, Ector_Renderer_Software_Gradient_Data *pd, const Efl_Gfx_Gradient_Stop *colors, unsigned int length)
{
   eo_super_efl_gfx_gradient_stop_set(ECTOR_RENDERER_SOFTWARE_GRADIENT_RADIAL_CLASS, obj, colors, length);

   destroy_color_table(pd);
}

static unsigned int
_ector_renderer_software_gradient_radial_ector_renderer_generic_base_crc_get(Eo *obj, Ector_Renderer_Software_Gradient_Data *pd)
{
   unsigned int crc;


   crc = eo_super_ector_renderer_crc_get(ECTOR_RENDERER_SOFTWARE_GRADIENT_RADIAL_CLASS, obj);

   crc = eina_crc((void*) pd->gd->s, sizeof (Efl_Gfx_Gradient_Spread), crc, EINA_FALSE);
   if (pd->gd->colors_count)
     crc = eina_crc((void*) pd->gd->colors, sizeof (Efl_Gfx_Gradient_Stop) * pd->gd->colors_count, crc, EINA_FALSE);
   crc = eina_crc((void*) pd->gld, sizeof (Ector_Renderer_Generic_Gradient_Radial_Data), crc, EINA_FALSE);

   return crc;
}

#include "ector_renderer_software_gradient_radial.eo.c"