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"
45 #include "util/u_rect.h"
46 #include "util/u_math.h"
47 #include "util/u_debug.h"
48 #include "util/u_format.h"
49 #include "util/u_surface.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_B8G8R8A8_UNORM
;
123 *picture_format
= PICT_a8r8g8b8
;
127 *format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
128 *picture_format
= PICT_x8r8g8b8
;
132 *format
= PIPE_FORMAT_B5G6R5_UNORM
;
133 *picture_format
= PICT_r5g6b5
;
137 *format
= PIPE_FORMAT_B5G5R5A1_UNORM
;
138 *picture_format
= PICT_x1r5g5b5
;
142 *format
= PIPE_FORMAT_L8_UNORM
;
143 *picture_format
= PICT_a8
;
148 *format
= PIPE_FORMAT_B8G8R8A8_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 transfer
= pipe_get_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
193 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
198 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
199 x
, y
, w
, h
, dst_pitch
);
202 util_copy_rect((unsigned char*)dst
, priv
->tex
->format
, dst_pitch
, 0, 0,
203 w
, h
, exa
->pipe
->transfer_map(exa
->pipe
, transfer
),
204 transfer
->stride
, 0, 0);
206 exa
->pipe
->transfer_unmap(exa
->pipe
, transfer
);
207 exa
->pipe
->transfer_destroy(exa
->pipe
, transfer
);
213 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
216 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
217 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
218 modesettingPtr ms
= modesettingPTR(pScrn
);
219 struct exa_context
*exa
= ms
->exa
;
220 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
221 struct pipe_transfer
*transfer
;
223 if (!priv
|| !priv
->tex
)
226 transfer
= pipe_get_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
227 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
232 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
233 x
, y
, w
, h
, src_pitch
);
236 util_copy_rect(exa
->pipe
->transfer_map(exa
->pipe
, transfer
),
237 priv
->tex
->format
, transfer
->stride
, 0, 0, w
, h
,
238 (unsigned char*)src
, src_pitch
, 0, 0);
240 exa
->pipe
->transfer_unmap(exa
->pipe
, transfer
);
241 exa
->pipe
->transfer_destroy(exa
->pipe
, transfer
);
247 ExaPrepareAccess(PixmapPtr pPix
, int index
)
249 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
250 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
251 modesettingPtr ms
= modesettingPTR(pScrn
);
252 struct exa_context
*exa
= ms
->exa
;
253 struct exa_pixmap_priv
*priv
;
255 priv
= exaGetPixmapDriverPrivate(pPix
);
263 if (priv
->map_count
== 0)
265 assert(pPix
->drawable
.width
<= priv
->tex
->width0
);
266 assert(pPix
->drawable
.height
<= priv
->tex
->height0
);
269 pipe_get_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
270 #ifdef EXA_MIXED_PIXMAPS
271 PIPE_TRANSFER_MAP_DIRECTLY
|
273 PIPE_TRANSFER_READ_WRITE
,
275 pPix
->drawable
.width
,
276 pPix
->drawable
.height
);
277 if (!priv
->map_transfer
)
278 #ifdef EXA_MIXED_PIXMAPS
281 FatalError("failed to create transfer\n");
284 pPix
->devPrivate
.ptr
=
285 exa
->pipe
->transfer_map(exa
->pipe
, priv
->map_transfer
);
286 pPix
->devKind
= priv
->map_transfer
->stride
;
295 ExaFinishAccess(PixmapPtr pPix
, int index
)
297 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
298 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
299 modesettingPtr ms
= modesettingPTR(pScrn
);
300 struct exa_context
*exa
= ms
->exa
;
301 struct exa_pixmap_priv
*priv
;
302 priv
= exaGetPixmapDriverPrivate(pPix
);
307 if (!priv
->map_transfer
)
310 if (--priv
->map_count
== 0) {
311 assert(priv
->map_transfer
);
312 exa
->pipe
->transfer_unmap(exa
->pipe
, priv
->map_transfer
);
313 exa
->pipe
->transfer_destroy(exa
->pipe
, priv
->map_transfer
);
314 priv
->map_transfer
= NULL
;
315 pPix
->devPrivate
.ptr
= NULL
;
319 /***********************************************************************
324 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
326 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
327 modesettingPtr ms
= modesettingPTR(pScrn
);
328 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
329 struct exa_context
*exa
= ms
->exa
;
332 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
338 XORG_FALLBACK("accle not enabled");
340 if (!priv
|| !priv
->tex
)
341 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
343 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
344 XORG_FALLBACK("planeMask is not solid");
347 XORG_FALLBACK("not GXcopy");
349 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
351 PIPE_BIND_RENDER_TARGET
, 0)) {
352 XORG_FALLBACK("format %s", util_format_name(priv
->tex
->format
));
355 return xorg_solid_bind_state(exa
, priv
, fg
);
359 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
361 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
362 modesettingPtr ms
= modesettingPTR(pScrn
);
363 struct exa_context
*exa
= ms
->exa
;
364 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
367 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
370 if (x0
== 0 && y0
== 0 &&
371 x1
== pPixmap
->drawable
.width
&& y1
== pPixmap
->drawable
.height
) {
372 exa
->pipe
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
, exa
->solid_color
, 0.0, 0);
376 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
381 ExaDoneSolid(PixmapPtr pPixmap
)
383 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
384 modesettingPtr ms
= modesettingPTR(pScrn
);
385 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
386 struct exa_context
*exa
= ms
->exa
;
391 xorg_composite_done(exa
);
394 /***********************************************************************
399 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
400 int ydir
, int alu
, Pixel planeMask
)
402 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
403 modesettingPtr ms
= modesettingPTR(pScrn
);
404 struct exa_context
*exa
= ms
->exa
;
405 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
406 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
409 debug_printf("ExaPrepareCopy\n");
416 XORG_FALLBACK("accle not enabled");
418 if (!priv
|| !priv
->tex
)
419 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
421 if (!src_priv
|| !src_priv
->tex
)
422 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
424 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
425 XORG_FALLBACK("planeMask is not solid");
428 XORG_FALLBACK("alu not GXcopy");
430 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
432 PIPE_BIND_RENDER_TARGET
, 0))
433 XORG_FALLBACK("pDst format %s", util_format_name(priv
->tex
->format
));
435 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
436 src_priv
->tex
->target
,
437 PIPE_BIND_SAMPLER_VIEW
, 0))
438 XORG_FALLBACK("pSrc format %s", util_format_name(src_priv
->tex
->format
));
440 exa
->copy
.src
= src_priv
;
441 exa
->copy
.dst
= priv
;
443 /* For same-surface copies, the pipe->surface_copy path is clearly
444 * superior, providing it is implemented. In other cases it's not
445 * clear what the better path would be, and eventually we'd
446 * probably want to gather timings and choose dynamically.
448 if (exa
->pipe
->surface_copy
&&
449 exa
->copy
.src
== exa
->copy
.dst
) {
451 exa
->copy
.use_surface_copy
= TRUE
;
453 exa
->copy
.src_surface
=
454 exa
->scrn
->get_tex_surface( exa
->scrn
,
457 PIPE_BIND_BLIT_SOURCE
);
459 exa
->copy
.dst_surface
=
460 exa
->scrn
->get_tex_surface( exa
->scrn
,
463 PIPE_BIND_BLIT_DESTINATION
);
466 exa
->copy
.use_surface_copy
= FALSE
;
468 if (exa
->copy
.dst
== exa
->copy
.src
)
469 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
470 exa
->copy
.src
->tex
);
472 pipe_resource_reference(&exa
->copy
.src_texture
,
475 exa
->copy
.dst_surface
=
476 exa
->scrn
->get_tex_surface(exa
->scrn
,
479 PIPE_BIND_BLIT_DESTINATION
);
482 renderer_copy_prepare(exa
->renderer
,
483 exa
->copy
.dst_surface
,
484 exa
->copy
.src_texture
);
492 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
493 int width
, int height
)
495 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
496 modesettingPtr ms
= modesettingPTR(pScrn
);
497 struct exa_context
*exa
= ms
->exa
;
498 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
501 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
502 srcX
, srcY
, dstX
, dstY
, width
, height
);
505 debug_assert(priv
== exa
->copy
.dst
);
508 if (exa
->copy
.use_surface_copy
) {
509 /* XXX: consider exposing >1 box in surface_copy interface.
511 exa
->pipe
->surface_copy( exa
->pipe
,
512 exa
->copy
.dst_surface
,
514 exa
->copy
.src_surface
,
519 renderer_copy_pixmap(exa
->renderer
,
523 exa
->copy
.src_texture
->width0
,
524 exa
->copy
.src_texture
->height0
);
529 ExaDoneCopy(PixmapPtr pPixmap
)
531 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
532 modesettingPtr ms
= modesettingPTR(pScrn
);
533 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
534 struct exa_context
*exa
= ms
->exa
;
539 renderer_draw_flush(exa
->renderer
);
541 exa
->copy
.src
= NULL
;
542 exa
->copy
.dst
= NULL
;
543 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
544 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
545 pipe_resource_reference(&exa
->copy
.src_texture
, NULL
);
551 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
553 if (pSrc
->picture_format
== pSrcPicture
->format
)
556 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
559 /* pSrc->picture_format == PICT_a8r8g8b8 */
560 switch (pSrcPicture
->format
) {
565 /* just treat these two as x8... */
569 #ifdef PICT_TYPE_BGRA
572 return FALSE
; /* does not support swizzleing the alpha channel yet */
573 case PICT_a2r10g10b10
:
574 case PICT_x2r10g10b10
:
575 case PICT_a2b10g10r10
:
576 case PICT_x2b10g10r10
:
585 /***********************************************************************
586 * Composite entrypoints
590 ExaCheckComposite(int op
,
591 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
592 PicturePtr pDstPicture
)
594 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
595 modesettingPtr ms
= modesettingPTR(pScrn
);
596 struct exa_context
*exa
= ms
->exa
;
599 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
600 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
606 return xorg_composite_accelerated(op
,
614 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
615 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
616 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
618 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
619 modesettingPtr ms
= modesettingPTR(pScrn
);
620 struct exa_context
*exa
= ms
->exa
;
621 struct exa_pixmap_priv
*priv
;
627 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
628 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
629 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
630 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
631 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
632 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
635 XORG_FALLBACK("accle not enabled");
637 priv
= exaGetPixmapDriverPrivate(pDst
);
638 if (!priv
|| !priv
->tex
)
639 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
641 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
643 PIPE_BIND_RENDER_TARGET
, 0))
644 XORG_FALLBACK("pDst format: %s", util_format_name(priv
->tex
->format
));
646 if (priv
->picture_format
!= pDstPicture
->format
)
647 XORG_FALLBACK("pDst pic_format: %s != %s",
648 render_format_name(priv
->picture_format
),
649 render_format_name(pDstPicture
->format
));
652 priv
= exaGetPixmapDriverPrivate(pSrc
);
653 if (!priv
|| !priv
->tex
)
654 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
656 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
658 PIPE_BIND_SAMPLER_VIEW
, 0))
659 XORG_FALLBACK("pSrc format: %s", util_format_name(priv
->tex
->format
));
661 if (!picture_check_formats(priv
, pSrcPicture
))
662 XORG_FALLBACK("pSrc pic_format: %s != %s",
663 render_format_name(priv
->picture_format
),
664 render_format_name(pSrcPicture
->format
));
669 priv
= exaGetPixmapDriverPrivate(pMask
);
670 if (!priv
|| !priv
->tex
)
671 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
673 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
675 PIPE_BIND_SAMPLER_VIEW
, 0))
676 XORG_FALLBACK("pMask format: %s", util_format_name(priv
->tex
->format
));
678 if (!picture_check_formats(priv
, pMaskPicture
))
679 XORG_FALLBACK("pMask pic_format: %s != %s",
680 render_format_name(priv
->picture_format
),
681 render_format_name(pMaskPicture
->format
));
684 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
686 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
687 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
688 exaGetPixmapDriverPrivate(pDst
));
692 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
693 int dstX
, int dstY
, int width
, int height
)
695 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
696 modesettingPtr ms
= modesettingPTR(pScrn
);
697 struct exa_context
*exa
= ms
->exa
;
698 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
701 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
702 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
703 debug_printf("\t Num bound samplers = %d\n",
704 exa
->num_bound_samplers
);
707 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
708 dstX
, dstY
, width
, height
);
714 ExaDoneComposite(PixmapPtr pPixmap
)
716 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
717 modesettingPtr ms
= modesettingPTR(pScrn
);
718 struct exa_context
*exa
= ms
->exa
;
720 xorg_composite_done(exa
);
724 /***********************************************************************
729 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
731 struct exa_pixmap_priv
*priv
;
733 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
741 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
743 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
748 pipe_resource_reference(&priv
->tex
, NULL
);
754 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
756 struct exa_pixmap_priv
*priv
;
758 priv
= exaGetPixmapDriverPrivate(pPixmap
);
770 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
772 struct exa_pixmap_priv
*priv
;
773 priv
= exaGetPixmapDriverPrivate(pPixmap
);
776 FatalError("NO PIXMAP PRIVATE\n");
780 priv
->flags
|= PIPE_BIND_SCANOUT
;
786 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
788 struct exa_pixmap_priv
*priv
;
789 priv
= exaGetPixmapDriverPrivate(pPixmap
);
792 FatalError("NO PIXMAP PRIVATE\n");
796 priv
->flags
|= PIPE_BIND_SHARED
;
804 size_match( int width
, int tex_width
)
806 #if ROUND_UP_TEXTURES
807 if (width
> tex_width
)
810 if (width
* 2 < tex_width
)
815 return width
== tex_width
;
820 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
821 int depth
, int bitsPerPixel
, int devKind
,
824 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
825 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
826 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
827 modesettingPtr ms
= modesettingPTR(pScrn
);
828 struct exa_context
*exa
= ms
->exa
;
830 if (!priv
|| pPixData
)
834 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
835 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
838 debug_printf(" ==> old texture %dx%d\n",
845 depth
= pPixmap
->drawable
.depth
;
847 if (bitsPerPixel
<= 0)
848 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
851 width
= pPixmap
->drawable
.width
;
854 height
= pPixmap
->drawable
.height
;
856 if (width
<= 0 || height
<= 0 || depth
<= 0)
859 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
860 bitsPerPixel
, devKind
, NULL
);
863 priv
->height
= height
;
865 /* Deal with screen resize */
866 if ((exa
->accel
|| priv
->flags
) &&
868 !size_match(width
, priv
->tex
->width0
) ||
869 !size_match(height
, priv
->tex
->height0
) ||
870 priv
->tex_flags
!= priv
->flags
)) {
871 struct pipe_resource
*texture
= NULL
;
872 struct pipe_resource
template;
874 memset(&template, 0, sizeof(template));
875 template.target
= PIPE_TEXTURE_2D
;
876 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
877 if (ROUND_UP_TEXTURES
&& priv
->flags
== 0) {
878 template.width0
= util_next_power_of_two(width
);
879 template.height0
= util_next_power_of_two(height
);
882 template.width0
= width
;
883 template.height0
= height
;
887 template.last_level
= 0;
888 template.bind
= PIPE_BIND_RENDER_TARGET
| priv
->flags
;
889 priv
->tex_flags
= priv
->flags
;
890 texture
= exa
->scrn
->resource_create(exa
->scrn
, &template);
893 struct pipe_surface
*dst_surf
;
894 struct pipe_surface
*src_surf
;
896 dst_surf
= exa
->scrn
->get_tex_surface(
897 exa
->scrn
, texture
, 0, 0, 0, PIPE_BIND_BLIT_DESTINATION
);
898 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
899 if (exa
->pipe
->surface_copy
) {
900 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
901 0, 0, min(width
, texture
->width0
),
902 min(height
, texture
->height0
));
904 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
905 0, 0, min(width
, texture
->width0
),
906 min(height
, texture
->height0
));
908 exa
->scrn
->tex_surface_destroy(dst_surf
);
909 exa
->scrn
->tex_surface_destroy(src_surf
);
912 pipe_resource_reference(&priv
->tex
, texture
);
913 /* the texture we create has one reference */
914 pipe_resource_reference(&texture
, NULL
);
920 struct pipe_resource
*
921 xorg_exa_get_texture(PixmapPtr pPixmap
)
923 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
924 struct pipe_resource
*tex
= NULL
;
925 pipe_resource_reference(&tex
, priv
->tex
);
930 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_resource
*tex
)
932 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
934 int mask
= PIPE_BIND_SHARED
| PIPE_BIND_SCANOUT
;
939 if (pPixmap
->drawable
.width
!= tex
->width0
||
940 pPixmap
->drawable
.height
!= tex
->height0
)
943 pipe_resource_reference(&priv
->tex
, tex
);
944 priv
->tex_flags
= tex
->bind
& mask
;
949 struct pipe_resource
*
950 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
951 int width
, int height
,
952 int depth
, int bitsPerPixel
)
954 modesettingPtr ms
= modesettingPTR(pScrn
);
955 struct exa_context
*exa
= ms
->exa
;
956 struct pipe_resource
template;
959 memset(&template, 0, sizeof(template));
960 template.target
= PIPE_TEXTURE_2D
;
961 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
962 template.width0
= width
;
963 template.height0
= height
;
965 template.last_level
= 0;
966 template.bind
|= PIPE_BIND_RENDER_TARGET
;
967 template.bind
|= PIPE_BIND_SCANOUT
;
968 template.bind
|= PIPE_BIND_SHARED
;
970 return exa
->scrn
->resource_create(exa
->scrn
, &template);
974 xorg_exa_close(ScrnInfoPtr pScrn
)
976 modesettingPtr ms
= modesettingPTR(pScrn
);
977 struct exa_context
*exa
= ms
->exa
;
979 pipe_sampler_view_reference(&exa
->bound_sampler_views
[0], NULL
);
980 pipe_sampler_view_reference(&exa
->bound_sampler_views
[1], NULL
);
982 renderer_destroy(exa
->renderer
);
985 exa
->pipe
->destroy(exa
->pipe
);
987 /* Since this was shared be proper with the pointer */
990 exaDriverFini(pScrn
->pScreen
);
996 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
998 modesettingPtr ms
= modesettingPTR(pScrn
);
999 struct exa_context
*exa
;
1002 exa
= xcalloc(1, sizeof(struct exa_context
));
1006 pExa
= exaDriverAlloc();
1011 memset(pExa
, 0, sizeof(*pExa
));
1013 pExa
->exa_major
= 2;
1014 pExa
->exa_minor
= 2;
1015 pExa
->memoryBase
= 0;
1016 pExa
->memorySize
= 0;
1017 pExa
->offScreenBase
= 0;
1018 pExa
->pixmapOffsetAlign
= 0;
1019 pExa
->pixmapPitchAlign
= 1;
1020 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
1021 #ifdef EXA_SUPPORTS_PREPARE_AUX
1022 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
1024 #ifdef EXA_MIXED_PIXMAPS
1025 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
1027 pExa
->maxX
= 8191; /* FIXME */
1028 pExa
->maxY
= 8191; /* FIXME */
1030 pExa
->WaitMarker
= ExaWaitMarker
;
1031 pExa
->MarkSync
= ExaMarkSync
;
1032 pExa
->PrepareSolid
= ExaPrepareSolid
;
1033 pExa
->Solid
= ExaSolid
;
1034 pExa
->DoneSolid
= ExaDoneSolid
;
1035 pExa
->PrepareCopy
= ExaPrepareCopy
;
1036 pExa
->Copy
= ExaCopy
;
1037 pExa
->DoneCopy
= ExaDoneCopy
;
1038 pExa
->CheckComposite
= ExaCheckComposite
;
1039 pExa
->PrepareComposite
= ExaPrepareComposite
;
1040 pExa
->Composite
= ExaComposite
;
1041 pExa
->DoneComposite
= ExaDoneComposite
;
1042 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1043 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1044 pExa
->UploadToScreen
= ExaUploadToScreen
;
1045 pExa
->PrepareAccess
= ExaPrepareAccess
;
1046 pExa
->FinishAccess
= ExaFinishAccess
;
1047 pExa
->CreatePixmap
= ExaCreatePixmap
;
1048 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1049 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1051 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1055 exa
->scrn
= ms
->screen
;
1056 exa
->pipe
= exa
->scrn
->context_create(exa
->scrn
, NULL
);
1057 if (exa
->pipe
== NULL
)
1060 /* Share context with DRI */
1061 ms
->ctx
= exa
->pipe
;
1063 exa
->renderer
= renderer_create(exa
->pipe
);
1069 xorg_exa_close(pScrn
);
1074 struct pipe_surface
*
1075 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1078 /* seems to get called both for blits and render target usage */
1079 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1080 PIPE_BIND_BLIT_SOURCE
|
1081 PIPE_BIND_BLIT_DESTINATION
|
1082 PIPE_BIND_RENDER_TARGET
);
1086 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1087 struct pipe_fence_handle
**fence
)
1089 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1092 void xorg_exa_finish(struct exa_context
*exa
)
1094 struct pipe_fence_handle
*fence
= NULL
;
1096 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1098 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1099 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);