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