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