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 "xorg_tracker.h"
35 #include "pipe/p_format.h"
36 #include "pipe/p_context.h"
37 #include "pipe/p_state.h"
38 #include "pipe/p_inlines.h"
40 #include "util/u_rect.h"
45 struct pipe_context
*ctx
;
46 struct pipe_screen
*scrn
;
52 struct pipe_texture
*tex
;
54 struct pipe_surface
*src_surf
; /* for copies */
56 struct pipe_transfer
*map_transfer
;
65 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
69 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
73 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
77 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
81 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
87 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
96 * Static exported EXA functions
100 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
105 ExaMarkSync(ScreenPtr pScreen
)
111 ExaPrepareAccess(PixmapPtr pPix
, int index
)
113 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
114 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
115 modesettingPtr ms
= modesettingPTR(pScrn
);
116 struct exa_entity
*exa
= ms
->exa
;
117 struct PixmapPriv
*priv
;
119 priv
= exaGetPixmapDriverPrivate(pPix
);
127 if (priv
->map_count
++ == 0)
130 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
131 PIPE_TRANSFER_READ_WRITE
,
132 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
134 pPix
->devPrivate
.ptr
=
135 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
136 pPix
->devKind
= priv
->map_transfer
->stride
;
143 ExaFinishAccess(PixmapPtr pPix
, int index
)
145 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
146 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
147 modesettingPtr ms
= modesettingPTR(pScrn
);
148 struct exa_entity
*exa
= ms
->exa
;
149 struct PixmapPriv
*priv
;
150 priv
= exaGetPixmapDriverPrivate(pPix
);
155 if (!priv
->map_transfer
)
158 if (--priv
->map_count
== 0) {
159 assert(priv
->map_transfer
);
160 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
161 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
162 priv
->map_transfer
= NULL
;
167 ExaDone(PixmapPtr pPixmap
)
169 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
170 modesettingPtr ms
= modesettingPTR(pScrn
);
171 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
172 struct exa_entity
*exa
= ms
->exa
;
178 exa
->scrn
->tex_surface_destroy(priv
->src_surf
);
179 priv
->src_surf
= NULL
;
183 ExaDoneComposite(PixmapPtr pPixmap
)
189 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
191 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
192 modesettingPtr ms
= modesettingPTR(pScrn
);
193 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
194 struct exa_entity
*exa
= ms
->exa
;
199 if (pPixmap
->drawable
.depth
< 15)
202 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
205 if (!priv
|| !priv
->tex
)
211 if (!exa
->ctx
|| !exa
->ctx
->surface_fill
)
220 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
222 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
223 modesettingPtr ms
= modesettingPTR(pScrn
);
224 struct exa_entity
*exa
= ms
->exa
;
225 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
226 struct pipe_surface
*surf
=
227 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
228 PIPE_BUFFER_USAGE_GPU_READ
|
229 PIPE_BUFFER_USAGE_GPU_WRITE
);
231 exa
->ctx
->surface_fill(exa
->ctx
, surf
, x0
, y0
, x1
- x0
, y1
- y0
,
234 exa
->scrn
->tex_surface_destroy(surf
);
238 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
239 int ydir
, int alu
, Pixel planeMask
)
241 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
242 modesettingPtr ms
= modesettingPTR(pScrn
);
243 struct exa_entity
*exa
= ms
->exa
;
244 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
245 struct PixmapPriv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
253 if (pSrcPixmap
->drawable
.depth
< 15 || pDstPixmap
->drawable
.depth
< 15)
256 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
259 if (!priv
|| !src_priv
)
262 if (!priv
->tex
|| !src_priv
->tex
)
265 if (!exa
->ctx
|| !exa
->ctx
->surface_copy
)
269 exa
->scrn
->get_tex_surface(exa
->scrn
, src_priv
->tex
, 0, 0, 0,
270 PIPE_BUFFER_USAGE_GPU_READ
|
271 PIPE_BUFFER_USAGE_GPU_WRITE
);
277 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
278 int width
, int height
)
280 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
281 modesettingPtr ms
= modesettingPTR(pScrn
);
282 struct exa_entity
*exa
= ms
->exa
;
283 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
284 struct pipe_surface
*surf
=
285 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
286 PIPE_BUFFER_USAGE_GPU_READ
|
287 PIPE_BUFFER_USAGE_GPU_WRITE
);
289 exa
->ctx
->surface_copy(exa
->ctx
, surf
, dstX
, dstY
, priv
->src_surf
,
290 srcX
, srcY
, width
, height
);
291 exa
->scrn
->tex_surface_destroy(surf
);
295 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
296 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
297 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
303 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
304 int dstX
, int dstY
, int width
, int height
)
309 ExaCheckComposite(int op
,
310 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
311 PicturePtr pDstPicture
)
317 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
319 struct PixmapPriv
*priv
;
321 priv
= xcalloc(1, sizeof(struct PixmapPriv
));
329 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
331 struct PixmapPriv
*priv
= (struct PixmapPriv
*)dPriv
;
332 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
333 modesettingPtr ms
= modesettingPTR(pScrn
);
339 ms
->screen
->texture_destroy(priv
->tex
);
345 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
347 struct PixmapPriv
*priv
;
349 priv
= exaGetPixmapDriverPrivate(pPixmap
);
361 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
)
363 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
364 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
365 modesettingPtr ms
= modesettingPTR(pScrn
);
366 struct PixmapPriv
*priv
;
367 struct pipe_buffer
*buffer
= NULL
;
372 FatalError("NO MS->EXA\n");
376 priv
= exaGetPixmapDriverPrivate(pPixmap
);
379 FatalError("NO PIXMAP PRIVATE\n");
383 drm_api_hooks
.buffer_from_texture(priv
->tex
, &buffer
, &stride
);
384 drm_api_hooks
.handle_from_buffer(ms
->screen
, buffer
, &handle
);
385 pipe_buffer_reference(&buffer
, NULL
);
390 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
391 int depth
, int bitsPerPixel
, int devKind
,
394 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
395 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
396 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
397 modesettingPtr ms
= modesettingPTR(pScrn
);
398 struct exa_entity
*exa
= ms
->exa
;
404 depth
= pPixmap
->drawable
.depth
;
406 if (bitsPerPixel
<= 0)
407 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
410 width
= pPixmap
->drawable
.width
;
413 height
= pPixmap
->drawable
.height
;
415 if (width
<= 0 || height
<= 0 || depth
<= 0)
418 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
419 bitsPerPixel
, devKind
, NULL
);
421 /* Deal with screen resize */
422 if (priv
->tex
&& (priv
->tex
->width
[0] != width
|| priv
->tex
->height
[0] != height
)) {
423 pipe_texture_reference(&priv
->tex
, NULL
);
427 struct pipe_texture
template;
429 memset(&template, 0, sizeof(template));
430 template.target
= PIPE_TEXTURE_2D
;
431 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
432 pf_get_block(template.format
, &template.block
);
433 template.width
[0] = width
;
434 template.height
[0] = height
;
435 template.depth
[0] = 1;
436 template.last_level
= 0;
437 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
438 priv
->tex
= exa
->scrn
->texture_create(exa
->scrn
, &template);
442 struct pipe_transfer
*transfer
=
443 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
445 0, 0, width
, height
);
446 pipe_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
447 &priv
->tex
->block
, transfer
->stride
, 0, 0,
448 width
, height
, pPixData
, pPixmap
->devKind
, 0, 0);
449 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
450 exa
->scrn
->tex_transfer_destroy(transfer
);
456 struct pipe_texture
*
457 xorg_exa_get_texture(PixmapPtr pPixmap
)
459 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
460 struct pipe_texture
*tex
= NULL
;
461 pipe_texture_reference(&tex
, priv
->tex
);
466 xorg_exa_close(ScrnInfoPtr pScrn
)
468 modesettingPtr ms
= modesettingPTR(pScrn
);
469 struct exa_entity
*exa
= ms
->exa
;
472 exa
->ctx
->destroy(exa
->ctx
);
474 exaDriverFini(pScrn
->pScreen
);
480 xorg_exa_init(ScrnInfoPtr pScrn
)
482 modesettingPtr ms
= modesettingPTR(pScrn
);
483 struct exa_entity
*exa
;
486 exa
= xcalloc(1, sizeof(struct exa_entity
));
490 pExa
= exaDriverAlloc();
495 memset(pExa
, 0, sizeof(*pExa
));
498 pExa
->memoryBase
= 0;
499 pExa
->memorySize
= 0;
500 pExa
->offScreenBase
= 0;
501 pExa
->pixmapOffsetAlign
= 0;
502 pExa
->pixmapPitchAlign
= 1;
503 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
504 pExa
->maxX
= 8191; /* FIXME */
505 pExa
->maxY
= 8191; /* FIXME */
506 pExa
->WaitMarker
= ExaWaitMarker
;
507 pExa
->MarkSync
= ExaMarkSync
;
508 pExa
->PrepareSolid
= ExaPrepareSolid
;
509 pExa
->Solid
= ExaSolid
;
510 pExa
->DoneSolid
= ExaDone
;
511 pExa
->PrepareCopy
= ExaPrepareCopy
;
512 pExa
->Copy
= ExaCopy
;
513 pExa
->DoneCopy
= ExaDone
;
514 pExa
->CheckComposite
= ExaCheckComposite
;
515 pExa
->PrepareComposite
= ExaPrepareComposite
;
516 pExa
->Composite
= ExaComposite
;
517 pExa
->DoneComposite
= ExaDoneComposite
;
518 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
519 pExa
->PrepareAccess
= ExaPrepareAccess
;
520 pExa
->FinishAccess
= ExaFinishAccess
;
521 pExa
->CreatePixmap
= ExaCreatePixmap
;
522 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
523 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
525 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
529 exa
->scrn
= ms
->screen
;
530 exa
->ctx
= drm_api_hooks
.create_context(exa
->scrn
);
531 /* Share context with DRI */
537 xorg_exa_close(pScrn
);
542 /* vim: set sw=4 ts=8 sts=4: */