1 /**********************************************************
2 * Copyright 2010 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_format.h"
34 * \file API for communication between state trackers and state tracker
37 * While both are state tackers, we use the term state tracker for rendering
38 * APIs such as OpenGL or OpenVG, and state tracker manager for window system
39 * APIs such as EGL or GLX in this file.
41 * This file defines an API to be implemented by both state trackers and state
46 * The supported rendering API of a state tracker.
58 * Used in st_context_iface->teximage.
60 enum st_texture_type
{
68 * Available attachments of framebuffer.
70 enum st_attachment_type
{
71 ST_ATTACHMENT_FRONT_LEFT
,
72 ST_ATTACHMENT_BACK_LEFT
,
73 ST_ATTACHMENT_FRONT_RIGHT
,
74 ST_ATTACHMENT_BACK_RIGHT
,
75 ST_ATTACHMENT_DEPTH_STENCIL
,
80 ST_ATTACHMENT_INVALID
= -1
83 /* for buffer_mask in st_visual */
84 #define ST_ATTACHMENT_FRONT_LEFT_MASK (1 << ST_ATTACHMENT_FRONT_LEFT)
85 #define ST_ATTACHMENT_BACK_LEFT_MASK (1 << ST_ATTACHMENT_BACK_LEFT)
86 #define ST_ATTACHMENT_FRONT_RIGHT_MASK (1 << ST_ATTACHMENT_FRONT_RIGHT)
87 #define ST_ATTACHMENT_BACK_RIGHT_MASK (1 << ST_ATTACHMENT_BACK_RIGHT)
88 #define ST_ATTACHMENT_DEPTH_STENCIL_MASK (1 << ST_ATTACHMENT_DEPTH_STENCIL)
89 #define ST_ATTACHMENT_ACCUM_MASK (1 << ST_ATTACHMENT_ACCUM)
90 #define ST_ATTACHMENT_SAMPLE_MASK (1 << ST_ATTACHMENT_SAMPLE)
93 * Enumerations of state tracker context resources.
95 enum st_context_resource_type
{
96 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_2D
,
97 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_3D
,
98 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_X
,
99 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
100 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
101 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
102 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
103 ST_CONTEXT_RESOURCE_OPENGL_TEXTURE_CUBE_MAP_NEGATIVE_Z
,
104 ST_CONTEXT_RESOURCE_OPENGL_RENDERBUFFER
,
105 ST_CONTEXT_RESOURCE_OPENVG_PARENT_IMAGE
109 * Value to st_manager->get_param function.
111 enum st_manager_param
{
116 * The return type of st_api->get_proc_address.
118 typedef void (*st_proc_t
)(void);
121 struct pipe_resource
;
122 struct pipe_fence_handle
;
125 * Used in st_context_iface->get_resource_for_egl_image.
127 struct st_context_resource
129 /* these fields are filled by the caller */
130 enum st_context_resource_type type
;
133 /* this is owned by the caller */
134 struct pipe_resource
*texture
;
138 * Used in st_manager_iface->get_egl_image.
142 /* these fields are filled by the caller */
143 struct st_context_iface
*stctxi
;
146 /* this is owned by the caller */
147 struct pipe_resource
*texture
;
155 * Represent the visual of a framebuffer.
160 * Available buffers. Tested with ST_FRAMEBUFFER_*_MASK.
162 unsigned buffer_mask
;
165 * Buffer formats. The formats are always set even when the buffer is
168 enum pipe_format color_format
;
169 enum pipe_format depth_stencil_format
;
170 enum pipe_format accum_format
;
174 * Desired render buffer.
176 enum st_attachment_type render_buffer
;
180 * Represent a windowing system drawable.
182 * The framebuffer is implemented by the state tracker manager and
183 * used by the state trackers.
185 * Instead of the winsys pokeing into the API context to figure
186 * out what buffers that might be needed in the future by the API
187 * context, it calls into the framebuffer to get the textures.
189 * This structure along with the notify_invalid_framebuffer
190 * allows framebuffers to be shared between different threads
191 * but at the same make the API context free from thread
192 * syncronisation primitves, with the exception of a small
193 * atomic flag used for notification of framebuffer dirty status.
195 * The thread syncronisation is put inside the framebuffer
196 * and only called once the framebuffer has become dirty.
198 struct st_framebuffer_iface
201 * Available for the state tracker manager to use.
203 void *st_manager_private
;
206 * The visual of a framebuffer.
208 const struct st_visual
*visual
;
211 * Flush the front buffer.
213 * On some window systems, changes to the front buffers are not immediately
214 * visible. They need to be flushed.
216 * @att is one of the front buffer attachments.
218 boolean (*flush_front
)(struct st_framebuffer_iface
*stfbi
,
219 enum st_attachment_type statt
);
222 * The state tracker asks for the textures it needs.
224 * It should try to only ask for attachments that it currently renders
225 * to, thus allowing the winsys to delay the allocation of textures not
226 * needed. For example front buffer attachments are not needed if you
227 * only do back buffer rendering.
229 * The implementor of this function needs to also ensure
230 * thread safty as this call might be done from multiple threads.
232 * The returned textures are owned by the caller. They should be
233 * unreferenced when no longer used. If this function is called multiple
234 * times with different sets of attachments, those buffers not included in
235 * the last call might be destroyed. This behavior might change in the
238 boolean (*validate
)(struct st_framebuffer_iface
*stfbi
,
239 const enum st_attachment_type
*statts
,
241 struct pipe_resource
**out
);
245 * Represent a rendering context.
247 * This entity is created from st_api and used by the state tracker manager.
249 struct st_context_iface
252 * Available for the state tracker and the manager to use.
254 void *st_context_private
;
255 void *st_manager_private
;
258 * Destroy the context.
260 void (*destroy
)(struct st_context_iface
*stctxi
);
263 * Invalidate the current textures that was taken from a framebuffer.
265 * The state tracker manager calls this function to let the rendering
266 * context know that it should update the textures it got from
267 * st_framebuffer_iface::validate. It should do so at the latest time possible.
268 * Possible right before sending triangles to the pipe context.
270 * For certain platforms this function might be called from a thread other
271 * than the thread that the context is currently bound in, and must
272 * therefore be thread safe. But it is the state tracker manager's
273 * responsibility to make sure that the framebuffer is bound to the context
274 * and the API context is current for the duration of this call.
276 * Thus reducing the sync primitive needed to a single atomic flag.
278 void (*notify_invalid_framebuffer
)(struct st_context_iface
*stctxi
,
279 struct st_framebuffer_iface
*stfbi
);
282 * Flush all drawing from context to the pipe also flushes the pipe.
284 void (*flush
)(struct st_context_iface
*stctxi
, unsigned flags
,
285 struct pipe_fence_handle
**fence
);
288 * Replace the texture image of a texture object at the specified level.
290 * This function is optional.
292 boolean (*teximage
)(struct st_context_iface
*stctxi
, enum st_texture_type target
,
293 int level
, enum pipe_format internal_format
,
294 struct pipe_resource
*tex
, boolean mipmap
);
297 * Used to implement glXCopyContext.
299 void (*copy
)(struct st_context_iface
*stctxi
,
300 struct st_context_iface
*stsrci
, unsigned mask
);
303 * Look up and return the info of a resource for EGLImage.
305 * This function is optional.
307 boolean (*get_resource_for_egl_image
)(struct st_context_iface
*stctxi
,
308 struct st_context_resource
*stres
);
313 * Represent a state tracker manager.
315 * This interface is implemented by the state tracker manager. It corresponds
316 * to a "display" in the window system.
320 struct pipe_screen
*screen
;
323 * Look up and return the info of an EGLImage.
325 * This function is optional.
327 boolean (*get_egl_image
)(struct st_manager
*smapi
,
328 struct st_egl_image
*stimg
);
331 * Query an manager param.
333 int (*get_param
)(struct st_manager
*smapi
,
334 enum st_manager_param param
);
338 * Represent a rendering API such as OpenGL or OpenVG.
340 * Implemented by the state tracker and used by the state tracker manager.
347 void (*destroy
)(struct st_api
*stapi
);
350 * Return an API entry point.
352 * For GL this is the same as _glapi_get_proc_address.
354 st_proc_t (*get_proc_address
)(struct st_api
*stapi
, const char *procname
);
357 * Return true if the visual is supported by the state tracker.
359 boolean (*is_visual_supported
)(struct st_api
*stapi
,
360 const struct st_visual
*visual
);
363 * Create a rendering context.
365 struct st_context_iface
*(*create_context
)(struct st_api
*stapi
,
366 struct st_manager
*smapi
,
367 const struct st_visual
*visual
,
368 struct st_context_iface
*stsharei
);
371 * Bind the context to the calling thread with draw and read as drawables.
373 * The framebuffers might have different visuals than the context does.
375 boolean (*make_current
)(struct st_api
*stapi
,
376 struct st_context_iface
*stctxi
,
377 struct st_framebuffer_iface
*stdrawi
,
378 struct st_framebuffer_iface
*streadi
);
381 * Get the currently bound context in the calling thread.
383 struct st_context_iface
*(*get_current
)(struct st_api
*stapi
);
387 * Return true if the visual has the specified buffers.
389 static INLINE boolean
390 st_visual_have_buffers(const struct st_visual
*visual
, unsigned mask
)
392 return ((visual
->buffer_mask
& mask
) == mask
);
395 /* these symbols may need to be dynamically lookup up */
396 extern PUBLIC
struct st_api
* st_api_create_OpenGL(void);
397 extern PUBLIC
struct st_api
* st_api_create_OpenGL_ES1(void);
398 extern PUBLIC
struct st_api
* st_api_create_OpenGL_ES2(void);
399 extern PUBLIC
struct st_api
* st_api_create_OpenVG(void);
402 * The entry points of the state trackers.
404 #define ST_CREATE_OPENGL_SYMBOL "st_api_create_OpenGL"
405 #define ST_CREATE_OPENGL_ES1_SYMBOL "st_api_create_OpenGL_ES1"
406 #define ST_CREATE_OPENGL_ES2_SYMBOL "st_api_create_OpenGL_ES2"
407 #define ST_CREATE_OPENVG_SYMBOL "st_api_create_OpenVG"
409 #endif /* _ST_API_H_ */