Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / gallium / state_trackers / dri / 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_context.h"
34 #include "dri_drawable.h"
35
36 #include "pipe/p_context.h"
37 #include "pipe/p_screen.h"
38 #include "pipe/p_inlines.h"
39 #include "main/mtypes.h"
40 #include "main/renderbuffer.h"
41 #include "state_tracker/drm_api.h"
42 #include "state_tracker/dri1_api.h"
43 #include "state_tracker/st_public.h"
44 #include "state_tracker/st_context.h"
45 #include "state_tracker/st_cb_fbo.h"
46
47 #include "util/u_memory.h"
48
49 static struct pipe_surface *
50 dri_surface_from_handle(struct drm_api *api,
51 struct pipe_screen *screen,
52 unsigned handle,
53 enum pipe_format format,
54 unsigned width, unsigned height, unsigned pitch)
55 {
56 struct pipe_surface *surface = NULL;
57 struct pipe_texture *texture = NULL;
58 struct pipe_texture templat;
59
60 memset(&templat, 0, sizeof(templat));
61 templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
62 templat.target = PIPE_TEXTURE_2D;
63 templat.last_level = 0;
64 templat.depth[0] = 1;
65 templat.format = format;
66 templat.width[0] = width;
67 templat.height[0] = height;
68 pf_get_block(templat.format, &templat.block);
69
70 texture = api->texture_from_shared_handle(api, screen, &templat,
71 "dri2 buffer", pitch, handle);
72
73 if (!texture) {
74 debug_printf("%s: Failed to blanket the buffer with a texture\n", __func__);
75 return NULL;
76 }
77
78 surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
79 PIPE_BUFFER_USAGE_GPU_READ |
80 PIPE_BUFFER_USAGE_GPU_WRITE);
81
82 /* we don't need the texture from this point on */
83 pipe_texture_reference(&texture, NULL);
84 return surface;
85 }
86
87 /**
88 * Pixmaps have will have the same name of fake front and front.
89 */
90 static boolean
91 dri2_check_if_pixmap(__DRIbuffer *buffers, int count)
92 {
93 boolean found = FALSE;
94 boolean is_pixmap = FALSE;
95 unsigned name;
96 int i;
97
98 for (i = 0; i < count; i++) {
99 switch (buffers[i].attachment) {
100 case __DRI_BUFFER_FRONT_LEFT:
101 case __DRI_BUFFER_FAKE_FRONT_LEFT:
102 if (found) {
103 is_pixmap = buffers[i].name == name;
104 } else {
105 name = buffers[i].name;
106 found = TRUE;
107 }
108 default:
109 continue;
110 }
111 }
112
113 return is_pixmap;
114 }
115
116 /**
117 * This will be called a drawable is known to have been resized.
118 */
119 void
120 dri_get_buffers(__DRIdrawablePrivate * dPriv)
121 {
122
123 struct dri_drawable *drawable = dri_drawable(dPriv);
124 struct pipe_surface *surface = NULL;
125 struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
126 __DRIbuffer *buffers = NULL;
127 __DRIscreen *dri_screen = drawable->sPriv;
128 __DRIdrawable *dri_drawable = drawable->dPriv;
129 struct drm_api *api = ((struct dri_screen*)(dri_screen->private))->api;
130 boolean have_depth = FALSE;
131 int i, count;
132
133 buffers = (*dri_screen->dri2.loader->getBuffers) (dri_drawable,
134 &dri_drawable->w,
135 &dri_drawable->h,
136 drawable->attachments,
137 drawable->
138 num_attachments, &count,
139 dri_drawable->
140 loaderPrivate);
141
142 if (buffers == NULL) {
143 return;
144 }
145
146 /* set one cliprect to cover the whole dri_drawable */
147 dri_drawable->x = 0;
148 dri_drawable->y = 0;
149 dri_drawable->backX = 0;
150 dri_drawable->backY = 0;
151 dri_drawable->numClipRects = 1;
152 dri_drawable->pClipRects[0].x1 = 0;
153 dri_drawable->pClipRects[0].y1 = 0;
154 dri_drawable->pClipRects[0].x2 = dri_drawable->w;
155 dri_drawable->pClipRects[0].y2 = dri_drawable->h;
156 dri_drawable->numBackClipRects = 1;
157 dri_drawable->pBackClipRects[0].x1 = 0;
158 dri_drawable->pBackClipRects[0].y1 = 0;
159 dri_drawable->pBackClipRects[0].x2 = dri_drawable->w;
160 dri_drawable->pBackClipRects[0].y2 = dri_drawable->h;
161
162 if (drawable->old_num == count &&
163 drawable->old_w == dri_drawable->w &&
164 drawable->old_h == dri_drawable->h &&
165 memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0) {
166 return;
167 } else {
168 drawable->old_num = count;
169 drawable->old_w = dri_drawable->w;
170 drawable->old_h = dri_drawable->h;
171 memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count);
172 }
173
174 drawable->is_pixmap = dri2_check_if_pixmap(buffers, count);
175
176 for (i = 0; i < count; i++) {
177 enum pipe_format format = 0;
178 int index = 0;
179
180 switch (buffers[i].attachment) {
181 case __DRI_BUFFER_FRONT_LEFT:
182 continue;
183 case __DRI_BUFFER_FAKE_FRONT_LEFT:
184 index = ST_SURFACE_FRONT_LEFT;
185 format = drawable->color_format;
186 break;
187 case __DRI_BUFFER_BACK_LEFT:
188 index = ST_SURFACE_BACK_LEFT;
189 format = drawable->color_format;
190 break;
191 case __DRI_BUFFER_DEPTH:
192 case __DRI_BUFFER_DEPTH_STENCIL:
193 case __DRI_BUFFER_STENCIL:
194 index = ST_SURFACE_DEPTH;
195 format = drawable->depth_stencil_format;
196 break;
197 case __DRI_BUFFER_ACCUM:
198 default:
199 assert(0);
200 }
201
202 if (index == ST_SURFACE_DEPTH) {
203 if (have_depth)
204 continue;
205 else
206 have_depth = TRUE;
207 }
208
209 surface = dri_surface_from_handle(api,
210 screen,
211 buffers[i].name,
212 format,
213 dri_drawable->w,
214 dri_drawable->h, buffers[i].pitch);
215
216 switch (buffers[i].attachment) {
217 case __DRI_BUFFER_FAKE_FRONT_LEFT:
218 case __DRI_BUFFER_BACK_LEFT:
219 drawable->color_format = surface->format;
220 break;
221 case __DRI_BUFFER_DEPTH:
222 case __DRI_BUFFER_DEPTH_STENCIL:
223 case __DRI_BUFFER_STENCIL:
224 drawable->depth_stencil_format = surface->format;
225 break;
226 }
227
228 st_set_framebuffer_surface(drawable->stfb, index, surface);
229 pipe_surface_reference(&surface, NULL);
230 }
231 /* this needed, or else the state tracker fails to pick the new buffers */
232 st_resize_framebuffer(drawable->stfb, dri_drawable->w, dri_drawable->h);
233 }
234
235 /**
236 * These are used for GLX_EXT_texture_from_pixmap
237 */
238 void dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
239 GLint format, __DRIdrawable *dPriv)
240 {
241 struct dri_drawable *drawable = dri_drawable(dPriv);
242 struct pipe_surface *ps;
243
244 if (!drawable->stfb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer) {
245 struct gl_renderbuffer *rb =
246 st_new_renderbuffer_fb(drawable->color_format, 0 /*XXX*/, FALSE);
247 _mesa_add_renderbuffer(&drawable->stfb->Base, BUFFER_FRONT_LEFT, rb);
248 }
249
250 dri_get_buffers(drawable->dPriv);
251 st_get_framebuffer_surface(drawable->stfb, ST_SURFACE_FRONT_LEFT, &ps);
252
253 st_bind_texture_surface(ps, target == GL_TEXTURE_2D ? ST_TEXTURE_2D :
254 ST_TEXTURE_RECT, 0, drawable->color_format);
255 }
256
257 void dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target,
258 __DRIdrawable *dPriv)
259 {
260 dri2_set_tex_buffer2(pDRICtx, target, GLX_TEXTURE_FORMAT_RGBA_EXT, dPriv);
261 }
262
263 void
264 dri_flush_frontbuffer(struct pipe_screen *screen,
265 struct pipe_surface *surf, void *context_private)
266 {
267 struct dri_context *ctx = (struct dri_context *)context_private;
268 struct dri_drawable *drawable = dri_drawable(ctx->dPriv);
269 __DRIdrawable *dri_drawable = ctx->dPriv;
270 __DRIscreen *dri_screen = ctx->sPriv;
271
272 /* XXX Does this function get called with DRI1? */
273
274 if (ctx->dPriv == NULL) {
275 debug_printf("%s: no drawable bound to context\n", __func__);
276 return;
277 }
278
279 #if 0
280 /* TODO if rendering to pixmaps is slow enable this code. */
281 if (drawable->is_pixmap)
282 return;
283 #else
284 (void)drawable;
285 #endif
286
287 (*dri_screen->dri2.loader->flushFrontBuffer)(dri_drawable,
288 dri_drawable->loaderPrivate);
289 }
290
291 /**
292 * This is called when we need to set up GL rendering to a new X window.
293 */
294 boolean
295 dri_create_buffer(__DRIscreenPrivate * sPriv,
296 __DRIdrawablePrivate * dPriv,
297 const __GLcontextModes * visual, boolean isPixmap)
298 {
299 struct dri_screen *screen = sPriv->private;
300 struct dri_drawable *drawable = NULL;
301 int i;
302
303 if (isPixmap)
304 goto fail; /* not implemented */
305
306 drawable = CALLOC_STRUCT(dri_drawable);
307 if (drawable == NULL)
308 goto fail;
309
310 if (visual->redBits == 8) {
311 if (visual->alphaBits == 8)
312 drawable->color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
313 else
314 drawable->color_format = PIPE_FORMAT_X8R8G8B8_UNORM;
315 } else {
316 drawable->color_format = PIPE_FORMAT_R5G6B5_UNORM;
317 }
318
319 switch(visual->depthBits) {
320 default:
321 case 0:
322 drawable->depth_stencil_format = PIPE_FORMAT_NONE;
323 break;
324 case 16:
325 drawable->depth_stencil_format = PIPE_FORMAT_Z16_UNORM;
326 break;
327 case 24:
328 if (visual->stencilBits == 0) {
329 drawable->depth_stencil_format = (screen->d_depth_bits_last) ?
330 PIPE_FORMAT_X8Z24_UNORM:
331 PIPE_FORMAT_Z24X8_UNORM;
332 } else {
333 drawable->depth_stencil_format = (screen->sd_depth_bits_last) ?
334 PIPE_FORMAT_S8Z24_UNORM:
335 PIPE_FORMAT_Z24S8_UNORM;
336 }
337 break;
338 case 32:
339 drawable->depth_stencil_format = PIPE_FORMAT_Z32_UNORM;
340 break;
341 }
342
343 drawable->stfb = st_create_framebuffer(visual,
344 drawable->color_format,
345 drawable->depth_stencil_format,
346 drawable->depth_stencil_format,
347 dPriv->w,
348 dPriv->h, (void *)drawable);
349 if (drawable->stfb == NULL)
350 goto fail;
351
352 drawable->sPriv = sPriv;
353 drawable->dPriv = dPriv;
354 dPriv->driverPrivate = (void *)drawable;
355
356 /* setup dri2 buffers information */
357 /* TODO incase of double buffer visual, delay fake creation */
358 i = 0;
359 drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
360
361 if (visual->doubleBufferMode)
362 drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT;
363 else
364 drawable->attachments[i++] = __DRI_BUFFER_FAKE_FRONT_LEFT;
365 if (visual->depthBits && visual->stencilBits)
366 drawable->attachments[i++] = __DRI_BUFFER_DEPTH_STENCIL;
367 else if (visual->depthBits)
368 drawable->attachments[i++] = __DRI_BUFFER_DEPTH;
369 else if (visual->stencilBits)
370 drawable->attachments[i++] = __DRI_BUFFER_STENCIL;
371 drawable->num_attachments = i;
372
373 drawable->desired_fences = 2;
374
375 return GL_TRUE;
376 fail:
377 FREE(drawable);
378 return GL_FALSE;
379 }
380
381 static struct pipe_fence_handle *
382 dri_swap_fences_pop_front(struct dri_drawable *draw)
383 {
384 struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
385 struct pipe_fence_handle *fence = NULL;
386
387 if (draw->cur_fences >= draw->desired_fences) {
388 screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]);
389 screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL);
390 --draw->cur_fences;
391 draw->tail &= DRI_SWAP_FENCES_MASK;
392 }
393 return fence;
394 }
395
396 static void
397 dri_swap_fences_push_back(struct dri_drawable *draw,
398 struct pipe_fence_handle *fence)
399 {
400 struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
401
402 if (!fence)
403 return;
404
405 if (draw->cur_fences < DRI_SWAP_FENCES_MAX) {
406 draw->cur_fences++;
407 screen->fence_reference(screen, &draw->swap_fences[draw->head++],
408 fence);
409 draw->head &= DRI_SWAP_FENCES_MASK;
410 }
411 }
412
413 void
414 dri_destroy_buffer(__DRIdrawablePrivate * dPriv)
415 {
416 struct dri_drawable *drawable = dri_drawable(dPriv);
417 struct pipe_fence_handle *fence;
418 struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
419
420 st_unreference_framebuffer(drawable->stfb);
421 drawable->desired_fences = 0;
422 while (drawable->cur_fences) {
423 fence = dri_swap_fences_pop_front(drawable);
424 screen->fence_reference(screen, &fence, NULL);
425 }
426
427 FREE(drawable);
428 }
429
430 static void
431 dri1_update_drawables_locked(struct dri_context *ctx,
432 __DRIdrawablePrivate * driDrawPriv,
433 __DRIdrawablePrivate * driReadPriv)
434 {
435 if (ctx->stLostLock) {
436 ctx->stLostLock = FALSE;
437 if (driDrawPriv == driReadPriv)
438 DRI_VALIDATE_DRAWABLE_INFO(ctx->sPriv, driDrawPriv);
439 else
440 DRI_VALIDATE_TWO_DRAWABLES_INFO(ctx->sPriv, driDrawPriv,
441 driReadPriv);
442 }
443 }
444
445 /**
446 * This ensures all contexts which bind to a drawable pick up the
447 * drawable change and signal new buffer state.
448 * Calling st_resize_framebuffer for each context may seem like overkill,
449 * but no new buffers will actually be allocated if the dimensions don't
450 * change.
451 */
452
453 static void
454 dri1_propagate_drawable_change(struct dri_context *ctx)
455 {
456 __DRIdrawablePrivate *dPriv = ctx->dPriv;
457 __DRIdrawablePrivate *rPriv = ctx->rPriv;
458 boolean flushed = FALSE;
459
460 if (dPriv && ctx->d_stamp != dPriv->lastStamp) {
461
462 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
463 flushed = TRUE;
464 ctx->d_stamp = dPriv->lastStamp;
465 st_resize_framebuffer(dri_drawable(dPriv)->stfb, dPriv->w, dPriv->h);
466
467 }
468
469 if (rPriv && dPriv != rPriv && ctx->r_stamp != rPriv->lastStamp) {
470
471 if (!flushed)
472 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
473 ctx->r_stamp = rPriv->lastStamp;
474 st_resize_framebuffer(dri_drawable(rPriv)->stfb, rPriv->w, rPriv->h);
475
476 } else if (rPriv && dPriv == rPriv) {
477
478 ctx->r_stamp = ctx->d_stamp;
479
480 }
481 }
482
483 void
484 dri1_update_drawables(struct dri_context *ctx,
485 struct dri_drawable *draw, struct dri_drawable *read)
486 {
487 dri_lock(ctx);
488 dri1_update_drawables_locked(ctx, draw->dPriv, read->dPriv);
489 dri_unlock(ctx);
490
491 dri1_propagate_drawable_change(ctx);
492 }
493
494 static INLINE boolean
495 dri1_intersect_src_bbox(struct drm_clip_rect *dst,
496 int dst_x,
497 int dst_y,
498 const struct drm_clip_rect *src,
499 const struct drm_clip_rect *bbox)
500 {
501 int xy1;
502 int xy2;
503
504 xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 :
505 (int)bbox->x1 + dst_x;
506 xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 :
507 (int)bbox->x2 + dst_x;
508 if (xy1 >= xy2 || xy1 < 0)
509 return FALSE;
510
511 dst->x1 = xy1;
512 dst->x2 = xy2;
513
514 xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 :
515 (int)bbox->y1 + dst_y;
516 xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 :
517 (int)bbox->y2 + dst_y;
518 if (xy1 >= xy2 || xy1 < 0)
519 return FALSE;
520
521 dst->y1 = xy1;
522 dst->y2 = xy2;
523 return TRUE;
524 }
525
526 static void
527 dri1_swap_copy(struct dri_context *ctx,
528 struct pipe_surface *dst,
529 struct pipe_surface *src,
530 __DRIdrawablePrivate * dPriv, const struct drm_clip_rect *bbox)
531 {
532 struct pipe_context *pipe = ctx->pipe;
533 struct drm_clip_rect clip;
534 struct drm_clip_rect *cur;
535 int i;
536
537 cur = dPriv->pClipRects;
538
539 for (i = 0; i < dPriv->numClipRects; ++i) {
540 if (dri1_intersect_src_bbox(&clip, dPriv->x, dPriv->y, cur++, bbox))
541 pipe->surface_copy(pipe, dst, clip.x1, clip.y1,
542 src,
543 (int)clip.x1 - dPriv->x,
544 (int)clip.y1 - dPriv->y,
545 clip.x2 - clip.x1, clip.y2 - clip.y1);
546 }
547 }
548
549 static void
550 dri1_copy_to_front(struct dri_context *ctx,
551 struct pipe_surface *surf,
552 __DRIdrawablePrivate * dPriv,
553 const struct drm_clip_rect *sub_box,
554 struct pipe_fence_handle **fence)
555 {
556 struct pipe_context *pipe = ctx->pipe;
557 boolean save_lost_lock;
558 uint cur_w;
559 uint cur_h;
560 struct drm_clip_rect bbox;
561 boolean visible = TRUE;
562
563 *fence = NULL;
564
565 dri_lock(ctx);
566 save_lost_lock = ctx->stLostLock;
567 dri1_update_drawables_locked(ctx, dPriv, dPriv);
568 st_get_framebuffer_dimensions(dri_drawable(dPriv)->stfb, &cur_w, &cur_h);
569
570 bbox.x1 = 0;
571 bbox.x2 = cur_w;
572 bbox.y1 = 0;
573 bbox.y2 = cur_h;
574
575 if (sub_box)
576 visible = dri1_intersect_src_bbox(&bbox, 0, 0, &bbox, sub_box);
577
578 if (visible && __dri1_api_hooks->present_locked) {
579
580 __dri1_api_hooks->present_locked(pipe,
581 surf,
582 dPriv->pClipRects,
583 dPriv->numClipRects,
584 dPriv->x, dPriv->y, &bbox, fence);
585
586 } else if (visible && __dri1_api_hooks->front_srf_locked) {
587
588 struct pipe_surface *front = __dri1_api_hooks->front_srf_locked(pipe);
589
590 if (front)
591 dri1_swap_copy(ctx, front, surf, dPriv, &bbox);
592
593 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, fence);
594 }
595
596 ctx->stLostLock = save_lost_lock;
597
598 /**
599 * FIXME: Revisit this: Update drawables on copy_sub_buffer ?
600 */
601
602 if (!sub_box)
603 dri1_update_drawables_locked(ctx, ctx->dPriv, ctx->rPriv);
604
605 dri_unlock(ctx);
606 dri1_propagate_drawable_change(ctx);
607 }
608
609 void
610 dri1_flush_frontbuffer(struct pipe_screen *screen,
611 struct pipe_surface *surf, void *context_private)
612 {
613 struct dri_context *ctx = (struct dri_context *)context_private;
614 struct pipe_fence_handle *dummy_fence;
615
616 dri1_copy_to_front(ctx, surf, ctx->dPriv, NULL, &dummy_fence);
617 screen->fence_reference(screen, &dummy_fence, NULL);
618
619 /**
620 * FIXME: Do we need swap throttling here?
621 */
622 }
623
624 void
625 dri_swap_buffers(__DRIdrawablePrivate * dPriv)
626 {
627 struct dri_context *ctx;
628 struct pipe_surface *back_surf;
629 struct dri_drawable *draw = dri_drawable(dPriv);
630 struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
631 struct pipe_fence_handle *fence;
632 struct st_context *st = st_get_current();
633
634 assert(__dri1_api_hooks != NULL);
635
636 if (!st)
637 return; /* For now */
638
639 ctx = (struct dri_context *)st->pipe->priv;
640
641 st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf);
642 if (back_surf) {
643 st_notify_swapbuffers(draw->stfb);
644 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
645 fence = dri_swap_fences_pop_front(draw);
646 if (fence) {
647 (void)screen->fence_finish(screen, fence, 0);
648 screen->fence_reference(screen, &fence, NULL);
649 }
650 dri1_copy_to_front(ctx, back_surf, dPriv, NULL, &fence);
651 dri_swap_fences_push_back(draw, fence);
652 screen->fence_reference(screen, &fence, NULL);
653 }
654 }
655
656 void
657 dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h)
658 {
659 struct pipe_screen *screen = dri_screen(dPriv->driScreenPriv)->pipe_screen;
660 struct drm_clip_rect sub_bbox;
661 struct dri_context *ctx;
662 struct pipe_surface *back_surf;
663 struct dri_drawable *draw = dri_drawable(dPriv);
664 struct pipe_fence_handle *dummy_fence;
665 struct st_context *st = st_get_current();
666
667 assert(__dri1_api_hooks != NULL);
668
669 if (!st)
670 return;
671
672 ctx = (struct dri_context *)st->pipe->priv;
673
674 sub_bbox.x1 = x;
675 sub_bbox.x2 = x + w;
676 sub_bbox.y1 = y;
677 sub_bbox.y2 = y + h;
678
679 st_get_framebuffer_surface(draw->stfb, ST_SURFACE_BACK_LEFT, &back_surf);
680 if (back_surf) {
681 st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
682 dri1_copy_to_front(ctx, back_surf, dPriv, &sub_bbox, &dummy_fence);
683 screen->fence_reference(screen, &dummy_fence, NULL);
684 }
685 }
686
687 /* vim: set sw=3 ts=8 sts=3 expandtab: */