summaryrefslogtreecommitdiff
path: root/src/lib/evas/canvas/evas_image_private.h
blob: b262999e840143a0c0f197d4aa120ad5a12b8301 (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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef EVAS_IMAGE_PRIVATE_H
#define EVAS_IMAGE_PRIVATE_H

/* Those functions are shared between legacy evas_object_image.c and the
 * new efl_canvas classes (image, snapshot, proxy, ...)
 */

#define EFL_CANVAS_FILTER_INTERNAL_PROTECTED
#define EFL_CANVAS_OBJECT_PROTECTED

#include "evas_common_private.h"

#include <sys/types.h>
#include <unistd.h>
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#include <math.h>

#include "evas_private.h"
#ifdef EVAS_CSERVE2
#include "../cserve2/evas_cs2_private.h"
#endif
#include "../common/evas_convert_color.h"
#include "../common/evas_convert_colorspace.h"
#include "../common/evas_convert_yuv.h"

#include "canvas/evas_image.eo.h"
#include "canvas/efl_canvas_filter_internal.eo.h"
#include "evas_filter.h"

/* private struct for rectangle object internal data */
typedef struct _Evas_Image_Data Evas_Image_Data;
typedef struct _Evas_Image_Map Evas_Image_Map;
typedef struct _Evas_Object_Image_Load_Opts Evas_Object_Image_Load_Opts;
typedef struct _Evas_Object_Image_Pixels Evas_Object_Image_Pixels;
typedef struct _Evas_Object_Image_State Evas_Object_Image_State;

struct _Evas_Object_Image_Load_Opts
{
   unsigned char  scale_down_by;
   double         dpi;
   short          w, h;
   struct {
      short       x, y, w, h;
   } region;
   struct {
      int src_x, src_y, src_w, src_h;
      int dst_w, dst_h;
      int smooth;
      int scale_hint;
   } scale_load;
   Eina_Bool  orientation : 1;
};

struct _Evas_Object_Image_Pixels
{
   Eina_List        *pixel_updates;
   struct {
      /* FIXME: no good match for eo */
      Evas_Object_Image_Pixels_Get_Cb  get_pixels;
      void                            *get_pixels_data;
   } func;

   Evas_Video_Surface video;
   unsigned int video_caps;
};

struct _Evas_Object_Image_State
{
   Evas_Coord_Rectangle fill;
   struct {
      short         w, h, stride;
   } image;
   struct {
      double        scale;
      short         l, r, t, b;
      unsigned char fill;
   } border;

   Evas_Object   *source;
   Evas_Map      *defmap;
   Evas_Canvas3D_Scene *scene;

   union {
      const char    *file;
      Eina_File     *f;
   } u;
   const char    *key;
   int            frame;

   Evas_Colorspace    cspace;
   Evas_Image_Orient  orient;

   Eina_Bool      smooth_scale : 1;
   Eina_Bool      has_alpha :1;
   Eina_Bool      opaque_valid : 1;
   Eina_Bool      opaque : 1;
   Eina_Bool      mmaped_source : 1;
};

struct _Evas_Image_Data
{
   const Evas_Object_Image_State *cur;
   const Evas_Object_Image_State *prev;
   const Evas_Object_Image_Load_Opts *load_opts;
   const Evas_Object_Image_Pixels *pixels;

   void             *engine_data;
   Efl_Vpath_File   *file_obj;

   int               pixels_checked_out;
   int               load_error;

   Efl_Image_Scale_Hint   scale_hint;
   Efl_Image_Content_Hint content_hint;
   Efl_Flip               flip_value;
   Efl_Orient             orient_value;

   Eina_Bool         changed : 1;
   Eina_Bool         dirty_pixels : 1;
   Eina_Bool         filled : 1;
   Eina_Bool         filled_set : 1;
   Eina_Bool         proxyrendering : 1;
   Eina_Bool         preloading : 1;
   Eina_Bool         video_surface : 1;
   Eina_Bool         video_visible : 1;
   Eina_Bool         created : 1;
   Eina_Bool         proxyerror : 1;
   Eina_Bool         proxy_src_clip : 1;
   Eina_Bool         written : 1;
   Eina_Bool         direct_render : 1;
   Eina_Bool         has_filter : 1;
   Eina_Bool         buffer_data_set : 1;
   struct
   {
      Eina_Bool      video_move : 1;
      Eina_Bool      video_resize : 1;
      Eina_Bool      video_show : 1;
      Eina_Bool      video_hide : 1;
   } delayed;
   Eina_Bool         legacy_type : 1;
};

/* shared functions between legacy and new eo classes */
void _evas_image_init_set(const Eina_File *f, const char *file, const char *key, Eo *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o, Evas_Image_Load_Opts *lo);
void _evas_image_done_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o);
void _evas_image_cleanup(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o);

/* Efl.Gfx.Fill */
void _evas_image_fill_set(Eo *eo_obj, Evas_Image_Data *o, int x, int y, int w, int h);

/* Efl.File */
Eina_Bool _evas_image_mmap_set(Eo *eo_obj, const Eina_File *f, const char *key);
void _evas_image_mmap_get(const Eo *eo_obj, const Eina_File **f, const char **key);
Eina_Bool _evas_image_file_set(Eo *eo_obj, const char *file, const char *key);
void _evas_image_file_get(const Eo *eo_obj, const char **file, const char **key);

