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"
46 #include "dri1_helper.h"
48 DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present
, "SWRAST_NO_PRESENT", FALSE
);
49 static boolean swrast_no_present
= FALSE
;
52 get_drawable_info(__DRIdrawable
*dPriv
, int *w
, int *h
)
54 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
55 const __DRIswrastLoaderExtension
*loader
= sPriv
->swrast_loader
;
58 loader
->getDrawableInfo(dPriv
,
60 dPriv
->loaderPrivate
);
64 put_image(__DRIdrawable
*dPriv
, void *data
, unsigned width
, unsigned height
)
66 __DRIscreen
*sPriv
= dPriv
->driScreenPriv
;
67 const __DRIswrastLoaderExtension
*loader
= sPriv
->swrast_loader
;
69 loader
->putImage(dPriv
, __DRI_SWRAST_IMAGE_OP_SWAP
,
71 data
, dPriv
->loaderPrivate
);
75 drisw_update_drawable_info(struct dri_drawable
*drawable
)
77 __DRIdrawable
*dPriv
= drawable
->dPriv
;
79 get_drawable_info(dPriv
, &dPriv
->w
, &dPriv
->h
);
83 drisw_put_image(struct dri_drawable
*drawable
,
84 void *data
, unsigned width
, unsigned height
)
86 __DRIdrawable
*dPriv
= drawable
->dPriv
;
88 put_image(dPriv
, data
, width
, height
);
92 drisw_present_texture(__DRIdrawable
*dPriv
,
93 struct pipe_resource
*ptex
)
95 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
96 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
97 struct pipe_surface
*psurf
;
99 if (swrast_no_present
)
102 psurf
= dri1_get_pipe_surface(drawable
, ptex
);
106 screen
->base
.screen
->flush_frontbuffer(screen
->base
.screen
, psurf
, drawable
);
110 drisw_invalidate_drawable(__DRIdrawable
*dPriv
)
112 struct dri_context
*ctx
= dri_get_current(dPriv
->driScreenPriv
);
113 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
115 drawable
->texture_stamp
= dPriv
->lastStamp
- 1;
117 /* check if swapping currently bound buffer */
118 if (ctx
&& ctx
->dPriv
== dPriv
)
119 ctx
->st
->notify_invalid_framebuffer(ctx
->st
, &drawable
->base
);
123 drisw_copy_to_front(__DRIdrawable
* dPriv
,
124 struct pipe_resource
*ptex
)
126 drisw_present_texture(dPriv
, ptex
);
128 drisw_invalidate_drawable(dPriv
);
132 * Backend functions for st_framebuffer interface and swap_buffers.
136 drisw_swap_buffers(__DRIdrawable
*dPriv
)
138 struct dri_context
*ctx
= dri_get_current(dPriv
->driScreenPriv
);
139 struct dri_drawable
*drawable
= dri_drawable(dPriv
);
140 struct pipe_resource
*ptex
;
145 ptex
= drawable
->textures
[ST_ATTACHMENT_BACK_LEFT
];
148 ctx
->st
->flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
150 drisw_copy_to_front(dPriv
, ptex
);
155 drisw_flush_frontbuffer(struct dri_drawable
*drawable
,
156 enum st_attachment_type statt
)
158 struct dri_context
*ctx
= dri_get_current(drawable
->sPriv
);
159 struct pipe_resource
*ptex
;
164 ptex
= drawable
->textures
[statt
];
167 drisw_copy_to_front(ctx
->dPriv
, ptex
);
172 * Allocate framebuffer attachments.
174 * During fixed-size operation, the function keeps allocating new attachments
175 * as they are requested. Unused attachments are not removed, not until the
176 * framebuffer is resized or destroyed.
178 * It should be possible for DRI1 and DRISW to share this function, but it
179 * seems a better seperation and safer for each DRI version to provide its own
183 drisw_allocate_textures(struct dri_drawable
*drawable
,
184 const enum st_attachment_type
*statts
,
187 struct dri_screen
*screen
= dri_screen(drawable
->sPriv
);
188 struct pipe_resource templ
;
189 unsigned width
, height
;
193 width
= drawable
->dPriv
->w
;
194 height
= drawable
->dPriv
->h
;
196 resized
= (drawable
->old_w
!= width
||
197 drawable
->old_h
!= height
);
199 /* remove outdated textures */
201 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++)
202 pipe_resource_reference(&drawable
->textures
[i
], NULL
);
205 memset(&templ
, 0, sizeof(templ
));
206 templ
.target
= PIPE_TEXTURE_2D
;
207 templ
.width0
= width
;
208 templ
.height0
= height
;
210 templ
.last_level
= 0;
212 for (i
= 0; i
< ST_ATTACHMENT_COUNT
; i
++) {
213 enum pipe_format format
;
216 /* the texture already exists or not requested */
217 if (drawable
->textures
[statts
[i
]])
220 dri_drawable_get_format(drawable
, statts
[i
], &format
, &bind
);
222 /* if we don't do any present, no need for display targets */
223 if (statts
[i
] != ST_ATTACHMENT_DEPTH_STENCIL
&& !swrast_no_present
)
224 bind
|= PIPE_BIND_DISPLAY_TARGET
;
226 if (format
== PIPE_FORMAT_NONE
)
229 templ
.format
= format
;
232 drawable
->textures
[statts
[i
]] =
233 screen
->base
.screen
->resource_create(screen
->base
.screen
, &templ
);
236 drawable
->old_w
= width
;
237 drawable
->old_h
= height
;
241 * Backend function for init_screen.
244 static const __DRIextension
*drisw_screen_extensions
[] = {
248 static struct drisw_loader_funcs drisw_lf
= {
249 .put_image
= drisw_put_image
252 static const __DRIconfig
**
253 drisw_init_screen(__DRIscreen
* sPriv
)
255 const __DRIconfig
**configs
;
256 struct dri_screen
*screen
;
257 struct pipe_screen
*pscreen
;
259 screen
= CALLOC_STRUCT(dri_screen
);
263 screen
->sPriv
= sPriv
;
265 screen
->allocate_textures
= drisw_allocate_textures
;
266 screen
->update_drawable_info
= drisw_update_drawable_info
;
267 screen
->flush_frontbuffer
= drisw_flush_frontbuffer
;
269 swrast_no_present
= debug_get_option_swrast_no_present();
271 sPriv
->private = (void *)screen
;
272 sPriv
->extensions
= drisw_screen_extensions
;
274 pscreen
= drisw_create_screen(&drisw_lf
);
275 /* dri_init_screen_helper checks pscreen for us */
277 configs
= dri_init_screen_helper(screen
, pscreen
, 32);
283 dri_destroy_screen_helper(screen
);
289 * DRI driver virtual function table.
291 * DRI versions differ in their implementation of init_screen and swap_buffers.
293 const struct __DriverAPIRec driDriverAPI
= {
294 .DestroyScreen
= dri_destroy_screen
,
295 .CreateContext
= dri_create_context
,
296 .DestroyContext
= dri_destroy_context
,
297 .CreateBuffer
= dri_create_buffer
,
298 .DestroyBuffer
= dri_destroy_buffer
,
299 .MakeCurrent
= dri_make_current
,
300 .UnbindContext
= dri_unbind_context
,
302 .InitScreen
= drisw_init_screen
,
303 .SwapBuffers
= drisw_swap_buffers
,
306 /* This is the table of extensions that the loader will dlsym() for. */
307 PUBLIC
const __DRIextension
*__driDriverExtensions
[] = {
308 &driCoreExtension
.base
,
309 &driSWRastExtension
.base
,
313 /* vim: set sw=3 ts=8 sts=3 expandtab: */