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
55 struct render_format_str
{
59 static const struct render_format_str formats_info
[] =
61 {PICT_a2r10g10b10
, "PICT_a2r10g10b10"},
62 {PICT_x2r10g10b10
, "PICT_x2r10g10b10"},
63 {PICT_a2b10g10r10
, "PICT_a2b10g10r10"},
64 {PICT_x2b10g10r10
, "PICT_x2b10g10r10"},
65 {PICT_a8r8g8b8
, "PICT_a8r8g8b8"},
66 {PICT_x8r8g8b8
, "PICT_x8r8g8b8"},
67 {PICT_a8b8g8r8
, "PICT_a8b8g8r8"},
68 {PICT_x8b8g8r8
, "PICT_x8b8g8r8"},
69 {PICT_b8g8r8a8
, "PICT_b8g8r8a8"},
70 {PICT_b8g8r8x8
, "PICT_b8g8r8x8"},
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
;
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
->width
[0], priv
->tex
->height
[0]);
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 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
472 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
473 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
475 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
476 modesettingPtr ms
= modesettingPTR(pScrn
);
477 struct exa_context
*exa
= ms
->exa
;
478 struct exa_pixmap_priv
*priv
;
481 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
482 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
483 debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
484 pSrcPicture
? render_format_name(pSrcPicture
->format
) : "none",
485 pMaskPicture
? render_format_name(pMaskPicture
->format
) : "none",
486 pDstPicture
? render_format_name(pDstPicture
->format
) : "none");
489 XORG_FALLBACK("accle not enabled");
491 priv
= exaGetPixmapDriverPrivate(pDst
);
492 if (!priv
|| !priv
->tex
)
493 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
495 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
497 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
498 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
500 if (priv
->picture_format
!= pDstPicture
->format
)
501 XORG_FALLBACK("pDst pic_format: %s != %s",
502 render_format_name(priv
->picture_format
),
503 render_format_name(pDstPicture
->format
));
506 priv
= exaGetPixmapDriverPrivate(pSrc
);
507 if (!priv
|| !priv
->tex
)
508 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
510 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
512 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
513 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
515 if (priv
->picture_format
!= pSrcPicture
->format
)
516 XORG_FALLBACK("pSrc pic_format: %s != %s",
517 render_format_name(priv
->picture_format
),
518 render_format_name(pSrcPicture
->format
));
522 priv
= exaGetPixmapDriverPrivate(pMask
);
523 if (!priv
|| !priv
->tex
)
524 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
526 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
528 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
529 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
531 if (priv
->picture_format
!= pMaskPicture
->format
)
532 XORG_FALLBACK("pMask pic_format: %s != %s",
533 render_format_name(priv
->picture_format
),
534 render_format_name(pMaskPicture
->format
));
537 return ACCEL_ENABLED
&&
538 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
540 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
541 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
542 exaGetPixmapDriverPrivate(pDst
));
546 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
547 int dstX
, int dstY
, int width
, int height
)
549 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
550 modesettingPtr ms
= modesettingPTR(pScrn
);
551 struct exa_context
*exa
= ms
->exa
;
552 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
555 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
556 srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
557 debug_printf("\t Num bound samplers = %d\n",
558 exa
->num_bound_samplers
);
561 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
562 dstX
, dstY
, width
, height
);
566 ExaCheckComposite(int op
,
567 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
568 PicturePtr pDstPicture
)
570 boolean accelerated
= xorg_composite_accelerated(op
,
575 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
576 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
578 return ACCEL_ENABLED
&& accelerated
;
582 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
584 struct exa_pixmap_priv
*priv
;
586 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
594 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
596 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
601 pipe_texture_reference(&priv
->tex
, NULL
);
607 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
609 struct exa_pixmap_priv
*priv
;
611 priv
= exaGetPixmapDriverPrivate(pPixmap
);
623 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
625 struct exa_pixmap_priv
*priv
;
626 priv
= exaGetPixmapDriverPrivate(pPixmap
);
629 FatalError("NO PIXMAP PRIVATE\n");
633 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
639 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
641 struct exa_pixmap_priv
*priv
;
642 priv
= exaGetPixmapDriverPrivate(pPixmap
);
645 FatalError("NO PIXMAP PRIVATE\n");
649 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
655 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
657 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
658 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
659 modesettingPtr ms
= modesettingPTR(pScrn
);
660 struct exa_pixmap_priv
*priv
;
665 FatalError("NO MS->EXA\n");
669 priv
= exaGetPixmapDriverPrivate(pPixmap
);
672 FatalError("NO PIXMAP PRIVATE\n");
676 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
678 *stride_out
= stride
;
684 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
685 int depth
, int bitsPerPixel
, int devKind
,
688 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
689 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
690 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
691 modesettingPtr ms
= modesettingPTR(pScrn
);
692 struct exa_context
*exa
= ms
->exa
;
694 if (!priv
|| pPixData
)
698 depth
= pPixmap
->drawable
.depth
;
700 if (bitsPerPixel
<= 0)
701 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
704 width
= pPixmap
->drawable
.width
;
707 height
= pPixmap
->drawable
.height
;
709 if (width
<= 0 || height
<= 0 || depth
<= 0)
712 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
713 bitsPerPixel
, devKind
, NULL
);
715 /* Deal with screen resize */
717 (priv
->tex
->width
[0] != width
||
718 priv
->tex
->height
[0] != height
||
719 priv
->tex_flags
!= priv
->flags
)) {
720 struct pipe_texture
*texture
= NULL
;
721 struct pipe_texture
template;
723 memset(&template, 0, sizeof(template));
724 template.target
= PIPE_TEXTURE_2D
;
725 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &priv
->picture_format
);
726 pf_get_block(template.format
, &template.block
);
727 template.width
[0] = width
;
728 template.height
[0] = height
;
729 template.depth
[0] = 1;
730 template.last_level
= 0;
731 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
732 priv
->tex_flags
= priv
->flags
;
733 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
736 struct pipe_surface
*dst_surf
;
737 struct pipe_surface
*src_surf
;
739 dst_surf
= exa
->scrn
->get_tex_surface(
740 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
741 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
742 if (exa
->pipe
->surface_copy
) {
743 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
744 0, 0, min(width
, texture
->width
[0]),
745 min(height
, texture
->height
[0]));
747 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
748 0, 0, min(width
, texture
->width
[0]),
749 min(height
, texture
->height
[0]));
751 exa
->scrn
->tex_surface_destroy(dst_surf
);
752 exa
->scrn
->tex_surface_destroy(src_surf
);
755 pipe_texture_reference(&priv
->tex
, texture
);
756 /* the texture we create has one reference */
757 pipe_texture_reference(&texture
, NULL
);
763 struct pipe_texture
*
764 xorg_exa_get_texture(PixmapPtr pPixmap
)
766 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
767 struct pipe_texture
*tex
= NULL
;
768 pipe_texture_reference(&tex
, priv
->tex
);
773 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
775 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
777 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
782 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
783 pPixmap
->drawable
.height
!= tex
->height
[0])
786 pipe_texture_reference(&priv
->tex
, tex
);
787 priv
->tex_flags
= tex
->tex_usage
& mask
;
792 struct pipe_texture
*
793 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
794 int width
, int height
,
795 int depth
, int bitsPerPixel
)
797 modesettingPtr ms
= modesettingPTR(pScrn
);
798 struct exa_context
*exa
= ms
->exa
;
799 struct pipe_texture
template;
802 memset(&template, 0, sizeof(template));
803 template.target
= PIPE_TEXTURE_2D
;
804 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
, &dummy
);
805 pf_get_block(template.format
, &template.block
);
806 template.width
[0] = width
;
807 template.height
[0] = height
;
808 template.depth
[0] = 1;
809 template.last_level
= 0;
810 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
811 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
812 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
814 return exa
->scrn
->texture_create(exa
->scrn
, &template);
818 xorg_exa_close(ScrnInfoPtr pScrn
)
820 modesettingPtr ms
= modesettingPTR(pScrn
);
821 struct exa_context
*exa
= ms
->exa
;
823 renderer_destroy(exa
->renderer
);
826 exa
->pipe
->destroy(exa
->pipe
);
828 exaDriverFini(pScrn
->pScreen
);
834 xorg_exa_init(ScrnInfoPtr pScrn
)
836 modesettingPtr ms
= modesettingPTR(pScrn
);
837 struct exa_context
*exa
;
840 exa
= xcalloc(1, sizeof(struct exa_context
));
844 pExa
= exaDriverAlloc();
849 memset(pExa
, 0, sizeof(*pExa
));
853 pExa
->memoryBase
= 0;
854 pExa
->memorySize
= 0;
855 pExa
->offScreenBase
= 0;
856 pExa
->pixmapOffsetAlign
= 0;
857 pExa
->pixmapPitchAlign
= 1;
858 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
859 #ifdef EXA_SUPPORTS_PREPARE_AUX
860 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
862 #ifdef EXA_MIXED_PIXMAPS
863 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
865 pExa
->maxX
= 8191; /* FIXME */
866 pExa
->maxY
= 8191; /* FIXME */
868 pExa
->WaitMarker
= ExaWaitMarker
;
869 pExa
->MarkSync
= ExaMarkSync
;
870 pExa
->PrepareSolid
= ExaPrepareSolid
;
871 pExa
->Solid
= ExaSolid
;
872 pExa
->DoneSolid
= ExaDone
;
873 pExa
->PrepareCopy
= ExaPrepareCopy
;
874 pExa
->Copy
= ExaCopy
;
875 pExa
->DoneCopy
= ExaDone
;
876 pExa
->CheckComposite
= ExaCheckComposite
;
877 pExa
->PrepareComposite
= ExaPrepareComposite
;
878 pExa
->Composite
= ExaComposite
;
879 pExa
->DoneComposite
= ExaDoneComposite
;
880 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
881 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
882 pExa
->UploadToScreen
= ExaUploadToScreen
;
883 pExa
->PrepareAccess
= ExaPrepareAccess
;
884 pExa
->FinishAccess
= ExaFinishAccess
;
885 pExa
->CreatePixmap
= ExaCreatePixmap
;
886 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
887 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
889 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
893 exa
->scrn
= ms
->screen
;
894 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
895 /* Share context with DRI */
898 exa
->renderer
= renderer_create(exa
->pipe
);
903 xorg_exa_close(pScrn
);
908 struct pipe_surface
*
909 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
911 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
912 PIPE_BUFFER_USAGE_GPU_READ
|
913 PIPE_BUFFER_USAGE_GPU_WRITE
);
917 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
918 struct pipe_fence_handle
**fence
)
920 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
923 void xorg_exa_finish(struct exa_context
*exa
)
925 struct pipe_fence_handle
*fence
= NULL
;
927 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
929 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
930 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);