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