summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/drm/evas_engine.c
blob: 68f586ae332cf722466a69d49e1178ee8adc61b2 (plain)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "evas_engine.h"

/* local structures */
typedef struct _Render_Engine Render_Engine;

struct _Render_Engine
{
   Render_Engine_Software_Generic generic;

   Evas_Engine_Info_Drm *info;
};

/* local function prototypes */
static void *_output_setup(Evas_Engine_Info_Drm *info, int w, int h);

/* function tables - filled in later (func and parent func) */
static Evas_Func func, pfunc;

/* external variables */
int _evas_engine_drm_log_dom;

/* local functions */
static void *
_output_setup(Evas_Engine_Info_Drm *info, int w, int h)
{
   Render_Engine *re;
   Outbuf *ob;

   /* try to allocate space for our render engine structure */
   if (!(re = calloc(1, sizeof(Render_Engine))))
     return NULL;

   /* try to create new outbuf */
   if (!(ob = evas_outbuf_setup(info, w, h)))
     goto on_error;

   if(!evas_render_engine_software_generic_init(&re->generic, ob,
                                                evas_outbuf_buffer_state_get,
                                                evas_outbuf_get_rot,
                                                evas_outbuf_reconfigure,
                                                evas_outbuf_update_region_new,
                                                evas_outbuf_update_region_push,
                                                evas_outbuf_update_region_free,
                                                NULL,
                                                evas_outbuf_flush,
                                                evas_outbuf_free,
                                                w, h))
     goto on_error;

   /* if we have no drm device, get one */
   if (info->info.fd < 0)
     {
        /* try to init drm (this includes openening the card & tty) */
        if (!evas_drm_init(info))
          goto on_error;
     }

   /* return the allocated render_engine structure */
   return re;

 on_error:
   evas_render_engine_software_generic_clean(&re->generic);

   /* shutdown drm card & tty */
   evas_drm_shutdown(info);

   free(re);
   return NULL;
}

/* engine api functions */
static void *
eng_info(Evas *evas EINA_UNUSED)
{
   Evas_Engine_Info_Drm *info;

   /* try to allocate space for our engine info structure */
   if (!(info = calloc(1, sizeof(Evas_Engine_Info_Drm))))
     return NULL;

   /* set some engine default properties */
   info->magic.magic = rand();
   info->render_mode = EVAS_RENDER_MODE_BLOCKING;

   return info;
}

static void
eng_info_free(Evas *evas EINA_UNUSED, void *einfo)
{
   Evas_Engine_Info_Drm *info;

   /* free the engine info */
   if ((info = (Evas_Engine_Info_Drm *)einfo))
     free(info);
}

static int
eng_setup(Evas *evas, void *einfo)
{
   Evas_Engine_Info_Drm *info;
   Evas_Public_Data *epd;
   Render_Engine *re;

   /* try to cast to our engine info structure */
   if (!(info = (Evas_Engine_Info_Drm *)einfo)) return 0;

   /* try to get the evas public data */
   if (!(epd = eo_data_scope_get(evas, EVAS_CANVAS_CLASS))) return 0;

   /* set canvas reference
    *
    * NB: We do this here so that on a vt switch, we can disable
    * rendering (or re-enable) for this canvas */
   info->info.evas = evas;

   /* check for valid engine output */
   if (!(re = epd->engine.data.output))
     {
        /* NB: If we have no valid output then assume we have not been
         * initialized yet and call any needed common init routines */
        evas_common_cpu_init();
        evas_common_blend_init();
        evas_common_image_init();
        evas_common_convert_init();
        evas_common_scale_init();
        evas_common_rectangle_init();
        evas_common_polygon_init();
        evas_common_line_init();
        evas_common_font_init();
        evas_common_draw_init();
        evas_common_tilebuf_init();

        /* try to create a new render_engine */
        if (!(re = _output_setup(info, epd->output.w, epd->output.h)))
          return 0;
     }
   else
     {
        Outbuf *ob;

        /* try to create a new outbuf */
        ob = evas_outbuf_setup(info, epd->output.w, epd->output.h);
        if (ob) return 0;

        /* if we have an existing outbuf, free it */
        evas_render_engine_software_generic_update(&re->generic, ob);
     }

   /* update the info structure pointer */
   re->info = info;

   /* reassign engine output */
   epd->engine.data.output = re;
   if (!epd->engine.data.output) return 0;

   /* check for valid engine context */
   if (!epd->engine.data.context)
     {
        /* create a context if needed */
        epd->engine.data.context =
          epd->engine.func->context_new(epd->engine.data.output);
     }

   return 1;
}

static void
eng_output_free(void *data)
{
   Render_Engine *re = data;

   evas_drm_shutdown(re->info);
   evas_render_engine_software_generic_clean(&re->generic);
   free(re);

   evas_common_font_shutdown();
   evas_common_image_shutdown();
}

/* module api functions */
static int
module_open(Evas_Module *em)
{
   /* check for valid evas module */
   if (!em) return 0;

   /* try to inherit functions from software_generic engine */
   if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;

   /* try to create eina logging domain */
   _evas_engine_drm_log_dom = 
     eina_log_domain_register("evas-drm", EVAS_DEFAULT_LOG_COLOR);

   /* if we could not create a logging domain, error out */
   if (_evas_engine_drm_log_dom < 0)
     {
        EINA_LOG_ERR("Can not create a module log domain.");
        return 0;
     }

   /* store parent functions */
   func = pfunc;

   /* override the methods we provide */
   EVAS_API_OVERRIDE(info, &func, eng_);
   EVAS_API_OVERRIDE(info_free, &func, eng_);
   EVAS_API_OVERRIDE(setup, &func, eng_);
   EVAS_API_OVERRIDE(output_free, &func, eng_);

   /* advertise our engine functions */
   em->functions = (void *)(&func);

   return 1;
}

static void 
module_close(Evas_Module *em EINA_UNUSED)
{
   /* unregister the eina log domain for this engine */
   eina_log_domain_unregister(_evas_engine_drm_log_dom);
}

static Evas_Module_Api evas_modapi =
{
   EVAS_MODULE_API_VERSION, "drm", "none", { module_open, module_close }
};

EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, drm);

#ifndef EVAS_STATIC_BUILD_DRM
EVAS_EINA_MODULE_DEFINE(engine, drm);
#endif