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"
42 #include "util/u_rect.h"
46 struct pipe_texture
*tex
;
47 struct pipe_buffer
*buf
;
51 driCreateBuffers(DrawablePtr pDraw
, unsigned int *attachments
, int count
)
53 struct pipe_texture
*depth
, *tex
;
54 struct pipe_buffer
*buf
;
55 ScreenPtr pScreen
= pDraw
->pScreen
;
56 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
57 modesettingPtr ms
= modesettingPTR(pScrn
);
58 BufferPrivatePtr privates
;
59 DRI2BufferPtr buffers
;
61 unsigned stride
, handle
;
64 buffers
= xcalloc(count
, sizeof *buffers
);
68 privates
= xcalloc(count
, sizeof *privates
);
73 for (i
= 0; i
< count
; i
++) {
77 if (attachments
[i
] == DRI2BufferFrontLeft
) {
78 if (pDraw
->type
== DRAWABLE_PIXMAP
)
79 pPixmap
= (PixmapPtr
) pDraw
;
81 pPixmap
= (*pScreen
->GetWindowPixmap
)((WindowPtr
) pDraw
);
83 tex
= xorg_exa_get_texture(pPixmap
);
84 } else if (attachments
[i
] == DRI2BufferStencil
) {
85 pipe_texture_reference(&tex
, depth
);
86 } else if (attachments
[i
] == DRI2BufferDepth
) {
87 struct pipe_texture
template;
88 memset(&template, 0, sizeof(template));
89 template.target
= PIPE_TEXTURE_2D
;
90 template.format
= PIPE_FORMAT_S8Z24_UNORM
;
91 pf_get_block(template.format
, &template.block
);
92 template.width
[0] = pDraw
->width
;
93 template.height
[0] = pDraw
->height
;
94 template.depth
[0] = 1;
95 template.last_level
= 0;
96 template.tex_usage
= PIPE_TEXTURE_USAGE_DEPTH_STENCIL
;
97 tex
= ms
->screen
->texture_create(ms
->screen
, &template);
100 struct pipe_texture
template;
101 memset(&template, 0, sizeof(template));
102 template.target
= PIPE_TEXTURE_2D
;
103 template.format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
104 pf_get_block(template.format
, &template.block
);
105 template.width
[0] = pDraw
->width
;
106 template.height
[0] = pDraw
->height
;
107 template.depth
[0] = 1;
108 template.last_level
= 0;
109 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
110 tex
= ms
->screen
->texture_create(ms
->screen
, &template);
114 FatalError("NO TEXTURE IN DRI2\n");
116 ms
->api
->buffer_from_texture(ms
->api
, tex
, &buf
, &stride
);
117 ms
->api
->global_handle_from_buffer(ms
->api
, ms
->screen
, buf
, &handle
);
119 buffers
[i
].name
= handle
;
120 buffers
[i
].attachment
= attachments
[i
];
121 buffers
[i
].pitch
= stride
;
123 buffers
[i
].driverPrivate
= &privates
[i
];
124 buffers
[i
].flags
= 0; /* not tiled */
125 privates
[i
].pPixmap
= pPixmap
;
126 privates
[i
].buf
= buf
;
127 privates
[i
].tex
= tex
;
139 driDestroyBuffers(DrawablePtr pDraw
, DRI2BufferPtr buffers
, int count
)
141 ScreenPtr pScreen
= pDraw
->pScreen
;
142 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
143 modesettingPtr ms
= modesettingPTR(pScrn
);
144 BufferPrivatePtr
private;
148 for (i
= 0; i
< count
; i
++) {
149 private = buffers
[i
].driverPrivate
;
151 if (private->pPixmap
)
152 (*pScreen
->DestroyPixmap
)(private->pPixmap
);
154 pipe_texture_reference(&private->tex
, NULL
);
155 pipe_buffer_reference(&private->buf
, NULL
);
159 xfree(buffers
[0].driverPrivate
);
165 driCopyRegion(DrawablePtr pDraw
, RegionPtr pRegion
,
166 DRI2BufferPtr pDestBuffer
, DRI2BufferPtr pSrcBuffer
)
168 ScreenPtr pScreen
= pDraw
->pScreen
;
169 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
170 modesettingPtr ms
= modesettingPTR(pScrn
);
171 BufferPrivatePtr dst_priv
= pDestBuffer
->driverPrivate
;
172 BufferPrivatePtr src_priv
= pSrcBuffer
->driverPrivate
;
174 struct pipe_surface
*dst_surf
=
175 ms
->screen
->get_tex_surface(ms
->screen
, dst_priv
->tex
, 0, 0, 0,
176 PIPE_BUFFER_USAGE_GPU_WRITE
);
177 struct pipe_surface
*src_surf
=
178 ms
->screen
->get_tex_surface(ms
->screen
, src_priv
->tex
, 0, 0, 0,
179 PIPE_BUFFER_USAGE_GPU_READ
);
182 ms
->ctx
->surface_copy(ms
->ctx
, dst_surf
, 0, 0, src_surf
,
183 0, 0, pDraw
->width
, pDraw
->height
);
185 util_surface_copy(ms
->ctx
, false, dst_surf
, 0, 0, src_surf
,
186 0, 0, pDraw
->width
, pDraw
->height
);
189 pipe_surface_reference(&dst_surf
, NULL
);
190 pipe_surface_reference(&src_surf
, NULL
);
194 driScreenInit(ScreenPtr pScreen
)
196 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
197 modesettingPtr ms
= modesettingPTR(pScrn
);
198 DRI2InfoRec dri2info
;
200 dri2info
.version
= 1;
201 dri2info
.fd
= ms
->fd
;
203 dri2info
.driverName
= pScrn
->name
;
205 dri2info
.driverName
= "i915"; /* FIXME */
207 dri2info
.deviceName
= "/dev/dri/card0"; /* FIXME */
209 dri2info
.CreateBuffers
= driCreateBuffers
;
210 dri2info
.DestroyBuffers
= driDestroyBuffers
;
211 dri2info
.CopyRegion
= driCopyRegion
;
213 return DRI2ScreenInit(pScreen
, &dri2info
);
217 driCloseScreen(ScreenPtr pScreen
)
219 DRI2CloseScreen(pScreen
);
222 /* vim: set sw=4 ts=8 sts=4: */