nouveau: Factor out common winsys bits into libnouveaudrm.a
[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 drm_clip_rect_t *pbox;
13 int nbox, i;
14
15 LOCK_HARDWARE(&nv->base);
16 if (!dri_drawable->num_cliprects) {
17 UNLOCK_HARDWARE(&nv->base);
18 return;
19 }
20 pbox = dri_drawable->cliprects;
21 nbox = dri_drawable->num_cliprects;
22
23 nv->base.surface_copy_prep(&nv->base, nv->base.frontbuffer, surf);
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 nv->base.surface_copy(&nv->base, dx, dy, sx, sy, w, h);
35 }
36
37 FIRE_RING(nv->base.nvc->channel);
38 UNLOCK_HARDWARE(&nv->base);
39 }
40
41 void
42 nouveau_copy_sub_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf, int x, int y, int w, int h)
43 {
44 if (surf) {
45 drm_clip_rect_t rect;
46 rect.x1 = x;
47 rect.y1 = y;
48 rect.x2 = x + w;
49 rect.y2 = y + h;
50
51 nouveau_copy_buffer(dri_drawable, surf, &rect);
52 }
53 }
54
55 void
56 nouveau_swap_buffers(dri_drawable_t *dri_drawable, struct pipe_surface *surf)
57 {
58 if (surf)
59 nouveau_copy_buffer(dri_drawable, surf, NULL);
60 }
61
62 void
63 nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf,
64 void *context_private)
65 {
66 struct nouveau_context_vl *nv;
67 dri_drawable_t *dri_drawable;
68
69 assert(pws);
70 assert(surf);
71 assert(context_private);
72
73 nv = context_private;
74 dri_drawable = nv->dri_drawable;
75
76 nouveau_copy_buffer(dri_drawable, surf, NULL);
77 }
78
79 void
80 nouveau_contended_lock(struct nouveau_context *nv)
81 {
82 struct nouveau_context_vl *nv_vl = (struct nouveau_context_vl*)nv;
83 dri_drawable_t *dri_drawable = nv_vl->dri_drawable;
84 dri_screen_t *dri_screen = nv_vl->dri_context->dri_screen;
85
86 /* If the window moved, may need to set a new cliprect now.
87 *
88 * NOTE: This releases and regains the hw lock, so all state
89 * checking must be done *after* this call:
90 */
91 if (dri_drawable)
92 DRI_VALIDATE_DRAWABLE_INFO(dri_screen, dri_drawable);
93 }