DRI2: report swap events correctly in direct rendered case
[mesa.git] / src / gallium / winsys / g3dvl / nouveau / nouveau_swapbuffers.c
1 #include <driclient.h>
2 #include <common/nouveau_local.h>
3 #include <common/nouveau_screen.h>
4 #include "nouveau_context_vl.h"
5 #include "nouveau_swapbuffers.h"
6
7 void
8 nouveau_copy_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf,
9 const drm_clip_rect_t *rect)
10 {
11 struct nouveau_context_vl *nv = dri_drawable->private;
12 struct pipe_context *pipe = nv->base.nvc->pctx[nv->base.pctx_id];
13 drm_clip_rect_t *pbox;
14 int nbox, i;
15
16 LOCK_HARDWARE(&nv->base);
17 if (!dri_drawable->num_cliprects) {
18 UNLOCK_HARDWARE(&nv->base);
19 return;
20 }
21 pbox = dri_drawable->cliprects;
22 nbox = dri_drawable->num_cliprects;
23
24 for (i = 0; i < nbox; i++, pbox++) {
25 int sx, sy, dx, dy, w, h;
26
27 sx = pbox->x1 - dri_drawable->x;
28 sy = pbox->y1 - dri_drawable->y;
29 dx = pbox->x1;
30 dy = pbox->y1;
31 w = pbox->x2 - pbox->x1;
32 h = pbox->y2 - pbox->y1;
33
34 pipe->surface_copy(pipe, nv->base.frontbuffer,
35 dx, dy, surf, sx, sy, w, h);
36 }
37
38 FIRE_RING(nv->base.nvc->channel);
39 UNLOCK_HARDWARE(&nv->base);
40 }
41
42 void
43 nouveau_copy_sub_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf, int x, int y, int w, int h)
44 {
45 if (surf) {
46 drm_clip_rect_t rect;
47 rect.x1 = x;
48 rect.y1 = y;
49 rect.x2 = x + w;
50 rect.y2 = y + h;
51
52 nouveau_copy_buffer(dri_drawable, surf, &rect);
53 }
54 }
55
56 void
57 nouveau_swap_buffers(dri_drawable_t *dri_drawable, struct pipe_surface *surf)
58 {
59 if (surf)
60 nouveau_copy_buffer(dri_drawable, surf, NULL);
61 }
62
63 void
64 nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf,
65 void *context_private)
66 {
67 struct nouveau_context_vl *nv;
68 dri_drawable_t *dri_drawable;
69
70 assert(pws);
71 assert(surf);
72 assert(context_private);
73
74 nv = context_private;
75 dri_drawable = nv->dri_drawable;
76
77 nouveau_copy_buffer(dri_drawable, surf, NULL);
78 }
79
80 void
81 nouveau_contended_lock(struct nouveau_context *nv)
82 {
83 struct nouveau_context_vl *nv_vl = (struct nouveau_context_vl*)nv;
84 dri_drawable_t *dri_drawable = nv_vl->dri_drawable;
85 dri_screen_t *dri_screen = nv_vl->dri_context->dri_screen;
86
87 /* If the window moved, may need to set a new cliprect now.
88 *
89 * NOTE: This releases and regains the hw lock, so all state
90 * checking must be done *after* this call:
91 */
92 if (dri_drawable)
93 DRI_VALIDATE_DRAWABLE_INFO(dri_screen, dri_drawable);
94 }