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"
53 struct render_format_str
{
57 static const struct render_format_str formats_info
[] =
59 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
60 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
61 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
62 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
64 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
65 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
66 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
67 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
68 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
69 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
71 {PICT_r8g8b8
, "PICT_r8g8b8"},
72 {PICT_b8g8r8
, "PICT_b8g8r8"},
73 {PICT_r5g6b5
, "PICT_r5g6b5"},
74 {PICT_b5g6r5
, "PICT_b5g6r5"},
75 {PICT_a1r5g5b5
, "PICT_a1r5g5b5"},
76 {PICT_x1r5g5b5
, "PICT_x1r5g5b5"},
77 {PICT_a1b5g5r5
, "PICT_a1b5g5r5"},
78 {PICT_x1b5g5r5
, "PICT_x1b5g5r5"},
79 {PICT_a4r4g4b4
, "PICT_a4r4g4b4"},
80 {PICT_x4r4g4b4
, "PICT_x4r4g4b4"},
81 {PICT_a4b4g4r4
, "PICT_a4b4g4r4"},
82 {PICT_x4b4g4r4
, "PICT_x4b4g4r4"},
84 {PICT_r3g3b2
, "PICT_r3g3b2"},
85 {PICT_b2g3r3
, "PICT_b2g3r3"},
86 {PICT_a2r2g2b2
, "PICT_a2r2g2b2"},
87 {PICT_a2b2g2r2
, "PICT_a2b2g2r2"},
90 {PICT_x4a4
, "PICT_x4a4"},
91 {PICT_x4c4
, "PICT_x4c4"},
92 {PICT_x4g4
, "PICT_x4g4"},
94 {PICT_r1g2b1
, "PICT_r1g2b1"},
95 {PICT_b1g2r1
, "PICT_b1g2r1"},
96 {PICT_a1r1g1b1
, "PICT_a1r1g1b1"},
97 {PICT_a1b1g1r1
, "PICT_a1b1g1r1"},
100 {PICT_a1
, "PICT_a1"},
103 static const char *render_format_name(int format
)
106 for (i
= 0; i
< sizeof(formats_info
)/sizeof(formats_info
[0]); ++i
) {
107 if (formats_info
[i
].format
== format
)
108 return formats_info
[i
].name
;
114 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
, int *picture_format
)
118 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
119 *picture_format
= PICT_a8r8g8b8
;
123 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
124 *picture_format
= PICT_x8r8g8b8
;
128 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
129 *picture_format
= PICT_r5g6b5
;
133 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
134 *picture_format
= PICT_x1r5g5b5
;
138 *format
= PIPE_FORMAT_L8_UNORM
;
139 *picture_format
= PICT_a8
;
144 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
154 * Static exported EXA functions
158 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
160 /* Nothing to do, handled in the PrepareAccess hook */
164 ExaMarkSync(ScreenPtr pScreen
)
170 /***********************************************************************
171 * Screen upload/download
175 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
178 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
179 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
180 modesettingPtr ms
= modesettingPTR(pScrn
);
181 struct exa_context
*exa
= ms
->exa
;
182 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
183 struct pipe_transfer
*transfer
;
185 if (!priv
|| !priv
->tex
)
188 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
189 PIPE_REFERENCED_FOR_WRITE
)
190 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
192 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
193 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
198 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
199 x
, y
, w
, h
, dst_pitch
);
202 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
203 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
204 transfer
->stride
, 0, 0);
206 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
207 exa
->scrn
->tex_transfer_destroy(transfer
);
213 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
216 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
217 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
218 modesettingPtr ms
= modesettingPTR(pScrn
);
219 struct exa_context
*exa
= ms
->exa
;
220 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
221 struct pipe_transfer
*transfer
;
223 if (!priv
|| !priv
->tex
)
226 /* make sure that any pending operations are flushed to hardware */
227 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
228 (PIPE_REFERENCED_FOR_READ
| PIPE_REFERENCED_FOR_WRITE
))
229 xorg_exa_flush(exa
, 0, NULL
);
231 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
232 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
237 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
238 x
, y
, w
, h
, src_pitch
);
241 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
242 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
243 (unsigned char*)src
, src_pitch
, 0, 0);
245 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
246 exa
->scrn
->tex_transfer_destroy(transfer
);
252 ExaPrepareAccess(PixmapPtr pPix
, int index
)
254 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
255 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
256 modesettingPtr ms
= modesettingPTR(pScrn
);
257 struct exa_context
*exa
= ms
->exa
;
258 struct exa_pixmap_priv
*priv
;
260 priv
= exaGetPixmapDriverPrivate(pPix
);
268 if (priv
->map_count
== 0)
270 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
271 PIPE_REFERENCED_FOR_WRITE
)
272 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
275 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
276 #ifdef EXA_MIXED_PIXMAPS
277 PIPE_TRANSFER_MAP_DIRECTLY
|
279 PIPE_TRANSFER_READ_WRITE
,
280 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
281 if (!priv
->map_transfer
)
282 #ifdef EXA_MIXED_PIXMAPS
285 FatalError("failed to create transfer\n");
288 pPix
->devPrivate
.ptr
=
289 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
290 pPix
->devKind
= priv
->map_transfer
->stride
;
299 ExaFinishAccess(PixmapPtr pPix
, int index
)
301 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
302 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
303 modesettingPtr ms
= modesettingPTR(pScrn
);
304 struct exa_context
*exa
= ms
->exa
;
305 struct exa_pixmap_priv
*priv
;
306 priv
= exaGetPixmapDriverPrivate(pPix
);
311 if (!priv
->map_transfer
)
314 if (--priv
->map_count
== 0) {
315 assert(priv
->map_transfer
);
316 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
317 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
318 priv
->map_transfer
= NULL
;
319 pPix
->devPrivate
.ptr
= NULL
;
323 /***********************************************************************
328 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
330 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
331 modesettingPtr ms
= modesettingPTR(pScrn
);
332 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
333 struct exa_context
*exa
= ms
->exa
;
336 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
339 XORG_FALLBACK("accle not enabled");
341 if (!priv
|| !priv
->tex
)
342 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
344 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
345 XORG_FALLBACK("planeMask is not solid");
348 XORG_FALLBACK("not GXcopy");
350 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
352 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
353 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
356 return exa
->accel
&& xorg_solid_bind_state(exa
, priv
, fg
);
360 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
362 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
363 modesettingPtr ms
= modesettingPTR(pScrn
);
364 struct exa_context
*exa
= ms
->exa
;
365 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
368 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
371 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
376 ExaDoneSolid(PixmapPtr pPixmap
)
378 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
379 modesettingPtr ms
= modesettingPTR(pScrn
);
380 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
381 struct exa_context
*exa
= ms
->exa
;
386 xorg_composite_done(exa
);
389 /***********************************************************************
394 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
395 int ydir
, int alu
, Pixel planeMask
)
397 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
398 modesettingPtr ms
= modesettingPTR(pScrn
);
399 struct exa_context
*exa
= ms
->exa
;
400 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
401 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
404 debug_printf("ExaPrepareCopy\n");
407 XORG_FALLBACK("accle not enabled");
409 if (!priv
|| !priv
->tex
)
410 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
412 if (!src_priv
|| !src_priv
->tex
)
413 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
415 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
416 XORG_FALLBACK("planeMask is not solid");
419 XORG_FALLBACK("alu not GXcopy");
421 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
423 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
424 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
426 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
427 src_priv
->tex
->target
,
428 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
429 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
431 exa
->copy
.src
= src_priv
;
432 exa
->copy
.dst
= priv
;
434 /* For same-surface copies, the pipe->surface_copy path is clearly
435 * superior, providing it is implemented. In other cases it's not
436 * clear what the better path would be, and eventually we'd
437 * probably want to gather timings and choose dynamically.
439 if (exa
->pipe
->surface_copy
&&
440 exa
->copy
.src
== exa
->copy
.dst
) {
442 exa
->copy
.use_surface_copy
= TRUE
;
444 exa
->copy
.src_surface
=
445 exa
->scrn
->get_tex_surface( exa
->scrn
,
448 PIPE_BUFFER_USAGE_GPU_READ
);
450 exa
->copy
.dst_surface
=
451 exa
->scrn
->get_tex_surface( exa
->scrn
,
454 PIPE_BUFFER_USAGE_GPU_WRITE
);
457 exa
->copy
.use_surface_copy
= FALSE
;
459 if (exa
->copy
.dst
== exa
->copy
.src
)
460 exa
->copy
.src_texture
= renderer_clone_texture( exa
->renderer
,
461 exa
->copy
.src
->tex
);
463 pipe_texture_reference(&exa
->copy
.src_texture
,
466 exa
->copy
.dst_surface
=
467 exa
->scrn
->get_tex_surface(exa
->scrn
,
470 PIPE_BUFFER_USAGE_GPU_WRITE
);
473 renderer_copy_prepare(exa
->renderer
,
474 exa
->copy
.dst_surface
,
475 exa
->copy
.src_texture
);
483 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
484 int width
, int height
)
486 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
487 modesettingPtr ms
= modesettingPTR(pScrn
);
488 struct exa_context
*exa
= ms
->exa
;
489 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
492 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
493 srcX
, srcY
, dstX
, dstY
, width
, height
);
496 debug_assert(priv
== exa
->copy
.dst
);
498 if (exa
->copy
.use_surface_copy
) {
499 /* XXX: consider exposing >1 box in surface_copy interface.
501 exa
->pipe
->surface_copy( exa
->pipe
,
502 exa
->copy
.dst_surface
,
504 exa
->copy
.src_surface
,
509 renderer_copy_pixmap(exa
->renderer
,
513 exa
->copy
.src_texture
->width
[0],
514 exa
->copy
.src_texture
->height
[0]);
519 ExaDoneCopy(PixmapPtr pPixmap
)
521 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
522 modesettingPtr ms
= modesettingPTR(pScrn
);
523 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
524 struct exa_context
*exa
= ms
->exa
;
529 renderer_draw_flush(exa
->renderer
);
531 exa
->copy
.src
= NULL
;
532 exa
->copy
.dst
= NULL
;
533 pipe_surface_reference(&exa
->copy
.src_surface
, NULL
);
534 pipe_surface_reference(&exa
->copy
.dst_surface
, NULL
);
535 pipe_texture_reference(&exa
->copy
.src_texture
, NULL
);
541 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
543 if (pSrc
->picture_format
== pSrcPicture
->format
)
546 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
549 /* pSrc->picture_format == PICT_a8r8g8b8 */
550 switch (pSrcPicture
->format
) {
555 /* just treat these two as x8... */
559 #ifdef PICT_TYPE_BGRA
562 return FALSE
; /* does not support swizzleing the alpha channel yet */
563 case PICT_a2r10g10b10
:
564 case PICT_x2r10g10b10
:
565 case PICT_a2b10g10r10
:
566 case PICT_x2b10g10r10
:
575 /***********************************************************************
576 * Composite entrypoints
580 ExaCheckComposite(int op
,
581 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
582 PicturePtr pDstPicture
)
584 ScrnInfoPtr pScrn
= xf86Screens
[pDstPicture
->pDrawable
->pScreen
->myNum
];
585 modesettingPtr ms
= modesettingPTR(pScrn
);
586 struct exa_context
*exa
= ms
->exa
;
587 boolean accelerated
= xorg_composite_accelerated(op
,
592 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
593 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
595 return exa
->accel
&& accelerated
;
600 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
601 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
602 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
604 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
605 modesettingPtr ms
= modesettingPTR(pScrn
);
606 struct exa_context
*exa
= ms
->exa
;
607 struct exa_pixmap_priv
*priv
;
610 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
611 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
612 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
613 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
614 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
615 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
618 XORG_FALLBACK("accle not enabled");
620 priv
= exaGetPixmapDriverPrivate(pDst
);
621 if (!priv
|| !priv
->tex
)
622 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
624 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
626 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
627 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
629 if (priv
->picture_format
!= pDstPicture
->format
)
630 XORG_FALLBACK("pDst pic_format: %s != %s",
631 render_format_name(priv
->picture_format
),
632 render_format_name(pDstPicture
->format
));
635 priv
= exaGetPixmapDriverPrivate(pSrc
);
636 if (!priv
|| !priv
->tex
)
637 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
639 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
641 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
642 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
644 if (!picture_check_formats(priv
, pSrcPicture
))
645 XORG_FALLBACK("pSrc pic_format: %s != %s",
646 render_format_name(priv
->picture_format
),
647 render_format_name(pSrcPicture
->format
));
652 priv
= exaGetPixmapDriverPrivate(pMask
);
653 if (!priv
|| !priv
->tex
)
654 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
656 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
658 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
659 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
661 if (!picture_check_formats(priv
, pMaskPicture
))
662 XORG_FALLBACK("pMask pic_format: %s != %s",
663 render_format_name(priv
->picture_format
),
664 render_format_name(pMaskPicture
->format
));
668 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
670 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
671 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
672 exaGetPixmapDriverPrivate(pDst
));
676 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
677 int dstX
, int dstY
, int width
, int height
)
679 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
680 modesettingPtr ms
= modesettingPTR(pScrn
);
681 struct exa_context
*exa
= ms
->exa
;
682 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
685 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
686 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
687 debug_printf("\t Num bound samplers = %d\n",
688 exa
->num_bound_samplers
);
691 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
692 dstX
, dstY
, width
, height
);
698 ExaDoneComposite(PixmapPtr pPixmap
)
700 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
701 modesettingPtr ms
= modesettingPTR(pScrn
);
702 struct exa_context
*exa
= ms
->exa
;
704 xorg_composite_done(exa
);
708 /***********************************************************************
713 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
715 struct exa_pixmap_priv
*priv
;
717 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
725 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
727 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
732 pipe_texture_reference(&priv
->tex
, NULL
);
738 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
740 struct exa_pixmap_priv
*priv
;
742 priv
= exaGetPixmapDriverPrivate(pPixmap
);
754 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
756 struct exa_pixmap_priv
*priv
;
757 priv
= exaGetPixmapDriverPrivate(pPixmap
);
760 FatalError("NO PIXMAP PRIVATE\n");
764 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
770 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
772 struct exa_pixmap_priv
*priv
;
773 priv
= exaGetPixmapDriverPrivate(pPixmap
);
776 FatalError("NO PIXMAP PRIVATE\n");
780 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
786 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
788 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
789 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
790 modesettingPtr ms
= modesettingPTR(pScrn
);
791 struct exa_pixmap_priv
*priv
;
796 FatalError("NO MS->EXA\n");
800 priv
= exaGetPixmapDriverPrivate(pPixmap
);
803 FatalError("NO PIXMAP PRIVATE\n");
807 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
809 *stride_out
= stride
;
815 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
816 int depth
, int bitsPerPixel
, int devKind
,
819 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
820 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
821 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
822 modesettingPtr ms
= modesettingPTR(pScrn
);
823 struct exa_context
*exa
= ms
->exa
;
825 if (!priv
|| pPixData
)
829 depth
= pPixmap
->drawable
.depth
;
831 if (bitsPerPixel
<= 0)
832 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
835 width
= pPixmap
->drawable
.width
;
838 height
= pPixmap
->drawable
.height
;
840 if (width
<= 0 || height
<= 0 || depth
<= 0)
843 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
844 bitsPerPixel
, devKind
, NULL
);
846 /* Deal with screen resize */
847 if ((exa
->accel
|| priv
->flags
) &&
849 (priv
->tex
->width
[0] != width
||
850 priv
->tex
->height
[0] != height
||
851 priv
->tex_flags
!= priv
->flags
))) {
852 struct pipe_texture
*texture
= NULL
;
853 struct pipe_texture
template;
855 memset(&template, 0, sizeof(template));
856 template.target
= PIPE_TEXTURE_2D
;
857 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
858 pf_get_block(template.format
, &template.block
);
859 template.width
[0] = width
;
860 template.height
[0] = height
;
861 template.depth
[0] = 1;
862 template.last_level
= 0;
863 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
864 priv
->tex_flags
= priv
->flags
;
865 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
868 struct pipe_surface
*dst_surf
;
869 struct pipe_surface
*src_surf
;
871 dst_surf
= exa
->scrn
->get_tex_surface(
872 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
873 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
874 if (exa
->pipe
->surface_copy
) {
875 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
876 0, 0, min(width
, texture
->width
[0]),
877 min(height
, texture
->height
[0]));
879 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
880 0, 0, min(width
, texture
->width
[0]),
881 min(height
, texture
->height
[0]));
883 exa
->scrn
->tex_surface_destroy(dst_surf
);
884 exa
->scrn
->tex_surface_destroy(src_surf
);
887 pipe_texture_reference(&priv
->tex
, texture
);
888 /* the texture we create has one reference */
889 pipe_texture_reference(&texture
, NULL
);
895 struct pipe_texture
*
896 xorg_exa_get_texture(PixmapPtr pPixmap
)
898 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
899 struct pipe_texture
*tex
= NULL
;
900 pipe_texture_reference(&tex
, priv
->tex
);
905 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
907 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
909 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
914 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
915 pPixmap
->drawable
.height
!= tex
->height
[0])
918 pipe_texture_reference(&priv
->tex
, tex
);
919 priv
->tex_flags
= tex
->tex_usage
& mask
;
924 struct pipe_texture
*
925 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
926 int width
, int height
,
927 int depth
, int bitsPerPixel
)
929 modesettingPtr ms
= modesettingPTR(pScrn
);
930 struct exa_context
*exa
= ms
->exa
;
931 struct pipe_texture
template;
934 memset(&template, 0, sizeof(template));
935 template.target
= PIPE_TEXTURE_2D
;
936 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
937 pf_get_block(template.format
, &template.block
);
938 template.width
[0] = width
;
939 template.height
[0] = height
;
940 template.depth
[0] = 1;
941 template.last_level
= 0;
942 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
943 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
944 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
946 return exa
->scrn
->texture_create(exa
->scrn
, &template);
950 xorg_exa_close(ScrnInfoPtr pScrn
)
952 modesettingPtr ms
= modesettingPTR(pScrn
);
953 struct exa_context
*exa
= ms
->exa
;
955 renderer_destroy(exa
->renderer
);
958 exa
->pipe
->destroy(exa
->pipe
);
960 exaDriverFini(pScrn
->pScreen
);
966 xorg_exa_init(ScrnInfoPtr pScrn
, Bool accel
)
968 modesettingPtr ms
= modesettingPTR(pScrn
);
969 struct exa_context
*exa
;
972 exa
= xcalloc(1, sizeof(struct exa_context
));
976 pExa
= exaDriverAlloc();
981 memset(pExa
, 0, sizeof(*pExa
));
985 pExa
->memoryBase
= 0;
986 pExa
->memorySize
= 0;
987 pExa
->offScreenBase
= 0;
988 pExa
->pixmapOffsetAlign
= 0;
989 pExa
->pixmapPitchAlign
= 1;
990 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
991 #ifdef EXA_SUPPORTS_PREPARE_AUX
992 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
994 #ifdef EXA_MIXED_PIXMAPS
995 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
997 pExa
->maxX
= 8191; /* FIXME */
998 pExa
->maxY
= 8191; /* FIXME */
1000 pExa
->WaitMarker
= ExaWaitMarker
;
1001 pExa
->MarkSync
= ExaMarkSync
;
1002 pExa
->PrepareSolid
= ExaPrepareSolid
;
1003 pExa
->Solid
= ExaSolid
;
1004 pExa
->DoneSolid
= ExaDoneSolid
;
1005 pExa
->PrepareCopy
= ExaPrepareCopy
;
1006 pExa
->Copy
= ExaCopy
;
1007 pExa
->DoneCopy
= ExaDoneCopy
;
1008 pExa
->CheckComposite
= ExaCheckComposite
;
1009 pExa
->PrepareComposite
= ExaPrepareComposite
;
1010 pExa
->Composite
= ExaComposite
;
1011 pExa
->DoneComposite
= ExaDoneComposite
;
1012 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
1013 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
1014 pExa
->UploadToScreen
= ExaUploadToScreen
;
1015 pExa
->PrepareAccess
= ExaPrepareAccess
;
1016 pExa
->FinishAccess
= ExaFinishAccess
;
1017 pExa
->CreatePixmap
= ExaCreatePixmap
;
1018 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
1019 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
1021 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
1025 exa
->scrn
= ms
->screen
;
1026 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
1027 /* Share context with DRI */
1028 ms
->ctx
= exa
->pipe
;
1030 exa
->renderer
= renderer_create(exa
->pipe
);
1036 xorg_exa_close(pScrn
);
1041 struct pipe_surface
*
1042 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
1044 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
1045 PIPE_BUFFER_USAGE_GPU_READ
|
1046 PIPE_BUFFER_USAGE_GPU_WRITE
);
1050 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
1051 struct pipe_fence_handle
**fence
)
1053 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
1056 void xorg_exa_finish(struct exa_context
*exa
)
1058 struct pipe_fence_handle
*fence
= NULL
;
1060 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
1062 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
1063 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);