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