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"
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
);
277 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
278 #ifdef EXA_MIXED_PIXMAPS
279 PIPE_TRANSFER_MAP_DIRECTLY
|
281 PIPE_TRANSFER_READ_WRITE
,
282 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
283 if (!priv
->map_transfer
)
284 #ifdef EXA_MIXED_PIXMAPS
287 FatalError("failed to create transfer\n");
290 pPix
->devPrivate
.ptr
=
291 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
292 pPix
->devKind
= priv
->map_transfer
->stride
;
301 ExaFinishAccess(PixmapPtr pPix
, int index
)
303 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
304 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
305 modesettingPtr ms
= modesettingPTR(pScrn
);
306 struct exa_context
*exa
= ms
->exa
;
307 struct exa_pixmap_priv
*priv
;
308 priv
= exaGetPixmapDriverPrivate(pPix
);
313 if (!priv
->map_transfer
)
316 if (--priv
->map_count
== 0) {
317 assert(priv
->map_transfer
);
318 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
319 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
320 priv
->map_transfer
= NULL
;
321 pPix
->devPrivate
.ptr
= NULL
;
325 /***********************************************************************
330 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
332 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
333 modesettingPtr ms
= modesettingPTR(pScrn
);
334 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
335 struct exa_context
*exa
= ms
->exa
;
338 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
341 XORG_FALLBACK("accle not enabled");
343 if (!priv
|| !priv
->tex
)
344 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
346 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
347 XORG_FALLBACK("planeMask is not solid");
350 XORG_FALLBACK("not GXcopy");
352 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
354 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
355 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
358 return exa
->accel
&& xorg_solid_bind_state(exa
, priv
, fg
);
362 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
364 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
365 modesettingPtr ms
= modesettingPTR(pScrn
);
366 struct exa_context
*exa
= ms
->exa
;
367 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
370 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
373 if (x0
== 0 && y0
== 0 &&
374 x1
== pPixmap
->drawable
.width
&& y1
== pPixmap
->drawable
.height
) {
375 exa
->pipe
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
, exa
->solid_color
, 0.0, 0);
379 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
384 ExaDoneSolid(PixmapPtr pPixmap
)
386 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
387 modesettingPtr ms
= modesettingPTR(pScrn
);
388 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
389 struct exa_context
*exa
= ms
->exa
;
394 xorg_composite_done(exa
);
397 /***********************************************************************
402 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
403 int ydir
, int alu
, Pixel planeMask
)
405 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
406 modesettingPtr ms
= modesettingPTR(pScrn
);
407 struct exa_context
*exa
= ms
->exa
;
408 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
409 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
412 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", pf_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", pf_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
);
506 if (exa
->copy
.use_surface_copy
) {
507 /* XXX: consider exposing >1 box in surface_copy interface.
509 exa
->pipe
->surface_copy( exa
->pipe
,
510 exa
->copy
.dst_surface
,
512 exa
->copy
.src_surface
,
517 renderer_copy_pixmap(exa
->renderer
,
521 exa
->copy
.src_texture
->width
[0],
522 exa
->copy
.src_texture
->height
[0]);
527 ExaDoneCopy(PixmapPtr pPixmap
)
529 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
530 modesettingPtr ms
= modesettingPTR(pScrn
);
531 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
532 struct exa_context
*exa
= ms
->exa
;
537 renderer_draw_flush(exa
->renderer
);
539 exa
->copy
.src
= NULL
;
540 exa
->copy
.dst
= NULL
;
541 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
542 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
543 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
549 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
551 if (pSrc
->picture_format
== pSrcPicture
->format
)
554 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
557 /* pSrc->picture_format == PICT_a8r8g8b8 */
558 switch (pSrcPicture
->format
) {
563 /* just treat these two as x8... */
567 #ifdef PICT_TYPE_BGRA
570 return FALSE
; /* does not support swizzleing the alpha channel yet */
571 case PICT_a2r10g10b10
:
572 case PICT_x2r10g10b10
:
573 case PICT_a2b10g10r10
:
574 case PICT_x2b10g10r10
:
583 /***********************************************************************
584 * Composite entrypoints
588 ExaCheckComposite(int op
,
589 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
590 PicturePtr pDstPicture
)
592 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
593 modesettingPtr ms
= modesettingPTR(pScrn
);
594 struct exa_context
*exa
= ms
->exa
;
595 boolean accelerated
= xorg_composite_accelerated(op
,
600 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
601 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
603 return exa
->accel
&& accelerated
;
608 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
609 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
610 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
612 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
613 modesettingPtr ms
= modesettingPTR(pScrn
);
614 struct exa_context
*exa
= ms
->exa
;
615 struct exa_pixmap_priv
*priv
;
618 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
619 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
620 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
621 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
622 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
623 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
626 XORG_FALLBACK("accle not enabled");
628 priv
= exaGetPixmapDriverPrivate(pDst
);
629 if (!priv
|| !priv
->tex
)
630 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
632 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
634 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
635 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
637 if (priv
->picture_format
!= pDstPicture
->format
)
638 XORG_FALLBACK("pDst pic_format: %s != %s",
639 render_format_name(priv
->picture_format
),
640 render_format_name(pDstPicture
->format
));
643 priv
= exaGetPixmapDriverPrivate(pSrc
);
644 if (!priv
|| !priv
->tex
)
645 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
647 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
649 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
650 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
652 if (!picture_check_formats(priv
, pSrcPicture
))
653 XORG_FALLBACK("pSrc pic_format: %s != %s",
654 render_format_name(priv
->picture_format
),
655 render_format_name(pSrcPicture
->format
));
660 priv
= exaGetPixmapDriverPrivate(pMask
);
661 if (!priv
|| !priv
->tex
)
662 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
664 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
666 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
667 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
669 if (!picture_check_formats(priv
, pMaskPicture
))
670 XORG_FALLBACK("pMask pic_format: %s != %s",
671 render_format_name(priv
->picture_format
),
672 render_format_name(pMaskPicture
->format
));
676 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
678 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
679 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
680 exaGetPixmapDriverPrivate(pDst
));
684 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
685 int dstX
, int dstY
, int width
, int height
)
687 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
688 modesettingPtr ms
= modesettingPTR(pScrn
);
689 struct exa_context
*exa
= ms
->exa
;
690 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
693 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
694 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
695 debug_printf("\t Num bound samplers = %d\n",
696 exa
->num_bound_samplers
);
699 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
700 dstX
, dstY
, width
, height
);
706 ExaDoneComposite(PixmapPtr pPixmap
)
708 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
709 modesettingPtr ms
= modesettingPTR(pScrn
);
710 struct exa_context
*exa
= ms
->exa
;
712 xorg_composite_done(exa
);
716 /***********************************************************************
721 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
723 struct exa_pixmap_priv
*priv
;
725 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
733 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
735 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
740 pipe_texture_reference(&priv
->tex
, NULL
);
746 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
748 struct exa_pixmap_priv
*priv
;
750 priv
= exaGetPixmapDriverPrivate(pPixmap
);
762 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
764 struct exa_pixmap_priv
*priv
;
765 priv
= exaGetPixmapDriverPrivate(pPixmap
);
768 FatalError("NO PIXMAP PRIVATE\n");
772 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
778 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
780 struct exa_pixmap_priv
*priv
;
781 priv
= exaGetPixmapDriverPrivate(pPixmap
);
784 FatalError("NO PIXMAP PRIVATE\n");
788 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
794 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
796 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
797 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
798 modesettingPtr ms
= modesettingPTR(pScrn
);
799 struct exa_pixmap_priv
*priv
;
804 FatalError("NO MS->EXA\n");
808 priv
= exaGetPixmapDriverPrivate(pPixmap
);
811 FatalError("NO PIXMAP PRIVATE\n");
815 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
817 *stride_out
= stride
;
823 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
824 int depth
, int bitsPerPixel
, int devKind
,
827 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
828 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
829 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
830 modesettingPtr ms
= modesettingPTR(pScrn
);
831 struct exa_context
*exa
= ms
->exa
;
833 if (!priv
|| pPixData
)
837 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
838 __FUNCTION__
, pPixmap
, width
, height
, bitsPerPixel
, devKind
);
841 debug_printf(" ==> old texture %dx%d\n",
843 priv
->tex
->height
[0]);
848 depth
= pPixmap
->drawable
.depth
;
850 if (bitsPerPixel
<= 0)
851 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
854 width
= pPixmap
->drawable
.width
;
857 height
= pPixmap
->drawable
.height
;
859 if (width
<= 0 || height
<= 0 || depth
<= 0)
862 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
863 bitsPerPixel
, devKind
, NULL
);
865 /* Deal with screen resize */
866 if ((exa
->accel
|| priv
->flags
) &&
868 (priv
->tex
->width
[0] != width
||
869 priv
->tex
->height
[0] != height
||
870 priv
->tex_flags
!= priv
->flags
))) {
871 struct pipe_texture
*texture
= NULL
;
872 struct pipe_texture
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 pf_get_block(template.format
, &template.block
);
879 template.width
[0] = util_next_power_of_two(width
);
880 template.height
[0] = util_next_power_of_two(height
);
882 template.width
[0] = width
;
883 template.height
[0] = height
;
885 template.depth
[0] = 1;
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
->width
[0]),
901 min(height
, texture
->height
[0]));
903 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
904 0, 0, min(width
, texture
->width
[0]),
905 min(height
, texture
->height
[0]));
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_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
938 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
939 pPixmap
->drawable
.height
!= tex
->height
[0])
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 pf_get_block(template.format
, &template.block
);
962 template.width
[0] = width
;
963 template.height
[0] = height
;
964 template.depth
[0] = 1;
965 template.last_level
= 0;
966 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
967 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
968 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
970 return exa
->scrn
->texture_create(exa
->scrn
, &template);
974 xorg_exa_close(ScrnInfoPtr pScrn
)
976 modesettingPtr ms
= modesettingPTR(pScrn
);
977 struct exa_context
*exa
= ms
->exa
;
979 renderer_destroy(exa
->renderer
);
982 exa
->pipe
->destroy(exa
->pipe
);
984 exaDriverFini(pScrn
->pScreen
);
990 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
992 modesettingPtr ms
= modesettingPTR(pScrn
);
993 struct exa_context
*exa
;
996 exa
= xcalloc(1, sizeof(struct exa_context
));
1000 pExa
= exaDriverAlloc();
1005 memset(pExa
, 0, sizeof(*pExa
));
1007 pExa
->exa_major
= 2;
1008 pExa
->exa_minor
= 2;
1009 pExa
->memoryBase
= 0;
1010 pExa
->memorySize
= 0;
1011 pExa
->offScreenBase
= 0;
1012 pExa
->pixmapOffsetAlign
= 0;
1013 pExa
->pixmapPitchAlign
= 1;
1014 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
1015 #ifdef EXA_SUPPORTS_PREPARE_AUX
1016 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
1018 #ifdef EXA_MIXED_PIXMAPS
1019 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
1021 pExa
->maxX
= 8191; /* FIXME */
1022 pExa
->maxY
= 8191; /* FIXME */
1024 pExa
->WaitMarker
= ExaWaitMarker
;
1025 pExa
->MarkSync
= ExaMarkSync
;
1026 pExa
->PrepareSolid
= ExaPrepareSolid
;
1027 pExa
->Solid
= ExaSolid
;
1028 pExa
->DoneSolid
= ExaDoneSolid
;
1029 pExa
->PrepareCopy
= ExaPrepareCopy
;
1030 pExa
->Copy
= ExaCopy
;
1031 pExa
->DoneCopy
= ExaDoneCopy
;
1032 pExa
->CheckComposite
= ExaCheckComposite
;
1033 pExa
->PrepareComposite
= ExaPrepareComposite
;
1034 pExa
->Composite
= ExaComposite
;
1035 pExa
->DoneComposite
= ExaDoneComposite
;
1036 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1037 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1038 pExa
->UploadToScreen
= ExaUploadToScreen
;
1039 pExa
->PrepareAccess
= ExaPrepareAccess
;
1040 pExa
->FinishAccess
= ExaFinishAccess
;
1041 pExa
->CreatePixmap
= ExaCreatePixmap
;
1042 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1043 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1045 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1049 exa
->scrn
= ms
->screen
;
1050 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
1051 /* Share context with DRI */
1052 ms
->ctx
= exa
->pipe
;
1054 exa
->renderer
= renderer_create(exa
->pipe
);
1060 xorg_exa_close(pScrn
);
1065 struct pipe_surface
*
1066 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1068 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1069 PIPE_BUFFER_USAGE_GPU_READ
|
1070 PIPE_BUFFER_USAGE_GPU_WRITE
);
1074 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1075 struct pipe_fence_handle
**fence
)
1077 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1080 void xorg_exa_finish(struct exa_context
*exa
)
1082 struct pipe_fence_handle
*fence
= NULL
;
1084 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1086 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1087 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);