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_rect.h"
47 #include "util/u_math.h"
48 #include "util/u_debug.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_A8R8G8B8_UNORM
;
122 *picture_format
= PICT_a8r8g8b8
;
126 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
127 *picture_format
= PICT_x8r8g8b8
;
131 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
132 *picture_format
= PICT_r5g6b5
;
136 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
137 *picture_format
= PICT_x1r5g5b5
;
141 *format
= PIPE_FORMAT_L8_UNORM
;
142 *picture_format
= PICT_a8
;
147 *format
= PIPE_FORMAT_A8R8G8B8_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 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
192 PIPE_REFERENCED_FOR_WRITE
)
193 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
195 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
196 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
201 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
202 x
, y
, w
, h
, dst_pitch
);
205 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
206 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
207 transfer
->stride
, 0, 0);
209 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
210 exa
->scrn
->tex_transfer_destroy(transfer
);
216 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
219 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
220 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
221 modesettingPtr ms
= modesettingPTR(pScrn
);
222 struct exa_context
*exa
= ms
->exa
;
223 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
224 struct pipe_transfer
*transfer
;
226 if (!priv
|| !priv
->tex
)
229 /* make sure that any pending operations are flushed to hardware */
230 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
231 (PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
))
232 xorg_exa_flush(exa
, 0, NULL
);
234 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
235 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
240 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
241 x
, y
, w
, h
, src_pitch
);
244 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
245 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
246 (unsigned char*)src
, src_pitch
, 0, 0);
248 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
249 exa
->scrn
->tex_transfer_destroy(transfer
);
255 ExaPrepareAccess(PixmapPtr pPix
, int index
)
257 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
258 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
259 modesettingPtr ms
= modesettingPTR(pScrn
);
260 struct exa_context
*exa
= ms
->exa
;
261 struct exa_pixmap_priv
*priv
;
263 priv
= exaGetPixmapDriverPrivate(pPix
);
271 if (priv
->map_count
== 0)
273 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
274 PIPE_REFERENCED_FOR_WRITE
)
275 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
277 assert(pPix
->drawable
.width
<= priv
->tex
->width0
);
278 assert(pPix
->drawable
.height
<= priv
->tex
->height0
);
281 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
282 #ifdef EXA_MIXED_PIXMAPS
283 PIPE_TRANSFER_MAP_DIRECTLY
|
285 PIPE_TRANSFER_READ_WRITE
,
286 <<<<<<< HEAD
:src
/gallium
/state_trackers
/xorg
/xorg_exa
.c
287 0, 0, priv
->tex
->width0
, priv
->tex
->height0
);
290 pPix
->drawable
.width
,
291 pPix
->drawable
.height
);
292 >>>>>>> origin
/mesa_7_7_branch
:src
/gallium
/state_trackers
/xorg
/xorg_exa
.c
293 if (!priv
->map_transfer
)
294 #ifdef EXA_MIXED_PIXMAPS
297 FatalError("failed to create transfer\n");
300 pPix
->devPrivate
.ptr
=
301 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
302 pPix
->devKind
= priv
->map_transfer
->stride
;
311 ExaFinishAccess(PixmapPtr pPix
, int index
)
313 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
314 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
315 modesettingPtr ms
= modesettingPTR(pScrn
);
316 struct exa_context
*exa
= ms
->exa
;
317 struct exa_pixmap_priv
*priv
;
318 priv
= exaGetPixmapDriverPrivate(pPix
);
323 if (!priv
->map_transfer
)
326 if (--priv
->map_count
== 0) {
327 assert(priv
->map_transfer
);
328 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
329 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
330 priv
->map_transfer
= NULL
;
331 pPix
->devPrivate
.ptr
= NULL
;
335 /***********************************************************************
340 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
342 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
343 modesettingPtr ms
= modesettingPTR(pScrn
);
344 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
345 struct exa_context
*exa
= ms
->exa
;
348 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 exa
->accel
&& 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");
425 XORG_FALLBACK("accle not enabled");
427 if (!priv
|| !priv
->tex
)
428 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
430 if (!src_priv
|| !src_priv
->tex
)
431 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
433 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
434 XORG_FALLBACK("planeMask is not solid");
437 XORG_FALLBACK("alu not GXcopy");
439 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
441 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
442 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
444 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
445 src_priv
->tex
->target
,
446 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
447 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
449 exa
->copy
.src
= src_priv
;
450 exa
->copy
.dst
= priv
;
452 /* For same-surface copies, the pipe->surface_copy path is clearly
453 * superior, providing it is implemented. In other cases it's not
454 * clear what the better path would be, and eventually we'd
455 * probably want to gather timings and choose dynamically.
457 if (exa
->pipe
->surface_copy
&&
458 exa
->copy
.src
== exa
->copy
.dst
) {
460 exa
->copy
.use_surface_copy
= TRUE
;
462 exa
->copy
.src_surface
=
463 exa
->scrn
->get_tex_surface( exa
->scrn
,
466 PIPE_BUFFER_USAGE_GPU_READ
);
468 exa
->copy
.dst_surface
=
469 exa
->scrn
->get_tex_surface( exa
->scrn
,
472 PIPE_BUFFER_USAGE_GPU_WRITE
);
475 exa
->copy
.use_surface_copy
= FALSE
;
477 if (exa
->copy
.dst
== exa
->copy
.src
)
478 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
479 exa
->copy
.src
->tex
);
481 pipe_texture_reference(&exa
->copy
.src_texture
,
484 exa
->copy
.dst_surface
=
485 exa
->scrn
->get_tex_surface(exa
->scrn
,
488 PIPE_BUFFER_USAGE_GPU_WRITE
);
491 renderer_copy_prepare(exa
->renderer
,
492 exa
->copy
.dst_surface
,
493 exa
->copy
.src_texture
);
501 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
502 int width
, int height
)
504 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
505 modesettingPtr ms
= modesettingPTR(pScrn
);
506 struct exa_context
*exa
= ms
->exa
;
507 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
510 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
511 srcX
, srcY
, dstX
, dstY
, width
, height
);
514 debug_assert(priv
== exa
->copy
.dst
);
516 if (exa
->copy
.use_surface_copy
) {
517 /* XXX: consider exposing >1 box in surface_copy interface.
519 exa
->pipe
->surface_copy( exa
->pipe
,
520 exa
->copy
.dst_surface
,
522 exa
->copy
.src_surface
,
527 renderer_copy_pixmap(exa
->renderer
,
531 exa
->copy
.src_texture
->width0
,
532 exa
->copy
.src_texture
->height0
);
537 ExaDoneCopy(PixmapPtr pPixmap
)
539 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
540 modesettingPtr ms
= modesettingPTR(pScrn
);
541 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
542 struct exa_context
*exa
= ms
->exa
;
547 renderer_draw_flush(exa
->renderer
);
549 exa
->copy
.src
= NULL
;
550 exa
->copy
.dst
= NULL
;
551 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
552 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
553 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
559 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
561 if (pSrc
->picture_format
== pSrcPicture
->format
)
564 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
567 /* pSrc->picture_format == PICT_a8r8g8b8 */
568 switch (pSrcPicture
->format
) {
573 /* just treat these two as x8... */
577 #ifdef PICT_TYPE_BGRA
580 return FALSE
; /* does not support swizzleing the alpha channel yet */
581 case PICT_a2r10g10b10
:
582 case PICT_x2r10g10b10
:
583 case PICT_a2b10g10r10
:
584 case PICT_x2b10g10r10
:
593 /***********************************************************************
594 * Composite entrypoints
598 ExaCheckComposite(int op
,
599 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
600 PicturePtr pDstPicture
)
602 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
603 modesettingPtr ms
= modesettingPTR(pScrn
);
604 struct exa_context
*exa
= ms
->exa
;
605 boolean accelerated
= xorg_composite_accelerated(op
,
610 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
611 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
613 return exa
->accel
&& accelerated
;
618 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
619 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
620 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
622 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
623 modesettingPtr ms
= modesettingPTR(pScrn
);
624 struct exa_context
*exa
= ms
->exa
;
625 struct exa_pixmap_priv
*priv
;
628 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
629 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
630 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
631 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
632 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
633 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
636 XORG_FALLBACK("accle not enabled");
638 priv
= exaGetPixmapDriverPrivate(pDst
);
639 if (!priv
|| !priv
->tex
)
640 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
642 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
644 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
645 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
647 if (priv
->picture_format
!= pDstPicture
->format
)
648 XORG_FALLBACK("pDst pic_format: %s != %s",
649 render_format_name(priv
->picture_format
),
650 render_format_name(pDstPicture
->format
));
653 priv
= exaGetPixmapDriverPrivate(pSrc
);
654 if (!priv
|| !priv
->tex
)
655 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
657 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
659 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
660 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
662 if (!picture_check_formats(priv
, pSrcPicture
))
663 XORG_FALLBACK("pSrc pic_format: %s != %s",
664 render_format_name(priv
->picture_format
),
665 render_format_name(pSrcPicture
->format
));
670 priv
= exaGetPixmapDriverPrivate(pMask
);
671 if (!priv
|| !priv
->tex
)
672 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
674 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
676 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
677 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
679 if (!picture_check_formats(priv
, pMaskPicture
))
680 XORG_FALLBACK("pMask pic_format: %s != %s",
681 render_format_name(priv
->picture_format
),
682 render_format_name(pMaskPicture
->format
));
686 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
688 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
689 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
690 exaGetPixmapDriverPrivate(pDst
));
694 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
695 int dstX
, int dstY
, int width
, int height
)
697 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
698 modesettingPtr ms
= modesettingPTR(pScrn
);
699 struct exa_context
*exa
= ms
->exa
;
700 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
703 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
704 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
705 debug_printf("\t Num bound samplers = %d\n",
706 exa
->num_bound_samplers
);
709 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
710 dstX
, dstY
, width
, height
);
716 ExaDoneComposite(PixmapPtr pPixmap
)
718 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
719 modesettingPtr ms
= modesettingPTR(pScrn
);
720 struct exa_context
*exa
= ms
->exa
;
722 xorg_composite_done(exa
);
726 /***********************************************************************
731 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
733 struct exa_pixmap_priv
*priv
;
735 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
743 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
745 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
750 pipe_texture_reference(&priv
->tex
, NULL
);
756 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
758 struct exa_pixmap_priv
*priv
;
760 priv
= exaGetPixmapDriverPrivate(pPixmap
);
772 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
774 struct exa_pixmap_priv
*priv
;
775 priv
= exaGetPixmapDriverPrivate(pPixmap
);
778 FatalError("NO PIXMAP PRIVATE\n");
782 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
788 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
790 struct exa_pixmap_priv
*priv
;
791 priv
= exaGetPixmapDriverPrivate(pPixmap
);
794 FatalError("NO PIXMAP PRIVATE\n");
798 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
804 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
806 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
807 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
808 modesettingPtr ms
= modesettingPTR(pScrn
);
809 struct exa_pixmap_priv
*priv
;
814 FatalError("NO MS->EXA\n");
818 priv
= exaGetPixmapDriverPrivate(pPixmap
);
821 FatalError("NO PIXMAP PRIVATE\n");
825 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
827 *stride_out
= stride
;
833 size_match( int width
, int tex_width
)
835 #if ROUND_UP_TEXTURES
836 if (width
> tex_width
)
839 if (width
* 2 < tex_width
)
844 return width
== tex_width
;
849 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
850 int depth
, int bitsPerPixel
, int devKind
,
853 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
854 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
855 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
856 modesettingPtr ms
= modesettingPTR(pScrn
);
857 struct exa_context
*exa
= ms
->exa
;
859 if (!priv
|| pPixData
)
863 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
864 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
867 debug_printf(" ==> old texture %dx%d\n",
874 depth
= pPixmap
->drawable
.depth
;
876 if (bitsPerPixel
<= 0)
877 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
880 width
= pPixmap
->drawable
.width
;
883 height
= pPixmap
->drawable
.height
;
885 if (width
<= 0 || height
<= 0 || depth
<= 0)
888 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
889 bitsPerPixel
, devKind
, NULL
);
892 priv
->height
= height
;
894 /* Deal with screen resize */
895 if ((exa
->accel
|| priv
->flags
) &&
897 !size_match(width
, priv
->tex
->width0
) ||
898 !size_match(height
, priv
->tex
->height0
) ||
899 priv
->tex_flags
!= priv
->flags
)) {
900 struct pipe_texture
*texture
= NULL
;
901 struct pipe_texture
template;
903 memset(&template, 0, sizeof(template));
904 template.target
= PIPE_TEXTURE_2D
;
905 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
906 pf_get_block(template.format
, &template.block
);
907 if (ROUND_UP_TEXTURES
&& priv
->flags
== 0) {
908 template.width0
= util_next_power_of_two(width
);
909 template.height0
= util_next_power_of_two(height
);
912 template.width0
= width
;
913 template.height0
= height
;
917 template.last_level
= 0;
918 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
919 priv
->tex_flags
= priv
->flags
;
920 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
923 struct pipe_surface
*dst_surf
;
924 struct pipe_surface
*src_surf
;
926 dst_surf
= exa
->scrn
->get_tex_surface(
927 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
928 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
929 if (exa
->pipe
->surface_copy
) {
930 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
931 0, 0, min(width
, texture
->width0
),
932 min(height
, texture
->height0
));
934 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
935 0, 0, min(width
, texture
->width0
),
936 min(height
, texture
->height0
));
938 exa
->scrn
->tex_surface_destroy(dst_surf
);
939 exa
->scrn
->tex_surface_destroy(src_surf
);
942 pipe_texture_reference(&priv
->tex
, texture
);
943 /* the texture we create has one reference */
944 pipe_texture_reference(&texture
, NULL
);
950 struct pipe_texture
*
951 xorg_exa_get_texture(PixmapPtr pPixmap
)
953 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
954 struct pipe_texture
*tex
= NULL
;
955 pipe_texture_reference(&tex
, priv
->tex
);
960 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
962 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
964 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
969 if (pPixmap
->drawable
.width
!= tex
->width0
||
970 pPixmap
->drawable
.height
!= tex
->height0
)
973 pipe_texture_reference(&priv
->tex
, tex
);
974 priv
->tex_flags
= tex
->tex_usage
& mask
;
979 struct pipe_texture
*
980 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
981 int width
, int height
,
982 int depth
, int bitsPerPixel
)
984 modesettingPtr ms
= modesettingPTR(pScrn
);
985 struct exa_context
*exa
= ms
->exa
;
986 struct pipe_texture
template;
989 memset(&template, 0, sizeof(template));
990 template.target
= PIPE_TEXTURE_2D
;
991 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
992 pf_get_block(template.format
, &template.block
);
993 template.width0
= width
;
994 template.height0
= height
;
996 template.last_level
= 0;
997 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
998 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
999 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
1001 return exa
->scrn
->texture_create(exa
->scrn
, &template);
1005 xorg_exa_close(ScrnInfoPtr pScrn
)
1007 modesettingPtr ms
= modesettingPTR(pScrn
);
1008 struct exa_context
*exa
= ms
->exa
;
1010 renderer_destroy(exa
->renderer
);
1013 exa
->pipe
->destroy(exa
->pipe
);
1015 exaDriverFini(pScrn
->pScreen
);
1021 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
1023 modesettingPtr ms
= modesettingPTR(pScrn
);
1024 struct exa_context
*exa
;
1027 exa
= xcalloc(1, sizeof(struct exa_context
));
1031 pExa
= exaDriverAlloc();
1036 memset(pExa
, 0, sizeof(*pExa
));
1038 pExa
->exa_major
= 2;
1039 pExa
->exa_minor
= 2;
1040 pExa
->memoryBase
= 0;
1041 pExa
->memorySize
= 0;
1042 pExa
->offScreenBase
= 0;
1043 pExa
->pixmapOffsetAlign
= 0;
1044 pExa
->pixmapPitchAlign
= 1;
1045 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
1046 #ifdef EXA_SUPPORTS_PREPARE_AUX
1047 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
1049 #ifdef EXA_MIXED_PIXMAPS
1050 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
1052 pExa
->maxX
= 8191; /* FIXME */
1053 pExa
->maxY
= 8191; /* FIXME */
1055 pExa
->WaitMarker
= ExaWaitMarker
;
1056 pExa
->MarkSync
= ExaMarkSync
;
1057 pExa
->PrepareSolid
= ExaPrepareSolid
;
1058 pExa
->Solid
= ExaSolid
;
1059 pExa
->DoneSolid
= ExaDoneSolid
;
1060 pExa
->PrepareCopy
= ExaPrepareCopy
;
1061 pExa
->Copy
= ExaCopy
;
1062 pExa
->DoneCopy
= ExaDoneCopy
;
1063 pExa
->CheckComposite
= ExaCheckComposite
;
1064 pExa
->PrepareComposite
= ExaPrepareComposite
;
1065 pExa
->Composite
= ExaComposite
;
1066 pExa
->DoneComposite
= ExaDoneComposite
;
1067 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1068 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1069 pExa
->UploadToScreen
= ExaUploadToScreen
;
1070 pExa
->PrepareAccess
= ExaPrepareAccess
;
1071 pExa
->FinishAccess
= ExaFinishAccess
;
1072 pExa
->CreatePixmap
= ExaCreatePixmap
;
1073 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1074 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1076 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1080 exa
->scrn
= ms
->screen
;
1081 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
1082 /* Share context with DRI */
1083 ms
->ctx
= exa
->pipe
;
1085 exa
->renderer
= renderer_create(exa
->pipe
);
1091 xorg_exa_close(pScrn
);
1096 struct pipe_surface
*
1097 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1099 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1100 PIPE_BUFFER_USAGE_GPU_READ
|
1101 PIPE_BUFFER_USAGE_GPU_WRITE
);
1105 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1106 struct pipe_fence_handle
**fence
)
1108 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1111 void xorg_exa_finish(struct exa_context
*exa
)
1113 struct pipe_fence_handle
*fence
= NULL
;
1115 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1117 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1118 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);