summaryrefslogtreecommitdiff
path: root/src/lib/ector
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2019-07-22 13:29:02 +0900
committerHermet Park <hermetpark@gmail.com>2019-07-22 13:29:02 +0900
commit1ce14bc85d87ece9b2e50204f1834ec5a2d0f4a1 (patch)
treec4c076ca1484056fae2f8a3e0db0890885ad4ca7 /src/lib/ector
parentde5eea226a705b908154e5b518c659d3917631c3 (diff)
Ector.Renderer : Implement Ector.Renderer.(Software).Image class
Summary: Implement a class and drawer that outputs image data from the Ector. Image data is output with a vector object and supports transform. Test Plan: N/A Reviewers: Hermet, smohanty, kimcinoo Reviewed By: Hermet Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9218
Diffstat (limited to 'src/lib/ector')
-rw-r--r--src/lib/ector/ector_private.h6
-rw-r--r--src/lib/ector/ector_renderer.h1
-rw-r--r--src/lib/ector/ector_renderer_image.c22
-rw-r--r--src/lib/ector/ector_renderer_image.eo16
-rw-r--r--src/lib/ector/meson.build2
-rw-r--r--src/lib/ector/software/Ector_Software.h1
-rw-r--r--src/lib/ector/software/ector_renderer_software_image.c194
-rw-r--r--src/lib/ector/software/ector_renderer_software_image.eo13
-rw-r--r--src/lib/ector/software/ector_software_surface.c2
-rw-r--r--src/lib/ector/software/meson.build2
10 files changed, 259 insertions, 0 deletions
diff --git a/src/lib/ector/ector_private.h b/src/lib/ector/ector_private.h
index 8604768..8e12820 100644
--- a/src/lib/ector/ector_private.h
+++ b/src/lib/ector/ector_private.h
@@ -47,6 +47,7 @@ typedef struct _Ector_Renderer_Gradient_Data Ector_Renderer_Gradient_Data;
47typedef struct _Ector_Renderer_Gradient_Linear_Data Ector_Renderer_Gradient_Linear_Data; 47typedef struct _Ector_Renderer_Gradient_Linear_Data Ector_Renderer_Gradient_Linear_Data;
48typedef struct _Ector_Renderer_Gradient_Radial_Data Ector_Renderer_Gradient_Radial_Data; 48typedef struct _Ector_Renderer_Gradient_Radial_Data Ector_Renderer_Gradient_Radial_Data;
49typedef struct _Ector_Renderer_Shape_Data Ector_Renderer_Shape_Data; 49typedef struct _Ector_Renderer_Shape_Data Ector_Renderer_Shape_Data;
50typedef struct _Ector_Renderer_Image_Data Ector_Renderer_Image_Data;
50typedef struct _Ector_Renderer_Buffer_Data Ector_Renderer_Buffer_Data; 51typedef struct _Ector_Renderer_Buffer_Data Ector_Renderer_Buffer_Data;
51 52
52struct _Ector_Renderer_Data 53struct _Ector_Renderer_Data
@@ -99,6 +100,11 @@ struct _Ector_Renderer_Shape_Data
99 } stroke; 100 } stroke;
100}; 101};
101 102
103struct _Ector_Renderer_Image_Data
104{
105 Ector_Buffer *buffer;
106};
107
102struct _Ector_Renderer_Buffer_Data 108struct _Ector_Renderer_Buffer_Data
103{ 109{
104 Ector_Buffer *eo_buffer; 110 Ector_Buffer *eo_buffer;
diff --git a/src/lib/ector/ector_renderer.h b/src/lib/ector/ector_renderer.h
index c8d20d2..482f6cb 100644
--- a/src/lib/ector/ector_renderer.h
+++ b/src/lib/ector/ector_renderer.h
@@ -3,6 +3,7 @@
3 3
4#include "ector_renderer.eo.h" 4#include "ector_renderer.eo.h"
5#include "ector_renderer_shape.eo.h" 5#include "ector_renderer_shape.eo.h"
6#include "ector_renderer_image.eo.h"
6#include "ector_renderer_gradient.eo.h" 7#include "ector_renderer_gradient.eo.h"
7#include "ector_renderer_gradient_linear.eo.h" 8#include "ector_renderer_gradient_linear.eo.h"
8#include "ector_renderer_gradient_radial.eo.h" 9#include "ector_renderer_gradient_radial.eo.h"
diff --git a/src/lib/ector/ector_renderer_image.c b/src/lib/ector/ector_renderer_image.c
new file mode 100644
index 0000000..3e34254
--- /dev/null
+++ b/src/lib/ector/ector_renderer_image.c
@@ -0,0 +1,22 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include "ector_private.h"
9
10#define MY_CLASS ECTOR_RENDERER_IMAGE_MIXIN
11
12
13static void
14_ector_renderer_image_buffer_set(Eo *obj EINA_UNUSED,
15 Ector_Renderer_Image_Data *pd,
16 Ector_Buffer *buffer)
17{
18 pd->buffer = buffer;
19}
20
21
22#include "ector_renderer_image.eo.c"
diff --git a/src/lib/ector/ector_renderer_image.eo b/src/lib/ector/ector_renderer_image.eo
new file mode 100644
index 0000000..9c2e7b3
--- /dev/null
+++ b/src/lib/ector/ector_renderer_image.eo
@@ -0,0 +1,16 @@
1import ector_renderer;
2
3mixin @beta Ector.Renderer.Image
4{
5 [[Ector image renderer mixin]]
6 c_prefix: ector_renderer_image;
7 methods {
8 @property buffer {
9 set {
10 }
11 values {
12 buffer : Ector.Buffer; [[Image buffer]]
13 }
14 }
15 }
16}
diff --git a/src/lib/ector/meson.build b/src/lib/ector/meson.build
index 069e98d..5bedb7e 100644
--- a/src/lib/ector/meson.build
+++ b/src/lib/ector/meson.build
@@ -14,6 +14,7 @@ ector_src = [
14 'ector_gl_internal.h', 14 'ector_gl_internal.h',
15 'ector_buffer.c', 15 'ector_buffer.c',
16 'ector_renderer_shape.c', 16 'ector_renderer_shape.c',
17 'ector_renderer_image.c',
17 'ector_renderer.c', 18 'ector_renderer.c',
18 'ector_renderer_gradient.c', 19 'ector_renderer_gradient.c',
19 'ector_renderer_gradient_radial.c', 20 'ector_renderer_gradient_radial.c',
@@ -25,6 +26,7 @@ pub_eo_files = [
25 'ector_buffer.eo', 26 'ector_buffer.eo',
26 'ector_renderer.eo', 27 'ector_renderer.eo',
27 'ector_renderer_shape.eo', 28 'ector_renderer_shape.eo',
29 'ector_renderer_image.eo',
28 'ector_renderer_gradient.eo', 30 'ector_renderer_gradient.eo',
29 'ector_renderer_gradient_radial.eo', 31 'ector_renderer_gradient_radial.eo',
30 'ector_renderer_gradient_linear.eo' 32 'ector_renderer_gradient_linear.eo'
diff --git a/src/lib/ector/software/Ector_Software.h b/src/lib/ector/software/Ector_Software.h
index 2f9192f..85529e6 100644
--- a/src/lib/ector/software/Ector_Software.h
+++ b/src/lib/ector/software/Ector_Software.h
@@ -36,6 +36,7 @@
36#include "software/ector_software_buffer_base.eo.h" 36#include "software/ector_software_buffer_base.eo.h"
37#include "software/ector_renderer_software.eo.h" 37#include "software/ector_renderer_software.eo.h"
38#include "software/ector_renderer_software_shape.eo.h" 38#include "software/ector_renderer_software_shape.eo.h"
39#include "software/ector_renderer_software_image.eo.h"
39#include "software/ector_renderer_software_gradient_linear.eo.h" 40#include "software/ector_renderer_software_gradient_linear.eo.h"
40#include "software/ector_renderer_software_gradient_radial.eo.h" 41#include "software/ector_renderer_software_gradient_radial.eo.h"
41 42
diff --git a/src/lib/ector/software/ector_renderer_software_image.c b/src/lib/ector/software/ector_renderer_software_image.c
new file mode 100644
index 0000000..cb8d93a
--- /dev/null
+++ b/src/lib/ector/software/ector_renderer_software_image.c
@@ -0,0 +1,194 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <math.h>
6#include <float.h>
7
8#include <Eina.h>
9#include <Ector.h>
10#include <software/Ector_Software.h>
11
12#include "ector_private.h"
13#include "ector_software_private.h"
14
15#define MY_CLASS ECTOR_RENDERER_SOFTWARE_IMAGE_CLASS
16
17typedef struct _Ector_Renderer_Software_Image_Data Ector_Renderer_Software_Image_Data;
18
19struct _Ector_Renderer_Software_Image_Data
20{
21 Ector_Software_Surface_Data *surface;
22 Ector_Renderer_Image_Data *image;
23 Ector_Renderer_Data *base;
24 Ector_Buffer *mask;
25 int mask_op;
26 int opacity;
27 Eina_Matrix3 inv_m;
28 struct {
29 int x1, y1, x2, y2;
30 } boundary;
31};
32
33static Eina_Bool
34_ector_renderer_software_image_ector_renderer_prepare(Eo *obj,
35 Ector_Renderer_Software_Image_Data *pd)
36{
37 if (!pd->surface)
38 pd->surface = efl_data_xref(pd->base->surface, ECTOR_SOFTWARE_SURFACE_CLASS, obj);
39
40 if (!pd->image->buffer || !pd->surface->rasterizer->fill_data.raster_buffer)
41 return EINA_FALSE;
42
43 Eina_Matrix3 m;
44 double m11, m12, m21, m22, m31, m32;
45 int x = pd->surface->x + (int)pd->base->origin.x;
46 int y = pd->surface->y + (int)pd->base->origin.y;
47 int image_w, image_h;
48 ector_buffer_size_get(pd->image->buffer, &image_w, &image_h);
49
50 double px[4] = {x, x + image_w, x, x + image_w};
51 double py[4] = {y, y, y + image_h, y + image_h};
52
53 //Only use alpha color
54 pd->opacity = pd->base->color.a;
55 /*ector_software_rasterizer_color_set(pd->surface->rasterizer,
56 pd->base->color.r,
57 pd->base->color.g,
58 pd->base->color.b,
59 pd->base->color.a);*/
60
61 if (!pd->base->m)
62 {
63 eina_matrix3_identity(&m);
64 eina_matrix3_scale(&m, (double)pd->surface->rasterizer->fill_data.raster_buffer->generic->w / (double)image_w,
65 (double)pd->surface->rasterizer->fill_data.raster_buffer->generic->h / (double)image_h);
66 }
67 else
68 eina_matrix3_copy(&m, pd->base->m);
69 eina_matrix3_values_get(&m, &m11, &m12, NULL,
70 &m21, &m22, NULL,
71 &m31, &m32, NULL);
72 //Calc draw boundbox
73 pd->boundary.x1 = MAX(pd->surface->rasterizer->fill_data.raster_buffer->generic->w , (unsigned int)image_w);
74 pd->boundary.y1 = MAX(pd->surface->rasterizer->fill_data.raster_buffer->generic->h , (unsigned int)image_h);
75 pd->boundary.x2 = 0; pd->boundary.y2 = 0;
76 for (int i = 0; i < 4; i++)
77 {
78 pd->boundary.x1 = MIN(pd->boundary.x1, (int)(((px[i] * m11) + (py[i] * m21) + m31) + 0.5));
79 pd->boundary.y1 = MIN(pd->boundary.y1, (int)(((px[i] * m12) + (py[i] * m22) + m32) + 0.5));
80
81 pd->boundary.x2 = MAX(pd->boundary.x2, (int)(((px[i] * m11) + (py[i] * m21) + m31) + 0.5));
82 pd->boundary.y2 = MAX(pd->boundary.y2, (int)(((px[i] * m12) + (py[i] * m22) + m32) + 0.5));
83 }
84
85 eina_matrix3_inverse(&m, &pd->inv_m);
86
87 return EINA_TRUE;
88}
89
90//FIXME: We need to implement that apply op, clips and mul_col.
91static Eina_Bool
92_ector_renderer_software_image_ector_renderer_draw(Eo *obj EINA_UNUSED,
93 Ector_Renderer_Software_Image_Data *pd,
94 Efl_Gfx_Render_Op op EINA_UNUSED, Eina_Array *clips EINA_UNUSED,
95 unsigned int mul_col EINA_UNUSED)
96{
97 if (!pd->image->buffer || !pd->surface->rasterizer->fill_data.raster_buffer->pixels.u32)
98 return EINA_FALSE;
99
100 if (pd->opacity == 0)
101 return EINA_TRUE;
102
103 const int pix_stride = pd->surface->rasterizer->fill_data.raster_buffer->stride / 4;
104 Ector_Software_Buffer_Base_Data *mask = pd->mask ? efl_data_scope_get(pd->mask, ECTOR_SOFTWARE_BUFFER_BASE_MIXIN) : NULL;
105 Ector_Software_Buffer_Base_Data *bpd = efl_data_scope_get(pd->image->buffer, ECTOR_SOFTWARE_BUFFER_BASE_MIXIN);
106 double im11, im12, im21, im22, im31, im32;
107 uint32_t *dst_buf, *src_buf;
108 int image_w, image_h;
109 ector_buffer_size_get(pd->image->buffer, &image_w, &image_h);
110
111 dst_buf = pd->surface->rasterizer->fill_data.raster_buffer->pixels.u32;
112 src_buf = bpd->pixels.u32;
113
114 eina_matrix3_values_get(&pd->inv_m, &im11, &im12, NULL,
115 &im21, &im22, NULL,
116 &im31, &im32, NULL);
117
118 //Draw
119 for (int local_y = pd->boundary.y1; local_y < pd->boundary.y2; local_y++)
120 {
121 for (int local_x = pd->boundary.x1; local_x < pd->boundary.x2; local_x++)
122 {
123 uint32_t *dst = dst_buf + ((int)local_x + ((int)local_y * pix_stride));
124 int rx, ry;
125 rx = (int)(((double)local_x * im11) + ((double)local_y * im21) + im31 + 0.5);
126 ry = (int)(((double)local_x * im12) + ((double)local_y * im22) + im32 + 0.5);
127 if (rx < 0 || rx >= image_w || ry < 0 || ry >= image_h)
128 continue;
129 uint32_t *src = src_buf + (rx + (ry * image_w)); //FIXME: use to stride
130 uint32_t temp = 0x0;
131 if (mask)
132 {
133 uint32_t *m = mask->pixels.u32 + ((int)local_x + ((int)local_y * mask->generic->w));
134 //FIXME : This masking can work only matte case.
135 // We need consider to inverse matte case.
136 temp = draw_mul_256((((*m)>>24) * pd->opacity)>>8, *src);
137 }
138 else
139 {
140 temp = draw_mul_256(pd->opacity, *src);
141 }
142 int inv_alpha = 255 - ((temp) >> 24);
143 *dst = temp + draw_mul_256(inv_alpha, *dst);
144 }
145 }
146
147 return EINA_TRUE;
148}
149
150static Eo *
151_ector_renderer_software_image_efl_object_constructor(Eo *obj, Ector_Renderer_Software_Image_Data *pd)
152{
153 obj = efl_constructor(efl_super(obj, MY_CLASS));
154 if (!obj) return NULL;
155
156 pd->image = efl_data_xref(obj, ECTOR_RENDERER_IMAGE_MIXIN, obj);
157 pd->base = efl_data_xref(obj, ECTOR_RENDERER_CLASS, obj);
158
159 return obj;
160}
161
162static void
163_ector_renderer_software_image_efl_object_destructor(Eo *obj, Ector_Renderer_Software_Image_Data *pd)
164{
165 efl_data_xunref(pd->base->surface, pd->surface, obj);
166 efl_data_xunref(obj, pd->base, obj);
167 efl_data_xunref(obj, pd->image, obj);
168
169 efl_destructor(efl_super(obj, MY_CLASS));
170}
171
172unsigned int
173_ector_renderer_software_image_ector_renderer_crc_get(const Eo *obj,
174 Ector_Renderer_Software_Image_Data *pd)
175{
176 unsigned int crc;
177
178 crc = ector_renderer_crc_get(efl_super(obj, MY_CLASS));
179
180 crc = eina_crc((void*) pd->image, sizeof (Ector_Renderer_Image_Data), crc, EINA_FALSE);
181 return crc;
182}
183
184static void
185_ector_renderer_software_image_ector_renderer_mask_set(Eo *obj EINA_UNUSED,
186 Ector_Renderer_Software_Image_Data *pd,
187 Ector_Buffer *mask,
188 int op)
189{
190 pd->mask = mask;
191 pd->mask_op = op;
192}
193
194#include "ector_renderer_software_image.eo.c"
diff --git a/src/lib/ector/software/ector_renderer_software_image.eo b/src/lib/ector/software/ector_renderer_software_image.eo
new file mode 100644
index 0000000..8a3f9c5
--- /dev/null
+++ b/src/lib/ector/software/ector_renderer_software_image.eo
@@ -0,0 +1,13 @@
1class @beta Ector.Renderer.Software.Image extends Ector.Renderer.Software implements Ector.Renderer.Image
2{
3 [[Ector software renderer image class]]
4 c_prefix: ector_renderer_software_image;
5 implements {
6 Ector.Renderer.prepare;
7 Ector.Renderer.draw;
8 Ector.Renderer.mask { set; }
9 Ector.Renderer.crc { get; }
10 Efl.Object.constructor;
11 Efl.Object.destructor;
12 }
13}
diff --git a/src/lib/ector/software/ector_software_surface.c b/src/lib/ector/software/ector_software_surface.c
index 08a2786..1008fe5 100644
--- a/src/lib/ector/software/ector_software_surface.c
+++ b/src/lib/ector/software/ector_software_surface.c
@@ -204,6 +204,8 @@ _ector_software_surface_ector_surface_renderer_factory_new(Eo *obj,
204{ 204{
205 if (type == ECTOR_RENDERER_SHAPE_MIXIN) 205 if (type == ECTOR_RENDERER_SHAPE_MIXIN)
206 return efl_add_ref(ECTOR_RENDERER_SOFTWARE_SHAPE_CLASS, NULL, ector_renderer_surface_set(efl_added, obj)); 206 return efl_add_ref(ECTOR_RENDERER_SOFTWARE_SHAPE_CLASS, NULL, ector_renderer_surface_set(efl_added, obj));
207 else if (type == ECTOR_RENDERER_IMAGE_MIXIN)
208 return efl_add_ref(ECTOR_RENDERER_SOFTWARE_IMAGE_CLASS, NULL, ector_renderer_surface_set(efl_added, obj));
207 else if (type == ECTOR_RENDERER_GRADIENT_LINEAR_MIXIN) 209 else if (type == ECTOR_RENDERER_GRADIENT_LINEAR_MIXIN)
208 return efl_add_ref(ECTOR_RENDERER_SOFTWARE_GRADIENT_LINEAR_CLASS, NULL, ector_renderer_surface_set(efl_added, obj)); 210 return efl_add_ref(ECTOR_RENDERER_SOFTWARE_GRADIENT_LINEAR_CLASS, NULL, ector_renderer_surface_set(efl_added, obj));
209 else if (type == ECTOR_RENDERER_GRADIENT_RADIAL_MIXIN) 211 else if (type == ECTOR_RENDERER_GRADIENT_RADIAL_MIXIN)
diff --git a/src/lib/ector/software/meson.build b/src/lib/ector/software/meson.build
index 2dff5be..7374252 100644
--- a/src/lib/ector/software/meson.build
+++ b/src/lib/ector/software/meson.build
@@ -3,6 +3,7 @@ ector_src += files([
3 'ector_renderer_software_gradient_linear.c', 3 'ector_renderer_software_gradient_linear.c',
4 'ector_renderer_software_gradient_radial.c', 4 'ector_renderer_software_gradient_radial.c',
5 'ector_renderer_software_shape.c', 5 'ector_renderer_software_shape.c',
6 'ector_renderer_software_image.c',
6 'ector_software_gradient.c', 7 'ector_software_gradient.c',
7 'ector_software_rasterizer.c', 8 'ector_software_rasterizer.c',
8 'ector_software_surface.c', 9 'ector_software_surface.c',
@@ -16,6 +17,7 @@ pub_eo_files = [
16 'ector_software_buffer_base.eo', 17 'ector_software_buffer_base.eo',
17 'ector_renderer_software.eo', 18 'ector_renderer_software.eo',
18 'ector_renderer_software_shape.eo', 19 'ector_renderer_software_shape.eo',
20 'ector_renderer_software_image.eo',
19 'ector_renderer_software_gradient_radial.eo', 21 'ector_renderer_software_gradient_radial.eo',
20 'ector_renderer_software_gradient_linear.eo', 22 'ector_renderer_software_gradient_linear.eo',
21] 23]