/* Efl.Image.Load */
Efl_Image_Load_Error _evas_image_load_error_get(const Eo *eo_obj);
void _evas_image_load_async_start(Eo *eo_obj);
void _evas_image_load_async_cancel(Eo *eo_obj);
void _evas_image_load_dpi_set(Eo *eo_obj, double dpi);
double _evas_image_load_dpi_get(const Eo *eo_obj);
void _evas_image_load_size_set(Eo *eo_obj, int w, int h);
void _evas_image_load_size_get(const Eo *eo_obj, int *w, int *h);
void _evas_image_load_scale_down_set(Eo *eo_obj, int scale_down);
int _evas_image_load_scale_down_get(const Eo *eo_obj);
void _evas_image_load_region_set(Eo *eo_obj, int x, int y, int w, int h);
void _evas_image_load_region_get(const Eo *eo_obj, int *x, int *y, int *w, int *h);
void _evas_image_load_orientation_set(Eo *eo_obj, Eina_Bool enable);
Eina_Bool _evas_image_load_orientation_get(const Eo *eo_obj);
Eina_Bool _evas_image_load_region_support_get(const Eo *eo_obj);
void _evas_image_orientation_set(Eo *eo_obj, Evas_Image_Data *o, Evas_Image_Orient orient);

/* Efl.Image.Animated */
Eina_Bool _evas_image_animated_get(const Eo *eo_obj);
int _evas_image_animated_frame_count_get(const Eo *eo_obj);
Efl_Image_Animated_Loop_Hint _evas_image_animated_loop_type_get(const Eo *eo_obj);
int _evas_image_animated_loop_count_get(const Eo *eo_obj);
double _evas_image_animated_frame_duration_get(const Eo *eo_obj, int start_frame, int frame_num);
Eina_Bool _evas_image_animated_frame_set(Eo *eo_obj, int frame_index);
int _evas_image_animated_frame_get(const Eo *eo_obj);

/* Efl.Canvas.Proxy */
void _evas_image_proxy_unset(Evas_Object *proxy, Evas_Object_Protected_Data *obj, Evas_Image_Data *o);
void _evas_image_proxy_set(Evas_Object *proxy, Evas_Object *src);
void _evas_image_proxy_error(Evas_Object *proxy, void *context, void *output, void *surface, int x, int y, Eina_Bool do_async);
Eina_Bool _evas_image_proxy_source_set(Eo *eo_obj, Evas_Object *eo_src);
Evas_Object *_evas_image_proxy_source_get(const Eo *eo_obj);
void _evas_image_proxy_source_clip_set(Eo *eo_obj, Eina_Bool source_clip);
Eina_Bool _evas_image_proxy_source_clip_get(const Eo *eo_obj);
void _evas_image_proxy_source_events_set(Eo *eo_obj, Eina_Bool source_events);
Eina_Bool _evas_image_proxy_source_events_get(const Eo *eo_obj);

/* Efl.Canvas.Scene3d */
void _evas_image_3d_render(Evas *eo_e, Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o, Evas_Canvas3D_Scene *scene);
void _evas_image_3d_set(Evas_Object *eo_obj, Evas_Canvas3D_Scene *scene);
void _evas_image_3d_unset(Evas_Object *eo_obj, Evas_Object_Protected_Data *image, Evas_Image_Data *o);

/* Efl.Canvas.Surface */
Eina_Bool _evas_image_native_surface_set(Eo *eo_obj, Evas_Native_Surface *surf);
Evas_Native_Surface *_evas_image_native_surface_get(const Evas_Object *eo_obj);

/* deprecated but in use */
void *_evas_image_data_convert_internal(Evas_Image_Data *o, void *data, Evas_Colorspace to_cspace);
void _evas_image_unload(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, Eina_Bool dirty);
void _evas_image_load(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o);

/* save typing */
#define ENFN obj->layer->evas->engine.func
#define ENDT obj->layer->evas->engine.data.output

# define EINA_COW_IMAGE_STATE_WRITE_BEGIN(Obj, Write) \
  EINA_COW_WRITE_BEGIN(evas_object_image_state_cow, Obj->cur, Evas_Object_Image_State, Write)

# define EINA_COW_IMAGE_STATE_WRITE_END(Obj, Write) \
  EINA_COW_WRITE_END(evas_object_image_state_cow, Obj->cur, Write)

# define EINA_COW_PIXEL_WRITE_BEGIN(Obj, Write) \
  EINA_COW_WRITE_BEGIN(evas_object_image_pixels_cow, Obj->pixels, Evas_Object_Image_Pixels, Write)

# define EINA_COW_PIXEL_WRITE_END(Obj, Write) \
  EINA_COW_WRITE_END(evas_object_image_pixels_cow, Obj->pixels, Write)

# define EINA_COW_LOAD_OPTS_WRITE_BEGIN(Obj, Write) \
  EINA_COW_WRITE_BEGIN(evas_object_image_load_opts_cow, Obj->load_opts, Evas_Object_Image_Load_Opts, Write)

# define EINA_COW_LOAD_OPTS_WRITE_END(Obj, Write) \
  EINA_COW_WRITE_END(evas_object_image_load_opts_cow, Obj->load_opts, Write)

# define EVAS_OBJECT_WRITE_IMAGE_FREE_FILE_AND_KEY(Obj)                 \
  if ((!Obj->cur->mmaped_source && Obj->cur->u.file) || Obj->cur->key) \
    {                                                                   \
       EINA_COW_IMAGE_STATE_WRITE_BEGIN(Obj, cur_write)                 \
         {                                                              \
            EINA_COW_WRITE_BEGIN(evas_object_image_state_cow, Obj->prev, Evas_Object_Image_State, prev_write) \
              EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(cur_write, prev_write); \
            EINA_COW_WRITE_END(evas_object_image_state_cow, Obj->prev, prev_write); \
         }                                                              \
       EINA_COW_IMAGE_STATE_WRITE_END(Obj, cur_write);                  \
    }

#define FRAME_MAX 1024

#endif // EVAS_IMAGE_PRIVATE_H