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"
35 #include "dri1_helper.h"
37 #include "pipe/p_screen.h"
38 #include "util/u_format.h"
39 #include "util/u_memory.h"
40 #include "util/u_inlines.h"
44 dri_st_framebuffer_validate(struct st_framebuffer_iface
*stfbi
,
45 const enum st_attachment_type
*statts
,
47 struct pipe_resource
**out
)
49 struct dri_drawable
*drawable
=
50 (struct dri_drawable
*) stfbi
->st_manager_private
;
51 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
52 unsigned statt_mask
, new_mask
;
57 for (i
= 0; i
< count
; i
++)
58 statt_mask
|= (1 << statts
[i
]);
60 /* record newly allocated textures */
61 new_mask
= (statt_mask
& ~drawable
->texture_mask
);
64 * dPriv->pStamp is the server stamp. It should be accessed with a lock, at
65 * least for DRI1. dPriv->lastStamp is the client stamp. It has the value
66 * of the server stamp when last checked.
68 new_stamp
= (drawable
->texture_stamp
!= drawable
->dPriv
->lastStamp
);
70 if (new_stamp
|| new_mask
) {
71 if (new_stamp
&& screen
->update_drawable_info
)
72 screen
->update_drawable_info(drawable
);
74 screen
->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_resource_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
;
103 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
105 /* XXX remove this and just set the correct one on the framebuffer */
106 screen
->flush_frontbuffer(drawable
, statt
);
112 * This is called when we need to set up GL rendering to a new X window.
115 dri_create_buffer(__DRIscreen
* sPriv
,
116 __DRIdrawable
* dPriv
,
117 const __GLcontextModes
* visual
, boolean isPixmap
)
119 struct dri_screen
*screen
= sPriv
->private;
120 struct dri_drawable
*drawable
= NULL
;
123 goto fail
; /* not implemented */
125 drawable
= CALLOC_STRUCT(dri_drawable
);
126 if (drawable
== NULL
)
129 dri_fill_st_visual(&drawable
->stvis
, screen
, visual
);
131 /* setup the st_framebuffer_iface */
132 drawable
->base
.visual
= &drawable
->stvis
;
133 drawable
->base
.flush_front
= dri_st_framebuffer_flush_front
;
134 drawable
->base
.validate
= dri_st_framebuffer_validate
;
135 drawable
->base
.st_manager_private
= (void *) drawable
;
137 drawable
->sPriv
= sPriv
;
138 drawable
->dPriv
= dPriv
;
139 dPriv
->driverPrivate
= (void *)drawable
;
141 drawable
->desired_fences
= 2;
150 dri_destroy_buffer(__DRIdrawable
* dPriv
)
152 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
155 dri1_swap_fences_clear(drawable
);
157 dri1_destroy_pipe_surface(drawable
);
159 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
160 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
162 drawable
->desired_fences
= 0;
168 * Validate the texture at an attachment. Allocate the texture if it does not
172 dri_drawable_validate_att(struct dri_drawable
*drawable
,
173 enum st_attachment_type statt
)
175 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
176 unsigned i
, count
= 0;
178 /* check if buffer already exists */
179 if (drawable
->texture_mask
& (1 << statt
))
182 /* make sure DRI2 does not destroy existing buffers */
183 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
184 if (drawable
->texture_mask
& (1 << i
)) {
188 statts
[count
++] = statt
;
190 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
- 1;
192 /* this calles into the manager */
193 drawable
->base
.validate(&drawable
->base
, statts
, count
, NULL
);
197 * Get the format and binding of an attachment.
200 dri_drawable_get_format(struct dri_drawable
*drawable
,
201 enum st_attachment_type statt
,
202 enum pipe_format
*format
,
206 case ST_ATTACHMENT_FRONT_LEFT
:
207 case ST_ATTACHMENT_BACK_LEFT
:
208 case ST_ATTACHMENT_FRONT_RIGHT
:
209 case ST_ATTACHMENT_BACK_RIGHT
:
210 *format
= drawable
->stvis
.color_format
;
211 *bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
213 case ST_ATTACHMENT_DEPTH_STENCIL
:
214 *format
= drawable
->stvis
.depth_stencil_format
;
215 *bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
218 *format
= PIPE_FORMAT_NONE
;
224 /* vim: set sw=3 ts=8 sts=3 expandtab: */