Tizen 2.1 base
[sdk/emulator/qemu.git] / hw / yagl_apis / egl / yagl_egl_surface.h
1 #ifndef _QEMU_YAGL_EGL_SURFACE_H
2 #define _QEMU_YAGL_EGL_SURFACE_H
3
4 #include "yagl_types.h"
5 #include "yagl_resource.h"
6 #include "yagl_egl_surface_attribs.h"
7 #include "qemu-thread.h"
8 #include <EGL/egl.h>
9
10 struct yagl_egl_display;
11 struct yagl_egl_config;
12 struct yagl_compiled_transfer;
13
14 struct yagl_egl_surface
15 {
16     struct yagl_resource res;
17
18     struct yagl_egl_display *dpy;
19
20     struct yagl_egl_config *cfg;
21
22     EGLenum type;
23
24     union
25     {
26         struct yagl_egl_window_attribs window;
27         struct yagl_egl_pixmap_attribs pixmap;
28         struct yagl_egl_pbuffer_attribs pbuffer;
29     } attribs;
30
31     /*
32      * Backing image compiled transfers are the only ones that
33      * can be accessed from multiple threads
34      * simultaneously. When we call
35      * eglDestroySurface we want to destroy backing image
36      * immediately, because target's pixmap will no longer be available
37      * after host 'eglDestroySurface' call is complete. The surface however
38      * may be accessed from another thread where it's current
39      * (from eglSwapBuffers for example), in that case the result of the call
40      * must be EGL_BAD_SURFACE.
41      */
42     QemuMutex bimage_mtx;
43
44     /*
45      * Compiled transfer for backing image. It'll become NULL
46      * after eglDestroySurface is called.
47      */
48     struct yagl_compiled_transfer *bimage_ct;
49     uint32_t width;
50     uint32_t height;
51     uint32_t bpp;
52
53     /*
54      * Host pre-allocated storage for backing image.
55      * This will go to compiled transfer above.
56      */
57     void *host_pixels;
58
59     /*
60      * Native pbuffer surface.
61      */
62     EGLSurface native_sfc;
63
64     /*
65      * Attribs with which this 'native_sfc' was created with.
66      */
67     struct yagl_egl_pbuffer_attribs native_sfc_attribs;
68 };
69
70 /*
71  * Takes ownership of 'bimage_ct'. byte-copies 'attribs'.
72  */
73 struct yagl_egl_surface
74     *yagl_egl_surface_create_window(struct yagl_egl_display *dpy,
75                                     struct yagl_egl_config *cfg,
76                                     const struct yagl_egl_window_attribs *attribs,
77                                     struct yagl_compiled_transfer *bimage_ct,
78                                     uint32_t width,
79                                     uint32_t height,
80                                     uint32_t bpp);
81
82 /*
83  * Takes ownership of 'bimage_ct'. byte-copies 'attribs'.
84  */
85 struct yagl_egl_surface
86     *yagl_egl_surface_create_pixmap(struct yagl_egl_display *dpy,
87                                     struct yagl_egl_config *cfg,
88                                     const struct yagl_egl_pixmap_attribs *attribs,
89                                     struct yagl_compiled_transfer *bimage_ct,
90                                     uint32_t width,
91                                     uint32_t height,
92                                     uint32_t bpp);
93
94 /*
95  * Takes ownership of 'bimage_ct'. byte-copies 'attribs'.
96  */
97 struct yagl_egl_surface
98     *yagl_egl_surface_create_pbuffer(struct yagl_egl_display *dpy,
99                                      struct yagl_egl_config *cfg,
100                                      const struct yagl_egl_pbuffer_attribs *attribs,
101                                      struct yagl_compiled_transfer *bimage_ct,
102                                      uint32_t width,
103                                      uint32_t height,
104                                      uint32_t bpp);
105
106 /*
107  * Lock/unlock surface for 'bimage' access, all 'bimage' operations
108  * must be carried out while surface is locked.
109  * @{
110  */
111
112 void yagl_egl_surface_lock(struct yagl_egl_surface *sfc);
113
114 void yagl_egl_surface_unlock(struct yagl_egl_surface *sfc);
115
116 /*
117  * @}
118  */
119
120 /*
121  * Takes ownership of 'native_sfc' and 'bimage_ct'.
122  *
123  * This will destroy old surface data and update it with new one.
124  * Must be called while surface is locked.
125  */
126 void yagl_egl_surface_update(struct yagl_egl_surface *sfc,
127                              EGLSurface native_sfc,
128                              struct yagl_compiled_transfer *bimage_ct,
129                              uint32_t width,
130                              uint32_t height,
131                              uint32_t bpp);
132
133 /*
134  * This will destroy old surface data.
135  * Must be called while surface is locked.
136  */
137 void yagl_egl_surface_invalidate(struct yagl_egl_surface *sfc);
138
139 /*
140  * Helper functions that simply acquire/release yagl_egl_surface::res
141  * @{
142  */
143
144 /*
145  * Passing NULL won't hurt, this is for convenience.
146  */
147 void yagl_egl_surface_acquire(struct yagl_egl_surface *sfc);
148
149 /*
150  * Passing NULL won't hurt, this is for convenience.
151  */
152 void yagl_egl_surface_release(struct yagl_egl_surface *sfc);
153
154 /*
155  * @}
156  */
157
158 #endif