0bdb73e07c0cd1d2c032b38ab3e507f813c9655d
[apps/native/widget/widget.git] / patch / pixmap_ee_widget.patch
1 diff --git a/src/virtual_window.c b/src/virtual_window.c
2 index 4f482ff..0e39eda 100644
3 --- a/src/virtual_window.c
4 +++ b/src/virtual_window.c
5 @@ -41,9 +41,11 @@
6  static struct static_info {
7         Ecore_Evas *(*alloc_canvas)(int w, int h, void *(*a)(void *data, int size), void (*f)(void *data, void *ptr), void *data);
8         Ecore_Evas *(*alloc_canvas_with_stride)(int w, int h, void *(*a)(void *data, int size, int *stride, int *bpp), void (*f)(void *data, void *ptr), void *data);
9 +       Ecore_Evas *(*alloc_canvas_with_pixmap)(const char *disp_name, Ecore_X_Window parent, int x, int y, int w, int h, Ecore_X_Pixmap (*alloc_cb)(void *data, Ecore_X_Window parent, int w, int h, int *depth), void (*free_cb)(void *data, Ecore_X_Pixmap pixmap), void *data);
10  } s_info = {
11         .alloc_canvas = NULL,
12         .alloc_canvas_with_stride = NULL,
13 +       .alloc_canvas_with_pixmap = NULL,
14  };
15  
16  /**
17 @@ -486,6 +488,58 @@ static int event_handler_cb(struct widget_buffer *handler, struct widget
18         return ret;
19  }
20  
21 +/**
22 + * @note
23 + * This callback can be called twice (or more) to get a several pixmaps
24 + * Acquired pixmaps are used for double/tripple buffering for canvas
25 + */
26 +static Ecore_X_Pixmap alloc_pixmap_cb(void *data, Ecore_X_Window parent, int w, int h, int *depth)
27 +{
28 +       struct info *info = data;
29 +
30 +       if (info->ee) {
31 +               ecore_evas_geometry_get(info->ee, NULL, NULL, &info->w, &info->h);
32 +               DbgPrint("Size of ee is updated: %dx%d (info: %p)\n", info->w, info->h, info);
33 +       }
34 +
35 +       /*!
36 +        * Acquire a buffer for canvas.
37 +        */
38 +       info->handle = widget_acquire_buffer(info->id, info->is_gbar,
39 +                                       info->w, info->h, sizeof(int), 0,
40 +                                       event_handler_cb, info);
41 +       if (!info->handle) {
42 +               ErrPrint("Failed to get the buffer\n");
43 +               return 0u;
44 +       }
45 +
46 +       info->is_hw = 0;
47 +       return (Ecore_X_Pixmap)widget_resource_id(info->handle);
48 +}
49 +
50 +static void free_pixmap_cb(void *data, Ecore_X_Pixmap pixmap)
51 +{
52 +       struct info *info = data;
53 +
54 +       if (!info->handle) {
55 +               return;
56 +       }
57 +
58 +       if (info->is_hw) {
59 +               ErrPrint("Impossible\n");
60 +       }
61 +
62 +       widget_release_buffer(info->handle);
63 +       info->handle = NULL;
64 +
65 +       if (info->deleted) {
66 +               free(info->id);
67 +               info->id = NULL;
68 +
69 +               free(info);
70 +       }
71 +}
72 +
73  static void *alloc_fb(void *data, int size)
74  {
75         struct info *info = data;
76 @@ -654,8 +708,14 @@ PUBLIC void *widget_get_evas_object(const char *id, int is_gbar)
77  {
78         struct info *info;
79         Evas_Object *rect;
80 +       const char *engine;
81 +
82 +       if (!s_info.alloc_canvas && !s_info.alloc_canvas_with_stride && !s_info.alloc_canvas_with_pixmap) {
83 +               s_info.alloc_canvas_with_pixmap = dlsym(RTLD_DEFAULT, "ecore_evas_gl_x11_pixmap_allocfunc_new");
84 +               if (!s_info.alloc_canvas_with_pixmap) {
85 +                       DbgPrint("pixmap_allocfunc_new is not found\n");
86 +               }
87  
88 -       if (!s_info.alloc_canvas && !s_info.alloc_canvas_with_stride) {
89                 s_info.alloc_canvas_with_stride = dlsym(RTLD_DEFAULT, "ecore_evas_buffer_allocfunc_with_stride_new");
90                 if (!s_info.alloc_canvas_with_stride) {
91                         DbgPrint("allocfunc_with_stirde_new is not found\n");
92 @@ -666,7 +726,7 @@ PUBLIC void *widget_get_evas_object(const char *id, int is_gbar)
93                         ErrPrint("allocfunc_new is not found\n");
94                 }
95  
96 -               if (!s_info.alloc_canvas_with_stride && !s_info.alloc_canvas) {
97 +               if (!s_info.alloc_canvas_with_stride && !s_info.alloc_canvas && !s_info.alloc_canvas_with_pixmap) {
98                         ErrPrint("No way to allocate canvas\n");
99                         return NULL;
100                 }
101 @@ -698,10 +758,20 @@ PUBLIC void *widget_get_evas_object(const char *id, int is_gbar)
102         info->w = 1;
103         info->h = 1;
104  
105 -       if (!widget_conf_auto_align() && s_info.alloc_canvas_with_stride) {
106 -               info->ee = s_info.alloc_canvas_with_stride(1, 1, alloc_stride_fb, free_fb, info);
107 -       } else if (s_info.alloc_canvas) {
108 -               info->ee = s_info.alloc_canvas(1, 1, alloc_fb, free_fb, info);
109 +        engine = elm_config_preferred_engine_get();
110 +       DbgPrint("Preferred engine: %s\n", engine);
111 +       if (engine && !strcmp(engine, "opengl_x11")) {
112 +           if (s_info.alloc_canvas_with_pixmap) {
113 +               info->ee = s_info.alloc_canvas_with_pixmap(NULL, 0u, 0, 0, 1, 1, alloc_pixmap_cb, free_pixmap_cb, info);
114 +           }
115 +       }
116 +
117 +       if (!info->ee) {
118 +           if (!widget_conf_auto_align() && s_info.alloc_canvas_with_stride) {
119 +                   info->ee = s_info.alloc_canvas_with_stride(1, 1, alloc_stride_fb, free_fb, info);
120 +           } else if (s_info.alloc_canvas) {
121 +                   info->ee = s_info.alloc_canvas(1, 1, alloc_fb, free_fb, info);
122 +           }
123         }
124  
125         if (!info->ee) {