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