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"
49 #define ACCEL_ENABLED TRUE
54 struct render_format_str
{
58 static const struct render_format_str formats_info
[] =
60 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
61 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
62 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
63 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
65 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
66 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
67 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
68 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
69 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
70 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
72 {PICT_r8g8b8
, "PICT_r8g8b8"},
73 {PICT_b8g8r8
, "PICT_b8g8r8"},
74 {PICT_r5g6b5
, "PICT_r5g6b5"},
75 {PICT_b5g6r5
, "PICT_b5g6r5"},
76 {PICT_a1r5g5b5
, "PICT_a1r5g5b5"},
77 {PICT_x1r5g5b5
, "PICT_x1r5g5b5"},
78 {PICT_a1b5g5r5
, "PICT_a1b5g5r5"},
79 {PICT_x1b5g5r5
, "PICT_x1b5g5r5"},
80 {PICT_a4r4g4b4
, "PICT_a4r4g4b4"},
81 {PICT_x4r4g4b4
, "PICT_x4r4g4b4"},
82 {PICT_a4b4g4r4
, "PICT_a4b4g4r4"},
83 {PICT_x4b4g4r4
, "PICT_x4b4g4r4"},
85 {PICT_r3g3b2
, "PICT_r3g3b2"},
86 {PICT_b2g3r3
, "PICT_b2g3r3"},
87 {PICT_a2r2g2b2
, "PICT_a2r2g2b2"},
88 {PICT_a2b2g2r2
, "PICT_a2b2g2r2"},
91 {PICT_x4a4
, "PICT_x4a4"},
92 {PICT_x4c4
, "PICT_x4c4"},
93 {PICT_x4g4
, "PICT_x4g4"},
95 {PICT_r1g2b1
, "PICT_r1g2b1"},
96 {PICT_b1g2r1
, "PICT_b1g2r1"},
97 {PICT_a1r1g1b1
, "PICT_a1r1g1b1"},
98 {PICT_a1b1g1r1
, "PICT_a1b1g1r1"},
100 {PICT_g4
, "PICT_g4"},
101 {PICT_a1
, "PICT_a1"},
104 static const char *render_format_name(int format
)
107 for (i
= 0; i
< sizeof(formats_info
)/sizeof(formats_info
[0]); ++i
) {
108 if (formats_info
[i
].format
== format
)
109 return formats_info
[i
].name
;
115 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
, int *picture_format
)
119 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
120 *picture_format
= PICT_a8r8g8b8
;
124 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
125 *picture_format
= PICT_x8r8g8b8
;
129 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
130 *picture_format
= PICT_r5g6b5
;
134 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
135 *picture_format
= PICT_x1r5g5b5
;
139 *format
= PIPE_FORMAT_L8_UNORM
;
140 *picture_format
= PICT_a8
;
145 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
154 xorg_exa_common_done(struct exa_context
*exa
)
156 renderer_draw_flush(exa
->renderer
);
158 exa
->copy
.src
= NULL
;
159 exa
->copy
.dst
= NULL
;
160 exa
->transform
.has_src
= FALSE
;
161 exa
->transform
.has_mask
= FALSE
;
162 exa
->has_solid_color
= FALSE
;
163 exa
->num_bound_samplers
= 0;
167 * Static exported EXA functions
171 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
173 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
174 modesettingPtr ms
= modesettingPTR(pScrn
);
175 struct exa_context
*exa
= ms
->exa
;
178 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
180 xorg_exa_finish(exa
);
185 ExaMarkSync(ScreenPtr pScreen
)
191 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
194 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
195 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
196 modesettingPtr ms
= modesettingPTR(pScrn
);
197 struct exa_context
*exa
= ms
->exa
;
198 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
199 struct pipe_transfer
*transfer
;
201 if (!priv
|| !priv
->tex
)
204 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
205 PIPE_REFERENCED_FOR_WRITE
)
206 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
208 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
209 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
214 debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
215 x
, y
, w
, h
, dst_pitch
);
218 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
219 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
220 transfer
->stride
, 0, 0);
222 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
223 exa
->scrn
->tex_transfer_destroy(transfer
);
229 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
232 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
233 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
234 modesettingPtr ms
= modesettingPTR(pScrn
);
235 struct exa_context
*exa
= ms
->exa
;
236 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
237 struct pipe_transfer
*transfer
;
239 if (!priv
|| !priv
->tex
)
242 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
243 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
248 debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
249 x
, y
, w
, h
, src_pitch
);
252 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
253 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
254 (unsigned char*)src
, src_pitch
, 0, 0);
256 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
257 exa
->scrn
->tex_transfer_destroy(transfer
);
263 ExaPrepareAccess(PixmapPtr pPix
, int index
)
265 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
266 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
267 modesettingPtr ms
= modesettingPTR(pScrn
);
268 struct exa_context
*exa
= ms
->exa
;
269 struct exa_pixmap_priv
*priv
;
271 priv
= exaGetPixmapDriverPrivate(pPix
);
279 if (priv
->map_count
== 0)
281 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
282 PIPE_REFERENCED_FOR_WRITE
)
283 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
286 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
287 #ifdef EXA_MIXED_PIXMAPS
288 PIPE_TRANSFER_MAP_DIRECTLY
|
290 PIPE_TRANSFER_READ_WRITE
,
291 0, 0, priv
->tex
->width0
, priv
->tex
->height0
);
292 if (!priv
->map_transfer
)
293 #ifdef EXA_MIXED_PIXMAPS
296 FatalError("failed to create transfer\n");
299 pPix
->devPrivate
.ptr
=
300 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
301 pPix
->devKind
= priv
->map_transfer
->stride
;
310 ExaFinishAccess(PixmapPtr pPix
, int index
)
312 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
313 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
314 modesettingPtr ms
= modesettingPTR(pScrn
);
315 struct exa_context
*exa
= ms
->exa
;
316 struct exa_pixmap_priv
*priv
;
317 priv
= exaGetPixmapDriverPrivate(pPix
);
322 if (!priv
->map_transfer
)
325 if (--priv
->map_count
== 0) {
326 assert(priv
->map_transfer
);
327 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
328 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
329 priv
->map_transfer
= NULL
;
330 pPix
->devPrivate
.ptr
= NULL
;
335 ExaDone(PixmapPtr pPixmap
)
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
;
345 xorg_exa_common_done(exa
);
349 ExaDoneComposite(PixmapPtr pPixmap
)
351 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
352 modesettingPtr ms
= modesettingPTR(pScrn
);
353 struct exa_context
*exa
= ms
->exa
;
355 xorg_exa_common_done(exa
);
359 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
361 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
362 modesettingPtr ms
= modesettingPTR(pScrn
);
363 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
364 struct exa_context
*exa
= ms
->exa
;
367 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
370 XORG_FALLBACK("accle not enabled");
372 if (!priv
|| !priv
->tex
)
373 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
375 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
376 XORG_FALLBACK("planeMask is not solid");
379 XORG_FALLBACK("not GXcopy");
381 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
383 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
384 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
387 return ACCEL_ENABLED
&& xorg_solid_bind_state(exa
, priv
, fg
);
391 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
393 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
394 modesettingPtr ms
= modesettingPTR(pScrn
);
395 struct exa_context
*exa
= ms
->exa
;
396 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
399 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
402 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
406 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
407 int ydir
, int alu
, Pixel planeMask
)
409 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
410 modesettingPtr ms
= modesettingPTR(pScrn
);
411 struct exa_context
*exa
= ms
->exa
;
412 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
413 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
416 debug_printf("ExaPrepareCopy\n");
419 XORG_FALLBACK("accle not enabled");
421 if (!priv
|| !priv
->tex
)
422 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
424 if (!src_priv
|| !src_priv
->tex
)
425 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
427 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
428 XORG_FALLBACK("planeMask is not solid");
431 XORG_FALLBACK("alu not GXcopy");
433 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
435 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
436 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
438 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
439 src_priv
->tex
->target
,
440 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
441 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
443 exa
->copy
.src
= src_priv
;
444 exa
->copy
.dst
= priv
;
446 return ACCEL_ENABLED
;
450 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
451 int width
, int height
)
453 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
454 modesettingPtr ms
= modesettingPTR(pScrn
);
455 struct exa_context
*exa
= ms
->exa
;
456 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
459 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
460 srcX
, srcY
, dstX
, dstY
, width
, height
);
463 debug_assert(priv
== exa
->copy
.dst
);
465 renderer_copy_pixmap(exa
->renderer
, exa
->copy
.dst
, dstX
, dstY
,
466 exa
->copy
.src
, srcX
, srcY
,
471 picture_check_formats(struct exa_pixmap_priv
*pSrc
, PicturePtr pSrcPicture
)
473 if (pSrc
->picture_format
== pSrcPicture
->format
)
476 if (pSrc
->picture_format
!= PICT_a8r8g8b8
)
479 /* pSrc->picture_format == PICT_a8r8g8b8 */
480 switch (pSrcPicture
->format
) {
485 /* just treat these two as x8... */
489 #ifdef PICT_TYPE_BGRA
492 return FALSE
; /* does not support swizzleing the alpha channel yet */
493 case PICT_a2r10g10b10
:
494 case PICT_x2r10g10b10
:
495 case PICT_a2b10g10r10
:
496 case PICT_x2b10g10r10
:
506 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
507 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
508 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
510 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
511 modesettingPtr ms
= modesettingPTR(pScrn
);
512 struct exa_context
*exa
= ms
->exa
;
513 struct exa_pixmap_priv
*priv
;
516 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
517 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
518 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
519 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
520 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
521 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
524 XORG_FALLBACK("accle not enabled");
526 priv
= exaGetPixmapDriverPrivate(pDst
);
527 if (!priv
|| !priv
->tex
)
528 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
530 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
532 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
533 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
535 if (priv
->picture_format
!= pDstPicture
->format
)
536 XORG_FALLBACK("pDst pic_format: %s != %s",
537 render_format_name(priv
->picture_format
),
538 render_format_name(pDstPicture
->format
));
541 priv
= exaGetPixmapDriverPrivate(pSrc
);
542 if (!priv
|| !priv
->tex
)
543 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
545 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
547 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
548 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
550 if (!picture_check_formats(priv
, pSrcPicture
))
551 XORG_FALLBACK("pSrc pic_format: %s != %s",
552 render_format_name(priv
->picture_format
),
553 render_format_name(pSrcPicture
->format
));
555 if (priv
->picture_format
== PICT_a8
)
556 XORG_FALLBACK("pSrc pic_format == PICT_a8");
560 priv
= exaGetPixmapDriverPrivate(pMask
);
561 if (!priv
|| !priv
->tex
)
562 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
564 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
566 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
567 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
569 if (!picture_check_formats(priv
, pMaskPicture
))
570 XORG_FALLBACK("pMask pic_format: %s != %s",
571 render_format_name(priv
->picture_format
),
572 render_format_name(pMaskPicture
->format
));
575 return ACCEL_ENABLED
&&
576 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
578 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
579 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
580 exaGetPixmapDriverPrivate(pDst
));
584 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
585 int dstX
, int dstY
, int width
, int height
)
587 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
588 modesettingPtr ms
= modesettingPTR(pScrn
);
589 struct exa_context
*exa
= ms
->exa
;
590 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
593 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
594 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
595 debug_printf("\t Num bound samplers = %d\n",
596 exa
->num_bound_samplers
);
599 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
600 dstX
, dstY
, width
, height
);
604 ExaCheckComposite(int op
,
605 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
606 PicturePtr pDstPicture
)
608 boolean accelerated
= xorg_composite_accelerated(op
,
613 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
614 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
616 return ACCEL_ENABLED
&& accelerated
;
620 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
622 struct exa_pixmap_priv
*priv
;
624 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
632 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
634 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
639 pipe_texture_reference(&priv
->tex
, NULL
);
645 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
647 struct exa_pixmap_priv
*priv
;
649 priv
= exaGetPixmapDriverPrivate(pPixmap
);
661 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
663 struct exa_pixmap_priv
*priv
;
664 priv
= exaGetPixmapDriverPrivate(pPixmap
);
667 FatalError("NO PIXMAP PRIVATE\n");
671 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
677 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
679 struct exa_pixmap_priv
*priv
;
680 priv
= exaGetPixmapDriverPrivate(pPixmap
);
683 FatalError("NO PIXMAP PRIVATE\n");
687 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
693 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
695 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
696 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
697 modesettingPtr ms
= modesettingPTR(pScrn
);
698 struct exa_pixmap_priv
*priv
;
703 FatalError("NO MS->EXA\n");
707 priv
= exaGetPixmapDriverPrivate(pPixmap
);
710 FatalError("NO PIXMAP PRIVATE\n");
714 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
716 *stride_out
= stride
;
722 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
723 int depth
, int bitsPerPixel
, int devKind
,
726 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
727 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
728 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
729 modesettingPtr ms
= modesettingPTR(pScrn
);
730 struct exa_context
*exa
= ms
->exa
;
732 if (!priv
|| pPixData
)
736 depth
= pPixmap
->drawable
.depth
;
738 if (bitsPerPixel
<= 0)
739 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
742 width
= pPixmap
->drawable
.width
;
745 height
= pPixmap
->drawable
.height
;
747 if (width
<= 0 || height
<= 0 || depth
<= 0)
750 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
751 bitsPerPixel
, devKind
, NULL
);
753 /* Deal with screen resize */
755 (priv
->tex
->width0
!= width
||
756 priv
->tex
->height0
!= height
||
757 priv
->tex_flags
!= priv
->flags
)) {
758 struct pipe_texture
*texture
= NULL
;
759 struct pipe_texture
template;
761 memset(&template, 0, sizeof(template));
762 template.target
= PIPE_TEXTURE_2D
;
763 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
764 pf_get_block(template.format
, &template.block
);
765 template.width0
= width
;
766 template.height0
= height
;
768 template.last_level
= 0;
769 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
770 priv
->tex_flags
= priv
->flags
;
771 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
774 struct pipe_surface
*dst_surf
;
775 struct pipe_surface
*src_surf
;
777 dst_surf
= exa
->scrn
->get_tex_surface(
778 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
779 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
780 if (exa
->pipe
->surface_copy
) {
781 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
782 0, 0, min(width
, texture
->width0
),
783 min(height
, texture
->height0
));
785 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
786 0, 0, min(width
, texture
->width0
),
787 min(height
, texture
->height0
));
789 exa
->scrn
->tex_surface_destroy(dst_surf
);
790 exa
->scrn
->tex_surface_destroy(src_surf
);
793 pipe_texture_reference(&priv
->tex
, texture
);
794 /* the texture we create has one reference */
795 pipe_texture_reference(&texture
, NULL
);
801 struct pipe_texture
*
802 xorg_exa_get_texture(PixmapPtr pPixmap
)
804 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
805 struct pipe_texture
*tex
= NULL
;
806 pipe_texture_reference(&tex
, priv
->tex
);
811 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
813 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
815 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
820 if (pPixmap
->drawable
.width
!= tex
->width0
||
821 pPixmap
->drawable
.height
!= tex
->height0
)
824 pipe_texture_reference(&priv
->tex
, tex
);
825 priv
->tex_flags
= tex
->tex_usage
& mask
;
830 struct pipe_texture
*
831 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
832 int width
, int height
,
833 int depth
, int bitsPerPixel
)
835 modesettingPtr ms
= modesettingPTR(pScrn
);
836 struct exa_context
*exa
= ms
->exa
;
837 struct pipe_texture
template;
840 memset(&template, 0, sizeof(template));
841 template.target
= PIPE_TEXTURE_2D
;
842 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
843 pf_get_block(template.format
, &template.block
);
844 template.width0
= width
;
845 template.height0
= height
;
847 template.last_level
= 0;
848 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
849 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
850 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
852 return exa
->scrn
->texture_create(exa
->scrn
, &template);
856 xorg_exa_close(ScrnInfoPtr pScrn
)
858 modesettingPtr ms
= modesettingPTR(pScrn
);
859 struct exa_context
*exa
= ms
->exa
;
861 renderer_destroy(exa
->renderer
);
864 exa
->pipe
->destroy(exa
->pipe
);
866 exaDriverFini(pScrn
->pScreen
);
872 xorg_exa_init(ScrnInfoPtr pScrn
)
874 modesettingPtr ms
= modesettingPTR(pScrn
);
875 struct exa_context
*exa
;
878 exa
= xcalloc(1, sizeof(struct exa_context
));
882 pExa
= exaDriverAlloc();
887 memset(pExa
, 0, sizeof(*pExa
));
891 pExa
->memoryBase
= 0;
892 pExa
->memorySize
= 0;
893 pExa
->offScreenBase
= 0;
894 pExa
->pixmapOffsetAlign
= 0;
895 pExa
->pixmapPitchAlign
= 1;
896 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
897 #ifdef EXA_SUPPORTS_PREPARE_AUX
898 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
900 #ifdef EXA_MIXED_PIXMAPS
901 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
903 pExa
->maxX
= 8191; /* FIXME */
904 pExa
->maxY
= 8191; /* FIXME */
906 pExa
->WaitMarker
= ExaWaitMarker
;
907 pExa
->MarkSync
= ExaMarkSync
;
908 pExa
->PrepareSolid
= ExaPrepareSolid
;
909 pExa
->Solid
= ExaSolid
;
910 pExa
->DoneSolid
= ExaDone
;
911 pExa
->PrepareCopy
= ExaPrepareCopy
;
912 pExa
->Copy
= ExaCopy
;
913 pExa
->DoneCopy
= ExaDone
;
914 pExa
->CheckComposite
= ExaCheckComposite
;
915 pExa
->PrepareComposite
= ExaPrepareComposite
;
916 pExa
->Composite
= ExaComposite
;
917 pExa
->DoneComposite
= ExaDoneComposite
;
918 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
919 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
920 pExa
->UploadToScreen
= ExaUploadToScreen
;
921 pExa
->PrepareAccess
= ExaPrepareAccess
;
922 pExa
->FinishAccess
= ExaFinishAccess
;
923 pExa
->CreatePixmap
= ExaCreatePixmap
;
924 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
925 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
927 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
931 exa
->scrn
= ms
->screen
;
932 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
933 /* Share context with DRI */
936 exa
->renderer
= renderer_create(exa
->pipe
);
941 xorg_exa_close(pScrn
);
946 struct pipe_surface
*
947 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
949 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
950 PIPE_BUFFER_USAGE_GPU_READ
|
951 PIPE_BUFFER_USAGE_GPU_WRITE
);
955 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
956 struct pipe_fence_handle
**fence
)
958 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
961 void xorg_exa_finish(struct exa_context
*exa
)
963 struct pipe_fence_handle
*fence
= NULL
;
965 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
967 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
968 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);