change buffer type from tdm_buffer to tbm_surface
[platform/core/uifw/libtdm.git] / include / tdm_backend.h
1 /**************************************************************************
2
3 libtdm
4
5 Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8          JinYoung Jeon <jy0.jeon@samsung.com>,
9          Taeheon Kim <th908.kim@samsung.com>,
10          YoungJun Cho <yj44.cho@samsung.com>,
11          SooChan Lim <sc1.lim@samsung.com>,
12          Boram Park <sc1.lim@samsung.com>
13
14 Permission is hereby granted, free of charge, to any person obtaining a
15 copy of this software and associated documentation files (the
16 "Software"), to deal in the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sub license, and/or sell copies of the Software, and to
19 permit persons to whom the Software is furnished to do so, subject to
20 the following conditions:
21
22 The above copyright notice and this permission notice (including the
23 next paragraph) shall be included in all copies or substantial portions
24 of the Software.
25
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
34 **************************************************************************/
35
36 #ifndef _TDM_BACKEND_H_
37 #define _TDM_BACKEND_H_
38
39 #include <tbm_surface.h>
40
41 #include "tdm_types.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 typedef void tdm_backend_data;
48
49 typedef struct _tdm_caps_display
50 {
51     /* -1: not defined */
52     int max_layer_count;
53 } tdm_caps_display;
54
55 typedef struct _tdm_caps_output
56 {
57     tdm_output_conn_status status;
58     tdm_output_type type;
59     unsigned int type_id;
60
61     unsigned int mode_count;
62     tdm_output_mode *modes;
63
64     unsigned int prop_count;
65     tdm_prop *props;
66
67     unsigned int mmWidth;
68     unsigned int mmHeight;
69     unsigned int subpixel;
70
71     /* -1: not defined */
72     int min_w;
73     int min_h;
74     int max_w;
75     int max_h;
76     int preferred_align;
77 } tdm_caps_output;
78
79 typedef struct _tdm_caps_layer
80 {
81     tdm_layer_capability capabilities;
82     unsigned int zpos;  /* if VIDEO layer, zpos is -1 */
83
84     unsigned int format_count;
85     tbm_format *formats;
86
87     unsigned int prop_count;
88     tdm_prop *props;
89 } tdm_caps_layer;
90
91 typedef struct _tdm_caps_pp
92 {
93     tdm_pp_capability capabilities;
94
95     unsigned int format_count;
96     tbm_format *formats;
97
98     /* -1: not defined */
99     int min_w;
100     int min_h;
101     int max_w;
102     int max_h;
103     int preferred_align;
104 } tdm_caps_pp;
105
106 typedef struct _tdm_caps_capture
107 {
108     tdm_capture_capability capabilities;
109
110     unsigned int format_count;
111     tbm_format *formats;
112
113     /* -1: not defined */
114     int min_w;
115     int min_h;
116     int max_w;
117     int max_h;
118     int preferred_align;
119 } tdm_caps_capture;
120
121 typedef struct _tdm_func_display
122 {
123     tdm_error    (*display_get_capabilitiy)(tdm_backend_data *bdata, tdm_caps_display *caps); /* init */
124     tdm_error    (*display_get_pp_capability)(tdm_backend_data *bdata, tdm_caps_pp *caps); /* init */
125     tdm_error    (*display_get_capture_capability)(tdm_backend_data *bdata, tdm_caps_capture *caps); /* init */
126     tdm_output **(*display_get_outputs)(tdm_backend_data *bdata, int *count, tdm_error *error); /* init */
127     tdm_error    (*display_get_fd)(tdm_backend_data *bdata, int *fd);
128     tdm_error    (*display_handle_events)(tdm_backend_data *bdata);
129     tdm_pp*      (*display_create_pp)(tdm_backend_data *bdata, tdm_error *error);
130
131     tdm_error    (*output_get_capability)(tdm_output *output, tdm_caps_output *caps); /* init */
132     tdm_layer  **(*output_get_layers)(tdm_output *output, int *count, tdm_error *error); /* init */
133     tdm_error    (*output_set_property)(tdm_output *output, unsigned int id, tdm_value value);
134     tdm_error    (*output_get_property)(tdm_output *output, unsigned int id, tdm_value *value);
135     tdm_error    (*output_wait_vblank)(tdm_output *output, int interval, int sync, void *user_data);
136     tdm_error    (*output_set_vblank_handler)(tdm_output *output, tdm_output_vblank_handler func);
137     tdm_error    (*output_commit)(tdm_output *output, int sync, void *user_data);
138     tdm_error    (*output_set_commit_handler)(tdm_output *output, tdm_output_commit_handler func);
139     tdm_error    (*output_set_dpms)(tdm_output *output, tdm_output_dpms dpms_value);
140     tdm_error    (*output_get_dpms)(tdm_output *output, tdm_output_dpms *dpms_value);
141     tdm_error    (*output_set_mode)(tdm_output *output, const tdm_output_mode *mode);
142     tdm_error    (*output_get_mode)(tdm_output *output, const tdm_output_mode **mode);
143     tdm_capture *(*output_create_capture)(tdm_output *output, tdm_error *error);
144
145     tdm_error    (*layer_get_capability)(tdm_layer *layer, tdm_caps_layer *caps); /* init */
146     tdm_error    (*layer_set_property)(tdm_layer *layer, unsigned int id, tdm_value value);
147     tdm_error    (*layer_get_property)(tdm_layer *layer, unsigned int id, tdm_value *value);
148     tdm_error    (*layer_set_info)(tdm_layer *layer, tdm_info_layer *info);
149     tdm_error    (*layer_get_info)(tdm_layer *layer, tdm_info_layer *info);
150     tdm_error    (*layer_set_buffer)(tdm_layer *layer, tbm_surface_h buffer);
151     tdm_error    (*layer_unset_buffer)(tdm_layer *layer);
152     tdm_error    (*layer_set_video_pos)(tdm_layer *layer, int zpos);
153     tdm_capture *(*layer_create_capture)(tdm_layer *layer, tdm_error *error);
154 } tdm_func_display;
155
156 typedef void (*tdm_pp_done_handler)(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst, void *user_data);
157
158 typedef struct _tdm_func_pp
159 {
160     void         (*pp_destroy)(tdm_pp *pp); /* init */
161     tdm_error    (*pp_set_info)(tdm_pp *pp, tdm_info_pp *info);
162     tdm_error    (*pp_attach)(tdm_pp *pp, tbm_surface_h src, tbm_surface_h dst);
163     tdm_error    (*pp_commit)(tdm_pp *pp); /* init */
164     tdm_error    (*pp_set_done_handler)(tdm_pp *pp, tdm_pp_done_handler func, void *user_data);
165 } tdm_func_pp;
166
167 typedef void (*tdm_capture_done_handler)(tdm_capture *capture, tbm_surface_h buffer, void *user_data);
168
169 typedef struct _tdm_func_capture
170 {
171     void         (*capture_destroy)(tdm_capture *capture); /* init */
172     tdm_error    (*capture_set_info)(tdm_capture *capture, tdm_info_capture *info);
173     tdm_error    (*capture_attach)(tdm_capture *capture, tbm_surface_h buffer);
174     tdm_error    (*capture_commit)(tdm_capture *capture); /* init */
175     tdm_error    (*capture_set_done_handler)(tdm_capture *capture, tdm_capture_done_handler func, void *user_data);
176 } tdm_func_capture;
177
178 #define TDM_BACKEND_MINOR_VERSION_MASK  0x0000FFFF
179 #define TDM_BACKEND_MAJOR_VERSION_MASK  0xFFFF0000
180 #define TDM_BACKEND_GET_ABI_MINOR(v)    ((v) & TDM_BACKEND_MINOR_VERSION_MASK)
181 #define TDM_BACKEND_GET_ABI_MAJOR(v)    (((v) & TDM_BACKEND_MAJOR_VERSION_MASK) >> 16)
182
183 #define SET_TDM_BACKEND_ABI_VERSION(major, minor) \
184         (((major) << 16) & TDM_BACKEND_MAJOR_VERSION_MASK) | \
185         ((major) & TDM_BACKEND_MINOR_VERSION_MASK)
186 #define TDM_BACKEND_ABI_VERSION     SET_TDM_BACKEND_ABI_VERSION(1, 1)
187
188 typedef struct _tdm_backend_module
189 {
190     const char *name;
191     const char *vendor;
192     unsigned long abi_version;
193
194     tdm_backend_data* (*init)(tdm_display *dpy, tdm_error *error);
195     void (*deinit)(tdm_backend_data *bdata);
196 } tdm_backend_module;
197
198 tdm_error tdm_backend_register_func_display(tdm_display *dpy, tdm_func_display *func_display);
199 tdm_error tdm_backend_register_func_pp(tdm_display *dpy, tdm_func_pp *func_pp);
200 tdm_error tdm_backend_register_func_capture(tdm_display *dpy, tdm_func_capture *func_capture);
201
202 typedef void (*tdm_buffer_destroy_handler)(tbm_surface_h buffer, void *user_data);
203
204 tbm_surface_h tdm_buffer_ref_backend(tbm_surface_h buffer);
205 void          tdm_buffer_unref_backend(tbm_surface_h buffer);
206 tdm_error     tdm_buffer_add_destroy_handler(tbm_surface_h buffer, tdm_buffer_destroy_handler func, void *user_data);
207 void          tdm_buffer_remove_destroy_handler(tbm_surface_h buffer, tdm_buffer_destroy_handler func, void *user_data);
208
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif /* _TDM_BACKEND_H_ */