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_drawable.h"
35 #include "pipe/p_screen.h"
36 #include "util/u_format.h"
37 #include "util/u_memory.h"
38 #include "util/u_inlines.h"
42 dri_st_framebuffer_validate(struct st_framebuffer_iface
*stfbi
,
43 const enum st_attachment_type
*statts
,
45 struct pipe_resource
**out
)
47 struct dri_drawable
*drawable
=
48 (struct dri_drawable
*) stfbi
->st_manager_private
;
49 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
50 unsigned statt_mask
, new_mask
;
55 for (i
= 0; i
< count
; i
++)
56 statt_mask
|= (1 << statts
[i
]);
58 /* record newly allocated textures */
59 new_mask
= (statt_mask
& ~drawable
->texture_mask
);
62 * dPriv->pStamp is the server stamp. It should be accessed with a lock, at
63 * least for DRI1. dPriv->lastStamp is the client stamp. It has the value
64 * of the server stamp when last checked.
66 new_stamp
= (drawable
->texture_stamp
!= drawable
->dPriv
->lastStamp
);
68 if (new_stamp
|| new_mask
|| screen
->broken_invalidate
) {
69 if (new_stamp
&& drawable
->update_drawable_info
)
70 drawable
->update_drawable_info(drawable
);
72 drawable
->allocate_textures(drawable
, statts
, count
);
74 /* add existing textures */
75 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
76 if (drawable
->textures
[i
])
77 statt_mask
|= (1 << i
);
80 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
;
81 drawable
->texture_mask
= statt_mask
;
87 for (i
= 0; i
< count
; i
++) {
89 pipe_resource_reference(&out
[i
], drawable
->textures
[statts
[i
]]);
96 dri_st_framebuffer_flush_front(struct st_framebuffer_iface
*stfbi
,
97 enum st_attachment_type statt
)
99 struct dri_drawable
*drawable
=
100 (struct dri_drawable
*) stfbi
->st_manager_private
;
102 /* XXX remove this and just set the correct one on the framebuffer */
103 drawable
->flush_frontbuffer(drawable
, statt
);
109 * This is called when we need to set up GL rendering to a new X window.
112 dri_create_buffer(__DRIscreen
* sPriv
,
113 __DRIdrawable
* dPriv
,
114 const __GLcontextModes
* visual
, boolean isPixmap
)
116 struct dri_screen
*screen
= sPriv
->private;
117 struct dri_drawable
*drawable
= NULL
;
120 goto fail
; /* not implemented */
122 drawable
= CALLOC_STRUCT(dri_drawable
);
123 if (drawable
== NULL
)
126 dri_fill_st_visual(&drawable
->stvis
, screen
, visual
);
128 /* setup the st_framebuffer_iface */
129 drawable
->base
.visual
= &drawable
->stvis
;
130 drawable
->base
.flush_front
= dri_st_framebuffer_flush_front
;
131 drawable
->base
.validate
= dri_st_framebuffer_validate
;
132 drawable
->base
.st_manager_private
= (void *) drawable
;
134 drawable
->sPriv
= sPriv
;
135 drawable
->dPriv
= dPriv
;
136 dPriv
->driverPrivate
= (void *)drawable
;
145 dri_destroy_buffer(__DRIdrawable
* dPriv
)
147 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
150 pipe_surface_reference(&drawable
->drisw_surface
, NULL
);
152 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
153 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
159 * Validate the texture at an attachment. Allocate the texture if it does not
163 dri_drawable_validate_att(struct dri_drawable
*drawable
,
164 enum st_attachment_type statt
)
166 enum st_attachment_type statts
[ST_ATTACHMENT_COUNT
];
167 unsigned i
, count
= 0;
169 /* check if buffer already exists */
170 if (drawable
->texture_mask
& (1 << statt
))
173 /* make sure DRI2 does not destroy existing buffers */
174 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
175 if (drawable
->texture_mask
& (1 << i
)) {
179 statts
[count
++] = statt
;
181 drawable
->texture_stamp
= drawable
->dPriv
->lastStamp
- 1;
183 /* this calles into the manager */
184 drawable
->base
.validate(&drawable
->base
, statts
, count
, NULL
);
188 * Get the format and binding of an attachment.
191 dri_drawable_get_format(struct dri_drawable
*drawable
,
192 enum st_attachment_type statt
,
193 enum pipe_format
*format
,
197 case ST_ATTACHMENT_FRONT_LEFT
:
198 case ST_ATTACHMENT_BACK_LEFT
:
199 case ST_ATTACHMENT_FRONT_RIGHT
:
200 case ST_ATTACHMENT_BACK_RIGHT
:
201 *format
= drawable
->stvis
.color_format
;
202 *bind
= PIPE_BIND_RENDER_TARGET
| PIPE_BIND_SAMPLER_VIEW
;
204 case ST_ATTACHMENT_DEPTH_STENCIL
:
205 *format
= drawable
->stvis
.depth_stencil_format
;
206 *bind
= PIPE_BIND_DEPTH_STENCIL
; /* XXX sampler? */
209 *format
= PIPE_FORMAT_NONE
;
215 /* vim: set sw=3 ts=8 sts=3 expandtab: */