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"
34 #include "xorg_exa_tgsi.h"
36 #include <xorg-server.h>
38 #include <picturestr.h>
41 #include "pipe/p_format.h"
42 #include "pipe/p_context.h"
43 #include "pipe/p_state.h"
44 #include "pipe/p_inlines.h"
46 #include "util/u_format.h"
47 #include "util/u_rect.h"
48 #include "util/u_math.h"
49 #include "util/u_debug.h"
52 #define ROUND_UP_TEXTURES 1
57 struct render_format_str
{
61 static const struct render_format_str formats_info
[] =
63 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
64 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
65 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
66 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
68 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
69 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
70 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
71 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
72 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
73 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
75 {PICT_r8g8b8
, "PICT_r8g8b8"},
76 {PICT_b8g8r8
, "PICT_b8g8r8"},
77 {PICT_r5g6b5
, "PICT_r5g6b5"},
78 {PICT_b5g6r5
, "PICT_b5g6r5"},
79 {PICT_a1r5g5b5
, "PICT_a1r5g5b5"},
80 {PICT_x1r5g5b5
, "PICT_x1r5g5b5"},
81 {PICT_a1b5g5r5
, "PICT_a1b5g5r5"},
82 {PICT_x1b5g5r5
, "PICT_x1b5g5r5"},
83 {PICT_a4r4g4b4
, "PICT_a4r4g4b4"},
84 {PICT_x4r4g4b4
, "PICT_x4r4g4b4"},
85 {PICT_a4b4g4r4
, "PICT_a4b4g4r4"},
86 {PICT_x4b4g4r4
, "PICT_x4b4g4r4"},
88 {PICT_r3g3b2
, "PICT_r3g3b2"},
89 {PICT_b2g3r3
, "PICT_b2g3r3"},
90 {PICT_a2r2g2b2
, "PICT_a2r2g2b2"},
91 {PICT_a2b2g2r2
, "PICT_a2b2g2r2"},
94 {PICT_x4a4
, "PICT_x4a4"},
95 {PICT_x4c4
, "PICT_x4c4"},
96 {PICT_x4g4
, "PICT_x4g4"},
98 {PICT_r1g2b1
, "PICT_r1g2b1"},
99 {PICT_b1g2r1
, "PICT_b1g2r1"},
100 {PICT_a1r1g1b1
, "PICT_a1r1g1b1"},
101 {PICT_a1b1g1r1
, "PICT_a1b1g1r1"},
102 {PICT_c4
, "PICT_c4"},
103 {PICT_g4
, "PICT_g4"},
104 {PICT_a1
, "PICT_a1"},
107 static const char *render_format_name(int format
)
110 for (i
= 0; i
< sizeof(formats_info
)/sizeof(formats_info
[0]); ++i
) {
111 if (formats_info
[i
].format
== format
)
112 return formats_info
[i
].name
;
118 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
, int *picture_format
)
122 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
123 *picture_format
= PICT_a8r8g8b8
;
127 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
128 *picture_format
= PICT_x8r8g8b8
;
132 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
133 *picture_format
= PICT_r5g6b5
;
137 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
138 *picture_format
= PICT_x1r5g5b5
;
142 *format
= PIPE_FORMAT_L8_UNORM
;
143 *picture_format
= PICT_a8
;
148 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
158 * Static exported EXA functions
162 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
164 /* Nothing to do, handled in the PrepareAccess hook */
168 ExaMarkSync(ScreenPtr pScreen
)
174 /***********************************************************************
175 * Screen upload/download
179 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
182 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
183 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
184 modesettingPtr ms
= modesettingPTR(pScrn
);
185 struct exa_context
*exa
= ms
->exa
;
186 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
187 struct pipe_transfer
*transfer
;
189 if (!priv
|| !priv
->tex
)
192 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
193 PIPE_REFERENCED_FOR_WRITE
)
194 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
196 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
197 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
202 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
203 x
, y
, w
, h
, dst_pitch
);
206 util_copy_rect((unsigned char*)dst
, priv
->tex
->format
, dst_pitch
, 0, 0,
207 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
208 transfer
->stride
, 0, 0);
210 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
211 exa
->scrn
->tex_transfer_destroy(transfer
);
217 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
220 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
221 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
222 modesettingPtr ms
= modesettingPTR(pScrn
);
223 struct exa_context
*exa
= ms
->exa
;
224 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
225 struct pipe_transfer
*transfer
;
227 if (!priv
|| !priv
->tex
)
230 /* make sure that any pending operations are flushed to hardware */
231 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
232 (PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
))
233 xorg_exa_flush(exa
, 0, NULL
);
235 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
236 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
241 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
242 x
, y
, w
, h
, src_pitch
);
245 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
246 priv
->tex
->format
, transfer
->stride
, 0, 0, w
, h
,
247 (unsigned char*)src
, src_pitch
, 0, 0);
249 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
250 exa
->scrn
->tex_transfer_destroy(transfer
);
256 ExaPrepareAccess(PixmapPtr pPix
, int index
)
258 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
259 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
260 modesettingPtr ms
= modesettingPTR(pScrn
);
261 struct exa_context
*exa
= ms
->exa
;
262 struct exa_pixmap_priv
*priv
;
264 priv
= exaGetPixmapDriverPrivate(pPix
);
272 if (priv
->map_count
== 0)
274 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
275 PIPE_REFERENCED_FOR_WRITE
)
276 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
278 assert(pPix
->drawable
.width
<= priv
->tex
->width0
);
279 assert(pPix
->drawable
.height
<= priv
->tex
->height0
);
282 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
283 #ifdef EXA_MIXED_PIXMAPS
284 PIPE_TRANSFER_MAP_DIRECTLY
|
286 PIPE_TRANSFER_READ_WRITE
,
288 pPix
->drawable
.width
,
289 pPix
->drawable
.height
);
290 if (!priv
->map_transfer
)
291 #ifdef EXA_MIXED_PIXMAPS
294 FatalError("failed to create transfer\n");
297 pPix
->devPrivate
.ptr
=
298 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
299 pPix
->devKind
= priv
->map_transfer
->stride
;
308 ExaFinishAccess(PixmapPtr pPix
, int index
)
310 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
311 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
312 modesettingPtr ms
= modesettingPTR(pScrn
);
313 struct exa_context
*exa
= ms
->exa
;
314 struct exa_pixmap_priv
*priv
;
315 priv
= exaGetPixmapDriverPrivate(pPix
);
320 if (!priv
->map_transfer
)
323 if (--priv
->map_count
== 0) {
324 assert(priv
->map_transfer
);
325 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
326 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
327 priv
->map_transfer
= NULL
;
328 pPix
->devPrivate
.ptr
= NULL
;
332 /***********************************************************************
337 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
339 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
340 modesettingPtr ms
= modesettingPTR(pScrn
);
341 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
342 struct exa_context
*exa
= ms
->exa
;
345 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
351 XORG_FALLBACK("accle not enabled");
353 if (!priv
|| !priv
->tex
)
354 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
356 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
357 XORG_FALLBACK("planeMask is not solid");
360 XORG_FALLBACK("not GXcopy");
362 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
364 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
365 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
368 return xorg_solid_bind_state(exa
, priv
, fg
);
372 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
374 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
375 modesettingPtr ms
= modesettingPTR(pScrn
);
376 struct exa_context
*exa
= ms
->exa
;
377 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
380 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
383 if (x0
== 0 && y0
== 0 &&
384 x1
== pPixmap
->drawable
.width
&& y1
== pPixmap
->drawable
.height
) {
385 exa
->pipe
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
, exa
->solid_color
, 0.0, 0);
389 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
394 ExaDoneSolid(PixmapPtr pPixmap
)
396 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
397 modesettingPtr ms
= modesettingPTR(pScrn
);
398 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
399 struct exa_context
*exa
= ms
->exa
;
404 xorg_composite_done(exa
);
407 /***********************************************************************
412 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
413 int ydir
, int alu
, Pixel planeMask
)
415 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
416 modesettingPtr ms
= modesettingPTR(pScrn
);
417 struct exa_context
*exa
= ms
->exa
;
418 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
419 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
422 debug_printf("ExaPrepareCopy\n");
429 XORG_FALLBACK("accle not enabled");
431 if (!priv
|| !priv
->tex
)
432 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
434 if (!src_priv
|| !src_priv
->tex
)
435 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
437 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
438 XORG_FALLBACK("planeMask is not solid");
441 XORG_FALLBACK("alu not GXcopy");
443 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
445 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
446 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
448 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
449 src_priv
->tex
->target
,
450 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
451 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
453 exa
->copy
.src
= src_priv
;
454 exa
->copy
.dst
= priv
;
456 /* For same-surface copies, the pipe->surface_copy path is clearly
457 * superior, providing it is implemented. In other cases it's not
458 * clear what the better path would be, and eventually we'd
459 * probably want to gather timings and choose dynamically.
461 if (exa
->pipe
->surface_copy
&&
462 exa
->copy
.src
== exa
->copy
.dst
) {
464 exa
->copy
.use_surface_copy
= TRUE
;
466 exa
->copy
.src_surface
=
467 exa
->scrn
->get_tex_surface( exa
->scrn
,
470 PIPE_BUFFER_USAGE_GPU_READ
);
472 exa
->copy
.dst_surface
=
473 exa
->scrn
->get_tex_surface( exa
->scrn
,
476 PIPE_BUFFER_USAGE_GPU_WRITE
);
479 exa
->copy
.use_surface_copy
= FALSE
;
481 if (exa
->copy
.dst
== exa
->copy
.src
)
482 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
483 exa
->copy
.src
->tex
);
485 pipe_texture_reference(&exa
->copy
.src_texture
,
488 exa
->copy
.dst_surface
=
489 exa
->scrn
->get_tex_surface(exa
->scrn
,
492 PIPE_BUFFER_USAGE_GPU_WRITE
);
495 renderer_copy_prepare(exa
->renderer
,
496 exa
->copy
.dst_surface
,
497 exa
->copy
.src_texture
);
505 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
506 int width
, int height
)
508 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
509 modesettingPtr ms
= modesettingPTR(pScrn
);
510 struct exa_context
*exa
= ms
->exa
;
511 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
514 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
515 srcX
, srcY
, dstX
, dstY
, width
, height
);
518 debug_assert(priv
== exa
->copy
.dst
);
521 if (exa
->copy
.use_surface_copy
) {
522 /* XXX: consider exposing >1 box in surface_copy interface.
524 exa
->pipe
->surface_copy( exa
->pipe
,
525 exa
->copy
.dst_surface
,
527 exa
->copy
.src_surface
,
532 renderer_copy_pixmap(exa
->renderer
,
536 exa
->copy
.src_texture
->width0
,
537 exa
->copy
.src_texture
->height0
);
542 ExaDoneCopy(PixmapPtr pPixmap
)
544 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
545 modesettingPtr ms
= modesettingPTR(pScrn
);
546 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
547 struct exa_context
*exa
= ms
->exa
;
552 renderer_draw_flush(exa
->renderer
);
554 exa
->copy
.src
= NULL
;
555 exa
->copy
.dst
= NULL
;
556 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
557 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
558 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
564 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
566 if (pSrc
->picture_format
== pSrcPicture
->format
)
569 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
572 /* pSrc->picture_format == PICT_a8r8g8b8 */
573 switch (pSrcPicture
->format
) {
578 /* just treat these two as x8... */
582 #ifdef PICT_TYPE_BGRA
585 return FALSE
; /* does not support swizzleing the alpha channel yet */
586 case PICT_a2r10g10b10
:
587 case PICT_x2r10g10b10
:
588 case PICT_a2b10g10r10
:
589 case PICT_x2b10g10r10
:
598 /***********************************************************************
599 * Composite entrypoints
603 ExaCheckComposite(int op
,
604 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
605 PicturePtr pDstPicture
)
607 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
608 modesettingPtr ms
= modesettingPTR(pScrn
);
609 struct exa_context
*exa
= ms
->exa
;
612 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
613 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
619 return xorg_composite_accelerated(op
,
627 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
628 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
629 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
631 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
632 modesettingPtr ms
= modesettingPTR(pScrn
);
633 struct exa_context
*exa
= ms
->exa
;
634 struct exa_pixmap_priv
*priv
;
640 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
641 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
642 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
643 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
644 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
645 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
648 XORG_FALLBACK("accle not enabled");
650 priv
= exaGetPixmapDriverPrivate(pDst
);
651 if (!priv
|| !priv
->tex
)
652 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
654 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
656 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
657 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
659 if (priv
->picture_format
!= pDstPicture
->format
)
660 XORG_FALLBACK("pDst pic_format: %s != %s",
661 render_format_name(priv
->picture_format
),
662 render_format_name(pDstPicture
->format
));
665 priv
= exaGetPixmapDriverPrivate(pSrc
);
666 if (!priv
|| !priv
->tex
)
667 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
669 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
671 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
672 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
674 if (!picture_check_formats(priv
, pSrcPicture
))
675 XORG_FALLBACK("pSrc pic_format: %s != %s",
676 render_format_name(priv
->picture_format
),
677 render_format_name(pSrcPicture
->format
));
682 priv
= exaGetPixmapDriverPrivate(pMask
);
683 if (!priv
|| !priv
->tex
)
684 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
686 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
688 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
689 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
691 if (!picture_check_formats(priv
, pMaskPicture
))
692 XORG_FALLBACK("pMask pic_format: %s != %s",
693 render_format_name(priv
->picture_format
),
694 render_format_name(pMaskPicture
->format
));
697 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
699 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
700 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
701 exaGetPixmapDriverPrivate(pDst
));
705 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
706 int dstX
, int dstY
, int width
, int height
)
708 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
709 modesettingPtr ms
= modesettingPTR(pScrn
);
710 struct exa_context
*exa
= ms
->exa
;
711 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
714 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
715 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
716 debug_printf("\t Num bound samplers = %d\n",
717 exa
->num_bound_samplers
);
720 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
721 dstX
, dstY
, width
, height
);
727 ExaDoneComposite(PixmapPtr pPixmap
)
729 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
730 modesettingPtr ms
= modesettingPTR(pScrn
);
731 struct exa_context
*exa
= ms
->exa
;
733 xorg_composite_done(exa
);
737 /***********************************************************************
742 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
744 struct exa_pixmap_priv
*priv
;
746 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
754 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
756 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
761 pipe_texture_reference(&priv
->tex
, NULL
);
767 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
769 struct exa_pixmap_priv
*priv
;
771 priv
= exaGetPixmapDriverPrivate(pPixmap
);
783 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
785 struct exa_pixmap_priv
*priv
;
786 priv
= exaGetPixmapDriverPrivate(pPixmap
);
789 FatalError("NO PIXMAP PRIVATE\n");
793 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
799 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
801 struct exa_pixmap_priv
*priv
;
802 priv
= exaGetPixmapDriverPrivate(pPixmap
);
805 FatalError("NO PIXMAP PRIVATE\n");
809 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
815 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
817 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
818 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
819 modesettingPtr ms
= modesettingPTR(pScrn
);
820 struct exa_pixmap_priv
*priv
;
825 FatalError("NO MS->EXA\n");
829 priv
= exaGetPixmapDriverPrivate(pPixmap
);
832 FatalError("NO PIXMAP PRIVATE\n");
836 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
838 *stride_out
= stride
;
844 size_match( int width
, int tex_width
)
846 #if ROUND_UP_TEXTURES
847 if (width
> tex_width
)
850 if (width
* 2 < tex_width
)
855 return width
== tex_width
;
860 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
861 int depth
, int bitsPerPixel
, int devKind
,
864 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
865 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
866 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
867 modesettingPtr ms
= modesettingPTR(pScrn
);
868 struct exa_context
*exa
= ms
->exa
;
870 if (!priv
|| pPixData
)
874 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
875 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
878 debug_printf(" ==> old texture %dx%d\n",
885 depth
= pPixmap
->drawable
.depth
;
887 if (bitsPerPixel
<= 0)
888 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
891 width
= pPixmap
->drawable
.width
;
894 height
= pPixmap
->drawable
.height
;
896 if (width
<= 0 || height
<= 0 || depth
<= 0)
899 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
900 bitsPerPixel
, devKind
, NULL
);
903 priv
->height
= height
;
905 /* Deal with screen resize */
906 if ((exa
->accel
|| priv
->flags
) &&
908 !size_match(width
, priv
->tex
->width0
) ||
909 !size_match(height
, priv
->tex
->height0
) ||
910 priv
->tex_flags
!= priv
->flags
)) {
911 struct pipe_texture
*texture
= NULL
;
912 struct pipe_texture
template;
914 memset(&template, 0, sizeof(template));
915 template.target
= PIPE_TEXTURE_2D
;
916 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
917 if (ROUND_UP_TEXTURES
&& priv
->flags
== 0) {
918 template.width0
= util_next_power_of_two(width
);
919 template.height0
= util_next_power_of_two(height
);
922 template.width0
= width
;
923 template.height0
= height
;
927 template.last_level
= 0;
928 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
929 priv
->tex_flags
= priv
->flags
;
930 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
933 struct pipe_surface
*dst_surf
;
934 struct pipe_surface
*src_surf
;
936 dst_surf
= exa
->scrn
->get_tex_surface(
937 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
938 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
939 if (exa
->pipe
->surface_copy
) {
940 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
941 0, 0, min(width
, texture
->width0
),
942 min(height
, texture
->height0
));
944 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
945 0, 0, min(width
, texture
->width0
),
946 min(height
, texture
->height0
));
948 exa
->scrn
->tex_surface_destroy(dst_surf
);
949 exa
->scrn
->tex_surface_destroy(src_surf
);
952 pipe_texture_reference(&priv
->tex
, texture
);
953 /* the texture we create has one reference */
954 pipe_texture_reference(&texture
, NULL
);
960 struct pipe_texture
*
961 xorg_exa_get_texture(PixmapPtr pPixmap
)
963 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
964 struct pipe_texture
*tex
= NULL
;
965 pipe_texture_reference(&tex
, priv
->tex
);
970 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
972 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
974 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
979 if (pPixmap
->drawable
.width
!= tex
->width0
||
980 pPixmap
->drawable
.height
!= tex
->height0
)
983 pipe_texture_reference(&priv
->tex
, tex
);
984 priv
->tex_flags
= tex
->tex_usage
& mask
;
989 struct pipe_texture
*
990 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
991 int width
, int height
,
992 int depth
, int bitsPerPixel
)
994 modesettingPtr ms
= modesettingPTR(pScrn
);
995 struct exa_context
*exa
= ms
->exa
;
996 struct pipe_texture
template;
999 memset(&template, 0, sizeof(template));
1000 template.target
= PIPE_TEXTURE_2D
;
1001 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
1002 template.width0
= width
;
1003 template.height0
= height
;
1004 template.depth0
= 1;
1005 template.last_level
= 0;
1006 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
1007 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
1008 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
1010 return exa
->scrn
->texture_create(exa
->scrn
, &template);
1014 xorg_exa_close(ScrnInfoPtr pScrn
)
1016 modesettingPtr ms
= modesettingPTR(pScrn
);
1017 struct exa_context
*exa
= ms
->exa
;
1019 renderer_destroy(exa
->renderer
);
1022 exa
->pipe
->destroy(exa
->pipe
);
1024 /* Since this was shared be proper with the pointer */
1027 exaDriverFini(pScrn
->pScreen
);
1033 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
1035 modesettingPtr ms
= modesettingPTR(pScrn
);
1036 struct exa_context
*exa
;
1039 exa
= xcalloc(1, sizeof(struct exa_context
));
1043 pExa
= exaDriverAlloc();
1048 memset(pExa
, 0, sizeof(*pExa
));
1050 pExa
->exa_major
= 2;
1051 pExa
->exa_minor
= 2;
1052 pExa
->memoryBase
= 0;
1053 pExa
->memorySize
= 0;
1054 pExa
->offScreenBase
= 0;
1055 pExa
->pixmapOffsetAlign
= 0;
1056 pExa
->pixmapPitchAlign
= 1;
1057 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
1058 #ifdef EXA_SUPPORTS_PREPARE_AUX
1059 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
1061 #ifdef EXA_MIXED_PIXMAPS
1062 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
1064 pExa
->maxX
= 8191; /* FIXME */
1065 pExa
->maxY
= 8191; /* FIXME */
1067 pExa
->WaitMarker
= ExaWaitMarker
;
1068 pExa
->MarkSync
= ExaMarkSync
;
1069 pExa
->PrepareSolid
= ExaPrepareSolid
;
1070 pExa
->Solid
= ExaSolid
;
1071 pExa
->DoneSolid
= ExaDoneSolid
;
1072 pExa
->PrepareCopy
= ExaPrepareCopy
;
1073 pExa
->Copy
= ExaCopy
;
1074 pExa
->DoneCopy
= ExaDoneCopy
;
1075 pExa
->CheckComposite
= ExaCheckComposite
;
1076 pExa
->PrepareComposite
= ExaPrepareComposite
;
1077 pExa
->Composite
= ExaComposite
;
1078 pExa
->DoneComposite
= ExaDoneComposite
;
1079 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1080 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1081 pExa
->UploadToScreen
= ExaUploadToScreen
;
1082 pExa
->PrepareAccess
= ExaPrepareAccess
;
1083 pExa
->FinishAccess
= ExaFinishAccess
;
1084 pExa
->CreatePixmap
= ExaCreatePixmap
;
1085 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1086 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1088 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1092 exa
->scrn
= ms
->screen
;
1093 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
1094 /* Share context with DRI */
1095 ms
->ctx
= exa
->pipe
;
1097 exa
->renderer
= renderer_create(exa
->pipe
);
1103 xorg_exa_close(pScrn
);
1108 struct pipe_surface
*
1109 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1111 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1112 PIPE_BUFFER_USAGE_GPU_READ
|
1113 PIPE_BUFFER_USAGE_GPU_WRITE
);
1117 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1118 struct pipe_fence_handle
**fence
)
1120 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1123 void xorg_exa_finish(struct exa_context
*exa
)
1125 struct pipe_fence_handle
*fence
= NULL
;
1127 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1129 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1130 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);