2 * Mesa 3-D graphics library
5 * Copyright (C) 2010 LunarG Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "util/u_memory.h"
29 #include "util/u_inlines.h"
30 #include "util/u_dl.h"
35 #include "egl_g3d_st.h"
37 struct egl_g3d_st_manager
{
38 struct st_manager base
;
42 static INLINE
struct egl_g3d_st_manager
*
43 egl_g3d_st_manager(struct st_manager
*smapi
)
45 return (struct egl_g3d_st_manager
*) smapi
;
49 egl_g3d_create_st_api(enum st_api_type api
)
51 const char *stmod_name
;
52 struct util_dl_library
*lib
;
53 const struct st_module
*mod
;
57 stmod_name
= ST_MODULE_OPENGL_SYMBOL
;
59 case ST_API_OPENGL_ES1
:
60 stmod_name
= ST_MODULE_OPENGL_ES1_SYMBOL
;
62 case ST_API_OPENGL_ES2
:
63 stmod_name
= ST_MODULE_OPENGL_ES2_SYMBOL
;
66 stmod_name
= ST_MODULE_OPENVG_SYMBOL
;
76 lib
= util_dl_open(NULL
);
78 mod
= (const struct st_module
*)
79 util_dl_get_proc_address(lib
, stmod_name
);
82 if (!mod
|| mod
->api
!= api
)
85 return mod
->create_api();
89 egl_g3d_create_st_manager(_EGLDisplay
*dpy
)
91 struct egl_g3d_display
*gdpy
= egl_g3d_display(dpy
);
92 struct egl_g3d_st_manager
*gsmapi
;
94 gsmapi
= CALLOC_STRUCT(egl_g3d_st_manager
);
96 gsmapi
->display
= dpy
;
98 gsmapi
->base
.screen
= gdpy
->native
->screen
;
101 return &gsmapi
->base
;;
105 egl_g3d_destroy_st_manager(struct st_manager
*smapi
)
107 struct egl_g3d_st_manager
*gsmapi
= egl_g3d_st_manager(smapi
);
112 egl_g3d_st_framebuffer_flush_front(struct st_framebuffer_iface
*stfbi
,
113 enum st_attachment_type statt
)
115 _EGLSurface
*surf
= (_EGLSurface
*) stfbi
->st_manager_private
;
116 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
118 return gsurf
->native
->flush_frontbuffer(gsurf
->native
);
122 egl_g3d_st_framebuffer_validate(struct st_framebuffer_iface
*stfbi
,
123 const enum st_attachment_type
*statts
,
125 struct pipe_texture
**out
)
127 _EGLSurface
*surf
= (_EGLSurface
*) stfbi
->st_manager_private
;
128 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
129 struct pipe_texture
*textures
[NUM_NATIVE_ATTACHMENTS
];
130 uint attachment_mask
= 0;
133 for (i
= 0; i
< count
; i
++) {
137 case ST_ATTACHMENT_FRONT_LEFT
:
138 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
140 case ST_ATTACHMENT_BACK_LEFT
:
141 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
143 case ST_ATTACHMENT_FRONT_RIGHT
:
144 natt
= NATIVE_ATTACHMENT_FRONT_RIGHT
;
146 case ST_ATTACHMENT_BACK_RIGHT
:
147 natt
= NATIVE_ATTACHMENT_BACK_RIGHT
;
155 attachment_mask
|= 1 << natt
;
158 if (!gsurf
->native
->validate(gsurf
->native
, attachment_mask
,
159 &gsurf
->sequence_number
, textures
, &gsurf
->base
.Width
,
160 &gsurf
->base
.Height
))
163 for (i
= 0; i
< count
; i
++) {
164 struct pipe_texture
*tex
;
168 case ST_ATTACHMENT_FRONT_LEFT
:
169 natt
= NATIVE_ATTACHMENT_FRONT_LEFT
;
171 case ST_ATTACHMENT_BACK_LEFT
:
172 natt
= NATIVE_ATTACHMENT_BACK_LEFT
;
174 case ST_ATTACHMENT_FRONT_RIGHT
:
175 natt
= NATIVE_ATTACHMENT_FRONT_RIGHT
;
177 case ST_ATTACHMENT_BACK_RIGHT
:
178 natt
= NATIVE_ATTACHMENT_BACK_RIGHT
;
186 tex
= textures
[natt
];
188 if (statts
[i
] == stfbi
->visual
->render_buffer
)
189 pipe_texture_reference(&gsurf
->render_texture
, tex
);
191 if (attachment_mask
& (1 << natt
)) {
192 /* transfer the ownership to the caller */
194 attachment_mask
&= ~(1 << natt
);
197 /* the attachment is listed more than once */
198 pipe_texture_reference(&out
[i
], tex
);
206 struct st_framebuffer_iface
*
207 egl_g3d_create_st_framebuffer(_EGLSurface
*surf
)
209 struct egl_g3d_surface
*gsurf
= egl_g3d_surface(surf
);
210 struct st_framebuffer_iface
*stfbi
;
212 stfbi
= CALLOC_STRUCT(st_framebuffer_iface
);
216 stfbi
->visual
= &gsurf
->stvis
;
217 stfbi
->flush_front
= egl_g3d_st_framebuffer_flush_front
;
218 stfbi
->validate
= egl_g3d_st_framebuffer_validate
;
219 stfbi
->st_manager_private
= (void *) &gsurf
->base
;
225 egl_g3d_destroy_st_framebuffer(struct st_framebuffer_iface
*stfbi
)