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"
50 #define ROUND_UP_TEXTURES 1
55 struct render_format_str
{
59 static const struct render_format_str formats_info
[] =
61 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
62 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
63 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
64 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
66 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
67 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
68 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
69 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
70 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
71 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
73 {PICT_r8g8b8
, "PICT_r8g8b8"},
74 {PICT_b8g8r8
, "PICT_b8g8r8"},
75 {PICT_r5g6b5
, "PICT_r5g6b5"},
76 {PICT_b5g6r5
, "PICT_b5g6r5"},
77 {PICT_a1r5g5b5
, "PICT_a1r5g5b5"},
78 {PICT_x1r5g5b5
, "PICT_x1r5g5b5"},
79 {PICT_a1b5g5r5
, "PICT_a1b5g5r5"},
80 {PICT_x1b5g5r5
, "PICT_x1b5g5r5"},
81 {PICT_a4r4g4b4
, "PICT_a4r4g4b4"},
82 {PICT_x4r4g4b4
, "PICT_x4r4g4b4"},
83 {PICT_a4b4g4r4
, "PICT_a4b4g4r4"},
84 {PICT_x4b4g4r4
, "PICT_x4b4g4r4"},
86 {PICT_r3g3b2
, "PICT_r3g3b2"},
87 {PICT_b2g3r3
, "PICT_b2g3r3"},
88 {PICT_a2r2g2b2
, "PICT_a2r2g2b2"},
89 {PICT_a2b2g2r2
, "PICT_a2b2g2r2"},
92 {PICT_x4a4
, "PICT_x4a4"},
93 {PICT_x4c4
, "PICT_x4c4"},
94 {PICT_x4g4
, "PICT_x4g4"},
96 {PICT_r1g2b1
, "PICT_r1g2b1"},
97 {PICT_b1g2r1
, "PICT_b1g2r1"},
98 {PICT_a1r1g1b1
, "PICT_a1r1g1b1"},
99 {PICT_a1b1g1r1
, "PICT_a1b1g1r1"},
100 {PICT_c4
, "PICT_c4"},
101 {PICT_g4
, "PICT_g4"},
102 {PICT_a1
, "PICT_a1"},
105 static const char *render_format_name(int format
)
108 for (i
= 0; i
< sizeof(formats_info
)/sizeof(formats_info
[0]); ++i
) {
109 if (formats_info
[i
].format
== format
)
110 return formats_info
[i
].name
;
116 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
, int *picture_format
)
120 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
121 *picture_format
= PICT_a8r8g8b8
;
125 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
126 *picture_format
= PICT_x8r8g8b8
;
130 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
131 *picture_format
= PICT_r5g6b5
;
135 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
136 *picture_format
= PICT_x1r5g5b5
;
140 *format
= PIPE_FORMAT_L8_UNORM
;
141 *picture_format
= PICT_a8
;
146 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
156 * Static exported EXA functions
160 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
162 /* Nothing to do, handled in the PrepareAccess hook */
166 ExaMarkSync(ScreenPtr pScreen
)
172 /***********************************************************************
173 * Screen upload/download
177 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
180 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
181 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
182 modesettingPtr ms
= modesettingPTR(pScrn
);
183 struct exa_context
*exa
= ms
->exa
;
184 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
185 struct pipe_transfer
*transfer
;
187 if (!priv
|| !priv
->tex
)
190 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
191 PIPE_REFERENCED_FOR_WRITE
)
192 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
194 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
195 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
200 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
201 x
, y
, w
, h
, dst_pitch
);
204 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
205 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
206 transfer
->stride
, 0, 0);
208 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
209 exa
->scrn
->tex_transfer_destroy(transfer
);
215 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
218 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
219 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
220 modesettingPtr ms
= modesettingPTR(pScrn
);
221 struct exa_context
*exa
= ms
->exa
;
222 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
223 struct pipe_transfer
*transfer
;
225 if (!priv
|| !priv
->tex
)
228 /* make sure that any pending operations are flushed to hardware */
229 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
230 (PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
))
231 xorg_exa_flush(exa
, 0, NULL
);
233 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
234 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
239 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
240 x
, y
, w
, h
, src_pitch
);
243 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
244 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
245 (unsigned char*)src
, src_pitch
, 0, 0);
247 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
248 exa
->scrn
->tex_transfer_destroy(transfer
);
254 ExaPrepareAccess(PixmapPtr pPix
, int index
)
256 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
257 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
258 modesettingPtr ms
= modesettingPTR(pScrn
);
259 struct exa_context
*exa
= ms
->exa
;
260 struct exa_pixmap_priv
*priv
;
262 priv
= exaGetPixmapDriverPrivate(pPix
);
270 if (priv
->map_count
== 0)
272 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
273 PIPE_REFERENCED_FOR_WRITE
)
274 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
276 assert(pPix
->drawable
.width
<= priv
->tex
->width
[0]);
277 assert(pPix
->drawable
.height
<= priv
->tex
->height
[0]);
280 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
281 #ifdef EXA_MIXED_PIXMAPS
282 PIPE_TRANSFER_MAP_DIRECTLY
|
284 PIPE_TRANSFER_READ_WRITE
,
286 pPix
->drawable
.width
,
287 pPix
->drawable
.height
);
288 if (!priv
->map_transfer
)
289 #ifdef EXA_MIXED_PIXMAPS
292 FatalError("failed to create transfer\n");
295 pPix
->devPrivate
.ptr
=
296 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
297 pPix
->devKind
= priv
->map_transfer
->stride
;
306 ExaFinishAccess(PixmapPtr pPix
, int index
)
308 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
309 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
310 modesettingPtr ms
= modesettingPTR(pScrn
);
311 struct exa_context
*exa
= ms
->exa
;
312 struct exa_pixmap_priv
*priv
;
313 priv
= exaGetPixmapDriverPrivate(pPix
);
318 if (!priv
->map_transfer
)
321 if (--priv
->map_count
== 0) {
322 assert(priv
->map_transfer
);
323 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
324 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
325 priv
->map_transfer
= NULL
;
326 pPix
->devPrivate
.ptr
= NULL
;
330 /***********************************************************************
335 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
337 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
338 modesettingPtr ms
= modesettingPTR(pScrn
);
339 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
340 struct exa_context
*exa
= ms
->exa
;
343 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
349 XORG_FALLBACK("accle not enabled");
351 if (!priv
|| !priv
->tex
)
352 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
354 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
355 XORG_FALLBACK("planeMask is not solid");
358 XORG_FALLBACK("not GXcopy");
360 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
362 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
363 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
366 return xorg_solid_bind_state(exa
, priv
, fg
);
370 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
372 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
373 modesettingPtr ms
= modesettingPTR(pScrn
);
374 struct exa_context
*exa
= ms
->exa
;
375 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
378 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
381 if (x0
== 0 && y0
== 0 &&
382 x1
== pPixmap
->drawable
.width
&& y1
== pPixmap
->drawable
.height
) {
383 exa
->pipe
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
, exa
->solid_color
, 0.0, 0);
387 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
392 ExaDoneSolid(PixmapPtr pPixmap
)
394 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
395 modesettingPtr ms
= modesettingPTR(pScrn
);
396 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
397 struct exa_context
*exa
= ms
->exa
;
402 xorg_composite_done(exa
);
405 /***********************************************************************
410 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
411 int ydir
, int alu
, Pixel planeMask
)
413 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
414 modesettingPtr ms
= modesettingPTR(pScrn
);
415 struct exa_context
*exa
= ms
->exa
;
416 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
417 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
420 debug_printf("ExaPrepareCopy\n");
427 XORG_FALLBACK("accle not enabled");
429 if (!priv
|| !priv
->tex
)
430 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
432 if (!src_priv
|| !src_priv
->tex
)
433 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
435 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
436 XORG_FALLBACK("planeMask is not solid");
439 XORG_FALLBACK("alu not GXcopy");
441 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
443 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
444 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
446 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
447 src_priv
->tex
->target
,
448 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
449 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
451 exa
->copy
.src
= src_priv
;
452 exa
->copy
.dst
= priv
;
454 /* For same-surface copies, the pipe->surface_copy path is clearly
455 * superior, providing it is implemented. In other cases it's not
456 * clear what the better path would be, and eventually we'd
457 * probably want to gather timings and choose dynamically.
459 if (exa
->pipe
->surface_copy
&&
460 exa
->copy
.src
== exa
->copy
.dst
) {
462 exa
->copy
.use_surface_copy
= TRUE
;
464 exa
->copy
.src_surface
=
465 exa
->scrn
->get_tex_surface( exa
->scrn
,
468 PIPE_BUFFER_USAGE_GPU_READ
);
470 exa
->copy
.dst_surface
=
471 exa
->scrn
->get_tex_surface( exa
->scrn
,
474 PIPE_BUFFER_USAGE_GPU_WRITE
);
477 exa
->copy
.use_surface_copy
= FALSE
;
479 if (exa
->copy
.dst
== exa
->copy
.src
)
480 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
481 exa
->copy
.src
->tex
);
483 pipe_texture_reference(&exa
->copy
.src_texture
,
486 exa
->copy
.dst_surface
=
487 exa
->scrn
->get_tex_surface(exa
->scrn
,
490 PIPE_BUFFER_USAGE_GPU_WRITE
);
493 renderer_copy_prepare(exa
->renderer
,
494 exa
->copy
.dst_surface
,
495 exa
->copy
.src_texture
);
503 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
504 int width
, int height
)
506 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
507 modesettingPtr ms
= modesettingPTR(pScrn
);
508 struct exa_context
*exa
= ms
->exa
;
509 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
512 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
513 srcX
, srcY
, dstX
, dstY
, width
, height
);
516 debug_assert(priv
== exa
->copy
.dst
);
519 if (exa
->copy
.use_surface_copy
) {
520 /* XXX: consider exposing >1 box in surface_copy interface.
522 exa
->pipe
->surface_copy( exa
->pipe
,
523 exa
->copy
.dst_surface
,
525 exa
->copy
.src_surface
,
530 renderer_copy_pixmap(exa
->renderer
,
534 exa
->copy
.src_texture
->width
[0],
535 exa
->copy
.src_texture
->height
[0]);
540 ExaDoneCopy(PixmapPtr pPixmap
)
542 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
543 modesettingPtr ms
= modesettingPTR(pScrn
);
544 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
545 struct exa_context
*exa
= ms
->exa
;
550 renderer_draw_flush(exa
->renderer
);
552 exa
->copy
.src
= NULL
;
553 exa
->copy
.dst
= NULL
;
554 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
555 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
556 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
562 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
564 if (pSrc
->picture_format
== pSrcPicture
->format
)
567 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
570 /* pSrc->picture_format == PICT_a8r8g8b8 */
571 switch (pSrcPicture
->format
) {
576 /* just treat these two as x8... */
580 #ifdef PICT_TYPE_BGRA
583 return FALSE
; /* does not support swizzleing the alpha channel yet */
584 case PICT_a2r10g10b10
:
585 case PICT_x2r10g10b10
:
586 case PICT_a2b10g10r10
:
587 case PICT_x2b10g10r10
:
596 /***********************************************************************
597 * Composite entrypoints
601 ExaCheckComposite(int op
,
602 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
603 PicturePtr pDstPicture
)
605 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
606 modesettingPtr ms
= modesettingPTR(pScrn
);
607 struct exa_context
*exa
= ms
->exa
;
610 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
611 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
617 return xorg_composite_accelerated(op
,
625 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
626 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
627 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
629 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
630 modesettingPtr ms
= modesettingPTR(pScrn
);
631 struct exa_context
*exa
= ms
->exa
;
632 struct exa_pixmap_priv
*priv
;
638 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
639 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
640 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
641 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
642 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
643 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
646 XORG_FALLBACK("accle not enabled");
648 priv
= exaGetPixmapDriverPrivate(pDst
);
649 if (!priv
|| !priv
->tex
)
650 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
652 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
654 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
655 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
657 if (priv
->picture_format
!= pDstPicture
->format
)
658 XORG_FALLBACK("pDst pic_format: %s != %s",
659 render_format_name(priv
->picture_format
),
660 render_format_name(pDstPicture
->format
));
663 priv
= exaGetPixmapDriverPrivate(pSrc
);
664 if (!priv
|| !priv
->tex
)
665 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
667 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
669 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
670 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
672 if (!picture_check_formats(priv
, pSrcPicture
))
673 XORG_FALLBACK("pSrc pic_format: %s != %s",
674 render_format_name(priv
->picture_format
),
675 render_format_name(pSrcPicture
->format
));
680 priv
= exaGetPixmapDriverPrivate(pMask
);
681 if (!priv
|| !priv
->tex
)
682 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
684 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
686 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
687 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
689 if (!picture_check_formats(priv
, pMaskPicture
))
690 XORG_FALLBACK("pMask pic_format: %s != %s",
691 render_format_name(priv
->picture_format
),
692 render_format_name(pMaskPicture
->format
));
695 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
697 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
698 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
699 exaGetPixmapDriverPrivate(pDst
));
703 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
704 int dstX
, int dstY
, int width
, int height
)
706 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
707 modesettingPtr ms
= modesettingPTR(pScrn
);
708 struct exa_context
*exa
= ms
->exa
;
709 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
712 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
713 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
714 debug_printf("\t Num bound samplers = %d\n",
715 exa
->num_bound_samplers
);
718 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
719 dstX
, dstY
, width
, height
);
725 ExaDoneComposite(PixmapPtr pPixmap
)
727 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
728 modesettingPtr ms
= modesettingPTR(pScrn
);
729 struct exa_context
*exa
= ms
->exa
;
731 xorg_composite_done(exa
);
735 /***********************************************************************
740 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
742 struct exa_pixmap_priv
*priv
;
744 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
752 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
754 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
759 pipe_texture_reference(&priv
->tex
, NULL
);
765 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
767 struct exa_pixmap_priv
*priv
;
769 priv
= exaGetPixmapDriverPrivate(pPixmap
);
781 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
783 struct exa_pixmap_priv
*priv
;
784 priv
= exaGetPixmapDriverPrivate(pPixmap
);
787 FatalError("NO PIXMAP PRIVATE\n");
791 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
797 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
799 struct exa_pixmap_priv
*priv
;
800 priv
= exaGetPixmapDriverPrivate(pPixmap
);
803 FatalError("NO PIXMAP PRIVATE\n");
807 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
813 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
815 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
816 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
817 modesettingPtr ms
= modesettingPTR(pScrn
);
818 struct exa_pixmap_priv
*priv
;
823 FatalError("NO MS->EXA\n");
827 priv
= exaGetPixmapDriverPrivate(pPixmap
);
830 FatalError("NO PIXMAP PRIVATE\n");
834 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
836 *stride_out
= stride
;
842 size_match( int width
, int tex_width
)
844 #if ROUND_UP_TEXTURES
845 if (width
> tex_width
)
848 if (width
* 2 < tex_width
)
853 return width
== tex_width
;
858 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
859 int depth
, int bitsPerPixel
, int devKind
,
862 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
863 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
864 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
865 modesettingPtr ms
= modesettingPTR(pScrn
);
866 struct exa_context
*exa
= ms
->exa
;
868 if (!priv
|| pPixData
)
872 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
873 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
876 debug_printf(" ==> old texture %dx%d\n",
878 priv
->tex
->height
[0]);
883 depth
= pPixmap
->drawable
.depth
;
885 if (bitsPerPixel
<= 0)
886 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
889 width
= pPixmap
->drawable
.width
;
892 height
= pPixmap
->drawable
.height
;
894 if (width
<= 0 || height
<= 0 || depth
<= 0)
897 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
898 bitsPerPixel
, devKind
, NULL
);
901 priv
->height
= height
;
903 /* Deal with screen resize */
904 if ((exa
->accel
|| priv
->flags
) &&
906 !size_match(width
, priv
->tex
->width
[0]) ||
907 !size_match(height
, priv
->tex
->height
[0]) ||
908 priv
->tex_flags
!= priv
->flags
)) {
909 struct pipe_texture
*texture
= NULL
;
910 struct pipe_texture
template;
912 memset(&template, 0, sizeof(template));
913 template.target
= PIPE_TEXTURE_2D
;
914 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
915 pf_get_block(template.format
, &template.block
);
916 if (ROUND_UP_TEXTURES
&& priv
->flags
== 0) {
917 template.width
[0] = util_next_power_of_two(width
);
918 template.height
[0] = util_next_power_of_two(height
);
921 template.width
[0] = width
;
922 template.height
[0] = height
;
925 template.depth
[0] = 1;
926 template.last_level
= 0;
927 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
928 priv
->tex_flags
= priv
->flags
;
929 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
932 struct pipe_surface
*dst_surf
;
933 struct pipe_surface
*src_surf
;
935 dst_surf
= exa
->scrn
->get_tex_surface(
936 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
937 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
938 if (exa
->pipe
->surface_copy
) {
939 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
940 0, 0, min(width
, texture
->width
[0]),
941 min(height
, texture
->height
[0]));
943 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
944 0, 0, min(width
, texture
->width
[0]),
945 min(height
, texture
->height
[0]));
947 exa
->scrn
->tex_surface_destroy(dst_surf
);
948 exa
->scrn
->tex_surface_destroy(src_surf
);
951 pipe_texture_reference(&priv
->tex
, texture
);
952 /* the texture we create has one reference */
953 pipe_texture_reference(&texture
, NULL
);
959 struct pipe_texture
*
960 xorg_exa_get_texture(PixmapPtr pPixmap
)
962 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
963 struct pipe_texture
*tex
= NULL
;
964 pipe_texture_reference(&tex
, priv
->tex
);
969 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
971 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
973 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
978 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
979 pPixmap
->drawable
.height
!= tex
->height
[0])
982 pipe_texture_reference(&priv
->tex
, tex
);
983 priv
->tex_flags
= tex
->tex_usage
& mask
;
988 struct pipe_texture
*
989 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
990 int width
, int height
,
991 int depth
, int bitsPerPixel
)
993 modesettingPtr ms
= modesettingPTR(pScrn
);
994 struct exa_context
*exa
= ms
->exa
;
995 struct pipe_texture
template;
998 memset(&template, 0, sizeof(template));
999 template.target
= PIPE_TEXTURE_2D
;
1000 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
1001 pf_get_block(template.format
, &template.block
);
1002 template.width
[0] = width
;
1003 template.height
[0] = height
;
1004 template.depth
[0] = 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
);