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"
51 #define ROUND_UP_TEXTURES 1
56 struct render_format_str
{
60 static const struct render_format_str formats_info
[] =
62 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
63 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
64 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
65 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
67 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
68 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
69 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
70 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
71 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
72 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
74 {PICT_r8g8b8
, "PICT_r8g8b8"},
75 {PICT_b8g8r8
, "PICT_b8g8r8"},
76 {PICT_r5g6b5
, "PICT_r5g6b5"},
77 {PICT_b5g6r5
, "PICT_b5g6r5"},
78 {PICT_a1r5g5b5
, "PICT_a1r5g5b5"},
79 {PICT_x1r5g5b5
, "PICT_x1r5g5b5"},
80 {PICT_a1b5g5r5
, "PICT_a1b5g5r5"},
81 {PICT_x1b5g5r5
, "PICT_x1b5g5r5"},
82 {PICT_a4r4g4b4
, "PICT_a4r4g4b4"},
83 {PICT_x4r4g4b4
, "PICT_x4r4g4b4"},
84 {PICT_a4b4g4r4
, "PICT_a4b4g4r4"},
85 {PICT_x4b4g4r4
, "PICT_x4b4g4r4"},
87 {PICT_r3g3b2
, "PICT_r3g3b2"},
88 {PICT_b2g3r3
, "PICT_b2g3r3"},
89 {PICT_a2r2g2b2
, "PICT_a2r2g2b2"},
90 {PICT_a2b2g2r2
, "PICT_a2b2g2r2"},
93 {PICT_x4a4
, "PICT_x4a4"},
94 {PICT_x4c4
, "PICT_x4c4"},
95 {PICT_x4g4
, "PICT_x4g4"},
97 {PICT_r1g2b1
, "PICT_r1g2b1"},
98 {PICT_b1g2r1
, "PICT_b1g2r1"},
99 {PICT_a1r1g1b1
, "PICT_a1r1g1b1"},
100 {PICT_a1b1g1r1
, "PICT_a1b1g1r1"},
101 {PICT_c4
, "PICT_c4"},
102 {PICT_g4
, "PICT_g4"},
103 {PICT_a1
, "PICT_a1"},
106 static const char *render_format_name(int format
)
109 for (i
= 0; i
< sizeof(formats_info
)/sizeof(formats_info
[0]); ++i
) {
110 if (formats_info
[i
].format
== format
)
111 return formats_info
[i
].name
;
117 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
, int *picture_format
)
121 *format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
122 *picture_format
= PICT_a8r8g8b8
;
126 *format
= PIPE_FORMAT_B8G8R8X8_UNORM
;
127 *picture_format
= PICT_x8r8g8b8
;
131 *format
= PIPE_FORMAT_B5G6R5_UNORM
;
132 *picture_format
= PICT_r5g6b5
;
136 *format
= PIPE_FORMAT_B5G5R5A1_UNORM
;
137 *picture_format
= PICT_x1r5g5b5
;
141 *format
= PIPE_FORMAT_L8_UNORM
;
142 *picture_format
= PICT_a8
;
147 *format
= PIPE_FORMAT_B8G8R8A8_UNORM
; /* bad bad bad */
157 * Static exported EXA functions
161 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
163 /* Nothing to do, handled in the PrepareAccess hook */
167 ExaMarkSync(ScreenPtr pScreen
)
173 /***********************************************************************
174 * Screen upload/download
178 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
181 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
182 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
183 modesettingPtr ms
= modesettingPTR(pScrn
);
184 struct exa_context
*exa
= ms
->exa
;
185 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
186 struct pipe_transfer
*transfer
;
188 if (!priv
|| !priv
->tex
)
191 transfer
= exa
->pipe
->get_tex_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
192 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
197 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
198 x
, y
, w
, h
, dst_pitch
);
201 util_copy_rect((unsigned char*)dst
, priv
->tex
->format
, dst_pitch
, 0, 0,
202 w
, h
, exa
->pipe
->transfer_map(exa
->pipe
, transfer
),
203 transfer
->stride
, 0, 0);
205 exa
->pipe
->transfer_unmap(exa
->pipe
, transfer
);
206 exa
->pipe
->tex_transfer_destroy(exa
->pipe
, transfer
);
212 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
215 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
216 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
217 modesettingPtr ms
= modesettingPTR(pScrn
);
218 struct exa_context
*exa
= ms
->exa
;
219 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
220 struct pipe_transfer
*transfer
;
222 if (!priv
|| !priv
->tex
)
225 transfer
= exa
->pipe
->get_tex_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
226 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
231 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
232 x
, y
, w
, h
, src_pitch
);
235 util_copy_rect(exa
->pipe
->transfer_map(exa
->pipe
, transfer
),
236 priv
->tex
->format
, transfer
->stride
, 0, 0, w
, h
,
237 (unsigned char*)src
, src_pitch
, 0, 0);
239 exa
->pipe
->transfer_unmap(exa
->pipe
, transfer
);
240 exa
->pipe
->tex_transfer_destroy(exa
->pipe
, transfer
);
246 ExaPrepareAccess(PixmapPtr pPix
, int index
)
248 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
249 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
250 modesettingPtr ms
= modesettingPTR(pScrn
);
251 struct exa_context
*exa
= ms
->exa
;
252 struct exa_pixmap_priv
*priv
;
254 priv
= exaGetPixmapDriverPrivate(pPix
);
262 if (priv
->map_count
== 0)
264 assert(pPix
->drawable
.width
<= priv
->tex
->width0
);
265 assert(pPix
->drawable
.height
<= priv
->tex
->height0
);
268 exa
->pipe
->get_tex_transfer(exa
->pipe
, priv
->tex
, 0, 0, 0,
269 #ifdef EXA_MIXED_PIXMAPS
270 PIPE_TRANSFER_MAP_DIRECTLY
|
272 PIPE_TRANSFER_READ_WRITE
,
274 pPix
->drawable
.width
,
275 pPix
->drawable
.height
);
276 if (!priv
->map_transfer
)
277 #ifdef EXA_MIXED_PIXMAPS
280 FatalError("failed to create transfer\n");
283 pPix
->devPrivate
.ptr
=
284 exa
->pipe
->transfer_map(exa
->pipe
, priv
->map_transfer
);
285 pPix
->devKind
= priv
->map_transfer
->stride
;
294 ExaFinishAccess(PixmapPtr pPix
, int index
)
296 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
297 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
298 modesettingPtr ms
= modesettingPTR(pScrn
);
299 struct exa_context
*exa
= ms
->exa
;
300 struct exa_pixmap_priv
*priv
;
301 priv
= exaGetPixmapDriverPrivate(pPix
);
306 if (!priv
->map_transfer
)
309 if (--priv
->map_count
== 0) {
310 assert(priv
->map_transfer
);
311 exa
->pipe
->transfer_unmap(exa
->pipe
, priv
->map_transfer
);
312 exa
->pipe
->tex_transfer_destroy(exa
->pipe
, priv
->map_transfer
);
313 priv
->map_transfer
= NULL
;
314 pPix
->devPrivate
.ptr
= NULL
;
318 /***********************************************************************
323 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
325 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
326 modesettingPtr ms
= modesettingPTR(pScrn
);
327 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
328 struct exa_context
*exa
= ms
->exa
;
331 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
337 XORG_FALLBACK("accle not enabled");
339 if (!priv
|| !priv
->tex
)
340 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
342 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
343 XORG_FALLBACK("planeMask is not solid");
346 XORG_FALLBACK("not GXcopy");
348 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
350 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
351 XORG_FALLBACK("format %s", util_format_name(priv
->tex
->format
));
354 return xorg_solid_bind_state(exa
, priv
, fg
);
358 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
360 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
361 modesettingPtr ms
= modesettingPTR(pScrn
);
362 struct exa_context
*exa
= ms
->exa
;
363 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
366 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
369 if (x0
== 0 && y0
== 0 &&
370 x1
== pPixmap
->drawable
.width
&& y1
== pPixmap
->drawable
.height
) {
371 exa
->pipe
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
, exa
->solid_color
, 0.0, 0);
375 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
380 ExaDoneSolid(PixmapPtr pPixmap
)
382 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
383 modesettingPtr ms
= modesettingPTR(pScrn
);
384 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
385 struct exa_context
*exa
= ms
->exa
;
390 xorg_composite_done(exa
);
393 /***********************************************************************
398 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
399 int ydir
, int alu
, Pixel planeMask
)
401 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
402 modesettingPtr ms
= modesettingPTR(pScrn
);
403 struct exa_context
*exa
= ms
->exa
;
404 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
405 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
408 debug_printf("ExaPrepareCopy\n");
415 XORG_FALLBACK("accle not enabled");
417 if (!priv
|| !priv
->tex
)
418 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
420 if (!src_priv
|| !src_priv
->tex
)
421 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
423 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
424 XORG_FALLBACK("planeMask is not solid");
427 XORG_FALLBACK("alu not GXcopy");
429 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
431 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
432 XORG_FALLBACK("pDst format %s", util_format_name(priv
->tex
->format
));
434 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
435 src_priv
->tex
->target
,
436 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
437 XORG_FALLBACK("pSrc format %s", util_format_name(src_priv
->tex
->format
));
439 exa
->copy
.src
= src_priv
;
440 exa
->copy
.dst
= priv
;
442 /* For same-surface copies, the pipe->surface_copy path is clearly
443 * superior, providing it is implemented. In other cases it's not
444 * clear what the better path would be, and eventually we'd
445 * probably want to gather timings and choose dynamically.
447 if (exa
->pipe
->surface_copy
&&
448 exa
->copy
.src
== exa
->copy
.dst
) {
450 exa
->copy
.use_surface_copy
= TRUE
;
452 exa
->copy
.src_surface
=
453 exa
->scrn
->get_tex_surface( exa
->scrn
,
456 PIPE_BUFFER_USAGE_GPU_READ
);
458 exa
->copy
.dst_surface
=
459 exa
->scrn
->get_tex_surface( exa
->scrn
,
462 PIPE_BUFFER_USAGE_GPU_WRITE
);
465 exa
->copy
.use_surface_copy
= FALSE
;
467 if (exa
->copy
.dst
== exa
->copy
.src
)
468 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
469 exa
->copy
.src
->tex
);
471 pipe_texture_reference(&exa
->copy
.src_texture
,
474 exa
->copy
.dst_surface
=
475 exa
->scrn
->get_tex_surface(exa
->scrn
,
478 PIPE_BUFFER_USAGE_GPU_WRITE
);
481 renderer_copy_prepare(exa
->renderer
,
482 exa
->copy
.dst_surface
,
483 exa
->copy
.src_texture
);
491 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
492 int width
, int height
)
494 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
495 modesettingPtr ms
= modesettingPTR(pScrn
);
496 struct exa_context
*exa
= ms
->exa
;
497 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
500 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
501 srcX
, srcY
, dstX
, dstY
, width
, height
);
504 debug_assert(priv
== exa
->copy
.dst
);
507 if (exa
->copy
.use_surface_copy
) {
508 /* XXX: consider exposing >1 box in surface_copy interface.
510 exa
->pipe
->surface_copy( exa
->pipe
,
511 exa
->copy
.dst_surface
,
513 exa
->copy
.src_surface
,
518 renderer_copy_pixmap(exa
->renderer
,
522 exa
->copy
.src_texture
->width0
,
523 exa
->copy
.src_texture
->height0
);
528 ExaDoneCopy(PixmapPtr pPixmap
)
530 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
531 modesettingPtr ms
= modesettingPTR(pScrn
);
532 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
533 struct exa_context
*exa
= ms
->exa
;
538 renderer_draw_flush(exa
->renderer
);
540 exa
->copy
.src
= NULL
;
541 exa
->copy
.dst
= NULL
;
542 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
543 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
544 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
550 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
552 if (pSrc
->picture_format
== pSrcPicture
->format
)
555 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
558 /* pSrc->picture_format == PICT_a8r8g8b8 */
559 switch (pSrcPicture
->format
) {
564 /* just treat these two as x8... */
568 #ifdef PICT_TYPE_BGRA
571 return FALSE
; /* does not support swizzleing the alpha channel yet */
572 case PICT_a2r10g10b10
:
573 case PICT_x2r10g10b10
:
574 case PICT_a2b10g10r10
:
575 case PICT_x2b10g10r10
:
584 /***********************************************************************
585 * Composite entrypoints
589 ExaCheckComposite(int op
,
590 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
591 PicturePtr pDstPicture
)
593 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
594 modesettingPtr ms
= modesettingPTR(pScrn
);
595 struct exa_context
*exa
= ms
->exa
;
598 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
599 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
605 return xorg_composite_accelerated(op
,
613 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
614 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
615 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
617 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
618 modesettingPtr ms
= modesettingPTR(pScrn
);
619 struct exa_context
*exa
= ms
->exa
;
620 struct exa_pixmap_priv
*priv
;
626 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
627 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
628 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
629 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
630 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
631 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
634 XORG_FALLBACK("accle not enabled");
636 priv
= exaGetPixmapDriverPrivate(pDst
);
637 if (!priv
|| !priv
->tex
)
638 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
640 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
642 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
643 XORG_FALLBACK("pDst format: %s", util_format_name(priv
->tex
->format
));
645 if (priv
->picture_format
!= pDstPicture
->format
)
646 XORG_FALLBACK("pDst pic_format: %s != %s",
647 render_format_name(priv
->picture_format
),
648 render_format_name(pDstPicture
->format
));
651 priv
= exaGetPixmapDriverPrivate(pSrc
);
652 if (!priv
|| !priv
->tex
)
653 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
655 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
657 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
658 XORG_FALLBACK("pSrc format: %s", util_format_name(priv
->tex
->format
));
660 if (!picture_check_formats(priv
, pSrcPicture
))
661 XORG_FALLBACK("pSrc pic_format: %s != %s",
662 render_format_name(priv
->picture_format
),
663 render_format_name(pSrcPicture
->format
));
668 priv
= exaGetPixmapDriverPrivate(pMask
);
669 if (!priv
|| !priv
->tex
)
670 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
672 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
674 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
675 XORG_FALLBACK("pMask format: %s", util_format_name(priv
->tex
->format
));
677 if (!picture_check_formats(priv
, pMaskPicture
))
678 XORG_FALLBACK("pMask pic_format: %s != %s",
679 render_format_name(priv
->picture_format
),
680 render_format_name(pMaskPicture
->format
));
683 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
685 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
686 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
687 exaGetPixmapDriverPrivate(pDst
));
691 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
692 int dstX
, int dstY
, int width
, int height
)
694 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
695 modesettingPtr ms
= modesettingPTR(pScrn
);
696 struct exa_context
*exa
= ms
->exa
;
697 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
700 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
701 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
702 debug_printf("\t Num bound samplers = %d\n",
703 exa
->num_bound_samplers
);
706 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
707 dstX
, dstY
, width
, height
);
713 ExaDoneComposite(PixmapPtr pPixmap
)
715 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
716 modesettingPtr ms
= modesettingPTR(pScrn
);
717 struct exa_context
*exa
= ms
->exa
;
719 xorg_composite_done(exa
);
723 /***********************************************************************
728 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
730 struct exa_pixmap_priv
*priv
;
732 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
740 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
742 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
747 pipe_texture_reference(&priv
->tex
, NULL
);
753 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
755 struct exa_pixmap_priv
*priv
;
757 priv
= exaGetPixmapDriverPrivate(pPixmap
);
769 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
771 struct exa_pixmap_priv
*priv
;
772 priv
= exaGetPixmapDriverPrivate(pPixmap
);
775 FatalError("NO PIXMAP PRIVATE\n");
779 priv
->flags
|= PIPE_TEXTURE_USAGE_SCANOUT
;
785 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
787 struct exa_pixmap_priv
*priv
;
788 priv
= exaGetPixmapDriverPrivate(pPixmap
);
791 FatalError("NO PIXMAP PRIVATE\n");
795 priv
->flags
|= PIPE_TEXTURE_USAGE_SHARED
;
803 size_match( int width
, int tex_width
)
805 #if ROUND_UP_TEXTURES
806 if (width
> tex_width
)
809 if (width
* 2 < tex_width
)
814 return width
== tex_width
;
819 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
820 int depth
, int bitsPerPixel
, int devKind
,
823 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
824 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
825 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
826 modesettingPtr ms
= modesettingPTR(pScrn
);
827 struct exa_context
*exa
= ms
->exa
;
829 if (!priv
|| pPixData
)
833 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
834 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
837 debug_printf(" ==> old texture %dx%d\n",
844 depth
= pPixmap
->drawable
.depth
;
846 if (bitsPerPixel
<= 0)
847 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
850 width
= pPixmap
->drawable
.width
;
853 height
= pPixmap
->drawable
.height
;
855 if (width
<= 0 || height
<= 0 || depth
<= 0)
858 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
859 bitsPerPixel
, devKind
, NULL
);
862 priv
->height
= height
;
864 /* Deal with screen resize */
865 if ((exa
->accel
|| priv
->flags
) &&
867 !size_match(width
, priv
->tex
->width0
) ||
868 !size_match(height
, priv
->tex
->height0
) ||
869 priv
->tex_flags
!= priv
->flags
)) {
870 struct pipe_texture
*texture
= NULL
;
871 struct pipe_texture
template;
873 memset(&template, 0, sizeof(template));
874 template.target
= PIPE_TEXTURE_2D
;
875 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
876 if (ROUND_UP_TEXTURES
&& priv
->flags
== 0) {
877 template.width0
= util_next_power_of_two(width
);
878 template.height0
= util_next_power_of_two(height
);
881 template.width0
= width
;
882 template.height0
= height
;
886 template.last_level
= 0;
887 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
888 priv
->tex_flags
= priv
->flags
;
889 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
892 struct pipe_surface
*dst_surf
;
893 struct pipe_surface
*src_surf
;
895 dst_surf
= exa
->scrn
->get_tex_surface(
896 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
897 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
898 if (exa
->pipe
->surface_copy
) {
899 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
900 0, 0, min(width
, texture
->width0
),
901 min(height
, texture
->height0
));
903 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
904 0, 0, min(width
, texture
->width0
),
905 min(height
, texture
->height0
));
907 exa
->scrn
->tex_surface_destroy(dst_surf
);
908 exa
->scrn
->tex_surface_destroy(src_surf
);
911 pipe_texture_reference(&priv
->tex
, texture
);
912 /* the texture we create has one reference */
913 pipe_texture_reference(&texture
, NULL
);
919 struct pipe_texture
*
920 xorg_exa_get_texture(PixmapPtr pPixmap
)
922 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
923 struct pipe_texture
*tex
= NULL
;
924 pipe_texture_reference(&tex
, priv
->tex
);
929 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
931 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
933 int mask
= PIPE_TEXTURE_USAGE_SHARED
| PIPE_TEXTURE_USAGE_SCANOUT
;
938 if (pPixmap
->drawable
.width
!= tex
->width0
||
939 pPixmap
->drawable
.height
!= tex
->height0
)
942 pipe_texture_reference(&priv
->tex
, tex
);
943 priv
->tex_flags
= tex
->tex_usage
& mask
;
948 struct pipe_texture
*
949 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
950 int width
, int height
,
951 int depth
, int bitsPerPixel
)
953 modesettingPtr ms
= modesettingPTR(pScrn
);
954 struct exa_context
*exa
= ms
->exa
;
955 struct pipe_texture
template;
958 memset(&template, 0, sizeof(template));
959 template.target
= PIPE_TEXTURE_2D
;
960 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
961 template.width0
= width
;
962 template.height0
= height
;
964 template.last_level
= 0;
965 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
966 template.tex_usage
|= PIPE_TEXTURE_USAGE_SCANOUT
;
967 template.tex_usage
|= PIPE_TEXTURE_USAGE_SHARED
;
969 return exa
->scrn
->texture_create(exa
->scrn
, &template);
973 xorg_exa_close(ScrnInfoPtr pScrn
)
975 modesettingPtr ms
= modesettingPTR(pScrn
);
976 struct exa_context
*exa
= ms
->exa
;
978 pipe_sampler_view_reference(&exa
->bound_sampler_views
[0], NULL
);
979 pipe_sampler_view_reference(&exa
->bound_sampler_views
[1], NULL
);
981 renderer_destroy(exa
->renderer
);
984 exa
->pipe
->destroy(exa
->pipe
);
986 /* Since this was shared be proper with the pointer */
989 exaDriverFini(pScrn
->pScreen
);
995 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
997 modesettingPtr ms
= modesettingPTR(pScrn
);
998 struct exa_context
*exa
;
1001 exa
= xcalloc(1, sizeof(struct exa_context
));
1005 pExa
= exaDriverAlloc();
1010 memset(pExa
, 0, sizeof(*pExa
));
1012 pExa
->exa_major
= 2;
1013 pExa
->exa_minor
= 2;
1014 pExa
->memoryBase
= 0;
1015 pExa
->memorySize
= 0;
1016 pExa
->offScreenBase
= 0;
1017 pExa
->pixmapOffsetAlign
= 0;
1018 pExa
->pixmapPitchAlign
= 1;
1019 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
1020 #ifdef EXA_SUPPORTS_PREPARE_AUX
1021 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
1023 #ifdef EXA_MIXED_PIXMAPS
1024 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
1026 pExa
->maxX
= 8191; /* FIXME */
1027 pExa
->maxY
= 8191; /* FIXME */
1029 pExa
->WaitMarker
= ExaWaitMarker
;
1030 pExa
->MarkSync
= ExaMarkSync
;
1031 pExa
->PrepareSolid
= ExaPrepareSolid
;
1032 pExa
->Solid
= ExaSolid
;
1033 pExa
->DoneSolid
= ExaDoneSolid
;
1034 pExa
->PrepareCopy
= ExaPrepareCopy
;
1035 pExa
->Copy
= ExaCopy
;
1036 pExa
->DoneCopy
= ExaDoneCopy
;
1037 pExa
->CheckComposite
= ExaCheckComposite
;
1038 pExa
->PrepareComposite
= ExaPrepareComposite
;
1039 pExa
->Composite
= ExaComposite
;
1040 pExa
->DoneComposite
= ExaDoneComposite
;
1041 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1042 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1043 pExa
->UploadToScreen
= ExaUploadToScreen
;
1044 pExa
->PrepareAccess
= ExaPrepareAccess
;
1045 pExa
->FinishAccess
= ExaFinishAccess
;
1046 pExa
->CreatePixmap
= ExaCreatePixmap
;
1047 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1048 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1050 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1054 exa
->scrn
= ms
->screen
;
1055 exa
->pipe
= exa
->scrn
->context_create(exa
->scrn
, NULL
);
1056 if (exa
->pipe
== NULL
)
1059 /* Share context with DRI */
1060 ms
->ctx
= exa
->pipe
;
1062 exa
->renderer
= renderer_create(exa
->pipe
);
1068 xorg_exa_close(pScrn
);
1073 struct pipe_surface
*
1074 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1076 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1077 PIPE_BUFFER_USAGE_GPU_READ
|
1078 PIPE_BUFFER_USAGE_GPU_WRITE
);
1082 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1083 struct pipe_fence_handle
**fence
)
1085 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1088 void xorg_exa_finish(struct exa_context
*exa
)
1090 struct pipe_fence_handle
*fence
= NULL
;
1092 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1094 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1095 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);