1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
5 * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * xshm / texture_from_pixmap / EGLImage:
33 * Allow the loaders to use the XSHM extension. It probably requires callbacks
34 * for createImage/destroyImage similar to DRI2 getBuffers.
37 #include "util/u_format.h"
38 #include "util/u_memory.h"
39 #include "util/u_inlines.h"
40 #include "pipe/p_context.h"
41 #include "state_tracker/drisw_api.h"
43 #include "dri_screen.h"
44 #include "dri_context.h"
45 #include "dri_drawable.h"
47 DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", FALSE);
48 static boolean swrast_no_present = FALSE;
51 get_drawable_info(__DRIdrawable *dPriv, int *w, int *h)
53 __DRIscreen *sPriv = dPriv->driScreenPriv;
54 const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
57 loader->getDrawableInfo(dPriv,
59 dPriv->loaderPrivate);
63 put_image(__DRIdrawable *dPriv, void *data, unsigned width, unsigned height)
65 __DRIscreen *sPriv = dPriv->driScreenPriv;
66 const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
68 loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
70 data, dPriv->loaderPrivate);
74 drisw_update_drawable_info(struct dri_drawable *drawable)
76 __DRIdrawable *dPriv = drawable->dPriv;
78 get_drawable_info(dPriv, &dPriv->w, &dPriv->h);
82 drisw_put_image(struct dri_drawable *drawable,
83 void *data, unsigned width, unsigned height)
85 __DRIdrawable *dPriv = drawable->dPriv;
87 put_image(dPriv, data, width, height);
91 drisw_present_texture(__DRIdrawable *dPriv,
92 struct pipe_resource *ptex)
94 struct dri_drawable *drawable = dri_drawable(dPriv);
95 struct dri_screen *screen = dri_screen(drawable->sPriv);
97 if (swrast_no_present)
100 screen->base.screen->flush_frontbuffer(screen->base.screen, ptex, 0, 0, drawable);
104 drisw_invalidate_drawable(__DRIdrawable *dPriv)
106 struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
107 struct dri_drawable *drawable = dri_drawable(dPriv);
109 drawable->texture_stamp = dPriv->lastStamp - 1;
111 /* check if swapping currently bound buffer */
112 if (ctx && ctx->dPriv == dPriv)
113 ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
117 drisw_copy_to_front(__DRIdrawable * dPriv,
118 struct pipe_resource *ptex)
120 drisw_present_texture(dPriv, ptex);
122 drisw_invalidate_drawable(dPriv);
126 * Backend functions for st_framebuffer interface and swap_buffers.
130 drisw_swap_buffers(__DRIdrawable *dPriv)
132 struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
133 struct dri_drawable *drawable = dri_drawable(dPriv);
134 struct pipe_resource *ptex;
139 ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
142 ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
144 drisw_copy_to_front(dPriv, ptex);
149 drisw_flush_frontbuffer(struct dri_drawable *drawable,
150 enum st_attachment_type statt)
152 struct dri_context *ctx = dri_get_current(drawable->sPriv);
153 struct pipe_resource *ptex;
158 ptex = drawable->textures[statt];
161 drisw_copy_to_front(ctx->dPriv, ptex);
166 * Allocate framebuffer attachments.
168 * During fixed-size operation, the function keeps allocating new attachments
169 * as they are requested. Unused attachments are not removed, not until the
170 * framebuffer is resized or destroyed.
173 drisw_allocate_textures(struct dri_drawable *drawable,
174 const enum st_attachment_type *statts,
177 struct dri_screen *screen = dri_screen(drawable->sPriv);
178 struct pipe_resource templ;
179 unsigned width, height;
183 width = drawable->dPriv->w;
184 height = drawable->dPriv->h;
186 resized = (drawable->old_w != width ||
187 drawable->old_h != height);
189 /* remove outdated textures */
191 for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
192 pipe_resource_reference(&drawable->textures[i], NULL);
195 memset(&templ, 0, sizeof(templ));
196 templ.target = screen->target;
197 templ.width0 = width;
198 templ.height0 = height;
200 templ.array_size = 1;
201 templ.last_level = 0;
203 for (i = 0; i < count; i++) {
204 enum pipe_format format;
207 /* the texture already exists or not requested */
208 if (drawable->textures[statts[i]])
211 dri_drawable_get_format(drawable, statts[i], &format, &bind);
213 /* if we don't do any present, no need for display targets */
214 if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !swrast_no_present)
215 bind |= PIPE_BIND_DISPLAY_TARGET;
217 if (format == PIPE_FORMAT_NONE)
220 templ.format = format;
223 drawable->textures[statts[i]] =
224 screen->base.screen->resource_create(screen->base.screen, &templ);
227 drawable->old_w = width;
228 drawable->old_h = height;
232 * Backend function for init_screen.
235 static const __DRIextension *drisw_screen_extensions[] = {
239 static struct drisw_loader_funcs drisw_lf = {
240 .put_image = drisw_put_image
243 static const __DRIconfig **
244 drisw_init_screen(__DRIscreen * sPriv)
246 const __DRIconfig **configs;
247 struct dri_screen *screen;
248 struct pipe_screen *pscreen;
250 screen = CALLOC_STRUCT(dri_screen);
254 screen->sPriv = sPriv;
257 swrast_no_present = debug_get_option_swrast_no_present();
259 sPriv->private = (void *)screen;
260 sPriv->extensions = drisw_screen_extensions;
262 pscreen = drisw_create_screen(&drisw_lf);
263 /* dri_init_screen_helper checks pscreen for us */
265 configs = dri_init_screen_helper(screen, pscreen, 32);
271 dri_destroy_screen_helper(screen);
277 drisw_create_buffer(__DRIscreen * sPriv,
278 __DRIdrawable * dPriv,
279 const struct gl_config * visual, boolean isPixmap)
281 struct dri_drawable *drawable = NULL;
283 if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap))
286 drawable = dPriv->driverPrivate;
288 drawable->allocate_textures = drisw_allocate_textures;
289 drawable->update_drawable_info = drisw_update_drawable_info;
290 drawable->flush_frontbuffer = drisw_flush_frontbuffer;
296 * DRI driver virtual function table.
298 * DRI versions differ in their implementation of init_screen and swap_buffers.
300 const struct __DriverAPIRec driDriverAPI = {
301 .InitScreen = drisw_init_screen,
302 .DestroyScreen = dri_destroy_screen,
303 .CreateContext = dri_create_context,
304 .DestroyContext = dri_destroy_context,
305 .CreateBuffer = drisw_create_buffer,
306 .DestroyBuffer = dri_destroy_buffer,
307 .MakeCurrent = dri_make_current,
308 .UnbindContext = dri_unbind_context,
310 .SwapBuffers = drisw_swap_buffers,
313 /* This is the table of extensions that the loader will dlsym() for. */
314 PUBLIC const __DRIextension *__driDriverExtensions[] = {
315 &driCoreExtension.base,
316 &driSWRastExtension.base,
320 /* vim: set sw=3 ts=8 sts=3 expandtab: */