1 #include "pipe/p_winsys.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_util.h"
4 #include "pipe/p_inlines.h"
6 #include "nouveau_context.h"
7 #include "nouveau_device.h"
8 #include "nouveau_local.h"
9 #include "nouveau_screen.h"
10 #include "nouveau_swapbuffers.h"
11 #include "nouveau_winsys_pipe.h"
14 nouveau_flush_frontbuffer(struct pipe_winsys
*pws
, struct pipe_surface
*surf
,
15 void *context_private
)
17 struct nouveau_context
*nv
= context_private
;
18 __DRIdrawablePrivate
*dPriv
= nv
->dri_drawable
;
20 nouveau_copy_buffer(dPriv
, surf
, NULL
);
24 nouveau_printf(struct pipe_winsys
*pws
, const char *fmt
, ...)
28 vfprintf(stderr
, fmt
, args
);
33 nouveau_get_name(struct pipe_winsys
*pws
)
38 static struct pipe_surface
*
39 nouveau_surface_alloc(struct pipe_winsys
*ws
)
41 struct pipe_surface
*surf
;
43 surf
= CALLOC_STRUCT(pipe_surface
);
53 nouveau_surface_alloc_storage(struct pipe_winsys
*ws
, struct pipe_surface
*surf
,
54 unsigned width
, unsigned height
,
55 enum pipe_format format
, unsigned flags
)
57 unsigned pitch
= ((width
* pf_get_size(format
)) + 63) & ~63;
59 surf
->format
= format
;
61 surf
->height
= height
;
62 surf
->cpp
= pf_get_size(format
);
63 surf
->pitch
= pitch
/ surf
->cpp
;
65 surf
->buffer
= ws
->buffer_create(ws
, 256, PIPE_BUFFER_USAGE_PIXEL
,
74 nouveau_surface_release(struct pipe_winsys
*ws
, struct pipe_surface
**s
)
76 struct pipe_surface
*surf
= *s
;
79 if (--surf
->refcount
<= 0) {
81 pipe_buffer_reference(ws
, &surf
->buffer
, NULL
);
86 static struct pipe_buffer
*
87 nouveau_pipe_bo_create(struct pipe_winsys
*pws
, unsigned alignment
,
88 unsigned usage
, unsigned size
)
90 struct nouveau_pipe_winsys
*nvpws
= (struct nouveau_pipe_winsys
*)pws
;
91 struct nouveau_device
*dev
= nvpws
->nv
->nv_screen
->device
;
92 struct nouveau_pipe_buffer
*nvbuf
;
95 nvbuf
= calloc(1, sizeof(*nvbuf
));
98 nvbuf
->base
.refcount
= 1;
99 nvbuf
->base
.alignment
= alignment
;
100 nvbuf
->base
.usage
= usage
;
101 nvbuf
->base
.size
= size
;
103 flags
= NOUVEAU_BO_LOCAL
;
104 if (nouveau_bo_new(dev
, flags
, alignment
, size
, &nvbuf
->bo
)) {
112 static struct pipe_buffer
*
113 nouveau_pipe_bo_user_create(struct pipe_winsys
*pws
, void *ptr
, unsigned bytes
)
115 struct nouveau_pipe_winsys
*nvpws
= (struct nouveau_pipe_winsys
*)pws
;
116 struct nouveau_device
*dev
= nvpws
->nv
->nv_screen
->device
;
117 struct nouveau_pipe_buffer
*nvbuf
;
119 nvbuf
= calloc(1, sizeof(*nvbuf
));
122 nvbuf
->base
.refcount
= 1;
123 nvbuf
->base
.size
= bytes
;
125 if (nouveau_bo_user(dev
, ptr
, bytes
, &nvbuf
->bo
)) {
134 nouveau_pipe_bo_del(struct pipe_winsys
*ws
, struct pipe_buffer
*buf
)
136 struct nouveau_pipe_buffer
*nvbuf
= nouveau_buffer(buf
);
138 nouveau_bo_del(&nvbuf
->bo
);
143 nouveau_pipe_bo_map(struct pipe_winsys
*pws
, struct pipe_buffer
*buf
,
146 struct nouveau_pipe_buffer
*nvbuf
= nouveau_buffer(buf
);
147 uint32_t map_flags
= 0;
149 if (flags
& PIPE_BUFFER_USAGE_CPU_READ
)
150 map_flags
|= NOUVEAU_BO_RD
;
151 if (flags
& PIPE_BUFFER_USAGE_CPU_WRITE
)
152 map_flags
|= NOUVEAU_BO_WR
;
154 if (nouveau_bo_map(nvbuf
->bo
, map_flags
))
156 return nvbuf
->bo
->map
;
160 nouveau_pipe_bo_unmap(struct pipe_winsys
*pws
, struct pipe_buffer
*buf
)
162 struct nouveau_pipe_buffer
*nvbuf
= nouveau_buffer(buf
);
164 nouveau_bo_unmap(nvbuf
->bo
);
168 nouveau_create_pipe_winsys(struct nouveau_context
*nv
)
170 struct nouveau_pipe_winsys
*nvpws
;
171 struct pipe_winsys
*pws
;
173 nvpws
= CALLOC_STRUCT(nouveau_pipe_winsys
);
179 pws
->flush_frontbuffer
= nouveau_flush_frontbuffer
;
180 pws
->printf
= nouveau_printf
;
182 pws
->surface_alloc
= nouveau_surface_alloc
;
183 pws
->surface_alloc_storage
= nouveau_surface_alloc_storage
;
184 pws
->surface_release
= nouveau_surface_release
;
186 pws
->buffer_create
= nouveau_pipe_bo_create
;
187 pws
->buffer_destroy
= nouveau_pipe_bo_del
;
188 pws
->user_buffer_create
= nouveau_pipe_bo_user_create
;
189 pws
->buffer_map
= nouveau_pipe_bo_map
;
190 pws
->buffer_unmap
= nouveau_pipe_bo_unmap
;
192 pws
->get_name
= nouveau_get_name
;