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"
43 struct pipe_context
*ctx
;
44 struct pipe_screen
*scrn
;
50 struct pipe_texture
*tex
;
52 struct pipe_surface
*src_surf
; /* for copies */
54 struct pipe_transfer
*map_transfer
;
63 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
67 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
71 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
75 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
79 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
85 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
94 * Static exported EXA functions
98 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
103 ExaMarkSync(ScreenPtr pScreen
)
109 ExaPrepareAccess(PixmapPtr pPix
, int index
)
111 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
112 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
113 modesettingPtr ms
= modesettingPTR(pScrn
);
114 struct exa_entity
*exa
= ms
->exa
;
115 struct PixmapPriv
*priv
;
117 priv
= exaGetPixmapDriverPrivate(pPix
);
125 if (priv
->map_count
++ == 0)
128 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
129 PIPE_TRANSFER_READ_WRITE
,
130 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
132 pPix
->devPrivate
.ptr
=
133 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
134 pPix
->devKind
= priv
->map_transfer
->stride
;
141 ExaFinishAccess(PixmapPtr pPix
, int index
)
143 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
144 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
145 modesettingPtr ms
= modesettingPTR(pScrn
);
146 struct exa_entity
*exa
= ms
->exa
;
147 struct PixmapPriv
*priv
;
148 priv
= exaGetPixmapDriverPrivate(pPix
);
153 if (!priv
->map_transfer
)
156 if (--priv
->map_count
== 0) {
157 assert(priv
->map_transfer
);
158 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
159 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
160 priv
->map_transfer
= NULL
;
165 ExaDone(PixmapPtr pPixmap
)
167 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
168 modesettingPtr ms
= modesettingPTR(pScrn
);
169 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
170 struct exa_entity
*exa
= ms
->exa
;
176 exa
->scrn
->tex_surface_destroy(priv
->src_surf
);
177 priv
->src_surf
= NULL
;
181 ExaDoneComposite(PixmapPtr pPixmap
)
187 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
189 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
190 modesettingPtr ms
= modesettingPTR(pScrn
);
191 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
192 struct exa_entity
*exa
= ms
->exa
;
197 if (pPixmap
->drawable
.depth
< 15)
200 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
203 if (!priv
|| !priv
->tex
)
209 if (!exa
->ctx
|| !exa
->ctx
->surface_fill
)
218 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
220 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
221 modesettingPtr ms
= modesettingPTR(pScrn
);
222 struct exa_entity
*exa
= ms
->exa
;
223 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
224 struct pipe_surface
*surf
=
225 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
226 PIPE_BUFFER_USAGE_GPU_READ
|
227 PIPE_BUFFER_USAGE_GPU_WRITE
);
229 exa
->ctx
->surface_fill(exa
->ctx
, surf
, x0
, y0
, x1
- x0
, y1
- y0
,
232 exa
->scrn
->tex_surface_destroy(surf
);
236 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
237 int ydir
, int alu
, Pixel planeMask
)
239 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
240 modesettingPtr ms
= modesettingPTR(pScrn
);
241 struct exa_entity
*exa
= ms
->exa
;
242 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
243 struct PixmapPriv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
251 if (pSrcPixmap
->drawable
.depth
< 15 || pDstPixmap
->drawable
.depth
< 15)
254 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
257 if (!priv
|| !src_priv
)
260 if (!priv
->tex
|| !src_priv
->tex
)
263 if (!exa
->ctx
|| !exa
->ctx
->surface_copy
)
267 exa
->scrn
->get_tex_surface(exa
->scrn
, src_priv
->tex
, 0, 0, 0,
268 PIPE_BUFFER_USAGE_GPU_READ
|
269 PIPE_BUFFER_USAGE_GPU_WRITE
);
275 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
276 int width
, int height
)
278 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
279 modesettingPtr ms
= modesettingPTR(pScrn
);
280 struct exa_entity
*exa
= ms
->exa
;
281 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
282 struct pipe_surface
*surf
=
283 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
284 PIPE_BUFFER_USAGE_GPU_READ
|
285 PIPE_BUFFER_USAGE_GPU_WRITE
);
287 exa
->ctx
->surface_copy(exa
->ctx
, surf
, dstX
, dstY
, priv
->src_surf
,
288 srcX
, srcY
, width
, height
);
289 exa
->scrn
->tex_surface_destroy(surf
);
293 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
294 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
295 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
301 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
302 int dstX
, int dstY
, int width
, int height
)
307 ExaCheckComposite(int op
,
308 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
309 PicturePtr pDstPicture
)
315 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
317 struct PixmapPriv
*priv
;
319 priv
= xcalloc(1, sizeof(struct PixmapPriv
));
327 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
329 struct PixmapPriv
*priv
= (struct PixmapPriv
*)dPriv
;
330 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
331 modesettingPtr ms
= modesettingPTR(pScrn
);
337 ms
->screen
->texture_destroy(priv
->tex
);
343 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
345 struct PixmapPriv
*priv
;
347 priv
= exaGetPixmapDriverPrivate(pPixmap
);
359 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
)
361 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
362 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
363 modesettingPtr ms
= modesettingPTR(pScrn
);
364 struct PixmapPriv
*priv
;
365 struct pipe_buffer
*buffer
= NULL
;
370 FatalError("NO MS->EXA\n");
374 priv
= exaGetPixmapDriverPrivate(pPixmap
);
377 FatalError("NO PIXMAP PRIVATE\n");
381 drm_api_hooks
.buffer_from_texture(priv
->tex
, &buffer
, &stride
);
382 drm_api_hooks
.handle_from_buffer(ms
->screen
, buffer
, &handle
);
383 pipe_buffer_reference(&buffer
, NULL
);
388 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
389 int depth
, int bitsPerPixel
, int devKind
,
392 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
393 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
394 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
395 modesettingPtr ms
= modesettingPTR(pScrn
);
396 struct exa_entity
*exa
= ms
->exa
;
402 depth
= pPixmap
->drawable
.depth
;
404 if (bitsPerPixel
<= 0)
405 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
408 width
= pPixmap
->drawable
.width
;
411 height
= pPixmap
->drawable
.height
;
413 if (width
<= 0 || height
<= 0 || depth
<= 0)
416 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
417 bitsPerPixel
, devKind
, NULL
);
419 /* Deal with screen resize */
420 if (priv
->tex
&& (priv
->tex
->width
[0] != width
|| priv
->tex
->height
[0] != height
)) {
421 pipe_texture_reference(&priv
->tex
, NULL
);
425 struct pipe_texture
template;
427 memset(&template, 0, sizeof(template));
428 template.target
= PIPE_TEXTURE_2D
;
429 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
430 pf_get_block(template.format
, &template.block
);
431 template.width
[0] = width
;
432 template.height
[0] = height
;
433 template.depth
[0] = 1;
434 template.last_level
= 0;
435 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
436 priv
->tex
= exa
->scrn
->texture_create(exa
->scrn
, &template);
442 struct pipe_texture
*
443 xorg_exa_get_texture(PixmapPtr pPixmap
)
445 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
446 struct pipe_texture
*tex
= NULL
;
447 pipe_texture_reference(&tex
, priv
->tex
);
452 xorg_exa_close(ScrnInfoPtr pScrn
)
454 modesettingPtr ms
= modesettingPTR(pScrn
);
455 struct exa_entity
*exa
= ms
->exa
;
458 exa
->ctx
->destroy(exa
->ctx
);
460 exaDriverFini(pScrn
->pScreen
);
466 xorg_exa_init(ScrnInfoPtr pScrn
)
468 modesettingPtr ms
= modesettingPTR(pScrn
);
469 struct exa_entity
*exa
;
472 exa
= xcalloc(1, sizeof(struct exa_entity
));
476 pExa
= exaDriverAlloc();
481 memset(pExa
, 0, sizeof(*pExa
));
484 pExa
->memoryBase
= 0;
485 pExa
->memorySize
= 0;
486 pExa
->offScreenBase
= 0;
487 pExa
->pixmapOffsetAlign
= 0;
488 pExa
->pixmapPitchAlign
= 1;
489 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
490 pExa
->maxX
= 8191; /* FIXME */
491 pExa
->maxY
= 8191; /* FIXME */
492 pExa
->WaitMarker
= ExaWaitMarker
;
493 pExa
->MarkSync
= ExaMarkSync
;
494 pExa
->PrepareSolid
= ExaPrepareSolid
;
495 pExa
->Solid
= ExaSolid
;
496 pExa
->DoneSolid
= ExaDone
;
497 pExa
->PrepareCopy
= ExaPrepareCopy
;
498 pExa
->Copy
= ExaCopy
;
499 pExa
->DoneCopy
= ExaDone
;
500 pExa
->CheckComposite
= ExaCheckComposite
;
501 pExa
->PrepareComposite
= ExaPrepareComposite
;
502 pExa
->Composite
= ExaComposite
;
503 pExa
->DoneComposite
= ExaDoneComposite
;
504 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
505 pExa
->PrepareAccess
= ExaPrepareAccess
;
506 pExa
->FinishAccess
= ExaFinishAccess
;
507 pExa
->CreatePixmap
= ExaCreatePixmap
;
508 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
509 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
511 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
515 exa
->scrn
= ms
->screen
;
516 exa
->ctx
= drm_api_hooks
.create_context(exa
->scrn
);
517 /* Share context with DRI */
523 xorg_exa_close(pScrn
);
528 /* vim: set sw=4 ts=8 sts=4: */