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