st/dri: Remove unnecessary headers.
[mesa.git] / src / gallium / state_trackers / dri / common / dri_drawable.c
1 /**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27 /*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
31
32 #include "dri_screen.h"
33 #include "dri_drawable.h"
34
35 #include "pipe/p_screen.h"
36 #include "util/u_format.h"
37 #include "util/u_memory.h"
38 #include "util/u_inlines.h"
39
40
41 static boolean
42 dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
43 const enum st_attachment_type *statts,
44 unsigned count,
45 struct pipe_resource **out)
46 {
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;
51 boolean new_stamp;
52 int i;
53
54 statt_mask = 0x0;
55 for (i = 0; i < count; i++)
56 statt_mask |= (1 << statts[i]);
57
58 /* record newly allocated textures */
59 new_mask = (statt_mask & ~drawable->texture_mask);
60
61 /*
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.
65 */
66 new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp);
67
68 if (new_stamp || new_mask || screen->broken_invalidate) {
69 if (new_stamp && drawable->update_drawable_info)
70 drawable->update_drawable_info(drawable);
71
72 drawable->allocate_textures(drawable, statts, count);
73
74 /* add existing textures */
75 for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
76 if (drawable->textures[i])
77 statt_mask |= (1 << i);
78 }
79
80 drawable->texture_stamp = drawable->dPriv->lastStamp;
81 drawable->texture_mask = statt_mask;
82 }
83
84 if (!out)
85 return TRUE;
86
87 for (i = 0; i < count; i++) {
88 out[i] = NULL;
89 pipe_resource_reference(&out[i], drawable->textures[statts[i]]);
90 }
91
92 return TRUE;
93 }
94
95 static boolean
96 dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi,
97 enum st_attachment_type statt)
98 {
99 struct dri_drawable *drawable =
100 (struct dri_drawable *) stfbi->st_manager_private;
101
102 /* XXX remove this and just set the correct one on the framebuffer */
103 drawable->flush_frontbuffer(drawable, statt);
104
105 return TRUE;
106 }
107
108 /**
109 * This is called when we need to set up GL rendering to a new X window.
110 */
111 boolean
112 dri_create_buffer(__DRIscreen * sPriv,
113 __DRIdrawable * dPriv,
114 const __GLcontextModes * visual, boolean isPixmap)
115 {
116 struct dri_screen *screen = sPriv->private;
117 struct dri_drawable *drawable = NULL;
118
119 if (isPixmap)
120 goto fail; /* not implemented */
121
122 drawable = CALLOC_STRUCT(dri_drawable);
123 if (drawable == NULL)
124 goto fail;
125
126 dri_fill_st_visual(&drawable->stvis, screen, visual);
127
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;
133
134 drawable->sPriv = sPriv;
135 drawable->dPriv = dPriv;
136 dPriv->driverPrivate = (void *)drawable;
137
138 return GL_TRUE;
139 fail:
140 FREE(drawable);
141 return GL_FALSE;
142 }
143
144 void
145 dri_destroy_buffer(__DRIdrawable * dPriv)
146 {
147 struct dri_drawable *drawable = dri_drawable(dPriv);
148 int i;
149
150 pipe_surface_reference(&drawable->drisw_surface, NULL);
151
152 for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
153 pipe_resource_reference(&drawable->textures[i], NULL);
154
155 FREE(drawable);
156 }
157
158 /**
159 * Validate the texture at an attachment. Allocate the texture if it does not
160 * exist.
161 */
162 void
163 dri_drawable_validate_att(struct dri_drawable *drawable,
164 enum st_attachment_type statt)
165 {
166 enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
167 unsigned i, count = 0;
168
169 /* check if buffer already exists */
170 if (drawable->texture_mask & (1 << statt))
171 return;
172
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)) {
176 statts[count++] = i;
177 }
178 }
179 statts[count++] = statt;
180
181 drawable->texture_stamp = drawable->dPriv->lastStamp - 1;
182
183 /* this calles into the manager */
184 drawable->base.validate(&drawable->base, statts, count, NULL);
185 }
186
187 /**
188 * Get the format and binding of an attachment.
189 */
190 void
191 dri_drawable_get_format(struct dri_drawable *drawable,
192 enum st_attachment_type statt,
193 enum pipe_format *format,
194 unsigned *bind)
195 {
196 switch (statt) {
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;
203 break;
204 case ST_ATTACHMENT_DEPTH_STENCIL:
205 *format = drawable->stvis.depth_stencil_format;
206 *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
207 break;
208 default:
209 *format = PIPE_FORMAT_NONE;
210 *bind = 0;
211 break;
212 }
213 }
214
215 /* vim: set sw=3 ts=8 sts=3 expandtab: */