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_format.h"
31 #include "util/u_debug.h"
32 #include "state_tracker/st_manager.h" /* for st_manager_create_api */
34 #include "dri_screen.h"
35 #include "dri_context.h"
36 #include "dri_drawable.h"
37 #include "dri_st_api.h"
42 dri_st_framebuffer_validate(struct st_framebuffer_iface
*stfbi
,
43 const enum st_attachment_type
*statts
,
45 struct pipe_texture
**out
)
47 struct dri_drawable
*drawable
=
48 (struct dri_drawable
*) stfbi
->st_manager_private
;
49 unsigned statt_mask
, new_mask
;
54 for (i
= 0; i
< count
; i
++)
55 statt_mask
|= (1 << statts
[i
]);
57 /* record newly allocated textures */
58 new_mask
= (statt_mask
& ~drawable
->texture_mask
);
61 * dPriv->pStamp is the server stamp. It should be accessed with a lock, at
62 * least for DRI1. dPriv->lastStamp is the client stamp. It has the value
63 * of the server stamp when last checked.
65 new_stamp
= (drawable
->texture_stamp
!= drawable
->dPriv
->lastStamp
);
67 if (new_stamp
|| new_mask
) {
69 if (__dri1_api_hooks
) {
70 dri1_allocate_textures(drawable
, statt_mask
);
73 dri_allocate_textures(drawable
, statts
, count
);
76 /* add existing textures */
77 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
78 if (drawable
->textures
[i
])
79 statt_mask
|= (1 << i
);
82 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
;
83 drawable
->texture_mask
= statt_mask
;
89 for (i
= 0; i
< count
; i
++) {
91 pipe_texture_reference(&out
[i
], drawable
->textures
[statts
[i
]]);
98 dri_st_framebuffer_flush_front(struct st_framebuffer_iface
*stfbi
,
99 enum st_attachment_type statt
)
101 struct dri_drawable
*drawable
=
102 (struct dri_drawable
*) stfbi
->st_manager_private
;
104 if (__dri1_api_hooks
) {
105 dri1_flush_frontbuffer(drawable
, statt
);
108 dri_flush_frontbuffer(drawable
, statt
);
115 * Create a framebuffer from the given drawable.
117 struct st_framebuffer_iface
*
118 dri_create_st_framebuffer(struct dri_drawable
*drawable
)
120 struct st_framebuffer_iface
*stfbi
;
122 stfbi
= CALLOC_STRUCT(st_framebuffer_iface
);
124 stfbi
->visual
= &drawable
->stvis
;
125 stfbi
->flush_front
= dri_st_framebuffer_flush_front
;
126 stfbi
->validate
= dri_st_framebuffer_validate
;
127 stfbi
->st_manager_private
= (void *) drawable
;
134 * Destroy a framebuffer.
137 dri_destroy_st_framebuffer(struct st_framebuffer_iface
*stfbi
)
143 * Validate the texture at an attachment. Allocate the texture if it does not
147 dri_st_framebuffer_validate_att(struct st_framebuffer_iface
*stfbi
,
148 enum st_attachment_type statt
)
150 struct dri_drawable
*drawable
=
151 (struct dri_drawable
*) stfbi
->st_manager_private
;
152 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
153 unsigned i
, count
= 0;
155 /* check if buffer already exists */
156 if (drawable
->texture_mask
& (1 << statt
))
159 /* make sure DRI2 does not destroy existing buffers */
160 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
161 if (drawable
->texture_mask
& (1 << i
)) {
165 statts
[count
++] = statt
;
167 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
- 1;
169 stfbi
->validate(stfbi
, statts
, count
, NULL
);
173 * Reference counted st_api.
177 struct st_api
*stapi
;
181 * Add a reference to the st_api of the state tracker.
184 _dri_get_st_api(void)
186 p_atomic_inc(&dri_st_api
.refcnt
);
187 if (p_atomic_read(&dri_st_api
.refcnt
) == 1)
188 dri_st_api
.stapi
= st_manager_create_api();
192 * Remove a reference to the st_api of the state tracker.
195 _dri_put_st_api(void)
197 struct st_api
*stapi
= dri_st_api
.stapi
;
199 if (p_atomic_dec_zero(&dri_st_api
.refcnt
)) {
200 stapi
->destroy(dri_st_api
.stapi
);
201 dri_st_api
.stapi
= NULL
;
206 * Create a state tracker manager from the given screen.
209 dri_create_st_manager(struct dri_screen
*screen
)
211 struct st_manager
*smapi
;
213 smapi
= CALLOC_STRUCT(st_manager
);
215 smapi
->screen
= screen
->pipe_screen
;
223 * Destroy a state tracker manager.
226 dri_destroy_st_manager(struct st_manager
*smapi
)
233 * Return the st_api of OpenGL state tracker.
238 assert(dri_st_api
.stapi
);
239 return dri_st_api
.stapi
;