2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
31 #include "xorg-server.h"
33 #include "xf86_OSproc.h"
35 #include "xorg_tracker.h"
39 #include "pipe/p_state.h"
40 #include "pipe/p_inlines.h"
44 struct pipe_texture
*tex
;
45 struct pipe_buffer
*buf
;
49 driCreateBuffers(DrawablePtr pDraw
, unsigned int *attachments
, int count
)
51 struct pipe_texture
*depth
, *tex
;
52 struct pipe_buffer
*buf
;
53 ScreenPtr pScreen
= pDraw
->pScreen
;
54 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
55 modesettingPtr ms
= modesettingPTR(pScrn
);
56 BufferPrivatePtr privates
;
57 DRI2BufferPtr buffers
;
59 unsigned stride
, handle
;
62 buffers
= xcalloc(count
, sizeof *buffers
);
66 privates
= xcalloc(count
, sizeof *privates
);
71 for (i
= 0; i
< count
; i
++) {
75 if (attachments
[i
] == DRI2BufferFrontLeft
) {
76 if (pDraw
->type
== DRAWABLE_PIXMAP
)
77 pPixmap
= (PixmapPtr
) pDraw
;
79 pPixmap
= (*pScreen
->GetWindowPixmap
)((WindowPtr
) pDraw
);
81 tex
= xorg_exa_get_texture(pPixmap
);
82 } else if (attachments
[i
] == DRI2BufferStencil
) {
83 pipe_texture_reference(&tex
, depth
);
84 } else if (attachments
[i
] == DRI2BufferDepth
) {
85 struct pipe_texture
template;
87 memset(&template, 0, sizeof(template));
88 template.target
= PIPE_TEXTURE_2D
;
89 template.format
= PIPE_FORMAT_S8Z24_UNORM
;
90 pf_get_block(template.format
, &template.block
);
91 template.width
[0] = pDraw
->width
;
92 template.height
[0] = pDraw
->height
;
93 template.depth
[0] = 1;
94 template.last_level
= 0;
95 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
96 tex
= ms
->screen
->texture_create(ms
->screen
, &template);
98 struct pipe_texture
template;
99 memset(&template, 0, sizeof(template));
100 template.target
= PIPE_TEXTURE_2D
;
101 template.format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
102 pf_get_block(template.format
, &template.block
);
103 template.width
[0] = pDraw
->width
;
104 template.height
[0] = pDraw
->height
;
105 template.depth
[0] = 1;
106 template.last_level
= 0;
107 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
108 tex
= ms
->screen
->texture_create(ms
->screen
, &template);
111 ms
->api
->buffer_from_texture(ms
->api
, tex
, &buf
, &stride
);
112 ms
->api
->global_handle_from_buffer(ms
->api
, ms
->screen
, buf
, &handle
);
114 buffers
[i
].name
= handle
;
115 buffers
[i
].attachment
= attachments
[i
];
116 buffers
[i
].pitch
= stride
;
118 buffers
[i
].driverPrivate
= &privates
[i
];
119 buffers
[i
].flags
= 0; /* not tiled */
120 privates
[i
].pPixmap
= pPixmap
;
121 privates
[i
].buf
= buf
;
122 privates
[i
].tex
= tex
;
134 driDestroyBuffers(DrawablePtr pDraw
, DRI2BufferPtr buffers
, int count
)
136 ScreenPtr pScreen
= pDraw
->pScreen
;
137 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
138 modesettingPtr ms
= modesettingPTR(pScrn
);
139 BufferPrivatePtr
private;
142 for (i
= 0; i
< count
; i
++) {
143 private = buffers
[i
].driverPrivate
;
145 if (private->pPixmap
)
146 (*pScreen
->DestroyPixmap
)(private->pPixmap
);
148 pipe_texture_reference(&private->tex
, NULL
);
149 pipe_buffer_reference(&private->buf
, NULL
);
153 xfree(buffers
[0].driverPrivate
);
159 driCopyRegion(DrawablePtr pDraw
, RegionPtr pRegion
,
160 DRI2BufferPtr pDestBuffer
, DRI2BufferPtr pSrcBuffer
)
162 ScreenPtr pScreen
= pDraw
->pScreen
;
163 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
164 modesettingPtr ms
= modesettingPTR(pScrn
);
165 BufferPrivatePtr dst_priv
= pDestBuffer
->driverPrivate
;
166 BufferPrivatePtr src_priv
= pSrcBuffer
->driverPrivate
;
168 struct pipe_surface
*dst_surf
=
169 ms
->screen
->get_tex_surface(ms
->screen
, dst_priv
->tex
, 0, 0, 0,
170 PIPE_BUFFER_USAGE_GPU_WRITE
);
171 struct pipe_surface
*src_surf
=
172 ms
->screen
->get_tex_surface(ms
->screen
, src_priv
->tex
, 0, 0, 0,
173 PIPE_BUFFER_USAGE_GPU_READ
);
175 ms
->ctx
->surface_copy(ms
->ctx
, dst_surf
, 0, 0, src_surf
,
176 0, 0, pDraw
->width
, pDraw
->height
);
178 pipe_surface_reference(&dst_surf
, NULL
);
179 pipe_surface_reference(&src_surf
, NULL
);
183 driScreenInit(ScreenPtr pScreen
)
185 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
186 modesettingPtr ms
= modesettingPTR(pScrn
);
187 DRI2InfoRec dri2info
;
189 dri2info
.version
= 1;
190 dri2info
.fd
= ms
->fd
;
192 dri2info
.driverName
= pScrn
->name
;
194 dri2info
.driverName
= "i915"; /* FIXME */
196 dri2info
.deviceName
= "/dev/dri/card0"; /* FIXME */
198 dri2info
.CreateBuffers
= driCreateBuffers
;
199 dri2info
.DestroyBuffers
= driDestroyBuffers
;
200 dri2info
.CopyRegion
= driCopyRegion
;
202 return DRI2ScreenInit(pScreen
, &dri2info
);
206 driCloseScreen(ScreenPtr pScreen
)
208 DRI2CloseScreen(pScreen
);
211 /* vim: set sw=4 ts=8 sts=4: */