summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSung Park <sungwoo@gmail.com>2013-01-07 06:16:18 +0000
committerSung Park <sungwoo@gmail.com>2013-01-07 06:16:18 +0000
commitedcb4cf295602d0fe6516c4f5a2b66527ee68a60 (patch)
treefee6b22f8bc22d5464659e2a4e380e6433643375 /src
parentfb1225caa7644ba84534b3904580b3d9d1cda047 (diff)
Pulled out evas gl backend binary shader file caching code from
evas_gl_shader.c file and made an internal generic caching api in evas_gl_common.h for use in other places ie. evas_gl. Then implemented evas_gl surface cap. caching code in gl backend to accelerate the engine creation. SVN revision: 82321
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Evas.am1
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_common.h9
-rwxr-xr-xsrc/modules/evas/engines/gl_common/evas_gl_core.c209
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_file_cache.c113
-rw-r--r--src/modules/evas/engines/gl_common/evas_gl_shader.c131
5 files changed, 316 insertions, 147 deletions
diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index c400164e72..1893e1cb50 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -448,6 +448,7 @@ GL_COMMON_SOURCES = \
448modules/evas/engines/gl_common/evas_gl_private.h \ 448modules/evas/engines/gl_common/evas_gl_private.h \
449modules/evas/engines/gl_common/evas_gl_common.h \ 449modules/evas/engines/gl_common/evas_gl_common.h \
450modules/evas/engines/gl_common/evas_gl_context.c \ 450modules/evas/engines/gl_common/evas_gl_context.c \
451modules/evas/engines/gl_common/evas_gl_file_cache.c \
451modules/evas/engines/gl_common/evas_gl_shader.c \ 452modules/evas/engines/gl_common/evas_gl_shader.c \
452modules/evas/engines/gl_common/evas_gl_rectangle.c \ 453modules/evas/engines/gl_common/evas_gl_rectangle.c \
453modules/evas/engines/gl_common/evas_gl_texture.c \ 454modules/evas/engines/gl_common/evas_gl_texture.c \
diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index 2110a52fb5..8ecaa8fa0b 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -555,6 +555,15 @@ int evas_gl_common_shader_program_init(Evas_GL_Shared *shared);
555void evas_gl_common_shader_program_init_done(void); 555void evas_gl_common_shader_program_init_done(void);
556void evas_gl_common_shader_program_shutdown(Evas_GL_Program *p); 556void evas_gl_common_shader_program_shutdown(Evas_GL_Program *p);
557 557
558Eina_Bool evas_gl_common_file_cache_is_dir(const char *file);
559Eina_Bool evas_gl_common_file_cache_mkdir(const char *dir);
560Eina_Bool evas_gl_common_file_cache_file_exists(const char *file);
561Eina_Bool evas_gl_common_file_cache_mkpath_if_not_exists(const char *path);
562Eina_Bool evas_gl_common_file_cache_mkpath(const char *path);
563int evas_gl_common_file_cache_dir_check(char *cache_dir, int num);
564int evas_gl_common_file_cache_file_check(const char *cache_dir, const char *cache_name, char *cache_file, int dir_num);
565int evas_gl_common_file_cache_save(Evas_GL_Shared *shared);
566
558void evas_gl_common_rect_draw(Evas_Engine_GL_Context *gc, int x, int y, int w, int h); 567void evas_gl_common_rect_draw(Evas_Engine_GL_Context *gc, int x, int y, int w, int h);
559 568
560void evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt); 569void evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt);
diff --git a/src/modules/evas/engines/gl_common/evas_gl_core.c b/src/modules/evas/engines/gl_common/evas_gl_core.c
index 862203f755..885acbbdca 100755
--- a/src/modules/evas/engines/gl_common/evas_gl_core.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_core.c
@@ -16,7 +16,7 @@ int _evas_gl_log_dom = -1;
16static void _surface_cap_print(EVGL_Engine *ee, int error); 16static void _surface_cap_print(EVGL_Engine *ee, int error);
17 17
18//---------------------------------------------------------------// 18//---------------------------------------------------------------//
19// Internal Resources: 19// Internal Resources:
20// - Surface and Context used for internal buffer creation 20// - Surface and Context used for internal buffer creation
21//---------------------------------------------------------------// 21//---------------------------------------------------------------//
22static int 22static int
@@ -262,7 +262,7 @@ _internal_resource_make_current(EVGL_Engine *ee, EVGL_Context *ctx)
262} 262}
263 263
264//---------------------------------------------------------------// 264//---------------------------------------------------------------//
265// Surface Related Functions 265// Surface Related Functions
266// - Texture/ Renderbuffer Creation/ Attachment to FBO 266// - Texture/ Renderbuffer Creation/ Attachment to FBO
267// - Surface capability check 267// - Surface capability check
268// - Internal config choose function 268// - Internal config choose function
@@ -364,7 +364,7 @@ _renderbuffer_attach(GLuint buf, GLenum attach)
364 364
365// Check whether the given FBO surface config is supported by the driver 365// Check whether the given FBO surface config is supported by the driver
366static int 366static int
367_fbo_surface_cap_test(GLint color_ifmt, GLenum color_fmt, 367_fbo_surface_cap_test(GLint color_ifmt, GLenum color_fmt,
368 GLenum depth_fmt, GLenum stencil_fmt, int mult_samples) 368 GLenum depth_fmt, GLenum stencil_fmt, int mult_samples)
369{ 369{
370 GLuint fbo = 0; 370 GLuint fbo = 0;
@@ -456,10 +456,10 @@ _surface_cap_test(EVGL_Surface_Format *fmt, GL_Format *color,
456 if ( (depth->bit == DEPTH_STENCIL) && (stencil->bit != STENCIL_BIT_8)) 456 if ( (depth->bit == DEPTH_STENCIL) && (stencil->bit != STENCIL_BIT_8))
457 return 0; 457 return 0;
458 458
459 ret = _fbo_surface_cap_test((GLint)color->fmt, 459 ret = _fbo_surface_cap_test((GLint)color->fmt,
460 color->fmt, 460 color->fmt,
461 depth->fmt, 461 depth->fmt,
462 stencil->fmt, samples); 462 stencil->fmt, samples);
463 if (ret) 463 if (ret)
464 { 464 {
465 fmt->color_bit = color->bit; 465 fmt->color_bit = color->bit;
@@ -478,7 +478,7 @@ _surface_cap_test(EVGL_Surface_Format *fmt, GL_Format *color,
478 } 478 }
479 else 479 else
480 { 480 {
481 fmt->depth_stencil_fmt = 0; 481 fmt->depth_stencil_fmt = 0;
482 fmt->depth_bit = depth->bit; 482 fmt->depth_bit = depth->bit;
483 fmt->depth_fmt = depth->fmt; 483 fmt->depth_fmt = depth->fmt;
484 fmt->stencil_bit = stencil->bit; 484 fmt->stencil_bit = stencil->bit;
@@ -503,16 +503,16 @@ _surface_cap_check(EVGL_Engine *ee)
503 }; 503 };
504 504
505#ifdef GL_GLES 505#ifdef GL_GLES
506 GL_Format depth[] = { 506 GL_Format depth[] = {
507 { DEPTH_NONE, 0 }, 507 { DEPTH_NONE, 0 },
508 { DEPTH_STENCIL, GL_DEPTH_STENCIL_OES }, 508 { DEPTH_STENCIL, GL_DEPTH_STENCIL_OES },
509 { DEPTH_BIT_8, GL_DEPTH_COMPONENT }, 509 { DEPTH_BIT_8, GL_DEPTH_COMPONENT },
510 { DEPTH_BIT_16, GL_DEPTH_COMPONENT16 }, 510 { DEPTH_BIT_16, GL_DEPTH_COMPONENT16 },
511 { DEPTH_BIT_24, GL_DEPTH_COMPONENT24_OES }, 511 { DEPTH_BIT_24, GL_DEPTH_COMPONENT24_OES },
512 { DEPTH_BIT_32, GL_DEPTH_COMPONENT32_OES }, 512 { DEPTH_BIT_32, GL_DEPTH_COMPONENT32_OES },
513 { -1, -1 }, 513 { -1, -1 },
514 }; 514 };
515 GL_Format stencil[] = { 515 GL_Format stencil[] = {
516 { STENCIL_NONE, 0 }, 516 { STENCIL_NONE, 0 },
517 { STENCIL_BIT_1, GL_STENCIL_INDEX1_OES }, 517 { STENCIL_BIT_1, GL_STENCIL_INDEX1_OES },
518 { STENCIL_BIT_4, GL_STENCIL_INDEX4_OES }, 518 { STENCIL_BIT_4, GL_STENCIL_INDEX4_OES },
@@ -520,7 +520,7 @@ _surface_cap_check(EVGL_Engine *ee)
520 { -1, -1 }, 520 { -1, -1 },
521 }; 521 };
522#else 522#else
523 GL_Format depth[] = { 523 GL_Format depth[] = {
524 { DEPTH_NONE, 0 }, 524 { DEPTH_NONE, 0 },
525 { DEPTH_STENCIL, GL_DEPTH24_STENCIL8 }, 525 { DEPTH_STENCIL, GL_DEPTH24_STENCIL8 },
526 { DEPTH_BIT_8, GL_DEPTH_COMPONENT }, 526 { DEPTH_BIT_8, GL_DEPTH_COMPONENT },
@@ -528,7 +528,7 @@ _surface_cap_check(EVGL_Engine *ee)
528 { DEPTH_BIT_24, GL_DEPTH_COMPONENT24 }, 528 { DEPTH_BIT_24, GL_DEPTH_COMPONENT24 },
529 { DEPTH_BIT_32, GL_DEPTH_COMPONENT32 }, 529 { DEPTH_BIT_32, GL_DEPTH_COMPONENT32 },
530 { -1, -1 }, 530 { -1, -1 },
531 }; 531 };
532 GL_Format stencil[] = { 532 GL_Format stencil[] = {
533 { STENCIL_NONE, 0 }, 533 { STENCIL_NONE, 0 },
534 { STENCIL_BIT_1, GL_STENCIL_INDEX1 }, 534 { STENCIL_BIT_1, GL_STENCIL_INDEX1 },
@@ -563,10 +563,10 @@ _surface_cap_check(EVGL_Engine *ee)
563 // Color Formats 563 // Color Formats
564 i = 0; 564 i = 0;
565 while ( color[i].bit >= 0 ) 565 while ( color[i].bit >= 0 )
566 { 566 {
567 j = 0; 567 j = 0;
568 // Depth Formats 568 // Depth Formats
569 while ( depth[j].bit >= 0 ) 569 while ( depth[j].bit >= 0 )
570 { 570 {
571 k = 0; 571 k = 0;
572 // Stencil Formats 572 // Stencil Formats
@@ -587,6 +587,156 @@ _surface_cap_check(EVGL_Engine *ee)
587} 587}
588 588
589static int 589static int
590_surface_cap_load(EVGL_Engine *ee, Eet_File *ef)
591{
592 int res = 0, i = 0, length = 0;
593 char tag[80];
594 void *data = 0;
595
596 data = eet_read(ef, "num_fbo_fmts", &length);
597 if ((!data) || (length <= 0)) goto finish;
598 ee->caps.num_fbo_fmts = atoi(data);
599 free(data);
600 data = 0;
601
602 // !!!FIXME
603 // Should use eet functionality instead of just reading using sscanfs...
604 for (i = 0; i < ee->caps.num_fbo_fmts; ++i)
605 {
606 EVGL_Surface_Format *fmt = &ee->caps.fbo_fmts[i];
607
608 snprintf(tag, sizeof(tag), "fbo_%d", i);
609 data = eet_read(ef, tag, &length);
610 if ((!data) || (length <= 0)) goto finish;
611 sscanf(data, "%d%d%d%d%d%d%d%d%d%d",
612 &(fmt->index),
613 (int*)(&(fmt->color_bit)), &(fmt->color_ifmt), &(fmt->color_fmt),
614 (int*)(&(fmt->depth_bit)), &(fmt->depth_fmt),
615 (int*)(&(fmt->stencil_bit)), &(fmt->stencil_fmt),
616 &(fmt->depth_stencil_fmt),
617 &(fmt->samples));
618 free(data);
619 data = 0;
620 }
621
622 res = 1;
623 goto finish;
624
625finish:
626 if (data) free(data);
627 return res;
628}
629
630static int
631_surface_cap_save(EVGL_Engine *ee, Eet_File *ef)
632{
633 int i = 0;
634 char tag[80], data[80];;
635
636 snprintf(data, sizeof(data), "%d", ee->caps.num_fbo_fmts);
637 if (eet_write(ef, "num_fbo_fmts", data, sizeof(data), 1) < 0)
638 return 0;
639
640 // !!!FIXME
641 // Should use eet functionality instead of just writing out using snprintfs...
642 for (i = 0; i < ee->caps.num_fbo_fmts; ++i)
643 {
644 EVGL_Surface_Format *fmt = &ee->caps.fbo_fmts[i];
645
646 snprintf(tag, sizeof(tag), "fbo_%d", i);
647 snprintf(data, sizeof(data), "%d %d %d %d %d %d %d %d %d %d",
648 fmt->index,
649 fmt->color_bit, fmt->color_ifmt, fmt->color_fmt,
650 fmt->depth_bit, fmt->depth_fmt,
651 fmt->stencil_bit, fmt->stencil_fmt,
652 fmt->depth_stencil_fmt,
653 fmt->samples);
654 if (eet_write(ef, tag, data, sizeof(data), 1) < 0) return 0;
655 }
656
657 return 1;
658}
659
660static int
661_surface_cap_cache_load(EVGL_Engine *ee)
662{
663 /* check eet */
664 Eet_File *et = NULL;
665 char cap_dir_path[PATH_MAX];
666 char cap_file_path[PATH_MAX];
667
668 if (!evas_gl_common_file_cache_dir_check(cap_dir_path, sizeof(cap_dir_path)))
669 return 0;
670
671 if (!evas_gl_common_file_cache_file_check(cap_dir_path, "surface_cap",
672 cap_file_path, sizeof(cap_dir_path)))
673 return 0;
674
675 /* use eet */
676 if (!eet_init()) return 0;
677 et = eet_open(cap_file_path, EET_FILE_MODE_READ);
678 if (!et) goto error;
679
680 if (!_surface_cap_load(ee, et))
681 goto error;
682
683 if (et) eet_close(et);
684 eet_shutdown();
685 return 1;
686
687error:
688 if (et) eet_close(et);
689 eet_shutdown();
690 return 0;
691}
692
693static int
694_surface_cap_cache_save(EVGL_Engine *ee)
695{
696 /* check eet */
697 Eet_File *et = NULL; //check eet file
698 int tmpfd;
699 int res = 0;
700 char cap_dir_path[PATH_MAX];
701 char cap_file_path[PATH_MAX];
702 char tmp_file[PATH_MAX];
703
704 if (!evas_gl_common_file_cache_dir_check(cap_dir_path, sizeof(cap_dir_path)))
705 {
706 res = evas_gl_common_file_cache_mkpath(cap_dir_path);
707 if (!res) return 0; /* we can't make directory */
708 }
709
710 evas_gl_common_file_cache_file_check(cap_dir_path, "surface_cap", cap_file_path,
711 sizeof(cap_dir_path));
712
713 /* use mkstemp for writing */
714 snprintf(tmp_file, sizeof(tmp_file), "%s.XXXXXX", cap_file_path);
715 tmpfd = mkstemp(tmp_file);
716 if (tmpfd < 0) goto error;
717 close(tmpfd);
718
719 /* use eet */
720 if (!eet_init()) goto error;
721
722 et = eet_open(tmp_file, EET_FILE_MODE_WRITE);
723 if (!et) goto error;
724
725 if (!_surface_cap_save(ee, et)) goto error;
726
727 if (eet_close(et) != EET_ERROR_NONE) goto error;
728 if (rename(tmp_file,cap_file_path) < 0) goto error;
729 eet_shutdown();
730 return 1;
731
732error:
733 if (et) eet_close(et);
734 if (evas_gl_common_file_cache_file_exists(tmp_file)) unlink(tmp_file);
735 eet_shutdown();
736 return 0;
737}
738
739static int
590_surface_cap_init(EVGL_Engine *ee) 740_surface_cap_init(EVGL_Engine *ee)
591{ 741{
592 int max_size = 0; 742 int max_size = 0;
@@ -623,16 +773,23 @@ _surface_cap_init(EVGL_Engine *ee)
623 } 773 }
624#endif 774#endif
625 775
626 int num_fmts = 0; 776 // Load Surface Cap
627 777 if (!_surface_cap_cache_load(ee))
628 // Check Surface Cap 778 {
629 num_fmts = _surface_cap_check(ee); 779 // Check Surface Cap
780 ee->caps.num_fbo_fmts = _surface_cap_check(ee);
781 _surface_cap_cache_save(ee);
782 DBG("Ran Evas GL Surface Cap and Cached the existing values.");
783 }
784 else
785 {
786 DBG("Loaded cached Evas GL Surface Cap values.");
787 }
630 788
631 if (num_fmts) 789 if (ee->caps.num_fbo_fmts)
632 { 790 {
633 ee->caps.num_fbo_fmts = num_fmts;
634 _surface_cap_print(ee, 0); 791 _surface_cap_print(ee, 0);
635 DBG("Number of supported surface formats: %d", num_fmts); 792 DBG("Number of supported surface formats: %d", ee->caps.num_fbo_fmts);
636 return 1; 793 return 1;
637 } 794 }
638 else 795 else
@@ -885,7 +1042,7 @@ _internal_config_set(EVGL_Engine *ee, EVGL_Surface *sfc, Evas_GL_Config *cfg)
885 color_bit = (1 << cfg->color_format); 1042 color_bit = (1 << cfg->color_format);
886 if (cfg->depth_bits) depth_bit = (1 << (cfg->depth_bits-1)); 1043 if (cfg->depth_bits) depth_bit = (1 << (cfg->depth_bits-1));
887 if (cfg->stencil_bits) stencil_bit = (1 << (cfg->stencil_bits-1)); 1044 if (cfg->stencil_bits) stencil_bit = (1 << (cfg->stencil_bits-1));
888 if (cfg->multisample_bits) 1045 if (cfg->multisample_bits)
889 msaa_samples = ee->caps.msaa_samples[cfg->multisample_bits-1]; 1046 msaa_samples = ee->caps.msaa_samples[cfg->multisample_bits-1];
890 1047
891 // Run through all the available formats and choose the first match 1048 // Run through all the available formats and choose the first match
@@ -1160,7 +1317,7 @@ int evgl_engine_destroy(EVGL_Engine *ee)
1160 if (_evas_gl_log_dom >= 0) return 0; 1317 if (_evas_gl_log_dom >= 0) return 0;
1161 eina_log_domain_unregister(_evas_gl_log_dom); 1318 eina_log_domain_unregister(_evas_gl_log_dom);
1162 _evas_gl_log_dom = -1; 1319 _evas_gl_log_dom = -1;
1163 1320
1164 // Destroy internal resources 1321 // Destroy internal resources
1165 _internal_resources_destroy(ee); 1322 _internal_resources_destroy(ee);
1166 1323
@@ -1240,7 +1397,7 @@ evgl_surface_create(EVGL_Engine *ee, Evas_GL_Config *cfg, int w, int h)
1240 ERR("Unable Create Specificed Surfaces. Unsupported format!"); 1397 ERR("Unable Create Specificed Surfaces. Unsupported format!");
1241 goto error; 1398 goto error;
1242 }; 1399 };
1243 1400
1244 return sfc; 1401 return sfc;
1245 1402
1246error: 1403error:
@@ -1413,7 +1570,7 @@ evgl_make_current(EVGL_Engine *ee, EVGL_Surface *sfc, EVGL_Context *ctx)
1413 ERR("Invalid Inputs. Engine: %p Surface: %p Context: %p!", ee, sfc, ctx); 1570 ERR("Invalid Inputs. Engine: %p Surface: %p Context: %p!", ee, sfc, ctx);
1414 return 0; 1571 return 0;
1415 } 1572 }
1416 1573
1417 // Get TLS Resources 1574 // Get TLS Resources
1418 if (!(rsc = _evgl_tls_resource_get(ee))) return 0; 1575 if (!(rsc = _evgl_tls_resource_get(ee))) return 0;
1419 1576
diff --git a/src/modules/evas/engines/gl_common/evas_gl_file_cache.c b/src/modules/evas/engines/gl_common/evas_gl_file_cache.c
new file mode 100644
index 0000000000..008de67568
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/evas_gl_file_cache.c
@@ -0,0 +1,113 @@
1#include "evas_gl_private.h"
2
3static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
4
5Eina_Bool
6evas_gl_common_file_cache_is_dir(const char *file)
7{
8 struct stat st;
9
10 if (stat(file, &st) < 0) return EINA_FALSE;
11 if (S_ISDIR(st.st_mode)) return EINA_TRUE;
12 return EINA_FALSE;
13}
14
15Eina_Bool
16evas_gl_common_file_cache_mkdir(const char *dir)
17{
18 /* evas gl only call this function when the dir is not exist */
19 if (mkdir(dir, default_mode) < 0) return EINA_FALSE;
20 return EINA_TRUE;
21}
22
23Eina_Bool
24evas_gl_common_file_cache_file_exists(const char *file)
25{
26 struct stat st;
27 if (!file) return EINA_FALSE;
28 if (stat(file, &st) < 0) return EINA_FALSE;
29 return EINA_TRUE;
30}
31
32Eina_Bool
33evas_gl_common_file_cache_mkpath_if_not_exists(const char *path)
34{
35 struct stat st;
36
37 if (stat(path, &st) < 0)
38 return evas_gl_common_file_cache_mkdir(path);
39 else if (!S_ISDIR(st.st_mode))
40 return EINA_FALSE;
41 else
42 return EINA_TRUE;
43}
44
45Eina_Bool
46evas_gl_common_file_cache_mkpath(const char *path)
47{
48 char ss[PATH_MAX];
49 unsigned int i;
50
51 if (evas_gl_common_file_cache_is_dir(path)) return EINA_TRUE;
52
53 for (i = 0; path[i]; ss[i] = path[i], i++)
54 {
55 if (i == sizeof(ss) - 1) return EINA_FALSE;
56 if ((path[i] == '/') && (i > 0))
57 {
58 ss[i] = 0;
59 if (!evas_gl_common_file_cache_mkpath_if_not_exists(ss))
60 return EINA_FALSE;
61 }
62 }
63 ss[i] = 0;
64 return evas_gl_common_file_cache_mkpath_if_not_exists(ss);
65}
66
67int
68evas_gl_common_file_cache_dir_check(char *cache_dir, int num)
69{
70 char *home = NULL;
71 char *subdir = ".cache/evas_gl_common_caches";
72
73 home = getenv("HOME");
74 if ((!home) || (!home[0])) return 0;
75
76 snprintf(cache_dir, num, "%s/%s", home, subdir);
77 return evas_gl_common_file_cache_file_exists(cache_dir);
78}
79
80int
81evas_gl_common_file_cache_file_check(const char *cache_dir, const char *cache_name, char *cache_file, int dir_num)
82{
83 char before_name[PATH_MAX];
84 char after_name[PATH_MAX];
85 int new_path_len = 0;
86 int i = 0, j = 0;
87
88 char *vendor = NULL;
89 char *driver = NULL;
90 char *version = NULL;
91
92 vendor = (char *)glGetString(GL_VENDOR);
93 driver = (char *)glGetString(GL_RENDERER);
94 version = (char *)glGetString(GL_VERSION);
95
96 new_path_len = snprintf(before_name, sizeof(before_name), "%s::%s::%s::%s::%s.eet", vendor, version, driver, MODULE_ARCH, cache_name);
97
98 /* remove '/' from file name */
99 for (i = 0; i < new_path_len; i++)
100 {
101 if (before_name[i] != '/')
102 {
103 after_name[j] = before_name[i];
104 j++;
105 }
106 }
107 after_name[j] = 0;
108
109 snprintf(cache_file, dir_num, "%s/%s", cache_dir, after_name);
110
111 return evas_gl_common_file_cache_file_exists(cache_file);
112}
113
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 fe6207c83e..af258d28e4 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_shader.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_shader.c
@@ -321,117 +321,6 @@ gl_compile_link_error(GLuint target, const char *action)
321 } 321 }
322} 322}
323 323
324static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
325
326static Eina_Bool
327_evas_gl_shader_file_is_dir(const char *file)
328{
329 struct stat st;
330
331 if (stat(file, &st) < 0) return EINA_FALSE;
332 if (S_ISDIR(st.st_mode)) return EINA_TRUE;
333 return EINA_FALSE;
334}
335
336static Eina_Bool
337_evas_gl_shader_file_mkdir(const char *dir)
338{
339 /* evas gl shader only call this function when the dir is not exist */
340 if (mkdir(dir, default_mode) < 0) return EINA_FALSE;
341 return EINA_TRUE;
342}
343
344static Eina_Bool
345_evas_gl_shader_file_exists(const char *file)
346{
347 struct stat st;
348 if (!file) return EINA_FALSE;
349 if (stat(file, &st) < 0) return EINA_FALSE;
350 return EINA_TRUE;
351}
352
353static inline Eina_Bool
354_evas_gl_shader_file_mkpath_if_not_exists(const char *path)
355{
356 struct stat st;
357
358 if (stat(path, &st) < 0)
359 return _evas_gl_shader_file_mkdir(path);
360 else if (!S_ISDIR(st.st_mode))
361 return EINA_FALSE;
362 else
363 return EINA_TRUE;
364}
365
366static Eina_Bool
367_evas_gl_shader_file_mkpath(const char *path)
368{
369 char ss[PATH_MAX];
370 unsigned int i;
371
372 if (_evas_gl_shader_file_is_dir(path)) return EINA_TRUE;
373
374 for (i = 0; path[i]; ss[i] = path[i], i++)
375 {
376 if (i == sizeof(ss) - 1) return EINA_FALSE;
377 if ((path[i] == '/') && (i > 0))
378 {
379 ss[i] = 0;
380 if (!_evas_gl_shader_file_mkpath_if_not_exists(ss))
381 return EINA_FALSE;
382 }
383 }
384 ss[i] = 0;
385 return _evas_gl_shader_file_mkpath_if_not_exists(ss);
386}
387
388static int
389_evas_gl_shader_dir_check(char *bin_shader_dir, int num)
390{
391 char *home = NULL;
392 char *subdir = ".cache/evas_gl_common_shaders";
393
394 home = getenv("HOME");
395 if ((!home) || (!home[0])) return 0;
396
397 snprintf(bin_shader_dir, num, "%s/%s", home, subdir);
398 return _evas_gl_shader_file_exists(bin_shader_dir);
399}
400
401static int
402_evas_gl_shader_file_check(const char *bin_shader_dir, char *bin_shader_file, int dir_num)
403{
404 char before_name[PATH_MAX];
405 char after_name[PATH_MAX];
406 int new_path_len = 0;
407 int i = 0, j = 0;
408
409 char *vendor = NULL;
410 char *driver = NULL;
411 char *version = NULL;
412
413 vendor = (char *)glGetString(GL_VENDOR);
414 driver = (char *)glGetString(GL_RENDERER);
415 version = (char *)glGetString(GL_VERSION);
416
417 new_path_len = snprintf(before_name, sizeof(before_name), "%s::%s::%s::%s::binary_shader.eet", vendor, version, driver, MODULE_ARCH);
418
419 /* remove '/' from file name */
420 for (i = 0; i < new_path_len; i++)
421 {
422 if (before_name[i] != '/')
423 {
424 after_name[j] = before_name[i];
425 j++;
426 }
427 }
428 after_name[j] = 0;
429
430 snprintf(bin_shader_file, dir_num, "%s/%s", bin_shader_dir, after_name);
431
432 return _evas_gl_shader_file_exists(bin_shader_file);
433}
434
435static int 324static int
436_evas_gl_common_shader_program_binary_init(Evas_GL_Program *p, 325_evas_gl_common_shader_program_binary_init(Evas_GL_Program *p,
437 const char *pname, 326 const char *pname,
@@ -459,8 +348,8 @@ _evas_gl_common_shader_program_binary_init(Evas_GL_Program *p,
459 p->prog = glCreateProgram(); 348 p->prog = glCreateProgram();
460 349
461#if 1 350#if 1
462 // TODO: invalid rendering error occurs when attempting to use a 351 // TODO: invalid rendering error occurs when attempting to use a
463 // glProgramBinary. in order to render correctly we should create a dummy 352 // glProgramBinary. in order to render correctly we should create a dummy
464 // vertex shader. 353 // vertex shader.
465 p->vert = glCreateShader(GL_VERTEX_SHADER); 354 p->vert = glCreateShader(GL_VERTEX_SHADER);
466 glAttachShader(p->prog, p->vert); 355 glAttachShader(p->prog, p->vert);
@@ -544,7 +433,7 @@ _evas_gl_common_shader_program_source_init(Evas_GL_Program *p,
544 433
545 p->vert = glCreateShader(GL_VERTEX_SHADER); 434 p->vert = glCreateShader(GL_VERTEX_SHADER);
546 p->frag = glCreateShader(GL_FRAGMENT_SHADER); 435 p->frag = glCreateShader(GL_FRAGMENT_SHADER);
547 436
548 glShaderSource(p->vert, 1, 437 glShaderSource(p->vert, 1,
549 (const char **)&(vert->src), NULL); 438 (const char **)&(vert->src), NULL);
550 GLERR(__FUNCTION__, __FILE__, __LINE__, ""); 439 GLERR(__FUNCTION__, __FILE__, __LINE__, "");
@@ -573,7 +462,7 @@ _evas_gl_common_shader_program_source_init(Evas_GL_Program *p,
573 ERR("Abort compile of shader frag (%s): %s", name, frag->src); 462 ERR("Abort compile of shader frag (%s): %s", name, frag->src);
574 return 0; 463 return 0;
575 } 464 }
576 465
577 p->prog = glCreateProgram(); 466 p->prog = glCreateProgram();
578#ifdef GL_GLES 467#ifdef GL_GLES
579#else 468#else
@@ -667,10 +556,10 @@ _evas_gl_common_shader_binary_init(Evas_GL_Shared *shared)
667 char bin_file_path[PATH_MAX]; 556 char bin_file_path[PATH_MAX];
668 unsigned int i; 557 unsigned int i;
669 558
670 if (!_evas_gl_shader_dir_check(bin_dir_path, sizeof(bin_dir_path))) 559 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
671 return 0; 560 return 0;
672 561
673 if (!_evas_gl_shader_file_check(bin_dir_path, bin_file_path, 562 if (!evas_gl_common_file_cache_file_check(bin_dir_path, "binary_shader", bin_file_path,
674 sizeof(bin_dir_path))) 563 sizeof(bin_dir_path)))
675 return 0; 564 return 0;
676 565
@@ -707,13 +596,13 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
707 char tmp_file[PATH_MAX]; 596 char tmp_file[PATH_MAX];
708 unsigned int i; 597 unsigned int i;
709 598
710 if (!_evas_gl_shader_dir_check(bin_dir_path, sizeof(bin_dir_path))) 599 if (!evas_gl_common_file_cache_dir_check(bin_dir_path, sizeof(bin_dir_path)))
711 { 600 {
712 res = _evas_gl_shader_file_mkpath(bin_dir_path); 601 res = evas_gl_common_file_cache_mkpath(bin_dir_path);
713 if (!res) return 0; /* we can't make directory */ 602 if (!res) return 0; /* we can't make directory */
714 } 603 }
715 604
716 _evas_gl_shader_file_check(bin_dir_path, bin_file_path, 605 evas_gl_common_file_cache_file_check(bin_dir_path, "binary_shader", bin_file_path,
717 sizeof(bin_dir_path)); 606 sizeof(bin_dir_path));
718 607
719 /* use mkstemp for writing */ 608 /* use mkstemp for writing */
@@ -741,7 +630,7 @@ _evas_gl_common_shader_binary_save(Evas_GL_Shared *shared)
741 630
742error: 631error:
743 if (et) eet_close(et); 632 if (et) eet_close(et);
744 if (_evas_gl_shader_file_exists(tmp_file)) unlink(tmp_file); 633 if (evas_gl_common_file_cache_file_exists(tmp_file)) unlink(tmp_file);
745 eet_shutdown(); 634 eet_shutdown();
746 return 0; 635 return 0;
747} 636}