1 #include <main/glheader.h>
2 #include <glapi/glthread.h>
3 #include <GL/internal/glcore.h>
5 #include <pipe/p_context.h>
6 #include <state_tracker/st_public.h>
7 #include <state_tracker/st_context.h>
8 #include <state_tracker/st_cb_fbo.h>
10 #include "../common/nouveau_local.h"
11 #include "nouveau_context_dri.h"
12 #include "nouveau_screen_dri.h"
13 #include "nouveau_swapbuffers.h"
16 nouveau_copy_buffer(__DRIdrawablePrivate
*dPriv
, struct pipe_surface
*surf
,
17 const drm_clip_rect_t
*rect
)
19 struct nouveau_context_dri
*nv
= dPriv
->driContextPriv
->driverPrivate
;
20 struct pipe_context
*pipe
= nv
->base
.nvc
->pctx
[nv
->base
.pctx_id
];
21 drm_clip_rect_t
*pbox
;
24 LOCK_HARDWARE(&nv
->base
);
25 if (!dPriv
->numClipRects
) {
26 UNLOCK_HARDWARE(&nv
->base
);
29 pbox
= dPriv
->pClipRects
;
30 nbox
= dPriv
->numClipRects
;
32 for (i
= 0; i
< nbox
; i
++, pbox
++) {
33 int sx
, sy
, dx
, dy
, w
, h
;
35 sx
= pbox
->x1
- dPriv
->x
;
36 sy
= pbox
->y1
- dPriv
->y
;
39 w
= pbox
->x2
- pbox
->x1
;
40 h
= pbox
->y2
- pbox
->y1
;
42 pipe
->surface_copy(pipe
, nv
->base
.frontbuffer
,
43 dx
, dy
, surf
, sx
, sy
, w
, h
);
46 FIRE_RING(nv
->base
.nvc
->channel
);
47 UNLOCK_HARDWARE(&nv
->base
);
49 if (nv
->last_stamp
!= dPriv
->lastStamp
) {
50 struct nouveau_framebuffer
*nvfb
= dPriv
->driverPrivate
;
51 st_resize_framebuffer(nvfb
->stfb
, dPriv
->w
, dPriv
->h
);
52 nv
->last_stamp
= dPriv
->lastStamp
;
57 nouveau_copy_sub_buffer(__DRIdrawablePrivate
*dPriv
, int x
, int y
, int w
, int h
)
59 struct nouveau_framebuffer
*nvfb
= dPriv
->driverPrivate
;
60 struct pipe_surface
*surf
;
62 st_get_framebuffer_surface(nvfb
->stfb
, ST_SURFACE_BACK_LEFT
, &surf
);
70 st_notify_swapbuffers(nvfb
->stfb
);
71 nouveau_copy_buffer(dPriv
, surf
, &rect
);
76 nouveau_swap_buffers(__DRIdrawablePrivate
*dPriv
)
78 struct nouveau_framebuffer
*nvfb
= dPriv
->driverPrivate
;
79 struct pipe_surface
*surf
;
81 st_get_framebuffer_surface(nvfb
->stfb
, ST_SURFACE_BACK_LEFT
, &surf
);
83 st_notify_swapbuffers(nvfb
->stfb
);
84 nouveau_copy_buffer(dPriv
, surf
, NULL
);
89 nouveau_flush_frontbuffer(struct pipe_winsys
*pws
, struct pipe_surface
*surf
,
90 void *context_private
)
92 struct nouveau_context_dri
*nv
= context_private
;
93 __DRIdrawablePrivate
*dPriv
= nv
->dri_drawable
;
95 nouveau_copy_buffer(dPriv
, surf
, NULL
);
99 nouveau_contended_lock(struct nouveau_context
*nv
)
101 struct nouveau_context_dri
*nv_sub
= (struct nouveau_context_dri
*)nv
;
102 __DRIdrawablePrivate
*dPriv
= nv_sub
->dri_drawable
;
103 __DRIscreenPrivate
*sPriv
= nv_sub
->dri_screen
;
105 /* If the window moved, may need to set a new cliprect now.
107 * NOTE: This releases and regains the hw lock, so all state
108 * checking must be done *after* this call:
111 DRI_VALIDATE_DRAWABLE_INFO(sPriv
, dPriv
);