1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
32 #include "dri_screen.h"
33 #include "dri_context.h"
34 #include "dri_drawable.h"
36 #include "pipe/p_screen.h"
37 #include "util/u_format.h"
38 #include "util/u_memory.h"
39 #include "util/u_inlines.h"
43 dri_st_framebuffer_validate(struct st_framebuffer_iface
*stfbi
,
44 const enum st_attachment_type
*statts
,
46 struct pipe_resource
**out
)
48 struct dri_drawable
*drawable
=
49 (struct dri_drawable
*) stfbi
->st_manager_private
;
50 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
51 unsigned statt_mask
, new_mask
;
56 for (i
= 0; i
< count
; i
++)
57 statt_mask
|= (1 << statts
[i
]);
59 /* record newly allocated textures */
60 new_mask
= (statt_mask
& ~drawable
->texture_mask
);
63 * dPriv->pStamp is the server stamp. It should be accessed with a lock, at
64 * least for DRI1. dPriv->lastStamp is the client stamp. It has the value
65 * of the server stamp when last checked.
67 new_stamp
= (drawable
->texture_stamp
!= drawable
->dPriv
->lastStamp
);
69 if (new_stamp
|| new_mask
|| screen
->broken_invalidate
) {
70 if (new_stamp
&& drawable
->update_drawable_info
)
71 drawable
->update_drawable_info(drawable
);
73 drawable
->allocate_textures(drawable
, statts
, count
);
75 /* add existing textures */
76 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
77 if (drawable
->textures
[i
])
78 statt_mask
|= (1 << i
);
81 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
;
82 drawable
->texture_mask
= statt_mask
;
88 for (i
= 0; i
< count
; i
++) {
90 pipe_resource_reference(&out
[i
], drawable
->textures
[statts
[i
]]);
97 dri_st_framebuffer_flush_front(struct st_framebuffer_iface
*stfbi
,
98 enum st_attachment_type statt
)
100 struct dri_drawable
*drawable
=
101 (struct dri_drawable
*) stfbi
->st_manager_private
;
103 /* XXX remove this and just set the correct one on the framebuffer */
104 drawable
->flush_frontbuffer(drawable
, statt
);
110 * This is called when we need to set up GL rendering to a new X window.
113 dri_create_buffer(__DRIscreen
* sPriv
,
114 __DRIdrawable
* dPriv
,
115 const struct gl_config
* visual
, boolean isPixmap
)
117 struct dri_screen
*screen
= sPriv
->private;
118 struct dri_drawable
*drawable
= NULL
;
121 goto fail
; /* not implemented */
123 drawable
= CALLOC_STRUCT(dri_drawable
);
124 if (drawable
== NULL
)
127 dri_fill_st_visual(&drawable
->stvis
, screen
, visual
);
129 /* setup the st_framebuffer_iface */
130 drawable
->base
.visual
= &drawable
->stvis
;
131 drawable
->base
.flush_front
= dri_st_framebuffer_flush_front
;
132 drawable
->base
.validate
= dri_st_framebuffer_validate
;
133 drawable
->base
.st_manager_private
= (void *) drawable
;
135 drawable
->screen
= screen
;
136 drawable
->sPriv
= sPriv
;
137 drawable
->dPriv
= dPriv
;
138 dPriv
->driverPrivate
= (void *)drawable
;
139 p_atomic_set(&drawable
->base
.stamp
, 1);
148 dri_destroy_buffer(__DRIdrawable
* dPriv
)
150 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
153 pipe_surface_reference(&drawable
->drisw_surface
, NULL
);
155 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
156 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
162 * Validate the texture at an attachment. Allocate the texture if it does not
163 * exist. Used by the TFP extension.
166 dri_drawable_validate_att(struct dri_drawable
*drawable
,
167 enum st_attachment_type statt
)
169 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
170 unsigned i
, count
= 0;
172 /* check if buffer already exists */
173 if (drawable
->texture_mask
& (1 << statt
))
176 /* make sure DRI2 does not destroy existing buffers */
177 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
178 if (drawable
->texture_mask
& (1 << i
)) {
182 statts
[count
++] = statt
;
184 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
- 1;
186 drawable
->base
.validate(&drawable
->base
, statts
, count
, NULL
);
190 * These are used for GLX_EXT_texture_from_pixmap
193 dri_set_tex_buffer2(__DRIcontext
*pDRICtx
, GLint target
,
194 GLint format
, __DRIdrawable
*dPriv
)
196 struct dri_context
*ctx
= dri_context(pDRICtx
);
197 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
198 struct pipe_resource
*pt
;
200 dri_drawable_validate_att(drawable
, ST_ATTACHMENT_FRONT_LEFT
);
202 pt
= drawable
->textures
[ST_ATTACHMENT_FRONT_LEFT
];
205 enum pipe_format internal_format
= pt
->format
;
207 if (format
== __DRI_TEXTURE_FORMAT_RGB
) {
208 /* only need to cover the formats recognized by dri_fill_st_visual */
209 switch (internal_format
) {
210 case PIPE_FORMAT_B8G8R8A8_UNORM
:
211 internal_format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
213 case PIPE_FORMAT_A8R8G8B8_UNORM
:
214 internal_format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
221 ctx
->st
->teximage(ctx
->st
,
222 (target
== GL_TEXTURE_2D
) ? ST_TEXTURE_2D
: ST_TEXTURE_RECT
,
223 0, internal_format
, pt
, FALSE
);
228 dri_set_tex_buffer(__DRIcontext
*pDRICtx
, GLint target
,
229 __DRIdrawable
*dPriv
)
231 dri_set_tex_buffer2(pDRICtx
, target
, __DRI_TEXTURE_FORMAT_RGBA
, dPriv
);
234 const __DRItexBufferExtension driTexBufferExtension
= {
235 { __DRI_TEX_BUFFER
, __DRI_TEX_BUFFER_VERSION
},
242 * Get the format and binding of an attachment.
245 dri_drawable_get_format(struct dri_drawable
*drawable
,
246 enum st_attachment_type statt
,
247 enum pipe_format
*format
,
251 case ST_ATTACHMENT_FRONT_LEFT
:
252 case ST_ATTACHMENT_BACK_LEFT
:
253 case ST_ATTACHMENT_FRONT_RIGHT
:
254 case ST_ATTACHMENT_BACK_RIGHT
:
255 *format
= drawable
->stvis
.color_format
;
256 *bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
258 case ST_ATTACHMENT_DEPTH_STENCIL
:
259 *format
= drawable
->stvis
.depth_stencil_format
;
260 *bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
263 *format
= PIPE_FORMAT_NONE
;
269 /* vim: set sw=3 ts=8 sts=3 expandtab: */