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>
32 #include "xf86_OSproc.h"
34 #include "xorg_tracker.h"
38 #include "pipe/p_state.h"
39 #include "pipe/p_inlines.h"
43 struct pipe_texture
*tex
;
44 struct pipe_buffer
*buf
;
48 driCreateBuffers(DrawablePtr pDraw
, unsigned int *attachments
, int count
)
50 struct pipe_texture
*depth
, *tex
;
51 struct pipe_buffer
*buf
;
52 ScreenPtr pScreen
= pDraw
->pScreen
;
53 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
54 modesettingPtr ms
= modesettingPTR(pScrn
);
55 BufferPrivatePtr privates
;
56 DRI2BufferPtr buffers
;
58 unsigned stride
, handle
;
61 buffers
= xcalloc(count
, sizeof *buffers
);
65 privates
= xcalloc(count
, sizeof *privates
);
70 for (i
= 0; i
< count
; i
++) {
74 if (attachments
[i
] == DRI2BufferFrontLeft
) {
75 if (pDraw
->type
== DRAWABLE_PIXMAP
)
76 pPixmap
= (PixmapPtr
) pDraw
;
78 pPixmap
= (*pScreen
->GetWindowPixmap
)((WindowPtr
) pDraw
);
80 tex
= xorg_exa_get_texture(pPixmap
);
81 } else if (attachments
[i
] == DRI2BufferStencil
) {
82 pipe_texture_reference(&tex
, depth
);
83 } else if (attachments
[i
] == DRI2BufferDepth
) {
84 struct pipe_texture
template;
86 memset(&template, 0, sizeof(template));
87 template.target
= PIPE_TEXTURE_2D
;
88 template.compressed
= 0;
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.compressed
= 0;
102 template.format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
103 pf_get_block(template.format
, &template.block
);
104 template.width
[0] = pDraw
->width
;
105 template.height
[0] = pDraw
->height
;
106 template.depth
[0] = 1;
107 template.last_level
= 0;
108 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
109 tex
= ms
->screen
->texture_create(ms
->screen
, &template);
112 drm_api_hooks
.buffer_from_texture(tex
, &buf
, &stride
);
113 drm_api_hooks
.global_handle_from_buffer(ms
->screen
, buf
, &handle
);
115 buffers
[i
].name
= handle
;
116 buffers
[i
].attachment
= attachments
[i
];
117 buffers
[i
].pitch
= stride
;
119 buffers
[i
].driverPrivate
= &privates
[i
];
120 buffers
[i
].flags
= 0; /* not tiled */
121 privates
[i
].pPixmap
= pPixmap
;
122 privates
[i
].buf
= buf
;
123 privates
[i
].tex
= tex
;
135 driDestroyBuffers(DrawablePtr pDraw
, DRI2BufferPtr buffers
, int count
)
137 ScreenPtr pScreen
= pDraw
->pScreen
;
138 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
139 modesettingPtr ms
= modesettingPTR(pScrn
);
140 BufferPrivatePtr
private;
143 for (i
= 0; i
< count
; i
++) {
144 private = buffers
[i
].driverPrivate
;
146 if (private->pPixmap
)
147 (*pScreen
->DestroyPixmap
)(private->pPixmap
);
149 pipe_texture_reference(&private->tex
, NULL
);
150 pipe_buffer_reference(&private->buf
, NULL
);
154 xfree(buffers
[0].driverPrivate
);
160 driCopyRegion(DrawablePtr pDraw
, RegionPtr pRegion
,
161 DRI2BufferPtr pDestBuffer
, DRI2BufferPtr pSrcBuffer
)
163 ScreenPtr pScreen
= pDraw
->pScreen
;
164 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
165 modesettingPtr ms
= modesettingPTR(pScrn
);
166 BufferPrivatePtr dst_priv
= pDestBuffer
->driverPrivate
;
167 BufferPrivatePtr src_priv
= pSrcBuffer
->driverPrivate
;
169 struct pipe_surface
*dst_surf
=
170 ms
->screen
->get_tex_surface(ms
->screen
, dst_priv
->tex
, 0, 0, 0,
171 PIPE_BUFFER_USAGE_GPU_WRITE
);
172 struct pipe_surface
*src_surf
=
173 ms
->screen
->get_tex_surface(ms
->screen
, src_priv
->tex
, 0, 0, 0,
174 PIPE_BUFFER_USAGE_GPU_READ
);
176 ms
->ctx
->surface_copy(ms
->ctx
, 0, dst_surf
, 0, 0, src_surf
,
177 0, 0, pDraw
->width
, pDraw
->height
);
179 pipe_surface_reference(&dst_surf
, NULL
);
180 pipe_surface_reference(&src_surf
, NULL
);
184 driScreenInit(ScreenPtr pScreen
)
186 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
187 modesettingPtr ms
= modesettingPTR(pScrn
);
188 DRI2InfoRec dri2info
;
190 dri2info
.version
= 1;
191 dri2info
.fd
= ms
->fd
;
193 dri2info
.driverName
= pScrn
->name
;
195 dri2info
.driverName
= "i915"; /* FIXME */
197 dri2info
.deviceName
= "/dev/dri/card0"; /* FIXME */
199 dri2info
.CreateBuffers
= driCreateBuffers
;
200 dri2info
.DestroyBuffers
= driDestroyBuffers
;
201 dri2info
.CopyRegion
= driCopyRegion
;
203 return DRI2ScreenInit(pScreen
, &dri2info
);
207 driCloseScreen(ScreenPtr pScreen
)
209 DRI2CloseScreen(pScreen
);
212 /* vim: set sw=4 ts=8 sts=4: */