summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-11-12 15:52:21 -0800
committerJean-Philippe Andre <jp.andre@samsung.com>2016-01-05 15:43:44 +0900
commit116fe3c65cd541b85623820605e237c4076024f2 (patch)
tree3eb399112740116ea2b3d1dbe75d42a3532d3dae
parent1adc3cd915f9bd55337e37fb782bd1c38080478c (diff)
ector: initial implementation of our own Ector GL backend.
-rw-r--r--configure.ac2
-rw-r--r--src/Makefile_Ector.am42
-rw-r--r--src/lib/ector/gl/Ector_GL.h24
-rw-r--r--src/lib/ector/gl/ector_gl_buffer.c60
-rw-r--r--src/lib/ector/gl/ector_gl_buffer.eo9
-rw-r--r--src/lib/ector/gl/ector_gl_buffer_base.eo14
-rw-r--r--src/lib/ector/gl/ector_gl_private.h69
-rw-r--r--src/lib/ector/gl/ector_gl_shader.c168
-rw-r--r--src/lib/ector/gl/ector_gl_surface.c383
-rw-r--r--src/lib/ector/gl/ector_gl_surface.eo35
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_base.c56
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_base.eo22
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_gradient_linear.c115
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_gradient_linear.eo15
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_gradient_radial.c113
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_gradient_radial.eo15
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_shape.c170
-rw-r--r--src/lib/ector/gl/ector_renderer_gl_shape.eo14
-rw-r--r--src/lib/ector/gl/shader/.gitignore1
-rw-r--r--src/lib/ector/gl/shader/ector_gl_shaders.x285
-rw-r--r--src/lib/ector/gl/shader/fragment.glsl168
-rwxr-xr-xsrc/lib/ector/gl/shader/gen_shaders.sh38
-rw-r--r--src/lib/ector/gl/shader/include.glsl22
-rw-r--r--src/lib/ector/gl/shader/vertex.glsl137
-rw-r--r--src/lib/eina/eina_util.c2
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c3
26 files changed, 1975 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index a7f97c94a8..9efb77bede 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1489,6 +1489,8 @@ EFL_LIB_START([Ector])
1489EFL_PLATFORM_DEPEND([ECTOR], [evil]) 1489EFL_PLATFORM_DEPEND([ECTOR], [evil])
1490 1490
1491EFL_INTERNAL_DEPEND_PKG([ECTOR], [eina]) 1491EFL_INTERNAL_DEPEND_PKG([ECTOR], [eina])
1492EFL_INTERNAL_DEPEND_PKG([ECTOR], [emile])
1493EFL_INTERNAL_DEPEND_PKG([ECTOR], [eet])
1492EFL_INTERNAL_DEPEND_PKG([ECTOR], [eo]) 1494EFL_INTERNAL_DEPEND_PKG([ECTOR], [eo])
1493EFL_INTERNAL_DEPEND_PKG([ECTOR], [efl]) 1495EFL_INTERNAL_DEPEND_PKG([ECTOR], [efl])
1494 1496
diff --git a/src/Makefile_Ector.am b/src/Makefile_Ector.am
index 83d765fcd0..e404df3402 100644
--- a/src/Makefile_Ector.am
+++ b/src/Makefile_Ector.am
@@ -33,10 +33,21 @@ ector_eolian_files_software = \
33 lib/ector/software/ector_renderer_software_gradient_linear.eo 33 lib/ector/software/ector_renderer_software_gradient_linear.eo
34ector_eolian_software_h = $(ector_eolian_files_software:%.eo=%.eo.h) 34ector_eolian_software_h = $(ector_eolian_files_software:%.eo=%.eo.h)
35 35
36# Handle gl backend
37ector_eolian_files_gl = \
38 lib/ector/gl/ector_gl_surface.eo \
39 lib/ector/gl/ector_gl_buffer.eo \
40 lib/ector/gl/ector_gl_buffer_base.eo \
41 lib/ector/gl/ector_renderer_gl_base.eo \
42 lib/ector/gl/ector_renderer_gl_shape.eo \
43 lib/ector/gl/ector_renderer_gl_gradient_radial.eo \
44 lib/ector/gl/ector_renderer_gl_gradient_linear.eo
45
36ector_eolian_files = \ 46ector_eolian_files = \
37 $(ector_eolian_files_generic) \ 47 $(ector_eolian_files_generic) \
38 $(ector_eolian_files_cairo) \ 48 $(ector_eolian_files_cairo) \
39 $(ector_eolian_files_software) 49 $(ector_eolian_files_software) \
50 $(ector_eolian_files_gl)
40 51
41ector_eolian_c = $(ector_eolian_files:%.eo=%.eo.c) 52ector_eolian_c = $(ector_eolian_files:%.eo=%.eo.c)
42ector_eolian_h = $(ector_eolian_files:%.eo=%.eo.h) 53ector_eolian_h = $(ector_eolian_files:%.eo=%.eo.h)
@@ -63,7 +74,8 @@ lib/ector/ector_util.h \
63lib/ector/ector_surface.h \ 74lib/ector/ector_surface.h \
64lib/ector/ector_renderer.h \ 75lib/ector/ector_renderer.h \
65lib/ector/cairo/Ector_Cairo.h \ 76lib/ector/cairo/Ector_Cairo.h \
66lib/ector/software/Ector_Software.h 77lib/ector/software/Ector_Software.h \
78lib/ector/gl/Ector_GL.h
67 79
68# And the generic implementation 80# And the generic implementation
69 81
@@ -115,6 +127,28 @@ static_libs/freetype/sw_ft_raster.c \
115static_libs/freetype/sw_ft_stroker.c \ 127static_libs/freetype/sw_ft_stroker.c \
116$(draw_sources) 128$(draw_sources)
117 129
130# And now the gl backend
131lib_ector_libector_la_SOURCES += \
132lib/ector/gl/ector_renderer_gl_gradient_linear.c \
133lib/ector/gl/ector_renderer_gl_gradient_radial.c \
134lib/ector/gl/ector_renderer_gl_shape.c \
135lib/ector/gl/ector_renderer_gl_base.c \
136lib/ector/gl/ector_gl_buffer.c \
137lib/ector/gl/ector_gl_surface.c \
138lib/ector/gl/ector_gl_private.h \
139lib/ector/gl/shader/ector_gl_shaders.x \
140lib/ector/gl/ector_gl_shader.c
141
142GL_SHADERS_GEN = \
143lib/ector/gl/shader/gen_shaders.sh \
144lib/ector/gl/shader/fragment.glsl \
145lib/ector/gl/shader/vertex.glsl \
146lib/ector/gl/shader/include.glsl
147
148lib/ector/gl/shader/ector_gl_shaders.x: $(GL_SHADERS_GEN)
149 @echo " SHADERS $@"
150 @bash $(srcdir)/lib/ector/gl/shader/gen_shaders.sh
151
118installed_ectorsoftwareheadersdir = $(includedir)/ector-@VMAJ@/software 152installed_ectorsoftwareheadersdir = $(includedir)/ector-@VMAJ@/software
119nodist_installed_ectorsoftwareheaders_DATA = $(ector_eolian_software_h) 153nodist_installed_ectorsoftwareheaders_DATA = $(ector_eolian_software_h)
120 154
@@ -122,6 +156,7 @@ lib_ector_libector_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
122-I$(top_builddir)/src/lib/ector \ 156-I$(top_builddir)/src/lib/ector \
123-I$(top_builddir)/src/lib/ector/cairo \ 157-I$(top_builddir)/src/lib/ector/cairo \
124-I$(top_builddir)/src/lib/ector/software \ 158-I$(top_builddir)/src/lib/ector/software \
159-I$(top_builddir)/src/lib/ector/gl \
125-I$(top_srcdir)/src/static_libs/freetype \ 160-I$(top_srcdir)/src/static_libs/freetype \
126-I$(top_srcdir)/src/static_libs/draw \ 161-I$(top_srcdir)/src/static_libs/draw \
127@ECTOR_CFLAGS@ \ 162@ECTOR_CFLAGS@ \
@@ -175,4 +210,5 @@ static_libs/freetype/sw_ft_raster.h \
175static_libs/freetype/sw_ft_stroker.h \ 210static_libs/freetype/sw_ft_stroker.h \
176static_libs/freetype/sw_ft_types.h \ 211static_libs/freetype/sw_ft_types.h \
177static_libs/draw/draw.h \ 212static_libs/draw/draw.h \
178static_libs/draw/draw_private.h 213static_libs/draw/draw_private.h \
214$(GL_SHADERS_GEN)
diff --git a/src/lib/ector/gl/Ector_GL.h b/src/lib/ector/gl/Ector_GL.h
new file mode 100644
index 0000000000..df49421813
--- /dev/null
+++ b/src/lib/ector/gl/Ector_GL.h
@@ -0,0 +1,24 @@
1#ifndef ECTOR_GL_H_
2# define ECTOR_GL_H_
3
4#include "Ector.h"
5
6#ifndef _ECTOR_GL_SURFACE_EO_CLASS_TYPE
7#define _ECTOR_GL_SURFACE_EO_CLASS_TYPE
8
9typedef Eo Ector_Cairo_Surface;
10
11#endif
12
13typedef unsigned int GLuint;
14typedef short GLshort;
15
16#include "gl/ector_gl_buffer.eo.h"
17#include "gl/ector_gl_buffer_base.eo.h"
18#include "gl/ector_gl_surface.eo.h"
19#include "gl/ector_renderer_gl_base.eo.h"
20#include "gl/ector_renderer_gl_shape.eo.h"
21#include "gl/ector_renderer_gl_gradient_linear.eo.h"
22#include "gl/ector_renderer_gl_gradient_radial.eo.h"
23
24#endif
diff --git a/src/lib/ector/gl/ector_gl_buffer.c b/src/lib/ector/gl/ector_gl_buffer.c
new file mode 100644
index 0000000000..e3732b9c74
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_buffer.c
@@ -0,0 +1,60 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#else
4# define EFL_BETA_API_SUPPORT
5#endif
6
7#include <Eo.h>
8#include "Ector_GL.h"
9#include "ector_private.h"
10#include "ector_gl_private.h"
11#include "ector_generic_buffer.eo.h"
12#include "ector_gl_buffer_base.eo.h"
13
14typedef struct _Ector_GL_Buffer_Base_Data Ector_GL_Buffer_Base_Data;
15struct _Ector_GL_Buffer_Base_Data
16{
17};
18
19static Ector_Buffer_Flag
20_ector_gl_buffer_base_ector_generic_buffer_flags_get(Eo *obj, Ector_GL_Buffer_Base_Data *pd)
21{
22}
23
24static Eina_Bool
25_ector_gl_buffer_base_ector_generic_buffer_pixels_set(Eo *obj, Ector_GL_Buffer_Base_Data *pd, void *pixels, int width, int height, int stride, Efl_Gfx_Colorspace cspace, Eina_Bool writable, unsigned char l, unsigned char r, unsigned char t, unsigned char b)
26{
27}
28
29static uint8_t *
30_ector_gl_buffer_base_ector_generic_buffer_span_get(Eo *obj, Ector_GL_Buffer_Base_Data *pd, int x, int y, unsigned int w, Efl_Gfx_Colorspace cspace, unsigned int *length)
31{
32}
33
34static void
35_ector_gl_buffer_base_ector_generic_buffer_span_free(Eo *obj, Ector_GL_Buffer_Base_Data *pd, uint8_t *data)
36{
37}
38
39static uint8_t *
40_ector_gl_buffer_base_ector_generic_buffer_map(Eo *obj, Ector_GL_Buffer_Base_Data *pd, int *offset, unsigned int *length, Ector_Buffer_Access_Flag mode, unsigned int x, unsigned int y, unsigned int w, unsigned int h, Efl_Gfx_Colorspace cspace, unsigned int *stride)
41{
42}
43
44static void
45_ector_gl_buffer_base_ector_generic_buffer_unmap(Eo *obj, Ector_GL_Buffer_Base_Data *pd, void *data, int offset, unsigned int length)
46{
47}
48
49static Eo_Base *
50_ector_gl_buffer_eo_base_constructor(Eo *obj, void *pd)
51{
52}
53
54static void
55_ector_gl_buffer_eo_base_destructor(Eo *obj, void *pd)
56{
57}
58
59#include "ector_gl_buffer.eo.c"
60#include "ector_gl_buffer_base.eo.c"
diff --git a/src/lib/ector/gl/ector_gl_buffer.eo b/src/lib/ector/gl/ector_gl_buffer.eo
new file mode 100644
index 0000000000..e83fda41f1
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_buffer.eo
@@ -0,0 +1,9 @@
1class Ector.GL.Buffer (Eo.Base, Ector.GL.Buffer.Base)
2{
3 legacy_prefix: null;
4 data: null;
5 implements {
6 Eo.Base.constructor;
7 Eo.Base.destructor;
8 }
9}
diff --git a/src/lib/ector/gl/ector_gl_buffer_base.eo b/src/lib/ector/gl/ector_gl_buffer_base.eo
new file mode 100644
index 0000000000..441f7814fe
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_buffer_base.eo
@@ -0,0 +1,14 @@
1mixin Ector.GL.Buffer.Base (Ector.Generic.Buffer)
2{
3 [[A buffer in Ector GL is a readable & optionally writable image]]
4 eo_prefix: ector_gl_buffer;
5 legacy_prefix: null;
6 implements {
7 Ector.Generic.Buffer.flags.get;
8 Ector.Generic.Buffer.pixels_set;
9 Ector.Generic.Buffer.span_get;
10 Ector.Generic.Buffer.span_free;
11 Ector.Generic.Buffer.map;
12 Ector.Generic.Buffer.unmap;
13 }
14}
diff --git a/src/lib/ector/gl/ector_gl_private.h b/src/lib/ector/gl/ector_gl_private.h
new file mode 100644
index 0000000000..0362e7e723
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_private.h
@@ -0,0 +1,69 @@
1#ifndef ECTOR_GL_PRIVATE_H_
2# define ECTOR_GL_PRIVATE_H_
3
4#define SHADER_FLAG_SAM_BITSHIFT 3
5#define SHADER_FLAG_MASKSAM_BITSHIFT 6
6
7typedef enum {
8 SHADER_FLAG_TEX = (1 << 0),
9 SHADER_FLAG_BGRA = (1 << 1),
10 SHADER_FLAG_MASK = (1 << 2),
11 SHADER_FLAG_SAM12 = (1 << (SHADER_FLAG_SAM_BITSHIFT + 0)),
12 SHADER_FLAG_SAM21 = (1 << (SHADER_FLAG_SAM_BITSHIFT + 1)),
13 SHADER_FLAG_SAM22 = (1 << (SHADER_FLAG_SAM_BITSHIFT + 2)),
14 SHADER_FLAG_MASKSAM12 = (1 << (SHADER_FLAG_MASKSAM_BITSHIFT + 0)),
15 SHADER_FLAG_MASKSAM21 = (1 << (SHADER_FLAG_MASKSAM_BITSHIFT + 1)),
16 SHADER_FLAG_MASKSAM22 = (1 << (SHADER_FLAG_MASKSAM_BITSHIFT + 2)),
17 SHADER_FLAG_IMG = (1 << 9),
18 SHADER_FLAG_BIGENDIAN = (1 << 10),
19 SHADER_FLAG_YUV = (1 << 11),
20 SHADER_FLAG_YUY2 = (1 << 12),
21 SHADER_FLAG_NV12 = (1 << 13),
22 SHADER_FLAG_YUV_709 = (1 << 14),
23 SHADER_FLAG_EXTERNAL = (1 << 15),
24 SHADER_FLAG_AFILL = (1 << 16),
25 SHADER_FLAG_NOMUL = (1 << 17),
26 SHADER_FLAG_ALPHA = (1 << 18),
27 SHADER_FLAG_RGB_A_PAIR = (1 << 19),
28} Shader_Flag;
29#define SHADER_FLAG_COUNT 20
30
31#define SHAD_VERTEX 0
32#define SHAD_COLOR 1
33#define SHAD_TEXUV 2
34#define SHAD_TEXUV2 3
35#define SHAD_TEXUV3 4
36#define SHAD_TEXA 5
37#define SHAD_TEXSAM 6
38#define SHAD_MASK 7
39#define SHAD_MASKSAM 8
40
41static inline void
42gl_compile_link_error(GLuint target, const char *action, Eina_Bool is_shader)
43{
44 int loglen = 0, chars = 0;
45 char *logtxt;
46
47 if (is_shader)
48 /* Shader info log */
49 GL.glGetShaderiv(target, GL_INFO_LOG_LENGTH, &loglen);
50 else
51 /* Program info log */
52 GL.glGetProgramiv(target, GL_INFO_LOG_LENGTH, &loglen);
53
54 if (loglen > 0)
55 {
56 logtxt = calloc(loglen, sizeof(char));
57 if (logtxt)
58 {
59 if (is_shader) GL.glGetShaderInfoLog(target, loglen, &chars, logtxt);
60 else GL.glGetProgramInfoLog(target, loglen, &chars, logtxt);
61 ERR("Failed to %s: %s", action, logtxt);
62 free(logtxt);
63 }
64 }
65}
66
67GLuint ector_gl_shader_compile(uint64_t flags);
68
69#endif
diff --git a/src/lib/ector/gl/ector_gl_shader.c b/src/lib/ector/gl/ector_gl_shader.c
new file mode 100644
index 0000000000..acc366e692
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_shader.c
@@ -0,0 +1,168 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include <dlfcn.h>
9
10#include "gl/Ector_GL.h"
11#include "ector_private.h"
12#include "ector_gl_private.h"
13
14#include "shader/ector_gl_shaders.x"
15
16static const char *_shader_flags[SHADER_FLAG_COUNT] = {
17 "TEX",
18 "BGRA",
19 "MASK",
20 "SAM12",
21 "SAM21",
22 "SAM22",
23 "MASKSAM12",
24 "MASKSAM21",
25 "MASKSAM22",
26 "IMG",
27 "BIGENDIAN",
28 "YUV",
29 "YUY2",
30 "NV12",
31 "YUV_709",
32 "EXTERNAL",
33 "AFILL",
34 "NOMUL",
35 "ALPHA",
36 "RGB_A_PAIR"
37};
38
39static Eina_Strbuf *
40_ector_gl_shader_glsl_get(uint64_t flags, const char *base)
41{
42 Eina_Strbuf *r;
43 unsigned int k;
44
45 r = eina_strbuf_new();
46 for (k =0; k < SHADER_FLAG_COUNT; k++)
47 {
48 if (flags & (1 << k))
49 eina_strbuf_append_printf(r, "#define SHD_%s\n", _shader_flags[k]);
50 }
51
52 eina_strbuf_append(r, base);
53
54 return r;
55}
56
57static GLint
58_ector_gl_shader_glsl_compile(GLuint s, const Eina_Strbuf *shader, const char *type)
59{
60 const char *str;
61 GLint ok = 0;
62
63 str = eina_strbuf_string_get(shader);
64
65 GL.glShaderSource(s, 1, &str, NULL);
66 GL.glCompileShader(s);
67 GL.glGetShaderiv(s, GL_COMPILE_STATUS, &ok);
68 if (!ok)
69 {
70 Eina_Strbuf *err;
71
72 err = eina_strbuf_new();
73 if (!err) goto on_error;
74 eina_strbuf_append_printf(err, "compile of %s shader", type);
75
76 gl_compile_link_error(s, eina_strbuf_string_get(err), EINA_TRUE);
77 ERR("Abort %s:\n%s", eina_strbuf_string_get(err), str);
78
79 eina_strbuf_free(err);
80 }
81
82 on_error:
83 return ok;
84}
85
86static GLint
87_ector_gl_shader_glsl_link(uint64_t flags,
88 const Eina_Strbuf *vertex,
89 const Eina_Strbuf *fragment)
90{
91 GLuint vtx = 0, frg = 0, prg = 0;
92 GLint ok = 0;
93
94 vtx = GL.glCreateShader(GL_VERTEX_SHADER);
95 frg = GL.glCreateShader(GL_FRAGMENT_SHADER);
96
97 // Compiling vertex shader
98 ok = _ector_gl_shader_glsl_compile(vtx, vertex, "vertex");
99 if (!ok) goto on_error;
100
101 // Compile fragment shader
102 ok = _ector_gl_shader_glsl_compile(frg, fragment, "fragment");
103 if (!ok) goto on_error;
104
105 // Link both shader together
106 ok = 0;
107
108 prg = GL.glCreateProgram();
109#ifndef GL_GLES
110 if ((GL.glGetProgramBinary) && (GL.glProgramParameteri))
111 GL.glProgramParameteri(prg, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
112#endif
113 GL.glAttachShader(prg, vtx);
114 GL.glAttachShader(prg, frg);
115
116 GL.glBindAttribLocation(prg, SHAD_VERTEX, "vertex");
117 GL.glBindAttribLocation(prg, SHAD_COLOR, "color");
118 GL.glBindAttribLocation(prg, SHAD_TEXUV, "tex_coord");
119 GL.glBindAttribLocation(prg, SHAD_TEXUV2, "tex_coord2");
120 GL.glBindAttribLocation(prg, SHAD_TEXUV3, "tex_coord3");
121 GL.glBindAttribLocation(prg, SHAD_TEXA, "tex_coorda");
122 GL.glBindAttribLocation(prg, SHAD_TEXSAM, "tex_sample");
123 GL.glBindAttribLocation(prg, SHAD_MASK, "mask_coord");
124 GL.glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
125
126 GL.glLinkProgram(prg);
127 GL.glGetProgramiv(prg, GL_LINK_STATUS, &ok);
128 if (!ok)
129 {
130 gl_compile_link_error(prg, "link fragment and vertex shaders", EINA_FALSE);
131 ERR("Abort compile of shader (flags: %16lx)", flags);
132 GL.glDeleteProgram(prg);
133 prg = 0;
134 goto on_error;
135 }
136
137 on_error:
138 if (vtx) GL.glDeleteShader(vtx);
139 if (frg) GL.glDeleteShader(frg);
140
141 return prg;
142}
143
144GLuint
145ector_gl_shader_compile(uint64_t flags)
146{
147 Eina_Strbuf *vertex, *fragment;
148 GLuint shd = 0;
149
150 vertex = _ector_gl_shader_glsl_get(flags, vertex_glsl);
151 fragment = _ector_gl_shader_glsl_get(flags, fragment_glsl);
152 if (!vertex || !fragment) goto on_error;
153
154 shd = _ector_gl_shader_glsl_link(flags, vertex, fragment);
155
156 on_error:
157 eina_strbuf_free(vertex);
158 eina_strbuf_free(fragment);
159
160#ifdef GL_GLES
161 GL.glReleaseShaderCompiler();
162#else
163 if (GL.glReleaseShaderCompiler)
164 GL.glReleaseShaderCompiler();
165#endif
166
167 return shd;
168}
diff --git a/src/lib/ector/gl/ector_gl_surface.c b/src/lib/ector/gl/ector_gl_surface.c
new file mode 100644
index 0000000000..3397e567ed
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_surface.c
@@ -0,0 +1,383 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Eet.h>
7#include <Ector.h>
8
9#include <dlfcn.h>
10
11#include "gl/Ector_GL.h"
12#include "ector_private.h"
13#include "ector_gl_private.h"
14
15typedef struct _Ector_GL_Surface_Data Ector_GL_Surface_Data;
16struct _Ector_GL_Surface_Data
17{
18 struct {
19 int x, y;
20 } reference_point;
21
22 Efl_Gfx_Render_Op op;
23};
24
25typedef struct _Ector_Shader Ector_Shader;
26struct _Ector_Shader
27{
28 uint64_t flags;
29 GLuint prg;
30};
31
32static Eina_Hash *shader_cache = NULL;
33static Eet_File *shader_file = NULL;
34
35static void
36_shader_free(void *s)
37{
38 Ector_Shader *shd = s;
39
40 GL.glDeleteProgram(shd->prg);
41 free(shd);
42}
43
44static Ector_Renderer *
45_ector_gl_surface_ector_generic_surface_renderer_factory_new(Eo *obj,
46 Ector_GL_Surface_Data *pd EINA_UNUSED,
47 const Eo_Class *type)
48{
49 if (type == ECTOR_RENDERER_GENERIC_SHAPE_MIXIN)
50 return eo_add(ECTOR_RENDERER_GL_SHAPE_CLASS, NULL,
51 ector_renderer_surface_set(obj));
52 else if (type == ECTOR_RENDERER_GENERIC_GRADIENT_LINEAR_MIXIN)
53 return eo_add(ECTOR_RENDERER_GL_GRADIENT_LINEAR_CLASS, NULL,
54 ector_renderer_surface_set(obj));
55 else if (type == ECTOR_RENDERER_GENERIC_GRADIENT_RADIAL_MIXIN)
56 return eo_add(ECTOR_RENDERER_GL_GRADIENT_RADIAL_CLASS, NULL,
57 ector_renderer_surface_set(obj));
58
59 ERR("Couldn't find class for type: %s\n", eo_class_name_get(type));
60 return NULL;
61}
62
63static void
64_ector_gl_surface_ector_generic_surface_reference_point_set(Eo *obj EINA_UNUSED,
65 Ector_GL_Surface_Data *pd,
66 int x, int y)
67{
68 pd->reference_point.x = x;
69 pd->reference_point.y = y;
70}
71
72#define VERTEX_CNT 3
73#define COLOR_CNT 4
74
75static Eina_Bool
76_ector_gl_surface_push(Eo *obj,
77 Ector_GL_Surface_Data *pd EINA_UNUSED,
78 uint64_t flags, GLshort *vertex, unsigned int vertex_count, unsigned int mul_col)
79{
80 unsigned int prog;
81
82 eo_do(obj, prog = ector_gl_surface_shader_get(flags));
83
84 // FIXME: Not using mapp/unmap buffer yet, nor any pipe
85 // FIXME: Move some of the state change to surface drawing start ?
86 GL.glUseProgram(prog);
87 GL.glDisable(GL_TEXTURE_2D);
88 GL.glDisable(GL_SCISSOR_TEST);
89 GL.glVertexAttribPointer(SHAD_VERTEX, VERTEX_CNT, GL_SHORT, GL_FALSE, 0, vertex);
90 GL.glEnableVertexAttribArray(SHAD_COLOR);
91 GL.glVertexAttribPointer(SHAD_COLOR, COLOR_CNT, GL_UNSIGNED_BYTE, GL_TRUE, 0, &mul_col);
92 GL.glDrawArrays(GL_TRIANGLES, 0, vertex_count);
93
94 return EINA_TRUE;
95}
96
97static Eina_Bool
98_ector_gl_surface_state_define(Eo *obj EINA_UNUSED, Ector_GL_Surface_Data *pd, Efl_Gfx_Render_Op op, Eina_Array *clips)
99{
100 if (pd->op == op) return EINA_TRUE;
101
102 // FIXME: no pipe yet, so we can just change the mode right away
103 // Get & apply matrix transformation to
104 switch (op)
105 {
106 case EFL_GFX_RENDER_OP_BLEND: /**< default op: d = d*(1-sa) + s */
107 GL.glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
108 GL.glEnable(GL_BLEND);
109 break;
110 case EFL_GFX_RENDER_OP_COPY: /**< d = s */
111 // just disable blend mode. no need to set blend func
112 GL.glDisable(GL_BLEND);
113 break;
114 case EFL_GFX_RENDER_OP_LAST:
115 default:
116 return EINA_FALSE;
117 }
118
119 pd->op = op;
120
121 //FIXME: we should not ignore clipping, but that can last for later
122 (void) clips;
123
124 return EINA_TRUE;
125}
126
127static void
128_ector_gl_shader_textures_bind(Ector_Shader *p)
129{
130 struct {
131 const char *name;
132 int enabled;
133 } textures[] = {
134 { "tex", 0 },
135 { "texm", 0 },
136 { "texa", 0 },
137 { "texu", 0 },
138 { "texv", 0 },
139 { "texuv", 0 },
140 { NULL, 0 }
141 };
142 Eina_Bool hastex = 0;
143 int tex_count = 0;
144 GLint loc;
145 int i;
146
147 if (!p) return;
148
149 if ((p->flags & SHADER_FLAG_TEX) != 0)
150 {
151 textures[0].enabled = 1;
152 hastex = 1;
153 }
154 if ((p->flags & SHADER_FLAG_MASK) != 0)
155 {
156 textures[1].enabled = 1;
157 hastex = 1;
158 }
159 if ((p->flags & SHADER_FLAG_RGB_A_PAIR) != 0)
160 {
161 textures[2].enabled = 1;
162 hastex = 1;
163 }
164 if (p->flags & SHADER_FLAG_YUV)
165 {
166 textures[3].enabled = 1;
167 textures[4].enabled = 1;
168 hastex = 1;
169 }
170 else if ((p->flags & SHADER_FLAG_NV12) || (p->flags & SHADER_FLAG_YUY2))
171 {
172 textures[5].enabled = 1;
173 hastex = 1;
174 }
175
176 if (hastex)
177 {
178 GL.glUseProgram(p->prg); // is this necessary??
179 for (i = 0; textures[i].name; i++)
180 {
181 if (!textures[i].enabled) continue;
182 loc = GL.glGetUniformLocation(p->prg, textures[i].name);
183 if (loc < 0)
184 {
185 ERR("Couldn't find uniform '%s' (shader: %16lx)",
186 textures[i].name, p->flags);
187 }
188 GL.glUniform1i(loc, tex_count++);
189 }
190 }
191}
192
193static Ector_Shader *
194_ector_gl_shader_load(uint64_t flags)
195{
196 Eina_Strbuf *buf;
197 Ector_Shader *r = NULL;
198 void *data;
199 int *formats = NULL;
200 int length = 0, num = 0;
201 GLuint prg;
202 GLint ok = 0, vtx = GL_NONE, frg = GL_NONE;
203 Eina_Bool direct = 1;
204
205 buf = eina_strbuf_new();
206 if (!buf) return NULL;
207
208 eina_strbuf_append_printf(buf, "ector/shader/%16lx", flags);
209
210 data = (void*) eet_read_direct(shader_file, eina_strbuf_string_get(buf), &length);
211 if (!data)
212 {
213 data = eet_read(shader_file, eina_strbuf_string_get(buf), &length);
214 direct = 0;
215 }
216 if ((!data) || (length <= 0)) goto on_error;
217
218 GL.glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &num);
219 if (num <= 0) goto on_error;
220
221 formats = calloc(num, sizeof(int));
222 if (!formats) goto on_error;
223
224 GL.glGetIntegerv(GL_PROGRAM_BINARY_FORMATS, formats);
225 if (!formats[0]) goto on_error;
226
227 prg = GL.glCreateProgram();
228 // TODO: invalid rendering error occurs when attempting to use a
229 // glProgramBinary. in order to render correctly we should create a dummy
230 // vertex shader.
231 vtx = GL.glCreateShader(GL_VERTEX_SHADER);
232 GL.glAttachShader(prg, vtx);
233 frg = GL.glCreateShader(GL_FRAGMENT_SHADER);
234 GL.glAttachShader(prg, frg);
235
236 GL.glProgramBinary(prg, formats[0], data, length);
237
238 GL.glBindAttribLocation(prg, SHAD_VERTEX, "vertex");
239 GL.glBindAttribLocation(prg, SHAD_COLOR, "color");
240 GL.glBindAttribLocation(prg, SHAD_TEXUV, "tex_coord");
241 GL.glBindAttribLocation(prg, SHAD_TEXUV2, "tex_coord2");
242 GL.glBindAttribLocation(prg, SHAD_TEXUV3, "tex_coord3");
243 GL.glBindAttribLocation(prg, SHAD_TEXA, "tex_coorda");
244 GL.glBindAttribLocation(prg, SHAD_TEXSAM, "tex_sample");
245 GL.glBindAttribLocation(prg, SHAD_MASK, "mask_coord");
246 GL.glBindAttribLocation(prg, SHAD_MASKSAM, "tex_masksample");
247
248 GL.glGetProgramiv(prg, GL_LINK_STATUS, &ok);
249 if (!ok)
250 {
251 gl_compile_link_error(prg, "load a program object", EINA_FALSE);
252 ERR("Abort load of program (%s)", eina_strbuf_string_get(buf));
253 GL.glDeleteProgram(prg);
254 goto on_error;
255 }
256
257 r = malloc(sizeof (Ector_Shader));
258 r->prg = prg;
259 r->flags = flags;
260
261 _ector_gl_shader_textures_bind(r);
262
263 on_error:
264 if (vtx) GL.glDeleteShader(vtx);
265 if (frg) GL.glDeleteShader(frg);
266 free(formats);
267
268 if (!direct) free(data);
269 eina_strbuf_free(buf);
270 return r;
271}
272
273static unsigned int
274_ector_gl_surface_shader_get(Eo *obj EINA_UNUSED, Ector_GL_Surface_Data *pd EINA_UNUSED, uint64_t flags)
275{
276 Ector_Shader *shd;
277 Eina_Strbuf *buf = NULL;
278 void *data = NULL;
279 int length = 0, size = 0;
280 GLenum format;
281 GLuint prg;
282
283 shd = eina_hash_find(shader_cache, &flags);
284 if (shd) return shd->prg;
285
286 shd = _ector_gl_shader_load(flags);
287 if (shd) return shd->prg;
288
289 prg = ector_gl_shader_compile(flags);
290 if (prg <= 0) return -1;
291
292 GL.glGetProgramiv(prg, GL_PROGRAM_BINARY_LENGTH, &length);
293 if (length <= 0) return prg;
294
295 if (GL.glGetProgramBinary)
296 {
297 data = malloc(length);
298 if (!data) return prg;
299
300 GL.glGetProgramBinary(prg, length, &size, &format, data);
301 if (length != size) goto on_error;
302 }
303
304 shd = malloc(sizeof (Ector_Shader));
305 if (!shd) goto on_error;
306
307 shd->prg = prg;
308 shd->flags = flags;
309
310 // Saving the shader in the memory cache
311 eina_hash_direct_add(shader_cache, &shd->flags, shd);
312
313 // Saving binary shader in the cache file.
314 if (GL.glGetProgramBinary)
315 {
316 buf = eina_strbuf_new();
317 eina_strbuf_append_printf(buf, "ector/shader/%16lx", flags);
318
319 eet_write(shader_file, eina_strbuf_string_get(buf), data, length, 1);
320
321 eina_strbuf_free(buf);
322 }
323
324 on_error:
325 free(data);
326
327 return prg;
328}
329
330static void
331_ector_gl_surface_eo_base_destructor(Eo *obj, Ector_GL_Surface_Data *pd EINA_UNUSED)
332{
333 eo_do_super(obj, ECTOR_GL_SURFACE_CLASS, eo_destructor());
334
335 eina_hash_free(shader_cache);
336 shader_cache = NULL;
337 eet_close(shader_file);
338 shader_file = NULL;
339}
340
341static Eo_Base *
342_ector_gl_surface_eo_base_constructor(Eo *obj, Ector_GL_Surface_Data *pd EINA_UNUSED)
343{
344 Eina_Strbuf *file_path = NULL;
345
346 eo_do_super(obj, ECTOR_GL_SURFACE_CLASS, obj = eo_constructor());
347 if (!obj) return NULL;
348
349 if (shader_cache) return obj;
350
351 // Only initialize things once
352 shader_cache = eina_hash_int64_new(_shader_free);
353
354 /* glsym_glProgramBinary = _ector_gl_symbol_get(obj, "glProgramBinary"); */
355 /* glsym_glGetProgramBinary = _ector_gl_symbol_get(obj, "glGetProgramBinary"); */
356 /* glsym_glProgramParameteri = _ector_gl_symbol_get(obj, "glProgramParameteri"); */
357 /* glsym_glReleaseShaderCompiler = _ector_gl_symbol_get(obj, "glReleaseShaderCompiler"); */
358
359 if (GL.glProgramBinary && GL.glGetProgramBinary)
360 {
361 file_path = eina_strbuf_new();
362 if (eina_environment_home_get())
363 eina_strbuf_append(file_path, eina_environment_home_get());
364 else
365 eina_strbuf_append(file_path, eina_environment_tmp_get());
366 eina_strbuf_append_printf(file_path, "%c.cache", EINA_PATH_SEP_C);
367 // FIXME: test and create path if necessary
368 eina_strbuf_append_printf(file_path, "%cector", EINA_PATH_SEP_C);
369 eina_strbuf_append_printf(file_path, "%cector-shader-%i.%i.eet",
370 EINA_PATH_SEP_C, EFL_VERSION_MAJOR, EFL_VERSION_MINOR);
371 shader_file = eet_open(eina_strbuf_string_get(file_path), EET_FILE_MODE_READ_WRITE);
372 }
373 if (!shader_file)
374 {
375 ERR("Unable to create '%s' ector binary shader file.", eina_strbuf_string_get(file_path));
376 GL.glProgramBinary = NULL;
377 }
378 eina_strbuf_free(file_path);
379
380 return obj;
381}
382
383#include "ector_gl_surface.eo.c"
diff --git a/src/lib/ector/gl/ector_gl_surface.eo b/src/lib/ector/gl/ector_gl_surface.eo
new file mode 100644
index 0000000000..31e6657975
--- /dev/null
+++ b/src/lib/ector/gl/ector_gl_surface.eo
@@ -0,0 +1,35 @@
1class Ector.GL.Surface (Ector.GL.Buffer, Ector.Generic.Surface)
2{
3 eo_prefix: ector_gl_surface;
4 legacy_prefix: null;
5 methods {
6 shader_get {
7 return: uint;
8 params {
9 @in flags: uint64_t;
10 }
11 }
12 push {
13 return: bool;
14 params {
15 @in flags: uint64_t;
16 @in vertex: GLshort *;
17 @in vertex_count: uint;
18 @in mul_col: uint;
19 }
20 }
21 state_define {
22 return: bool;
23 params {
24 @in op: Efl.Gfx.Render_Op;
25 @in clips: array<Eina.Rectangle *> *; [[array of @Eina.Rectangle clip]]
26 }
27 }
28 }
29 implements {
30 Ector.Generic.Surface.renderer_factory_new;
31 Ector.Generic.Surface.reference_point.set;
32 Eo.Base.destructor;
33 Eo.Base.constructor;
34 }
35}
diff --git a/src/lib/ector/gl/ector_renderer_gl_base.c b/src/lib/ector/gl/ector_renderer_gl_base.c
new file mode 100644
index 0000000000..a659d3dfb6
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_base.c
@@ -0,0 +1,56 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include "gl/Ector_GL.h"
9#include "ector_private.h"
10#include "ector_gl_private.h"
11
12typedef struct _Ector_Renderer_GL_Base_Data Ector_Renderer_GL_Base_Data;
13struct _Ector_Renderer_GL_Base_Data
14{
15 Ector_Renderer_Generic_Base_Data *base;
16};
17
18static Eina_Bool
19_ector_renderer_gl_base_ector_renderer_generic_base_prepare(Eo *obj EINA_UNUSED,
20 Ector_Renderer_GL_Base_Data *pd EINA_UNUSED)
21{
22 return EINA_TRUE;
23}
24
25static Eina_Bool
26_ector_renderer_gl_base_ector_renderer_generic_base_draw(Eo *obj EINA_UNUSED,
27 Ector_Renderer_GL_Base_Data *pd,
28 Efl_Gfx_Render_Op op,
29 Eina_Array *clips,
30 unsigned int mul_col EINA_UNUSED)
31{
32 Eina_Bool r;
33
34 eo_do(pd->base->surface,
35 r = ector_gl_surface_state_define(op, clips));
36
37 return r;
38}
39
40static Eo_Base *
41_ector_renderer_gl_base_eo_base_constructor(Eo *obj, Ector_Renderer_GL_Base_Data *pd)
42{
43 eo_do_super(obj, ECTOR_RENDERER_GL_BASE_CLASS, obj = eo_constructor());
44 if (!obj) return NULL;
45
46 pd->base = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_BASE_CLASS, obj);
47 return obj;
48}
49
50static void
51_ector_renderer_gl_base_eo_base_destructor(Eo *obj, Ector_Renderer_GL_Base_Data *pd)
52{
53 eo_data_xunref(obj, pd->base, obj);
54}
55
56#include "ector_renderer_gl_base.eo.c"
diff --git a/src/lib/ector/gl/ector_renderer_gl_base.eo b/src/lib/ector/gl/ector_renderer_gl_base.eo
new file mode 100644
index 0000000000..0bbcd56a32
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_base.eo
@@ -0,0 +1,22 @@
1abstract Ector.Renderer.GL.Base (Ector.Renderer.Generic.Base)
2{
3 legacy_prefix: null;
4 methods {
5 fill {
6 return: bool;
7 params {
8 @in flags: uint64_t;
9 @in vertex: GLshort*;
10 @in vertex_count: uint;
11 @in mul_col: uint;
12 }
13 }
14 }
15 implements {
16 @virtual .fill;
17 Ector.Renderer.Generic.Base.prepare;
18 Ector.Renderer.Generic.Base.draw;
19 Eo.Base.constructor;
20 Eo.Base.destructor;
21 }
22}
diff --git a/src/lib/ector/gl/ector_renderer_gl_gradient_linear.c b/src/lib/ector/gl/ector_renderer_gl_gradient_linear.c
new file mode 100644
index 0000000000..6920ac1ad1
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_gradient_linear.c
@@ -0,0 +1,115 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include "gl/Ector_GL.h"
9#include "ector_private.h"
10#include "ector_gl_private.h"
11
12typedef struct _Ector_Renderer_GL_Gradient_Linear_Data Ector_Renderer_GL_Gradient_Linear_Data;
13struct _Ector_Renderer_GL_Gradient_Linear_Data
14{
15 Ector_Renderer_Generic_Gradient_Linear_Data *linear;
16 Ector_Renderer_Generic_Gradient_Data *gradient;
17 Ector_Renderer_Generic_Base_Data *base;
18};
19
20static Eina_Bool
21_ector_renderer_gl_gradient_linear_ector_renderer_generic_base_prepare(Eo *obj,
22 Ector_Renderer_GL_Gradient_Linear_Data *pd)
23{
24 // FIXME: prepare something
25 (void) obj;
26 (void) pd;
27
28 return EINA_TRUE;
29}
30
31static Eina_Bool
32_ector_renderer_gl_gradient_linear_ector_renderer_generic_base_draw(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd, Efl_Gfx_Render_Op op, Eina_Array *clips, unsigned int mul_col)
33{
34 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_LINEAR_CLASS,
35 ector_renderer_draw(op, clips, mul_col));
36
37 // FIXME: draw something !
38 (void) pd;
39
40 return EINA_TRUE;
41}
42
43static void
44_ector_renderer_gl_gradient_linear_ector_renderer_generic_base_bounds_get(Eo *obj EINA_UNUSED,
45 Ector_Renderer_GL_Gradient_Linear_Data *pd,
46 Eina_Rectangle *r)
47{
48 EINA_RECTANGLE_SET(r,
49 pd->base->origin.x + pd->linear->start.x,
50 pd->base->origin.y + pd->linear->start.y,
51 pd->linear->end.x - pd->linear->start.x,
52 pd->linear->end.y - pd->linear->start.y);
53}
54
55static Eina_Bool
56_ector_renderer_gl_gradient_linear_ector_renderer_gl_base_fill(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd, uint64_t flags, GLshort *vertex, unsigned int vertex_count, unsigned int mul_col)
57{
58 // FIXME: The idea here is to select the right shader and push the needed parameter for it
59 // along with the other value
60 (void) obj;
61 (void) pd;
62 (void) flags;
63 (void) vertex;
64 (void) vertex_count;
65 (void) mul_col;
66
67 return EINA_TRUE;
68}
69
70static Eo_Base *
71_ector_renderer_gl_gradient_linear_eo_base_constructor(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd)
72{
73 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_LINEAR_CLASS, obj = eo_constructor());
74
75 if (!obj) return NULL;
76
77 pd->base = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_BASE_CLASS, obj);
78 pd->linear = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_LINEAR_MIXIN, obj);
79 pd->gradient = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_MIXIN, obj);
80
81 return obj;
82}
83
84static void
85_ector_renderer_gl_gradient_linear_eo_base_destructor(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd)
86{
87 eo_data_xunref(obj, pd->base, obj);
88 eo_data_xunref(obj, pd->linear, obj);
89 eo_data_xunref(obj, pd->gradient, obj);
90}
91
92static void
93_ector_renderer_gl_gradient_linear_efl_gfx_gradient_base_stop_set(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd EINA_UNUSED, const Efl_Gfx_Gradient_Stop *colors, unsigned int length)
94{
95 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_LINEAR_CLASS,
96 efl_gfx_gradient_stop_set(colors, length));
97}
98
99static unsigned int
100_ector_renderer_gl_gradient_linear_ector_renderer_generic_base_crc_get(Eo *obj, Ector_Renderer_GL_Gradient_Linear_Data *pd)
101{
102 unsigned int crc;
103
104 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_LINEAR_CLASS,
105 crc = ector_renderer_crc_get());
106
107 crc = eina_crc((void*) pd->gradient->s, sizeof (Efl_Gfx_Gradient_Spread), crc, EINA_FALSE);
108 if (pd->gradient->colors_count)
109 crc = eina_crc((void*) pd->gradient->colors, sizeof (Efl_Gfx_Gradient_Stop) * pd->gradient->colors_count, crc, EINA_FALSE);
110 crc = eina_crc((void*) pd->linear, sizeof (Ector_Renderer_Generic_Gradient_Linear_Data), crc, EINA_FALSE);
111
112 return crc;
113}
114
115#include "ector_renderer_gl_gradient_linear.eo.c"
diff --git a/src/lib/ector/gl/ector_renderer_gl_gradient_linear.eo b/src/lib/ector/gl/ector_renderer_gl_gradient_linear.eo
new file mode 100644
index 0000000000..4ba0d5b3a6
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_gradient_linear.eo
@@ -0,0 +1,15 @@
1class Ector.Renderer.GL.Gradient_Linear (Ector.Renderer.GL.Base, Ector.Renderer.Generic.Gradient, Ector.Renderer.Generic.Gradient_Linear)
2{
3 eo_prefix: ector_renderer_gl_gradient_linear;
4 legacy_prefix: null;
5 implements {
6 Ector.Renderer.Generic.Base.prepare;
7 Ector.Renderer.Generic.Base.draw;
8 Ector.Renderer.Generic.Base.bounds_get;
9 Ector.Renderer.Generic.Base.crc.get;
10 Ector.Renderer.GL.Base.fill;
11 Eo.Base.constructor;
12 Eo.Base.destructor;
13 Efl.Gfx.Gradient.Base.stop.set;
14 }
15}
diff --git a/src/lib/ector/gl/ector_renderer_gl_gradient_radial.c b/src/lib/ector/gl/ector_renderer_gl_gradient_radial.c
new file mode 100644
index 0000000000..9d7d65c886
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_gradient_radial.c
@@ -0,0 +1,113 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include "gl/Ector_GL.h"
9#include "ector_private.h"
10#include "ector_gl_private.h"
11
12typedef struct _Ector_Renderer_GL_Gradient_Radial_Data Ector_Renderer_GL_Gradient_Radial_Data;
13struct _Ector_Renderer_GL_Gradient_Radial_Data
14{
15 Ector_Renderer_Generic_Gradient_Radial_Data *radial;
16 Ector_Renderer_Generic_Gradient_Data *gradient;
17 Ector_Renderer_Generic_Base_Data *base;
18};
19
20static Eina_Bool
21_ector_renderer_gl_gradient_radial_ector_renderer_generic_base_prepare(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd)
22{
23 // FIXME: prepare something
24 (void) obj;
25 (void) pd;
26
27 return EINA_TRUE;
28}
29
30static Eina_Bool
31_ector_renderer_gl_gradient_radial_ector_renderer_generic_base_draw(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd, Efl_Gfx_Render_Op op, Eina_Array *clips, unsigned int mul_col)
32{
33 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_RADIAL_CLASS,
34 ector_renderer_draw(op, clips, mul_col));
35
36 // FIXME: draw something !
37 (void) pd;
38
39 return EINA_TRUE;
40}
41
42static Eina_Bool
43_ector_renderer_gl_gradient_radial_ector_renderer_gl_base_fill(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd, uint64_t flags, GLshort *vertex, unsigned int vertex_count, unsigned int mul_col)
44{
45 // FIXME: The idea here is to select the right shader and push the needed parameter for it
46 // along with the other value
47 (void) obj;
48 (void) pd;
49 (void) flags;
50 (void) vertex;
51 (void) vertex_count;
52 (void) mul_col;
53
54 return EINA_TRUE;
55}
56
57static void
58_ector_renderer_gl_gradient_radial_ector_renderer_generic_base_bounds_get(Eo *obj EINA_UNUSED,
59 Ector_Renderer_GL_Gradient_Radial_Data *pd,
60 Eina_Rectangle *r)
61{
62 EINA_RECTANGLE_SET(r,
63 pd->base->origin.x + pd->radial->radial.x - pd->radial->radius,
64 pd->base->origin.y + pd->radial->radial.y - pd->radial->radius,
65 pd->radial->radius * 2, pd->radial->radius * 2 );
66}
67
68static unsigned int
69_ector_renderer_gl_gradient_radial_ector_renderer_generic_base_crc_get(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd)
70{
71 unsigned int crc;
72
73 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_RADIAL_CLASS,
74 crc = ector_renderer_crc_get());
75
76 crc = eina_crc((void*) pd->gradient->s, sizeof (Efl_Gfx_Gradient_Spread), crc, EINA_FALSE);
77 if (pd->gradient->colors_count)
78 crc = eina_crc((void*) pd->gradient->colors, sizeof (Efl_Gfx_Gradient_Stop) * pd->gradient->colors_count, crc, EINA_FALSE);
79 crc = eina_crc((void*) pd->radial, sizeof (Ector_Renderer_Generic_Gradient_Radial_Data), crc, EINA_FALSE);
80
81 return crc;
82}
83
84static Eo_Base *
85_ector_renderer_gl_gradient_radial_eo_base_constructor(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd)
86{
87 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_RADIAL_CLASS, obj = eo_constructor());
88
89 if (!obj) return NULL;
90
91 pd->base = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_BASE_CLASS, obj);
92 pd->radial = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_RADIAL_MIXIN, obj);
93 pd->gradient = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_GRADIENT_MIXIN, obj);
94
95 return obj;
96}
97
98static void
99_ector_renderer_gl_gradient_radial_eo_base_destructor(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd)
100{
101 eo_data_xunref(obj, pd->base, obj);
102 eo_data_xunref(obj, pd->radial, obj);
103 eo_data_xunref(obj, pd->gradient, obj);
104}
105
106static void
107_ector_renderer_gl_gradient_radial_efl_gfx_gradient_base_stop_set(Eo *obj, Ector_Renderer_GL_Gradient_Radial_Data *pd EINA_UNUSED, const Efl_Gfx_Gradient_Stop *colors, unsigned int length)
108{
109 eo_do_super(obj, ECTOR_RENDERER_GL_GRADIENT_RADIAL_CLASS,
110 efl_gfx_gradient_stop_set(colors, length));
111}
112
113#include "ector_renderer_gl_gradient_radial.eo.c"
diff --git a/src/lib/ector/gl/ector_renderer_gl_gradient_radial.eo b/src/lib/ector/gl/ector_renderer_gl_gradient_radial.eo
new file mode 100644
index 0000000000..c1c7a81440
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_gradient_radial.eo
@@ -0,0 +1,15 @@
1class Ector.Renderer.GL.Gradient_Radial (Ector.Renderer.GL.Base, Ector.Renderer.Generic.Gradient, Ector.Renderer.Generic.Gradient_Radial)
2{
3 eo_prefix: ector_renderer_gl_gradient_radial;
4 legacy_prefix: null;
5 implements {
6 Ector.Renderer.Generic.Base.prepare;
7 Ector.Renderer.Generic.Base.draw;
8 Ector.Renderer.Generic.Base.bounds_get;
9 Ector.Renderer.Generic.Base.crc.get;
10 Ector.Renderer.GL.Base.fill;
11 Eo.Base.constructor;
12 Eo.Base.destructor;
13 Efl.Gfx.Gradient.Base.stop.set;
14 }
15}
diff --git a/src/lib/ector/gl/ector_renderer_gl_shape.c b/src/lib/ector/gl/ector_renderer_gl_shape.c
new file mode 100644
index 0000000000..bf69e0b42b
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_shape.c
@@ -0,0 +1,170 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <Eina.h>
6#include <Ector.h>
7
8#include "gl/Ector_GL.h"
9#include "ector_private.h"
10#include "ector_gl_private.h"
11
12typedef struct _Ector_Renderer_GL_Shape_Data Ector_Renderer_GL_Shape_Data;
13struct _Ector_Renderer_GL_Shape_Data
14{
15 Efl_Gfx_Shape_Public *public_shape;
16
17 Ector_Renderer_Generic_Shape_Data *shape;
18 Ector_Renderer_Generic_Base_Data *base;
19
20 GLshort *vertex;
21};
22
23static Eina_Bool
24_ector_renderer_gl_shape_path_changed(void *data, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
25{
26 Ector_Renderer_GL_Shape_Data *pd = data;
27
28 free(pd->vertex);
29 pd->vertex = NULL;
30
31 return EINA_TRUE;
32}
33
34static Eina_Bool
35_ector_renderer_gl_shape_ector_renderer_generic_base_prepare(Eo *obj, Ector_Renderer_GL_Shape_Data *pd)
36{
37 Eina_Rectangle bounding_box;
38 Eina_Bool r;
39
40 if (pd->vertex) return EINA_TRUE;
41
42 eo_do_super(obj, ECTOR_RENDERER_GL_SHAPE_CLASS, r = ector_renderer_prepare());
43
44 eo_do(obj, ector_renderer_bounds_get(&bounding_box));
45
46 pd->vertex = malloc(sizeof (GLshort) * 6 * 3);
47
48 // Pushing 2 triangles
49 pd->vertex[0] = bounding_box.x;
50 pd->vertex[1] = bounding_box.y;
51 pd->vertex[2] = 0;
52 pd->vertex[3] = bounding_box.x + bounding_box.w;
53 pd->vertex[4] = bounding_box.y;
54 pd->vertex[5] = 0;
55 pd->vertex[6] = bounding_box.x;
56 pd->vertex[7] = bounding_box.y + bounding_box.h;
57 pd->vertex[8] = 0;
58
59 pd->vertex[9] = bounding_box.x;
60 pd->vertex[10] = bounding_box.y + bounding_box.h;
61 pd->vertex[11] = 0;
62 pd->vertex[12] = bounding_box.x + bounding_box.w;
63 pd->vertex[13] = bounding_box.y + bounding_box.h;
64 pd->vertex[14] = 0;
65 pd->vertex[15] = bounding_box.x + bounding_box.w;
66 pd->vertex[16] = bounding_box.y;
67 pd->vertex[17] = 0;
68
69 return r;
70}
71
72static Eina_Bool
73_ector_renderer_gl_shape_ector_renderer_generic_base_draw(Eo *obj, Ector_Renderer_GL_Shape_Data *pd, Efl_Gfx_Render_Op op, Eina_Array *clips, unsigned int mul_col)
74{
75 uint64_t flags = 0;
76
77 eo_do_super(obj, ECTOR_RENDERER_GL_SHAPE_CLASS, ector_renderer_draw(op, clips, mul_col));
78
79 // FIXME: adjust flags content correctly
80 // FIXME: should not ignore clips (idea is that the geometry will be cliped here and the
81 // context will just look up clips for match with current pipe to render)...
82
83 if (pd->shape->fill)
84 {
85 eo_do(pd->shape->fill, ector_renderer_gl_base_fill(flags, pd->vertex, 6, mul_col));
86 }
87 else
88 {
89 eo_do(pd->base->surface,
90 ector_gl_surface_push(flags, pd->vertex, 6, mul_col));
91 }
92
93 return EINA_TRUE;
94}
95
96static Eina_Bool
97_ector_renderer_gl_shape_ector_renderer_gl_base_fill(Eo *obj EINA_UNUSED,
98 Ector_Renderer_GL_Shape_Data *pd EINA_UNUSED,
99 uint64_t flags EINA_UNUSED,
100 GLshort *vertex EINA_UNUSED,
101 unsigned int vertex_count EINA_UNUSED,
102 unsigned int mul_col EINA_UNUSED)
103{
104 // FIXME: let's find out how to fill a shape with a shape later.
105 // I need to read SVG specification and see what to do here.
106 ERR("fill with shape not implemented\n");
107 return EINA_FALSE;
108}
109
110static void
111_ector_renderer_gl_shape_ector_renderer_generic_base_bounds_get(Eo *obj, Ector_Renderer_GL_Shape_Data *pd, Eina_Rectangle *r)
112{
113 eo_do(obj, efl_gfx_shape_bounds_get(r));
114
115 r->x += pd->base->origin.x;
116 r->y += pd->base->origin.y;
117}
118
119static unsigned int
120_ector_renderer_gl_shape_ector_renderer_generic_base_crc_get(Eo *obj, Ector_Renderer_GL_Shape_Data *pd)
121{
122 unsigned int crc;
123
124 eo_do_super(obj, ECTOR_RENDERER_GL_SHAPE_CLASS,
125 crc = ector_renderer_crc_get());
126
127 // This code should be shared with other implementation
128 crc = eina_crc((void*) &pd->shape->stroke.marker, sizeof (pd->shape->stroke.marker), crc, EINA_FALSE);
129 crc = eina_crc((void*) &pd->public_shape->stroke.scale, sizeof (pd->public_shape->stroke.scale) * 3, crc, EINA_FALSE); // scale, width, centered
130 crc = eina_crc((void*) &pd->public_shape->stroke.color, sizeof (pd->public_shape->stroke.color), crc, EINA_FALSE);
131 crc = eina_crc((void*) &pd->public_shape->stroke.cap, sizeof (pd->public_shape->stroke.cap), crc, EINA_FALSE);
132 crc = eina_crc((void*) &pd->public_shape->stroke.join, sizeof (pd->public_shape->stroke.join), crc, EINA_FALSE);
133
134 if (pd->shape->fill) crc = _renderer_crc_get(pd->shape->fill, crc);
135 if (pd->shape->stroke.fill) crc = _renderer_crc_get(pd->shape->stroke.fill, crc);
136 if (pd->shape->stroke.marker) crc = _renderer_crc_get(pd->shape->stroke.marker, crc);
137 if (pd->public_shape->stroke.dash_length)
138 {
139 crc = eina_crc((void*) pd->public_shape->stroke.dash, sizeof (Efl_Gfx_Dash) * pd->public_shape->stroke.dash_length, crc, EINA_FALSE);
140 }
141
142 return crc;
143}
144
145static Eo_Base *
146_ector_renderer_gl_shape_eo_base_constructor(Eo *obj, Ector_Renderer_GL_Shape_Data *pd)
147{
148 eo_do_super(obj, ECTOR_RENDERER_GL_SHAPE_CLASS, obj = eo_constructor());
149
150 if (!obj) return NULL;
151
152 pd->public_shape = eo_data_xref(obj, EFL_GFX_SHAPE_MIXIN, obj);
153 pd->shape = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_SHAPE_MIXIN, obj);
154 pd->base = eo_data_xref(obj, ECTOR_RENDERER_GENERIC_BASE_CLASS, obj);
155
156 eo_do(obj,
157 eo_event_callback_add(EFL_GFX_PATH_CHANGED, _ector_renderer_gl_shape_path_changed, pd));
158
159 return obj;
160}
161
162static void
163_ector_renderer_gl_shape_eo_base_destructor(Eo *obj, Ector_Renderer_GL_Shape_Data *pd)
164{
165 eo_data_xunref(obj, pd->shape, obj);
166 eo_data_xunref(obj, pd->base, obj);
167 eo_data_xunref(obj, pd->public_shape, obj);
168}
169
170#include "ector_renderer_gl_shape.eo.c"
diff --git a/src/lib/ector/gl/ector_renderer_gl_shape.eo b/src/lib/ector/gl/ector_renderer_gl_shape.eo
new file mode 100644
index 0000000000..46d6a5e23b
--- /dev/null
+++ b/src/lib/ector/gl/ector_renderer_gl_shape.eo
@@ -0,0 +1,14 @@
1class Ector.Renderer.GL.Shape (Ector.Renderer.GL.Base, Ector.Renderer.Generic.Shape)
2{
3 eo_prefix: ector_renderer_gl_shape;
4 legacy_prefix: null;
5 implements {
6 Ector.Renderer.Generic.Base.prepare;
7 Ector.Renderer.Generic.Base.draw;
8 Ector.Renderer.Generic.Base.bounds_get;
9 Ector.Renderer.Generic.Base.crc.get;
10 Ector.Renderer.GL.Base.fill;
11 Eo.Base.constructor;
12 Eo.Base.destructor;
13 }
14}
diff --git a/src/lib/ector/gl/shader/.gitignore b/src/lib/ector/gl/shader/.gitignore
new file mode 100644
index 0000000000..0074827b13
--- /dev/null
+++ b/src/lib/ector/gl/shader/.gitignore
@@ -0,0 +1 @@
*.shd
diff --git a/src/lib/ector/gl/shader/ector_gl_shaders.x b/src/lib/ector/gl/shader/ector_gl_shaders.x
new file mode 100644
index 0000000000..19120e26c3
--- /dev/null
+++ b/src/lib/ector/gl/shader/ector_gl_shaders.x
@@ -0,0 +1,285 @@
1/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */
2/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */
3
4static const char fragment_glsl[] =
5 "/* General-purpose fragment shader for all operations in Evas.\n"
6 " * This file can either be used directly by evas at runtime to\n"
7 " * generate its shaders with the appropriate #defines, or passed\n"
8 " * through cpp first (in which case the precision must be manually added).\n"
9 " */\n"
10 "#ifdef GL_ES\n"
11 "# ifdef GL_FRAGMENT_PRECISION_HIGH\n"
12 "precision highp float;\n"
13 "# else\n"
14 "precision mediump float;\n"
15 "# endif\n"
16 "# ifdef SHD_EXTERNAL\n"
17 "extension GL_OES_EGL_image_external : require\n"
18 "# define SAMPLER_EXTERNAL_OES samplerExternalOES\n"
19 "# endif\n"
20 "#else\n"
21 "# define SAMPLER_EXTERNAL_OES sampler2D\n"
22 "#endif\n"
23 "#ifndef SHD_NOMUL\n"
24 "varying vec4 col;\n"
25 "#endif\n"
26 "#ifdef SHD_EXTERNAL\n"
27 "uniform SAMPLER_EXTERNAL_OES tex;\n"
28 "varying vec2 tex_c;\n"
29 "#elif defined(SHD_TEX)\n"
30 "uniform sampler2D tex;\n"
31 "varying vec2 tex_c;\n"
32 "#endif\n"
33 "#if defined(SHD_NV12) || defined(SHD_YUY2)\n"
34 "uniform sampler2D texuv;\n"
35 "varying vec2 tex_c2;\n"
36 "#endif\n"
37 "#if defined(SHD_YUV)\n"
38 "uniform sampler2D texu;\n"
39 "uniform sampler2D texv;\n"
40 "varying vec2 tex_c2;\n"
41 "varying vec2 tex_c3;\n"
42 "#endif\n"
43 "#ifdef SHD_TEXA\n"
44 "uniform sampler2D texa;\n"
45 "varying vec2 tex_a;\n"
46 "#endif\n"
47 "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
48 "varying vec4 div_s;\n"
49 "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
50 "varying vec2 tex_s[2];\n"
51 "# else\n"
52 "varying vec2 tex_s[4];\n"
53 "# endif\n"
54 "#endif\n"
55 "#ifdef SHD_MASK\n"
56 "uniform sampler2D texm;\n"
57 "varying vec2 tex_m;\n"
58 "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
59 "varying float maskdiv_s;\n"
60 "varying vec2 masktex_s[2];\n"
61 "# elif defined(SHD_MASKSAM22)\n"
62 "varying float maskdiv_s;\n"
63 "varying vec2 masktex_s[4];\n"
64 "# endif\n"
65 "#endif\n"
66 "#ifdef SHD_ALPHA\n"
67 "# define SWZ aaaa\n"
68 "#else\n"
69 "# ifndef SHD_BGRA\n"
70 "# if defined(SHD_IMG) && defined(BIGENDIAN)\n"
71 "# define SWZ gbar\n"
72 "# else\n"
73 "# define SWZ bgra\n"
74 "#endif\n"
75 "# else\n"
76 "# if defined(SHD_IMG) && defined(BIGENDIAN)\n"
77 "# define SWZ grab\n"
78 "# else\n"
79 "# define SWZ rgba\n"
80 "# endif\n"
81 "# endif\n"
82 "#endif\n"
83 "void main()\n"
84 "{\n"
85 " vec4 c;\n"
86 "#if defined(SHD_YUV) || defined(SHD_NV12) || defined(SHD_YUY2)\n"
87 " float r, g, b, y, u, v, vmu;\n"
88 "# if defined(SHD_YUV)\n"
89 " y = texture2D(tex, tex_c).r;\n"
90 " u = texture2D(texu, tex_c2).r;\n"
91 " v = texture2D(texv, tex_c3).r;\n"
92 "# elif defined(SHD_NV12) || defined(SHD_YUY2)\n"
93 " y = texture2D(tex, tex_c).g;\n"
94 " u = texture2D(texuv, tex_c2).g;\n"
95 " v = texture2D(texuv, tex_c2).a;\n"
96 "# endif\n"
97 "// center u and v around 0 for uv and y (with 128/255 for u + v, 16/255 for y)\n"
98 " u = u - 0.5;\n"
99 " v = v - 0.5;\n"
100 "# if defined (SHD_YUV_709)\n"
101 "// 709 yuv colorspace for hd content\n"
102 " y = (y - 0.062) * 1.164;\n"
103 " vmu = (v * 0.534) + (u * 0.213);\n"
104 " v = v * 1.793;\n"
105 " u = u * 2.115;\n"
106 "# else\n"
107 "// 601 colorspace constants (older yuv content)\n"
108 " y = (y - 0.062) * 1.164;\n"
109 " vmu = (v * 0.813) + (u * 0.391);\n"
110 " v = v * 1.596;\n"
111 " u = u * 2.018;\n"
112 "# endif\n"
113 "// common yuv\n"
114 " r = y + v;\n"
115 " g = y - vmu;\n"
116 " b = y + u;\n"
117 " c = vec4(r, g, b, 1.0);\n"
118 "#elif defined(SHD_SAM12) || defined(SHD_SAM21)\n"
119 " vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;\n"
120 " vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;\n"
121 " c = (col00 + col01) / div_s;\n"
122 "#elif defined(SHD_SAM22)\n"
123 " vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;\n"
124 " vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;\n"
125 " vec4 col10 = texture2D(tex, tex_c + tex_s[2]).SWZ;\n"
126 " vec4 col11 = texture2D(tex, tex_c + tex_s[3]).SWZ;\n"
127 " c = (col00 + col01 + col10 + col11) / div_s;\n"
128 "#elif defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
129 " c = texture2D(tex, tex_c).SWZ;\n"
130 "#else\n"
131 " c = vec4(1, 1, 1, 1);\n"
132 "#endif\n"
133 "#ifdef SHD_MASK\n"
134 " float ma;\n"
135 "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
136 " float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
137 " float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
138 " ma = (ma00 + ma01) / maskdiv_s;\n"
139 "# elif defined(SHD_MASKSAM22)\n"
140 " float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;\n"
141 " float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;\n"
142 " float ma10 = texture2D(texm, tex_m + masktex_s[2]).a;\n"
143 " float ma11 = texture2D(texm, tex_m + masktex_s[3]).a;\n"
144 " ma = (ma00 + ma01 + ma10 + ma11) / maskdiv_s;\n"
145 "# else\n"
146 " ma = texture2D(texm, tex_m).a;\n"
147 "# endif\n"
148 "#endif\n"
149 " gl_FragColor =\n"
150 " c\n"
151 "#ifndef SHD_NOMUL\n"
152 " * col\n"
153 "#endif\n"
154 "#ifdef SHD_MASK\n"
155 " * ma\n"
156 "#endif\n"
157 "#ifdef SHD_TEXA\n"
158 " * texture2D(texa, tex_a).r\n"
159 "#endif\n"
160 " ;\n"
161 "#ifdef SHD_AFILL\n"
162 " gl_FragColor.a = 1.0;\n"
163 "#endif\n"
164 "}\n";
165
166static const char vertex_glsl[] =
167 "/* General-purpose vertex shader for all operations in Evas.\n"
168 " * This file can either be used directly by evas at runtime to\n"
169 " * generate its shaders with the appropriate #defines, or passed\n"
170 " * through cpp first (in which case the precision must be manually added).\n"
171 " */\n"
172 "#ifdef GL_ES\n"
173 "precision highp float;\n"
174 "#endif\n"
175 "attribute vec4 vertex;\n"
176 "uniform mat4 mvp;\n"
177 "/* All except nomul */\n"
178 "#ifndef SHD_NOMUL\n"
179 "attribute vec4 color;\n"
180 "varying vec4 col;\n"
181 "#endif\n"
182 "/* All images & fonts */\n"
183 "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
184 "attribute vec2 tex_coord;\n"
185 "varying vec2 tex_c;\n"
186 "#endif\n"
187 "/* NV12, YUY2 */\n"
188 "#if defined(SHD_NV12) || defined(SHD_YUY2) || defined(SHD_YUV)\n"
189 "attribute vec2 tex_coord2;\n"
190 "varying vec2 tex_c2;\n"
191 "#endif\n"
192 "/* YUV */\n"
193 "#ifdef SHD_YUV\n"
194 "attribute vec2 tex_coord3;\n"
195 "varying vec2 tex_c3;\n"
196 "#endif\n"
197 "/* RGB+A */\n"
198 "#ifdef SHD_TEXA\n"
199 "attribute vec2 tex_coorda;\n"
200 "varying vec2 tex_a;\n"
201 "#endif\n"
202 "/* Sampling */\n"
203 "#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)\n"
204 "attribute vec2 tex_sample;\n"
205 "varying vec4 div_s;\n"
206 "# if defined(SHD_SAM12) || defined(SHD_SAM21)\n"
207 "varying vec2 tex_s[2];\n"
208 "# else\n"
209 "varying vec2 tex_s[4];\n"
210 "# endif\n"
211 "#endif\n"
212 "/* Masking */\n"
213 "#ifdef SHD_MASK\n"
214 "attribute vec4 mask_coord;\n"
215 "varying vec2 tex_m;\n"
216 "# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)\n"
217 "attribute vec2 tex_masksample;\n"
218 "varying float maskdiv_s;\n"
219 "varying vec2 masktex_s[2];\n"
220 "# elif defined(SHD_MASKSAM22)\n"
221 "attribute vec2 tex_masksample;\n"
222 "varying float maskdiv_s;\n"
223 "varying vec2 masktex_s[4];\n"
224 "# endif\n"
225 "#endif\n"
226 "void main()\n"
227 "{\n"
228 " gl_Position = mvp * vertex;\n"
229 "#ifndef SHD_NOMUL\n"
230 " col = color;\n"
231 "#endif\n"
232 "#if defined(SHD_TEX) || defined(SHD_EXTERNAL)\n"
233 " tex_c = tex_coord;\n"
234 "#endif\n"
235 "#ifdef SHD_NV12\n"
236 " tex_c2 = tex_coord2 * 0.5;\n"
237 "#endif\n"
238 "#ifdef SHD_YUY2\n"
239 " tex_c2 = vec2(tex_coord2.x * 0.5, tex_coord2.y);\n"
240 "#endif\n"
241 "#ifdef SHD_YUV\n"
242 " tex_c2 = tex_coord2;\n"
243 " tex_c3 = tex_coord3;\n"
244 "#endif\n"
245 "#ifdef SHD_TEXA\n"
246 " tex_a = tex_coorda;\n"
247 "#endif\n"
248 "#if defined(SHD_SAM12)\n"
249 " tex_s[0] = vec2(0, -tex_sample.y);\n"
250 " tex_s[1] = vec2(0, tex_sample.y);\n"
251 " div_s = vec4(2, 2, 2, 2);\n"
252 "#elif defined(SHD_SAM21)\n"
253 " tex_s[0] = vec2(-tex_sample.x, 0);\n"
254 " tex_s[1] = vec2( tex_sample.x, 0);\n"
255 " div_s = vec4(2, 2, 2, 2);\n"
256 "#elif defined(SHD_SAM22)\n"
257 " tex_s[0] = vec2(-tex_sample.x, -tex_sample.y);\n"
258 " tex_s[1] = vec2( tex_sample.x, -tex_sample.y);\n"
259 " tex_s[2] = vec2( tex_sample.x, tex_sample.y);\n"
260 " tex_s[3] = vec2(-tex_sample.x, tex_sample.y);\n"
261 " div_s = vec4(4, 4, 4, 4);\n"
262 "#endif\n"
263 "#if defined(SHD_MASKSAM12)\n"
264 " masktex_s[0] = vec2(0, -tex_masksample.y);\n"
265 " masktex_s[1] = vec2(0, tex_masksample.y);\n"
266 " maskdiv_s = 2.0;\n"
267 "#elif defined(SHD_MASKSAM21)\n"
268 " masktex_s[0] = vec2(-tex_masksample.x, 0);\n"
269 " masktex_s[1] = vec2( tex_masksample.x, 0);\n"
270 " maskdiv_s = 2.0;\n"
271 "#elif defined(SHD_MASKSAM22)\n"
272 " masktex_s[0] = vec2(-tex_masksample.x, -tex_masksample.y);\n"
273 " masktex_s[1] = vec2( tex_masksample.x, -tex_masksample.y);\n"
274 " masktex_s[2] = vec2( tex_masksample.x, tex_masksample.y);\n"
275 " masktex_s[3] = vec2(-tex_masksample.x, tex_masksample.y);\n"
276 " maskdiv_s = 4.0;\n"
277 "#endif\n"
278 "#ifdef SHD_MASK\n"
279 " // mask_coord.w contains the Y-invert flag\n"
280 " // position on screen in [0..1] range of current pixel\n"
281 " vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);\n"
282 " tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;\n"
283 "#endif\n"
284 "}\n";
285
diff --git a/src/lib/ector/gl/shader/fragment.glsl b/src/lib/ector/gl/shader/fragment.glsl
new file mode 100644
index 0000000000..3dce873f40
--- /dev/null
+++ b/src/lib/ector/gl/shader/fragment.glsl
@@ -0,0 +1,168 @@
1/* General-purpose fragment shader for all operations in Evas.
2 * This file can either be used directly by evas at runtime to
3 * generate its shaders with the appropriate #defines, or passed
4 * through cpp first (in which case the precision must be manually added).
5 */
6
7FRAGMENT_SHADER
8
9#ifndef SHD_NOMUL
10varying vec4 col;
11#endif
12
13#ifdef SHD_EXTERNAL
14uniform SAMPLER_EXTERNAL_OES tex;
15varying vec2 tex_c;
16#elif defined(SHD_TEX)
17uniform sampler2D tex;
18varying vec2 tex_c;
19#endif
20
21#if defined(SHD_NV12) || defined(SHD_YUY2)
22uniform sampler2D texuv;
23varying vec2 tex_c2;
24#endif
25
26#if defined(SHD_YUV)
27uniform sampler2D texu;
28uniform sampler2D texv;
29varying vec2 tex_c2;
30varying vec2 tex_c3;
31#endif
32
33#ifdef SHD_TEXA
34uniform sampler2D texa;
35varying vec2 tex_a;
36#endif
37
38#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)
39varying vec4 div_s;
40# if defined(SHD_SAM12) || defined(SHD_SAM21)
41varying vec2 tex_s[2];
42# else
43varying vec2 tex_s[4];
44# endif
45#endif
46
47#ifdef SHD_MASK
48uniform sampler2D texm;
49varying vec2 tex_m;
50# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)
51varying float maskdiv_s;
52varying vec2 masktex_s[2];
53# elif defined(SHD_MASKSAM22)
54varying float maskdiv_s;
55varying vec2 masktex_s[4];
56# endif
57#endif
58
59#ifdef SHD_ALPHA
60# define SWZ aaaa
61#else
62# ifndef SHD_BGRA
63# if defined(SHD_IMG) && defined(BIGENDIAN)
64# define SWZ gbar
65# else
66# define SWZ bgra
67#endif
68# else
69# if defined(SHD_IMG) && defined(BIGENDIAN)
70# define SWZ grab
71# else
72# define SWZ rgba
73# endif
74# endif
75#endif
76
77void main()
78{
79 vec4 c;
80
81#if defined(SHD_YUV) || defined(SHD_NV12) || defined(SHD_YUY2)
82 float r, g, b, y, u, v, vmu;
83# if defined(SHD_YUV)
84 y = texture2D(tex, tex_c).r;
85 u = texture2D(texu, tex_c2).r;
86 v = texture2D(texv, tex_c3).r;
87# elif defined(SHD_NV12) || defined(SHD_YUY2)
88 y = texture2D(tex, tex_c).g;
89 u = texture2D(texuv, tex_c2).g;
90 v = texture2D(texuv, tex_c2).a;
91# endif
92// center u and v around 0 for uv and y (with 128/255 for u + v, 16/255 for y)
93 u = u - 0.5;
94 v = v - 0.5;
95
96# if defined (SHD_YUV_709)
97// 709 yuv colorspace for hd content
98 y = (y - 0.062) * 1.164;
99 vmu = (v * 0.534) + (u * 0.213);
100 v = v * 1.793;
101 u = u * 2.115;
102# else
103// 601 colorspace constants (older yuv content)
104 y = (y - 0.062) * 1.164;
105 vmu = (v * 0.813) + (u * 0.391);
106 v = v * 1.596;
107 u = u * 2.018;
108# endif
109// common yuv
110 r = y + v;
111 g = y - vmu;
112 b = y + u;
113 c = vec4(r, g, b, 1.0);
114
115#elif defined(SHD_SAM12) || defined(SHD_SAM21)
116 vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;
117 vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;
118 c = (col00 + col01) / div_s;
119
120#elif defined(SHD_SAM22)
121 vec4 col00 = texture2D(tex, tex_c + tex_s[0]).SWZ;
122 vec4 col01 = texture2D(tex, tex_c + tex_s[1]).SWZ;
123 vec4 col10 = texture2D(tex, tex_c + tex_s[2]).SWZ;
124 vec4 col11 = texture2D(tex, tex_c + tex_s[3]).SWZ;
125 c = (col00 + col01 + col10 + col11) / div_s;
126
127#elif defined(SHD_TEX) || defined(SHD_EXTERNAL)
128 c = texture2D(tex, tex_c).SWZ;
129
130#else
131 c = vec4(1, 1, 1, 1);
132#endif
133
134#ifdef SHD_MASK
135 float ma;
136# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)
137 float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;
138 float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;
139 ma = (ma00 + ma01) / maskdiv_s;
140# elif defined(SHD_MASKSAM22)
141 float ma00 = texture2D(texm, tex_m + masktex_s[0]).a;
142 float ma01 = texture2D(texm, tex_m + masktex_s[1]).a;
143 float ma10 = texture2D(texm, tex_m + masktex_s[2]).a;
144 float ma11 = texture2D(texm, tex_m + masktex_s[3]).a;
145 ma = (ma00 + ma01 + ma10 + ma11) / maskdiv_s;
146# else
147 ma = texture2D(texm, tex_m).a;
148# endif
149#endif
150
151 gl_FragColor =
152 c
153#ifndef SHD_NOMUL
154 * col
155#endif
156#ifdef SHD_MASK
157 * ma
158#endif
159#ifdef SHD_TEXA
160 * texture2D(texa, tex_a).r
161#endif
162 ;
163
164#ifdef SHD_AFILL
165 gl_FragColor.a = 1.0;
166#endif
167}
168
diff --git a/src/lib/ector/gl/shader/gen_shaders.sh b/src/lib/ector/gl/shader/gen_shaders.sh
new file mode 100755
index 0000000000..139d5ea109
--- /dev/null
+++ b/src/lib/ector/gl/shader/gen_shaders.sh
@@ -0,0 +1,38 @@
1#!/bin/bash
2
3# This script will generate a C file containing all the shaders used by Evas
4
5DIR=`dirname $0`
6
7OUTPUT=${DIR}/ector_gl_shaders.x
8
9# Skip generation if there is no diff (or no git)
10if ! git rev-parse 2>> /dev/null >> /dev/null ; then exit 0 ; fi
11if git diff --quiet --exit-code -- "$DIR"
12then
13 touch "${OUTPUT}"
14 exit 0
15fi
16
17exec 1<&-
18exec 1>${OUTPUT}
19
20# Write header
21printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */\n"
22printf "/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */\n\n"
23
24for shd in fragment vertex ; do
25 m4 ${DIR}/include.glsl ${DIR}/${shd}.glsl > ${shd}.tmp
26
27 OIFS=$IFS
28 IFS=$'\n'
29 printf "static const char ${shd}_glsl[] ="
30 for line in `cat ${shd}.tmp` ; do
31 printf "\n \"${line}\\\n\""
32 done
33 printf ";\n\n"
34 IFS=${OIFS}
35
36 rm ${shd}.tmp
37done
38
diff --git a/src/lib/ector/gl/shader/include.glsl b/src/lib/ector/gl/shader/include.glsl
new file mode 100644
index 0000000000..b8f8ac115e
--- /dev/null
+++ b/src/lib/ector/gl/shader/include.glsl
@@ -0,0 +1,22 @@
1define(`FRAGMENT_SHADER',`
2#ifdef GL_ES
3# ifdef GL_FRAGMENT_PRECISION_HIGH
4precision highp float;
5# else
6precision mediump float;
7# endif
8# ifdef SHD_EXTERNAL
9extension GL_OES_EGL_image_external : require
10# define SAMPLER_EXTERNAL_OES samplerExternalOES
11# endif
12#else
13# define SAMPLER_EXTERNAL_OES sampler2D
14#endif
15')
16
17define(`VERTEX_SHADER',`
18#ifdef GL_ES
19precision highp float;
20#endif
21')
22
diff --git a/src/lib/ector/gl/shader/vertex.glsl b/src/lib/ector/gl/shader/vertex.glsl
new file mode 100644
index 0000000000..d67eb0684e
--- /dev/null
+++ b/src/lib/ector/gl/shader/vertex.glsl
@@ -0,0 +1,137 @@
1/* General-purpose vertex shader for all operations in Evas.
2 * This file can either be used directly by evas at runtime to
3 * generate its shaders with the appropriate #defines, or passed
4 * through cpp first (in which case the precision must be manually added).
5 */
6
7VERTEX_SHADER
8
9attribute vec4 vertex;
10uniform mat4 mvp;
11
12/* All except nomul */
13#ifndef SHD_NOMUL
14attribute vec4 color;
15varying vec4 col;
16#endif
17
18/* All images & fonts */
19#if defined(SHD_TEX) || defined(SHD_EXTERNAL)
20attribute vec2 tex_coord;
21varying vec2 tex_c;
22#endif
23
24/* NV12, YUY2 */
25#if defined(SHD_NV12) || defined(SHD_YUY2) || defined(SHD_YUV)
26attribute vec2 tex_coord2;
27varying vec2 tex_c2;
28#endif
29
30/* YUV */
31#ifdef SHD_YUV
32attribute vec2 tex_coord3;
33varying vec2 tex_c3;
34#endif
35
36/* RGB+A */
37#ifdef SHD_TEXA
38attribute vec2 tex_coorda;
39varying vec2 tex_a;
40#endif
41
42/* Sampling */
43#if defined(SHD_SAM12) || defined(SHD_SAM21) || defined(SHD_SAM22)
44attribute vec2 tex_sample;
45varying vec4 div_s;
46# if defined(SHD_SAM12) || defined(SHD_SAM21)
47varying vec2 tex_s[2];
48# else
49varying vec2 tex_s[4];
50# endif
51#endif
52
53/* Masking */
54#ifdef SHD_MASK
55attribute vec4 mask_coord;
56varying vec2 tex_m;
57# if defined(SHD_MASKSAM12) || defined(SHD_MASKSAM21)
58attribute vec2 tex_masksample;
59varying float maskdiv_s;
60varying vec2 masktex_s[2];
61# elif defined(SHD_MASKSAM22)
62attribute vec2 tex_masksample;
63varying float maskdiv_s;
64varying vec2 masktex_s[4];
65# endif
66#endif
67
68
69void main()
70{
71 gl_Position = mvp * vertex;
72
73#ifndef SHD_NOMUL
74 col = color;
75#endif
76
77#if defined(SHD_TEX) || defined(SHD_EXTERNAL)
78 tex_c = tex_coord;
79#endif
80
81#ifdef SHD_NV12
82 tex_c2 = tex_coord2 * 0.5;
83#endif
84
85#ifdef SHD_YUY2
86 tex_c2 = vec2(tex_coord2.x * 0.5, tex_coord2.y);
87#endif
88
89#ifdef SHD_YUV
90 tex_c2 = tex_coord2;
91 tex_c3 = tex_coord3;
92#endif
93
94#ifdef SHD_TEXA
95 tex_a = tex_coorda;
96#endif
97
98#if defined(SHD_SAM12)
99 tex_s[0] = vec2(0, -tex_sample.y);
100 tex_s[1] = vec2(0, tex_sample.y);
101 div_s = vec4(2, 2, 2, 2);
102#elif defined(SHD_SAM21)
103 tex_s[0] = vec2(-tex_sample.x, 0);
104 tex_s[1] = vec2( tex_sample.x, 0);
105 div_s = vec4(2, 2, 2, 2);
106#elif defined(SHD_SAM22)
107 tex_s[0] = vec2(-tex_sample.x, -tex_sample.y);
108 tex_s[1] = vec2( tex_sample.x, -tex_sample.y);
109 tex_s[2] = vec2( tex_sample.x, tex_sample.y);
110 tex_s[3] = vec2(-tex_sample.x, tex_sample.y);
111 div_s = vec4(4, 4, 4, 4);
112#endif
113
114#if defined(SHD_MASKSAM12)
115 masktex_s[0] = vec2(0, -tex_masksample.y);
116 masktex_s[1] = vec2(0, tex_masksample.y);
117 maskdiv_s = 2.0;
118#elif defined(SHD_MASKSAM21)
119 masktex_s[0] = vec2(-tex_masksample.x, 0);
120 masktex_s[1] = vec2( tex_masksample.x, 0);
121 maskdiv_s = 2.0;
122#elif defined(SHD_MASKSAM22)
123 masktex_s[0] = vec2(-tex_masksample.x, -tex_masksample.y);
124 masktex_s[1] = vec2( tex_masksample.x, -tex_masksample.y);
125 masktex_s[2] = vec2( tex_masksample.x, tex_masksample.y);
126 masktex_s[3] = vec2(-tex_masksample.x, tex_masksample.y);
127 maskdiv_s = 4.0;
128#endif
129
130#ifdef SHD_MASK
131 // mask_coord.w contains the Y-invert flag
132 // position on screen in [0..1] range of current pixel
133 vec4 mask_Position = mvp * vertex * vec4(0.5, sign(mask_coord.w) * 0.5, 0.5, 0.5) + vec4(0.5, 0.5, 0, 0);
134 tex_m = mask_Position.xy * abs(mask_coord.zw) + mask_coord.xy;
135#endif
136}
137
diff --git a/src/lib/eina/eina_util.c b/src/lib/eina/eina_util.c
index 0adc412008..02f90d47bd 100644
--- a/src/lib/eina/eina_util.c
+++ b/src/lib/eina/eina_util.c
@@ -91,7 +91,7 @@ eina_environment_tmp_get(void)
91# endif 91# endif
92 { 92 {
93 tmp = getenv("TMPDIR"); 93 tmp = getenv("TMPDIR");
94 if (!tmp) tmp = getenv("XDG_RUNTIME_DIR"); 94 if (!tmp) tmp = getenv("XDG_RUNTIME_DIR");
95 } 95 }
96 if (!tmp) tmp = "/tmp"; 96 if (!tmp) tmp = "/tmp";
97 97
diff --git a/src/modules/evas/engines/gl_common/evas_gl_shader.c b/src/modules/evas/engines/gl_common/evas_gl_shader.c
index 9df1806630..6a7209cd8b 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -123,7 +123,6 @@ _evas_gl_common_shader_program_binary_load(Eet_File *ef, unsigned int flags)
123 if (!formats[0]) goto finish; 123 if (!formats[0]) goto finish;
124 124
125 prg = glCreateProgram(); 125 prg = glCreateProgram();
126
127#if 1 126#if 1
128 // TODO: invalid rendering error occurs when attempting to use a 127 // TODO: invalid rendering error occurs when attempting to use a
129 // glProgramBinary. in order to render correctly we should create a dummy 128 // glProgramBinary. in order to render correctly we should create a dummy
@@ -151,8 +150,6 @@ _evas_gl_common_shader_program_binary_load(Eet_File *ef, unsigned int flags)
151 gl_compile_link_error(prg, "load a program object", EINA_FALSE); 150 gl_compile_link_error(prg, "load a program object", EINA_FALSE);
152 ERR("Abort load of program (%s)", pname); 151 ERR("Abort load of program (%s)", pname);
153 glDeleteProgram(prg); 152 glDeleteProgram(prg);
154 glDeleteShader(vtx);
155 glDeleteShader(frg);
156 goto finish; 153 goto finish;
157 } 154 }
158 155