tizen 2.4 release
[sdk/emulator-yagl.git] / EGL / yagl_offscreen.c
1 /*
2  * YaGL
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact :
7  * Stanislav Vorobiov <s.vorobiov@samsung.com>
8  * Jinhyung Jo <jinhyung.jo@samsung.com>
9  * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights
14  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15  * copies of the Software, and to permit persons to whom the Software is
16  * furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27  * THE SOFTWARE.
28  *
29  * Contributors:
30  * - S-Core Co., Ltd
31  *
32  */
33
34 #include "yagl_offscreen.h"
35 #include "yagl_offscreen_surface.h"
36 #include "yagl_offscreen_image_pixmap.h"
37 #include "yagl_display.h"
38 #include "yagl_native_display.h"
39 #include "yagl_backend.h"
40 #include "yagl_malloc.h"
41 #include "yagl_native_platform.h"
42 #include "yagl_egl_state.h"
43 #include "yagl_host_egl_calls.h"
44
45 static struct yagl_display
46     *yagl_offscreen_create_display(struct yagl_native_platform *platform,
47                                    yagl_os_display os_dpy)
48 {
49     EGLint error = 0;
50     struct yagl_display *dpy;
51     yagl_host_handle host_dpy;
52     struct yagl_native_display *native_dpy;
53
54     native_dpy = platform->wrap_display(os_dpy, 0);
55
56     if (!native_dpy) {
57         return NULL;
58     }
59
60     host_dpy = yagl_host_eglGetDisplay((uint32_t)os_dpy, &error);
61
62     if (!host_dpy) {
63         yagl_set_error(error);
64         native_dpy->destroy(native_dpy);
65         return NULL;
66     }
67
68     dpy = yagl_malloc0(sizeof(*dpy));
69
70     yagl_display_init(dpy, os_dpy, native_dpy, host_dpy);
71
72     return dpy;
73 }
74
75 static struct yagl_surface
76     *yagl_offscreen_create_window_surface(struct yagl_display *dpy,
77                                           yagl_host_handle host_config,
78                                           struct yagl_native_drawable *native_window,
79                                           const EGLint* attrib_list)
80 {
81     struct yagl_offscreen_surface *sfc =
82         yagl_offscreen_surface_create_window(dpy,
83                                              host_config,
84                                              native_window,
85                                              attrib_list);
86
87     return sfc ? &sfc->base : NULL;
88 }
89
90 static struct yagl_surface
91     *yagl_offscreen_create_pixmap_surface(struct yagl_display *dpy,
92                                           yagl_host_handle host_config,
93                                           struct yagl_native_drawable *native_pixmap,
94                                           const EGLint* attrib_list)
95 {
96     struct yagl_offscreen_surface *sfc =
97         yagl_offscreen_surface_create_pixmap(dpy,
98                                              host_config,
99                                              native_pixmap,
100                                              attrib_list);
101
102     return sfc ? &sfc->base : NULL;
103 }
104
105 static struct yagl_surface
106     *yagl_offscreen_create_pbuffer_surface(struct yagl_display *dpy,
107                                            yagl_host_handle host_config,
108                                            const EGLint* attrib_list)
109 {
110     struct yagl_offscreen_surface *sfc =
111         yagl_offscreen_surface_create_pbuffer(dpy, host_config, attrib_list);
112
113     return sfc ? &sfc->base : NULL;
114 }
115
116 static struct yagl_image
117     *yagl_offscreen_create_image_pixmap(struct yagl_display *dpy,
118                                         struct yagl_native_drawable *native_pixmap,
119                                         struct yagl_client_interface *iface)
120 {
121     struct yagl_offscreen_image_pixmap *image =
122         yagl_offscreen_image_pixmap_create(dpy,
123                                            native_pixmap,
124                                            iface);
125
126     return image ? &image->base : NULL;
127 }
128
129 static struct yagl_image
130     *yagl_offscreen_create_image_wl_buffer(struct yagl_display *dpy,
131                                            struct wl_resource *buffer,
132                                            struct yagl_client_interface *iface)
133 {
134     return NULL;
135 }
136
137 static struct yagl_image
138     *yagl_offscreen_create_image_gl_texture_2d(struct yagl_display *dpy,
139                                                struct yagl_context *ctx,
140                                                yagl_object_name texture,
141                                                struct yagl_client_interface *iface)
142 {
143     return NULL;
144 }
145
146 static struct yagl_image
147     *yagl_offscreen_create_image_tizen_sfc(struct yagl_display *dpy,
148                                            EGLClientBuffer buffer,
149                                            struct yagl_client_interface *iface)
150 {
151     return NULL;
152 }
153
154 static struct yagl_fence
155     *yagl_offscreen_create_fence(struct yagl_display *dpy)
156 {
157     return NULL;
158 }
159
160 static void yagl_offscreen_destroy(struct yagl_backend *backend)
161 {
162     yagl_free(backend);
163 }
164
165 struct yagl_backend *yagl_offscreen_create()
166 {
167     struct yagl_backend *backend;
168
169     backend = yagl_malloc0(sizeof(*backend));
170
171     backend->create_display = &yagl_offscreen_create_display;
172     backend->create_window_surface = &yagl_offscreen_create_window_surface;
173     backend->create_pixmap_surface = &yagl_offscreen_create_pixmap_surface;
174     backend->create_pbuffer_surface = &yagl_offscreen_create_pbuffer_surface;
175     backend->create_image_pixmap = &yagl_offscreen_create_image_pixmap;
176     backend->create_image_wl_buffer = &yagl_offscreen_create_image_wl_buffer;
177     backend->create_image_gl_texture_2d = &yagl_offscreen_create_image_gl_texture_2d;
178     backend->create_image_tizen_sfc = &yagl_offscreen_create_image_tizen_sfc;
179     backend->create_fence = &yagl_offscreen_create_fence;
180     backend->destroy = &yagl_offscreen_destroy;
181     backend->y_inverted = 1;
182     backend->fence_supported = 0;
183
184     return backend;
185 }