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