virtual:add virtual backend
[platform/core/uifw/libtdm.git] / backends / dummy / tdm_dummy.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #include "tdm_dummy.h"
6
7 static tdm_dummy_data *dummy_data;
8
9 void
10 tdm_dummy_deinit(tdm_backend_data *bdata)
11 {
12         if (dummy_data != bdata)
13                 return;
14
15         TDM_INFO("deinit");
16
17         tdm_dummy_display_destroy_output_list(dummy_data);
18
19         if (dummy_data->pipe[0] >= 0)
20                 close(dummy_data->pipe[0]);
21         if (dummy_data->pipe[1] >= 0)
22                 close(dummy_data->pipe[1]);
23
24         free(dummy_data);
25         dummy_data = NULL;
26 }
27
28 tdm_backend_data *
29 tdm_dummy_init(tdm_display *dpy, tdm_error *error)
30 {
31         tdm_func_display dummy_func_display;
32         tdm_func_output dummy_func_output;
33         tdm_func_layer dummy_func_layer;
34         tdm_error ret;
35
36         if (!dpy) {
37                 TDM_ERR("display is null");
38                 if (error)
39                         *error = TDM_ERROR_INVALID_PARAMETER;
40                 return NULL;
41         }
42
43         if (dummy_data) {
44                 TDM_ERR("failed: init twice");
45                 if (error)
46                         *error = TDM_ERROR_BAD_REQUEST;
47                 return NULL;
48         }
49
50         dummy_data = calloc(1, sizeof(tdm_dummy_data));
51         if (!dummy_data) {
52                 TDM_ERR("alloc failed");
53                 if (error)
54                         *error = TDM_ERROR_OUT_OF_MEMORY;
55                 return NULL;
56         }
57
58         LIST_INITHEAD(&dummy_data->output_list);
59         LIST_INITHEAD(&dummy_data->buffer_list);
60
61         memset(&dummy_func_display, 0, sizeof(dummy_func_display));
62         dummy_func_display.display_get_capability = dummy_display_get_capability;
63         dummy_func_display.display_get_outputs = dummy_display_get_outputs;
64         dummy_func_display.display_get_fd = dummy_display_get_fd;
65         dummy_func_display.display_handle_events = dummy_display_handle_events;
66
67         memset(&dummy_func_output, 0, sizeof(dummy_func_output));
68         dummy_func_output.output_get_capability = dummy_output_get_capability;
69         dummy_func_output.output_get_layers = dummy_output_get_layers;
70         dummy_func_output.output_wait_vblank = dummy_output_wait_vblank;
71         dummy_func_output.output_set_vblank_handler = dummy_output_set_vblank_handler;
72         dummy_func_output.output_commit = dummy_output_commit;
73         dummy_func_output.output_set_commit_handler = dummy_output_set_commit_handler;
74         dummy_func_output.output_set_mode = dummy_output_set_mode;
75         dummy_func_output.output_get_mode = dummy_output_get_mode;
76
77         memset(&dummy_func_layer, 0, sizeof(dummy_func_layer));
78         dummy_func_layer.layer_get_capability = dummy_layer_get_capability;
79         dummy_func_layer.layer_set_info = dummy_layer_set_info;
80         dummy_func_layer.layer_get_info = dummy_layer_get_info;
81         dummy_func_layer.layer_set_buffer = dummy_layer_set_buffer;
82         dummy_func_layer.layer_unset_buffer = dummy_layer_unset_buffer;
83
84         ret = tdm_backend_register_func_display(dpy, &dummy_func_display);
85         if (ret != TDM_ERROR_NONE)
86                 goto failed;
87
88         ret = tdm_backend_register_func_output(dpy, &dummy_func_output);
89         if (ret != TDM_ERROR_NONE)
90                 goto failed;
91
92         ret = tdm_backend_register_func_layer(dpy, &dummy_func_layer);
93         if (ret != TDM_ERROR_NONE)
94                 goto failed;
95
96         dummy_data->dpy = dpy;
97
98         if (pipe(dummy_data->pipe) < 0) {
99                 TDM_ERR("failed get pipe: %m");
100                 ret = TDM_ERROR_OPERATION_FAILED;
101                 goto failed;
102         }
103
104         ret = tdm_dummy_display_create_output_list(dummy_data);
105         if (ret != TDM_ERROR_NONE)
106                 goto failed;
107
108         ret = tdm_dummy_display_create_layer_list(dummy_data);
109         if (ret != TDM_ERROR_NONE)
110                 goto failed;
111
112         if (error)
113                 *error = TDM_ERROR_NONE;
114
115         TDM_INFO("init success!");
116
117         return (tdm_backend_data *)dummy_data;
118 failed:
119         if (error)
120                 *error = ret;
121
122         tdm_dummy_deinit(dummy_data);
123
124         TDM_ERR("init failed!");
125         return NULL;
126 }
127
128 tdm_backend_module tdm_backend_module_data = {
129         "Dummy",
130         "Samsung",
131         TDM_BACKEND_SET_ABI_VERSION(1, 1),
132         tdm_dummy_init,
133         tdm_dummy_deinit
134 };