1 #include <stdio.h>
2 #include <Eina.h>
3 #include <Ecore.h>
4 #include <Ecore_Evas.h>
5 #include <Evas.h>
6 #include <Ecore_Buffer.h>
7 #include <Ecore_Buffer_Queue.h>
8
9 #define WIDTH 720
10 #define HEIGHT 960
11
12 struct _Window
13 {
14 Evas *e;
15 Ecore_Evas *ee;
16 Evas_Object *bg, *img;
17 Ecore_Buffer *buffer;
18 };
19
20 struct _Window win;
21 Eina_List *hdls;
22
23 static void
paint_pixels(void * image,int padding,int width,int height,uint32_t time)24 paint_pixels(void *image, int padding, int width, int height, uint32_t time)
25 {
26 const int halfh = padding + (height - padding * 2) / 2;
27 const int halfw = padding + (width - padding * 2) / 2;
28 int ir, or;
29 uint32_t *pixel = image;
30 int y;
31
32 /* squared radii thresholds */
33 or = (halfw < halfh ? halfw : halfh) - 8;
34 ir = or - 32;
35 or *= or;
36 ir *= ir;
37
38 pixel += padding * width;
39 for (y = padding; y < height - padding; y++) {
40 int x;
41 int y2 = (y - halfh) * (y - halfh);
42
43 pixel += padding;
44 for (x = padding; x < width - padding; x++) {
45 uint32_t v;
46
47 /* squared distance from center */
48 int r2 = (x - halfw) * (x - halfw) + y2;
49
50 if (r2 < ir)
51 v = (r2 / 32 + time / 64) * 0x0080401;
52 else if (r2 < or)
53 v = (y + time / 32) * 0x0080401;
54 else
55 v = (x + time / 16) * 0x0080401;
56 v &= 0x00ffffff;
57 v |= 0xff000000;
58
59 *pixel++ = v;
60 }
61
62 pixel += padding;
63 }
64 }
65
66 static void
_cb_post_render(Ecore_Evas * ee EINA_UNUSED)67 _cb_post_render(Ecore_Evas *ee EINA_UNUSED)
68 {
69 void *data;
70
71 // Get pixel data and update.
72 data = ecore_buffer_data_get(win.buffer);
73 paint_pixels(data, 0, WIDTH, HEIGHT, ecore_loop_time_get() * 1000);
74 evas_object_image_data_set(win.img, data);
75 evas_object_image_data_update_add(win.img, 0, 0, WIDTH, HEIGHT);
76 }
77
78 int
main(void)79 main(void)
80 {
81 Evas_Object *o;
82 void *data;
83
84 eina_init();
85 ecore_init();
86 ecore_evas_init();
87 ecore_buffer_init();
88
89 win.ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
90 win.e = ecore_evas_get(win.ee);
91
92 o = evas_object_rectangle_add(win.e);
93 evas_object_move(o, 0, 0);
94 evas_object_resize(o, WIDTH, HEIGHT);
95 evas_object_color_set(o, 255, 0, 0, 255);
96 evas_object_show(o);
97 win.bg = o;
98
99 o = evas_object_image_add(win.e);
100 evas_object_image_fill_set(o, 0, 0, WIDTH, HEIGHT);
101 evas_object_image_size_set(o, WIDTH, HEIGHT);
102
103 evas_object_move(o, 0, 0);
104 evas_object_resize(o, WIDTH, HEIGHT);
105 evas_object_show(o);
106 win.img = o;
107
108 // Create buffer and drawing.
109 win.buffer = ecore_buffer_new("shm", WIDTH, HEIGHT, 0, 0);
110 data = ecore_buffer_data_get(win.buffer);
111 paint_pixels(data, 0, WIDTH, HEIGHT, 0);
112 evas_object_image_data_set(win.img, data);
113 evas_object_image_data_update_add(win.img, 0, 0, WIDTH, HEIGHT);
114
115 ecore_evas_show(win.ee);
116
117 ecore_evas_callback_post_render_set(win.ee, _cb_post_render);
118
119 ecore_main_loop_begin();
120
121 ecore_buffer_free(win.buffer);
122 ecore_buffer_shutdown();
123 ecore_evas_shutdown();
124 ecore_shutdown();
125 eina_shutdown();
126
127 return 0;
128 }
129