aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/evas/canvas/render2/evas_render2.c
blob: aefc0ae762e636acb207af054cb73b4410a0f4f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "evas_render2.h"

#include <sys/time.h>

#include "region.c"

#ifndef _WIN32
static inline double
get_time(void)
{
   struct timeval timev;
   gettimeofday(&timev, NULL);
   return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
}
#else
static inline double
get_time(void)
{
   return (double)GetTickCount()/1000.0;
}
#endif

static inline void
out_time(double t)
{
   double b = (t * 100.0) / (1.0 / 60.0);
   printf("%1.2f%% / 60fps\n", b);
}

static void
_always_call(Eo *eo_e, Evas_Callback_Type type, void *event_info)
{
   int freeze_num = 0, i;

   eo_do(eo_e, freeze_num = eo_event_freeze_count_get(eo_e));
   for (i = 0; i < freeze_num; i++) eo_do(eo_e, eo_event_thaw(eo_e));
   evas_event_callback_call(eo_e, type, event_info);
   for (i = 0; i < freeze_num; i++) eo_do(eo_e, eo_event_freeze(eo_e));
}

// a list of canvases currently rendering
static Eina_List *_rendering = NULL;

// just put the thread code inlined here for now as opposed to separate files
#include "evas_render2_th_main.c"

// init all relevant render threads if needed
static void
_evas_render2_th_init(void)
{
   static Eina_Bool initted = EINA_FALSE;

   if (initted) return;
   initted = EINA_TRUE;
   _th_main_queue = eina_thread_queue_new();
   if (!eina_thread_create(&_th_main, EINA_THREAD_URGENT, 0,
                           _evas_render2_th_main, NULL))
     ERR("Cannot create render2 thread");
}

Eina_Bool
_evas_render2(Eo *eo_e, Evas_Public_Data *e)
{
   double t;

   // if nothing changed at all since last render - skip this frame
   if (!e->changed) return EINA_FALSE;
   // we are still rendering while being asked to render - skip this
   if (e->rendering) return EINA_FALSE;
   // mark this canvas as a render2 canvas - not normal render
   e->render2 = EINA_TRUE;
   // check viewport size is same as output - not allowed to differ
   if ((e->output.w != e->viewport.w) || (e->output.h != e->viewport.h))
     ERR("viewport size != output size!");

   // if render threads not initted - init them - maybe move this later?
   _evas_render2_th_init();

   printf("-------------------------------------------- %p %p\n", eo_e, e);
   // wait for any previous render pass to do its thing
   t = get_time();
   evas_canvas_async_block(e);
   t = get_time() - t;
   printf("T: block wait: "); out_time(t);
   // we have to calculate smare objects before render so do that here
   t = get_time();
   evas_call_smarts_calculate(eo_e);
   t = get_time() - t;
   printf("T: smart calc: "); out_time(t);
   // call canvas callbacks saying we are in the pre-render state
   _always_call(eo_e, EVAS_CALLBACK_RENDER_PRE, NULL);
   // bock any susbequent rneders from doing this walk
   eina_lock_take(&(e->lock_objects));
   // gain a reference
   eo_ref(eo_e);
   // put into the "i'm rendering" pool
   e->rendering = EINA_TRUE;
   _rendering = eina_list_append(_rendering, eo_e);

   // call our flush pre at this point before rendering begins...
   _always_call(eo_e, EVAS_CALLBACK_RENDER_FLUSH_PRE, NULL);

   // tell main render thread to wake up and begin processing this canvas
   _evas_render2_th_main_msg_render(eo_e, e);

   return EINA_FALSE;
}

Eina_List *
_evas_render2_updates(Eo *eo_e, Evas_Public_Data *e)
{
   if (!_evas_render2(eo_e, e)) return NULL;
   return _evas_render2_updates_wait(eo_e, e);
}

Eina_List *
_evas_render2_updates_wait(Eo *eo_e EINA_UNUSED, Evas_Public_Data *e)
{
   evas_canvas_async_block(e);
   while (e->rendering) evas_async_events_process_blocking();
   return NULL;
}

void
_evas_norender2(Eo *eo_e EINA_UNUSED, Evas_Public_Data *e)
{
   evas_canvas_async_block(e);
}

void
_evas_render2_idle_flush(Eo *eo_e EINA_UNUSED, Evas_Public_Data *e)
{
   evas_canvas_async_block(e);
}

void
_evas_render2_sync(Eo *eo_e EINA_UNUSED, Evas_Public_Data *e)
{
   evas_canvas_async_block(e);
}

void
_evas_render2_dump(Eo *eo_e EINA_UNUSED, Evas_Public_Data *e)
{
   evas_canvas_async_block(e);
}