summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/efl_canvas_vg_image.c
blob: 1a72c69624524755d8667f6da58b8150725623b5 (plain)
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
#include "evas_common_private.h"
#include "evas_private.h"

#include "evas_vg_private.h"

#define MY_CLASS EFL_CANVAS_VG_IMAGE_CLASS

typedef struct _Efl_Canvas_Vg_Image_Data Efl_Canvas_Vg_Image_Data;
struct _Efl_Canvas_Vg_Image_Data
{
   Ector_Buffer *buffer;
   void *image;
   int w;
   int h;
};

static void
_efl_canvas_vg_image_render_pre(Evas_Object_Protected_Data *vg_pd,
                                Efl_VG *obj EINA_UNUSED,
                                Efl_Canvas_Vg_Node_Data *nd,
                                void *engine EINA_UNUSED, void *output EINA_UNUSED, void *context EINA_UNUSED,
                                Ector_Surface *surface,
                                Eina_Matrix3 *ptransform,
                                Ector_Buffer *mask,
                                int mask_op,
                                void *data)
{
   Efl_Canvas_Vg_Image_Data *pd = data;

   if (nd->flags == EFL_GFX_CHANGE_FLAG_NONE) return;

   nd->flags = EFL_GFX_CHANGE_FLAG_NONE;

   EFL_CANVAS_VG_COMPUTE_MATRIX(ctransform, ptransform, nd);

   if (!nd->renderer)
     {
        efl_domain_current_push(EFL_ID_DOMAIN_SHARED);
        nd->renderer = ector_surface_renderer_factory_new(surface, ECTOR_RENDERER_IMAGE_MIXIN);
        efl_domain_current_pop();
     }

   if (!pd->buffer && pd->image)
     {
        Evas_Object_Protected_Data *obj = vg_pd;
        if (pd->buffer) efl_unref(pd->buffer);
        pd->buffer = ENFN->ector_buffer_new(ENC, obj->layer->evas->evas,
                                            pd->w, pd->h,
                                            EFL_GFX_COLORSPACE_ARGB8888,
                                            ECTOR_BUFFER_FLAG_DRAWABLE |
                                            ECTOR_BUFFER_FLAG_CPU_READABLE |
                                            ECTOR_BUFFER_FLAG_CPU_WRITABLE);
        ector_buffer_pixels_set(pd->buffer, pd->image,
                                pd->w, pd->h, 0,
                                EFL_GFX_COLORSPACE_ARGB8888, EINA_TRUE);
     }
   ector_renderer_image_buffer_set(nd->renderer, pd->buffer);
   ector_renderer_transformation_set(nd->renderer, ctransform);



   ector_renderer_origin_set(nd->renderer, nd->x, nd->y);
   ector_renderer_color_set(nd->renderer, nd->r, nd->g, nd->b, nd->a);
   ector_renderer_visibility_set(nd->renderer, nd->visibility);

   ector_renderer_mask_set(nd->renderer, mask, mask_op);
   ector_renderer_prepare(nd->renderer);
}

static Eo *
_efl_canvas_vg_image_efl_object_constructor(Eo *obj, Efl_Canvas_Vg_Image_Data *pd)
{
   Efl_Canvas_Vg_Node_Data *nd;

   obj = efl_constructor(efl_super(obj, MY_CLASS));

   nd = efl_data_scope_get(obj, EFL_CANVAS_VG_NODE_CLASS);
   nd->render_pre = _efl_canvas_vg_image_render_pre;
   nd->data = pd;

   efl_gfx_color_set(obj , 255, 255, 255, 255);

   return obj;
}

static void
_efl_canvas_vg_image_efl_object_destructor(Eo *obj, Efl_Canvas_Vg_Image_Data *pd EINA_UNUSED)
{
   efl_destructor(efl_super(obj, MY_CLASS));
   if (pd->buffer)
     {
        efl_unref(pd->buffer);
        pd->buffer = NULL;
     }
}

static void
_efl_canvas_vg_image_data_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Image_Data *pd, void *data, int w, int h)
{
   if (!data || w <= 0 || h <= 0)
     return;

   if ((pd->image != data || pd->w != w || pd->h != h) && pd->buffer)
     {
        efl_unref(pd->buffer);
        pd->buffer= NULL;
     }

   pd->image = data;
   pd->w = w;
   pd->h = h;
}

#include "efl_canvas_vg_image.eo.c"