summaryrefslogtreecommitdiff
path: root/src/modules/evas/engines/software_ddraw/evas_engine.c
blob: b8fb1ce831fd7a7a85839a18f438c19a2661f076 (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
#include "evas_common_private.h"
#include "evas_private.h"
#include "evas_engine.h"
#include "Evas_Engine_Software_DDraw.h"

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

/* engine struct data */
typedef struct _Render_Engine Render_Engine;

struct _Render_Engine
{
   Render_Engine_Software_Generic generic;
};

/* log domain variable */
int _evas_log_dom_module = -1;

static void *
_output_setup(int  width,
              int  height,
              int  rot,
              HWND window,
              int  depth,
              int  fullscreen)
{
   Render_Engine *re;
   Outbuf *ob;

   re = calloc(1, sizeof(Render_Engine));
   if (!re)
     return NULL;

   evas_software_ddraw_outbuf_init();

   ob = evas_software_ddraw_outbuf_setup(width, height, rot,
                                         OUTBUF_DEPTH_INHERIT,
                                         window, depth, fullscreen);
   if (!ob) goto on_error;

   if (!evas_render_engine_software_generic_init(&re->generic, ob, NULL,
                                                 evas_software_ddraw_outbuf_rot_get,
                                                 evas_software_ddraw_outbuf_reconfigure,
                                                 NULL,
                                                 NULL,
                                                 evas_software_ddraw_outbuf_new_region_for_update,
                                                 evas_software_ddraw_outbuf_push_updated_region,
                                                 evas_software_ddraw_outbuf_free_region_for_update,
                                                 evas_software_ddraw_outbuf_idle_flush,
                                                 evas_software_ddraw_outbuf_flush,
                                                 NULL,
                                                 evas_software_ddraw_outbuf_free,
                                                 width, height))
     goto on_error;

   return re;

 on_error:
   if (ob) evas_software_ddraw_outbuf_free(ob);
   free(re);
   return NULL;
}


/* engine api this module provides */

static void *
eng_info(Evas *e EINA_UNUSED)
{
   Evas_Engine_Info_Software_DDraw *info;

   info = calloc(1, sizeof(Evas_Engine_Info_Software_DDraw));
   if (!info) return NULL;
   info->magic.magic = rand();
   info->render_mode = EVAS_RENDER_MODE_BLOCKING;
   return info;
}

static void
eng_info_free(Evas *e EINA_UNUSED, void *info)
{
   Evas_Engine_Info_Software_DDraw *in;

   in = (Evas_Engine_Info_Software_DDraw *)info;
   free(in);
}

static int
eng_setup(Evas *eo_e, void *in)
{
   Evas_Public_Data *e = efl_data_scope_get(eo_e, EVAS_CANVAS_CLASS);
   Render_Engine *re;
   Evas_Engine_Info_Software_DDraw *info;

   info = (Evas_Engine_Info_Software_DDraw *)in;
   if (!e->engine.data.output)
     e->engine.data.output = _output_setup(e->output.w,
                                           e->output.h,
                                           info->info.rotation,
                                           info->info.window,
                                           info->info.depth,
                                           info->info.fullscreen);
   else
     {
        Outbuf *ob;
        int ponebuf = 0;

        re = e->engine.data.output;
        ponebuf = re->generic.ob->onebuf;

        ob = evas_software_ddraw_outbuf_setup(e->output.w,
                                              e->output.h,
                                              info->info.rotation,
                                              OUTBUF_DEPTH_INHERIT,
                                              info->info.window,
                                              info->info.depth,
                                              info->info.fullscreen);
        if (!ob) return 0;
        evas_render_engine_software_generic_update(&re->generic, ob, e->output.w, e->output.h);

        re->generic.ob->onebuf = ponebuf;
     }
   if (!e->engine.data.output) return 0;
   if (!e->engine.data.context)
     e->engine.data.context = e->engine.func->context_new(e->engine.data.output);

   re = e->engine.data.output;

   return 1;
}

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

   if (!data) return;

   re = (Render_Engine *)data;
   evas_render_engine_software_generic_clean(&re->generic);
   free(re);
}

static Eina_Bool
eng_canvas_alpha_get(void *data EINA_UNUSED, void *context EINA_UNUSED)
{
#warning "We need to handle window with alpha channel."
   return EINA_FALSE;
}

/* module advertising code */
static int
module_open(Evas_Module *em)
{
   if (!em) return 0;
   /* get whatever engine module we inherit from */
   if (!_evas_module_engine_inherit(&pfunc, "software_generic")) return 0;
   _evas_log_dom_module = eina_log_domain_register
     ("evas-software_ddraw", EVAS_DEFAULT_LOG_COLOR);
   if (_evas_log_dom_module < 0)
     {
        EINA_LOG_ERR("Can not create a module log domain.");
        return 0;
     }
   /* store it for later use */
   func = pfunc;
   /* now to override methods */
#define ORD(f) EVAS_API_OVERRIDE(f, &func, eng_)
   ORD(info);
   ORD(info_free);
   ORD(setup);
   ORD(canvas_alpha_get);
   ORD(output_free);
   /* now advertise out own api */
   em->functions = (void *)(&func);
   return 1;
}

static void
module_close(Evas_Module *em EINA_UNUSED)
{
   if (_evas_log_dom_module >= 0)
     {
        eina_log_domain_unregister(_evas_log_dom_module);
        _evas_log_dom_module = -1;
     }
}

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

EVAS_MODULE_DEFINE(EVAS_MODULE_TYPE_ENGINE, engine, software_ddraw);

#ifndef EVAS_STATIC_BUILD_SOFTWARE_DDRAW
EVAS_EINA_MODULE_DEFINE(engine, software_ddraw);
#endif