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 "xorg_tracker.h"
33 #include "xorg_composite.h"
35 #include <xorg-server.h>
37 #include <picturestr.h>
40 #include "pipe/p_format.h"
41 #include "pipe/p_context.h"
42 #include "pipe/p_state.h"
43 #include "pipe/p_inlines.h"
45 #include "cso_cache/cso_context.h"
47 #include "util/u_rect.h"
54 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
58 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
62 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
66 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
70 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
76 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
85 * Static exported EXA functions
89 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
94 ExaMarkSync(ScreenPtr pScreen
)
100 ExaPrepareAccess(PixmapPtr pPix
, int index
)
102 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
103 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
104 modesettingPtr ms
= modesettingPTR(pScrn
);
105 struct exa_context
*exa
= ms
->exa
;
106 struct exa_pixmap_priv
*priv
;
108 priv
= exaGetPixmapDriverPrivate(pPix
);
116 if (priv
->map_count
++ == 0)
119 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
120 PIPE_TRANSFER_READ_WRITE
,
121 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
123 pPix
->devPrivate
.ptr
=
124 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
125 pPix
->devKind
= priv
->map_transfer
->stride
;
132 ExaFinishAccess(PixmapPtr pPix
, int index
)
134 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
135 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
136 modesettingPtr ms
= modesettingPTR(pScrn
);
137 struct exa_context
*exa
= ms
->exa
;
138 struct exa_pixmap_priv
*priv
;
139 priv
= exaGetPixmapDriverPrivate(pPix
);
144 if (!priv
->map_transfer
)
147 if (--priv
->map_count
== 0) {
148 assert(priv
->map_transfer
);
149 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
150 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
151 priv
->map_transfer
= NULL
;
156 ExaDone(PixmapPtr pPixmap
)
158 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
159 modesettingPtr ms
= modesettingPTR(pScrn
);
160 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
161 struct exa_context
*exa
= ms
->exa
;
167 exa
->scrn
->tex_surface_destroy(priv
->src_surf
);
168 priv
->src_surf
= NULL
;
172 ExaDoneComposite(PixmapPtr pPixmap
)
178 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
180 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
181 modesettingPtr ms
= modesettingPTR(pScrn
);
182 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
183 struct exa_context
*exa
= ms
->exa
;
188 if (pPixmap
->drawable
.depth
< 15)
191 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
194 if (!priv
|| !priv
->tex
)
200 if (!exa
->ctx
|| !exa
->ctx
->surface_fill
)
209 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
211 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
212 modesettingPtr ms
= modesettingPTR(pScrn
);
213 struct exa_context
*exa
= ms
->exa
;
214 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
215 struct pipe_surface
*surf
=
216 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
217 PIPE_BUFFER_USAGE_GPU_READ
|
218 PIPE_BUFFER_USAGE_GPU_WRITE
);
220 exa
->ctx
->surface_fill(exa
->ctx
, surf
, x0
, y0
, x1
- x0
, y1
- y0
,
223 exa
->scrn
->tex_surface_destroy(surf
);
227 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
228 int ydir
, int alu
, Pixel planeMask
)
230 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
231 modesettingPtr ms
= modesettingPTR(pScrn
);
232 struct exa_context
*exa
= ms
->exa
;
233 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
234 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
242 if (pSrcPixmap
->drawable
.depth
< 15 || pDstPixmap
->drawable
.depth
< 15)
245 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
248 if (!priv
|| !src_priv
)
251 if (!priv
->tex
|| !src_priv
->tex
)
254 if (!exa
->ctx
|| !exa
->ctx
->surface_copy
)
258 exa
->scrn
->get_tex_surface(exa
->scrn
, src_priv
->tex
, 0, 0, 0,
259 PIPE_BUFFER_USAGE_GPU_READ
|
260 PIPE_BUFFER_USAGE_GPU_WRITE
);
266 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
267 int width
, int height
)
269 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
270 modesettingPtr ms
= modesettingPTR(pScrn
);
271 struct exa_context
*exa
= ms
->exa
;
272 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
273 struct pipe_surface
*surf
=
274 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
275 PIPE_BUFFER_USAGE_GPU_READ
|
276 PIPE_BUFFER_USAGE_GPU_WRITE
);
278 exa
->ctx
->surface_copy(exa
->ctx
, surf
, dstX
, dstY
, priv
->src_surf
,
279 srcX
, srcY
, width
, height
);
280 exa
->scrn
->tex_surface_destroy(surf
);
284 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
285 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
286 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
288 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
289 modesettingPtr ms
= modesettingPTR(pScrn
);
290 struct exa_context
*exa
= ms
->exa
;
292 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
297 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
298 int dstX
, int dstY
, int width
, int height
)
300 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
301 modesettingPtr ms
= modesettingPTR(pScrn
);
302 struct exa_context
*exa
= ms
->exa
;
303 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
305 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
306 dstX
, dstY
, width
, height
);
310 ExaCheckComposite(int op
,
311 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
312 PicturePtr pDstPicture
)
314 return xorg_composite_accelerated(op
,
321 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
323 struct exa_pixmap_priv
*priv
;
325 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
333 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
335 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
336 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
337 modesettingPtr ms
= modesettingPTR(pScrn
);
343 ms
->screen
->texture_destroy(priv
->tex
);
349 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
351 struct exa_pixmap_priv
*priv
;
353 priv
= exaGetPixmapDriverPrivate(pPixmap
);
365 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
367 struct exa_pixmap_priv
*priv
;
368 priv
= exaGetPixmapDriverPrivate(pPixmap
);
371 FatalError("NO PIXMAP PRIVATE\n");
375 if (priv
->flags
& ~PIPE_TEXTURE_USAGE_PRIMARY
) {
376 FatalError("BAD FLAGS\n");
379 priv
->flags
= PIPE_TEXTURE_USAGE_PRIMARY
;
385 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
387 struct exa_pixmap_priv
*priv
;
388 priv
= exaGetPixmapDriverPrivate(pPixmap
);
391 FatalError("NO PIXMAP PRIVATE\n");
395 if (priv
->flags
& ~PIPE_TEXTURE_USAGE_DISPLAY_TARGET
) {
396 FatalError("BAD FLAGS\n");
399 priv
->flags
= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
405 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
407 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
408 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
409 modesettingPtr ms
= modesettingPTR(pScrn
);
410 struct exa_pixmap_priv
*priv
;
411 struct pipe_buffer
*buffer
= NULL
;
416 FatalError("NO MS->EXA\n");
420 priv
= exaGetPixmapDriverPrivate(pPixmap
);
423 FatalError("NO PIXMAP PRIVATE\n");
427 ms
->api
->buffer_from_texture(ms
->api
, priv
->tex
, &buffer
, &stride
);
428 ms
->api
->handle_from_buffer(ms
->api
, ms
->screen
, buffer
, &handle
);
429 pipe_buffer_reference(&buffer
, NULL
);
431 *stride_out
= stride
;
437 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
438 int depth
, int bitsPerPixel
, int devKind
,
441 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
442 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
443 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
444 modesettingPtr ms
= modesettingPTR(pScrn
);
445 struct exa_context
*exa
= ms
->exa
;
451 depth
= pPixmap
->drawable
.depth
;
453 if (bitsPerPixel
<= 0)
454 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
457 width
= pPixmap
->drawable
.width
;
460 height
= pPixmap
->drawable
.height
;
462 if (width
<= 0 || height
<= 0 || depth
<= 0)
465 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
466 bitsPerPixel
, devKind
, NULL
);
468 /* Deal with screen resize */
469 if (priv
->tex
&& (priv
->tex
->width
[0] != width
||
470 priv
->tex
->height
[0] != height
||
471 priv
->tex_flags
!= priv
->flags
)) {
472 pipe_texture_reference(&priv
->tex
, NULL
);
476 struct pipe_texture
template;
478 memset(&template, 0, sizeof(template));
479 template.target
= PIPE_TEXTURE_2D
;
480 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
481 pf_get_block(template.format
, &template.block
);
482 template.width
[0] = width
;
483 template.height
[0] = height
;
484 template.depth
[0] = 1;
485 template.last_level
= 0;
486 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
487 priv
->tex_flags
= priv
->flags
;
488 priv
->tex
= exa
->scrn
->texture_create(exa
->scrn
, &template);
492 struct pipe_transfer
*transfer
=
493 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
495 0, 0, width
, height
);
496 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
497 &priv
->tex
->block
, transfer
->stride
, 0, 0,
498 width
, height
, pPixData
, pPixmap
->devKind
, 0, 0);
499 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
500 exa
->scrn
->tex_transfer_destroy(transfer
);
506 struct pipe_texture
*
507 xorg_exa_get_texture(PixmapPtr pPixmap
)
509 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
510 struct pipe_texture
*tex
= NULL
;
511 pipe_texture_reference(&tex
, priv
->tex
);
516 xorg_exa_close(ScrnInfoPtr pScrn
)
518 modesettingPtr ms
= modesettingPTR(pScrn
);
519 struct exa_context
*exa
= ms
->exa
;
522 cso_release_all(exa
->cso
);
523 cso_destroy_context(exa
->cso
);
527 exa
->ctx
->destroy(exa
->ctx
);
529 exaDriverFini(pScrn
->pScreen
);
535 xorg_exa_init(ScrnInfoPtr pScrn
)
537 modesettingPtr ms
= modesettingPTR(pScrn
);
538 struct exa_context
*exa
;
541 exa
= xcalloc(1, sizeof(struct exa_context
));
545 pExa
= exaDriverAlloc();
550 memset(pExa
, 0, sizeof(*pExa
));
554 pExa
->memoryBase
= 0;
555 pExa
->memorySize
= 0;
556 pExa
->offScreenBase
= 0;
557 pExa
->pixmapOffsetAlign
= 0;
558 pExa
->pixmapPitchAlign
= 1;
559 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
560 pExa
->maxX
= 8191; /* FIXME */
561 pExa
->maxY
= 8191; /* FIXME */
563 pExa
->WaitMarker
= ExaWaitMarker
;
564 pExa
->MarkSync
= ExaMarkSync
;
565 pExa
->PrepareSolid
= ExaPrepareSolid
;
566 pExa
->Solid
= ExaSolid
;
567 pExa
->DoneSolid
= ExaDone
;
568 pExa
->PrepareCopy
= ExaPrepareCopy
;
569 pExa
->Copy
= ExaCopy
;
570 pExa
->DoneCopy
= ExaDone
;
571 pExa
->CheckComposite
= ExaCheckComposite
;
572 pExa
->PrepareComposite
= ExaPrepareComposite
;
573 pExa
->Composite
= ExaComposite
;
574 pExa
->DoneComposite
= ExaDoneComposite
;
575 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
576 pExa
->PrepareAccess
= ExaPrepareAccess
;
577 pExa
->FinishAccess
= ExaFinishAccess
;
578 pExa
->CreatePixmap
= ExaCreatePixmap
;
579 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
580 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
582 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
586 exa
->scrn
= ms
->screen
;
587 exa
->ctx
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
588 /* Share context with DRI */
591 exa
->cso
= cso_create_context(exa
->ctx
);
596 xorg_exa_close(pScrn
);
601 /* vim: set sw=4 ts=8 sts=4: */