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