2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
32 #include "xorg_tracker.h"
33 #include "xorg_composite.h"
34 #include "xorg_exa_tgsi.h"
36 #include <xorg-server.h>
38 #include <picturestr.h>
41 #include "pipe/p_format.h"
42 #include "pipe/p_context.h"
43 #include "pipe/p_state.h"
45 #include "util/u_rect.h"
46 #include "util/u_math.h"
47 #include "util/u_debug.h"
48 #include "util/u_format.h"
49 #include "util/u_box.h"
50 #include "util/u_surface.h"
52 #define ROUND_UP_TEXTURES 1
55 exa_debug_printf(const char *format, ...) _util_printf_format(1,2);
58 exa_debug_printf(const char *format, ...)
63 _debug_vprintf(format, ap);
66 (void) format; /* silence warning */
73 struct render_format_str {
77 static const struct render_format_str formats_info[] =
79 {PICT_a8r8g8b8, "PICT_a8r8g8b8"},
80 {PICT_x8r8g8b8, "PICT_x8r8g8b8"},
81 {PICT_a8b8g8r8, "PICT_a8b8g8r8"},
82 {PICT_x8b8g8r8, "PICT_x8b8g8r8"},
84 {PICT_b8g8r8a8, "PICT_b8g8r8a8"},
85 {PICT_b8g8r8x8, "PICT_b8g8r8x8"},
86 {PICT_a2r10g10b10, "PICT_a2r10g10b10"},
87 {PICT_x2r10g10b10, "PICT_x2r10g10b10"},
88 {PICT_a2b10g10r10, "PICT_a2b10g10r10"},
89 {PICT_x2b10g10r10, "PICT_x2b10g10r10"},
91 {PICT_r8g8b8, "PICT_r8g8b8"},
92 {PICT_b8g8r8, "PICT_b8g8r8"},
93 {PICT_r5g6b5, "PICT_r5g6b5"},
94 {PICT_b5g6r5, "PICT_b5g6r5"},
95 {PICT_a1r5g5b5, "PICT_a1r5g5b5"},
96 {PICT_x1r5g5b5, "PICT_x1r5g5b5"},
97 {PICT_a1b5g5r5, "PICT_a1b5g5r5"},
98 {PICT_x1b5g5r5, "PICT_x1b5g5r5"},
99 {PICT_a4r4g4b4, "PICT_a4r4g4b4"},
100 {PICT_x4r4g4b4, "PICT_x4r4g4b4"},
101 {PICT_a4b4g4r4, "PICT_a4b4g4r4"},
102 {PICT_x4b4g4r4, "PICT_x4b4g4r4"},
103 {PICT_a8, "PICT_a8"},
104 {PICT_r3g3b2, "PICT_r3g3b2"},
105 {PICT_b2g3r3, "PICT_b2g3r3"},
106 {PICT_a2r2g2b2, "PICT_a2r2g2b2"},
107 {PICT_a2b2g2r2, "PICT_a2b2g2r2"},
108 {PICT_c8, "PICT_c8"},
109 {PICT_g8, "PICT_g8"},
110 {PICT_x4a4, "PICT_x4a4"},
111 {PICT_x4c4, "PICT_x4c4"},
112 {PICT_x4g4, "PICT_x4g4"},
113 {PICT_a4, "PICT_a4"},
114 {PICT_r1g2b1, "PICT_r1g2b1"},
115 {PICT_b1g2r1, "PICT_b1g2r1"},
116 {PICT_a1r1g1b1, "PICT_a1r1g1b1"},
117 {PICT_a1b1g1r1, "PICT_a1b1g1r1"},
118 {PICT_c4, "PICT_c4"},
119 {PICT_g4, "PICT_g4"},
120 {PICT_a1, "PICT_a1"},
123 static const char *render_format_name(int format)
126 for (i = 0; i < sizeof(formats_info)/sizeof(formats_info[0]); ++i) {
127 if (formats_info[i].format == format)
128 return formats_info[i].name;
134 exa_get_pipe_format(int depth, enum pipe_format *format, int *bbp, int *picture_format)
138 *format = PIPE_FORMAT_B8G8R8A8_UNORM;
139 *picture_format = PICT_a8r8g8b8;
143 *format = PIPE_FORMAT_B8G8R8X8_UNORM;
144 *picture_format = PICT_x8r8g8b8;
148 *format = PIPE_FORMAT_B5G6R5_UNORM;
149 *picture_format = PICT_r5g6b5;
153 *format = PIPE_FORMAT_B5G5R5A1_UNORM;
154 *picture_format = PICT_x1r5g5b5;
158 *format = PIPE_FORMAT_L8_UNORM;
159 *picture_format = PICT_a8;
164 *format = PIPE_FORMAT_B8G8R8A8_UNORM; /* bad bad bad */
174 * Static exported EXA functions
178 ExaWaitMarker(ScreenPtr pScreen, int marker)
180 /* Nothing to do, handled in the PrepareAccess hook */
184 ExaMarkSync(ScreenPtr pScreen)
190 /***********************************************************************
191 * Screen upload/download
195 ExaDownloadFromScreen(PixmapPtr pPix, int x, int y, int w, int h, char *dst,
198 ScreenPtr pScreen = pPix->drawable.pScreen;
199 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
200 modesettingPtr ms = modesettingPTR(pScrn);
201 struct exa_context *exa = ms->exa;
202 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix);
203 struct pipe_transfer *transfer;
205 if (!priv || !priv->tex)
208 transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0,
209 PIPE_TRANSFER_READ, x, y, w, h);
213 exa_debug_printf("------ ExaDownloadFromScreen(%d, %d, %d, %d, %d)\n",
214 x, y, w, h, dst_pitch);
216 util_copy_rect((unsigned char*)dst, priv->tex->format, dst_pitch, 0, 0,
217 w, h, exa->pipe->transfer_map(exa->pipe, transfer),
218 transfer->stride, 0, 0);
220 exa->pipe->transfer_unmap(exa->pipe, transfer);
221 exa->pipe->transfer_destroy(exa->pipe, transfer);
227 ExaUploadToScreen(PixmapPtr pPix, int x, int y, int w, int h, char *src,
230 ScreenPtr pScreen = pPix->drawable.pScreen;
231 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
232 modesettingPtr ms = modesettingPTR(pScrn);
233 struct exa_context *exa = ms->exa;
234 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPix);
235 struct pipe_transfer *transfer;
237 if (!priv || !priv->tex)
240 transfer = pipe_get_transfer(exa->pipe, priv->tex, 0, 0,
241 PIPE_TRANSFER_WRITE, x, y, w, h);
245 exa_debug_printf("++++++ ExaUploadToScreen(%d, %d, %d, %d, %d)\n",
246 x, y, w, h, src_pitch);
248 util_copy_rect(exa->pipe->transfer_map(exa->pipe, transfer),
249 priv->tex->format, transfer->stride, 0, 0, w, h,
250 (unsigned char*)src, src_pitch, 0, 0);
252 exa->pipe->transfer_unmap(exa->pipe, transfer);
253 exa->pipe->transfer_destroy(exa->pipe, transfer);
259 ExaPrepareAccess(PixmapPtr pPix, int index)
261 ScreenPtr pScreen = pPix->drawable.pScreen;
262 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
263 modesettingPtr ms = modesettingPTR(pScrn);
264 struct exa_context *exa = ms->exa;
265 struct exa_pixmap_priv *priv;
267 priv = exaGetPixmapDriverPrivate(pPix);
275 exa_debug_printf("ExaPrepareAccess %d\n", index);
277 if (priv->map_count == 0)
279 assert(pPix->drawable.width <= priv->tex->width0);
280 assert(pPix->drawable.height <= priv->tex->height0);
283 pipe_get_transfer(exa->pipe, priv->tex, 0, 0,
284 #ifdef EXA_MIXED_PIXMAPS
285 PIPE_TRANSFER_MAP_DIRECTLY |
287 PIPE_TRANSFER_READ_WRITE,
289 pPix->drawable.width,
290 pPix->drawable.height );
291 if (!priv->map_transfer)
292 #ifdef EXA_MIXED_PIXMAPS
295 FatalError("failed to create transfer\n");
298 pPix->devPrivate.ptr =
299 exa->pipe->transfer_map(exa->pipe, priv->map_transfer);
300 pPix->devKind = priv->map_transfer->stride;
305 exa_debug_printf("ExaPrepareAccess %d prepared\n", index);
311 ExaFinishAccess(PixmapPtr pPix, int index)
313 ScreenPtr pScreen = pPix->drawable.pScreen;
314 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
315 modesettingPtr ms = modesettingPTR(pScrn);
316 struct exa_context *exa = ms->exa;
317 struct exa_pixmap_priv *priv;
318 priv = exaGetPixmapDriverPrivate(pPix);
323 if (!priv->map_transfer)
326 exa_debug_printf("ExaFinishAccess %d\n", index);
328 if (--priv->map_count == 0) {
329 assert(priv->map_transfer);
330 exa->pipe->transfer_unmap(exa->pipe, priv->map_transfer);
331 exa->pipe->transfer_destroy(exa->pipe, priv->map_transfer);
332 priv->map_transfer = NULL;
333 pPix->devPrivate.ptr = NULL;
336 exa_debug_printf("ExaFinishAccess %d finished\n", index);
339 /***********************************************************************
344 ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
346 ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
347 modesettingPtr ms = modesettingPTR(pScrn);
348 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
349 struct exa_context *exa = ms->exa;
351 exa_debug_printf("ExaPrepareSolid(0x%x)\n", fg);
357 XORG_FALLBACK("accel not enabled");
359 if (!priv || !priv->tex)
360 XORG_FALLBACK("%s", !priv ? "!priv" : "!priv->tex");
362 if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
363 XORG_FALLBACK("planeMask is not solid");
366 XORG_FALLBACK("not GXcopy");
368 if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
369 priv->tex->target, 0,
370 PIPE_BIND_RENDER_TARGET)) {
371 XORG_FALLBACK("format %s", util_format_name(priv->tex->format));
374 return xorg_solid_bind_state(exa, priv, fg);
378 ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
380 ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
381 modesettingPtr ms = modesettingPTR(pScrn);
382 struct exa_context *exa = ms->exa;
383 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
385 exa_debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0, y0, x1, y1);
387 if (x0 == 0 && y0 == 0 &&
388 x1 == pPixmap->drawable.width && y1 == pPixmap->drawable.height) {
389 union pipe_color_union solid_color;
390 solid_color.f[0] = exa->solid_color[0];
391 solid_color.f[1] = exa->solid_color[1];
392 solid_color.f[2] = exa->solid_color[2];
393 solid_color.f[3] = exa->solid_color[3];
394 exa->pipe->clear(exa->pipe, PIPE_CLEAR_COLOR, &solid_color, 0.0, 0);
398 xorg_solid(exa, priv, x0, y0, x1, y1) ;
403 ExaDoneSolid(PixmapPtr pPixmap)
405 ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
406 modesettingPtr ms = modesettingPTR(pScrn);
407 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
408 struct exa_context *exa = ms->exa;
413 exa_debug_printf("ExaDoneSolid\n");
414 xorg_composite_done(exa);
415 exa_debug_printf("ExaDoneSolid done\n");
418 /***********************************************************************
423 ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
424 int ydir, int alu, Pixel planeMask)
426 ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPixmap->drawable.pScreen);
427 modesettingPtr ms = modesettingPTR(pScrn);
428 struct exa_context *exa = ms->exa;
429 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
430 struct exa_pixmap_priv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
432 exa_debug_printf("ExaPrepareCopy\n");
438 XORG_FALLBACK("accel not enabled");
440 if (!priv || !priv->tex)
441 XORG_FALLBACK("pDst %s", !priv ? "!priv" : "!priv->tex");
443 if (!src_priv || !src_priv->tex)
444 XORG_FALLBACK("pSrc %s", !src_priv ? "!priv" : "!priv->tex");
446 if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
447 XORG_FALLBACK("planeMask is not solid");
450 XORG_FALLBACK("alu not GXcopy");
452 if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
453 priv->tex->target, 0,
454 PIPE_BIND_RENDER_TARGET))
455 XORG_FALLBACK("pDst format %s", util_format_name(priv->tex->format));
457 if (!exa->scrn->is_format_supported(exa->scrn, src_priv->tex->format,
458 src_priv->tex->target, 0,
459 PIPE_BIND_SAMPLER_VIEW))
460 XORG_FALLBACK("pSrc format %s", util_format_name(src_priv->tex->format));
462 exa->copy.src = src_priv;
463 exa->copy.dst = priv;
469 ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
470 int width, int height)
472 ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPixmap->drawable.pScreen);
473 modesettingPtr ms = modesettingPTR(pScrn);
474 struct exa_context *exa = ms->exa;
475 struct pipe_box src_box;
477 exa_debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
478 srcX, srcY, dstX, dstY, width, height);
480 debug_assert(exaGetPixmapDriverPrivate(pDstPixmap) == exa->copy.dst);
482 u_box_2d(srcX, srcY, width, height, &src_box);
484 /* If source and destination overlap, we have to copy to/from a scratch
487 if (exa->copy.dst == exa->copy.src &&
488 !((dstX + width) < srcX || dstX > (srcX + width) ||
489 (dstY + height) < srcY || dstY > (srcY + height))) {
490 struct exa_pixmap_priv *tmp_priv;
492 if (!exa->copy.tmp_pix) {
493 exa->copy.tmp_pix = pScrn->pScreen->CreatePixmap(pScrn->pScreen,
494 pDstPixmap->drawable.width,
495 pDstPixmap->drawable.height,
496 pDstPixmap->drawable.depth,
497 pDstPixmap->drawable.width);
498 exaMoveInPixmap(exa->copy.tmp_pix);
501 tmp_priv = exaGetPixmapDriverPrivate(exa->copy.tmp_pix);
503 exa->pipe->resource_copy_region( exa->pipe,
509 exa->pipe->resource_copy_region( exa->pipe,
516 exa->pipe->resource_copy_region( exa->pipe,
525 ExaDoneCopy(PixmapPtr pPixmap)
527 ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
528 modesettingPtr ms = modesettingPTR(pScrn);
529 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
530 struct exa_context *exa = ms->exa;
535 exa_debug_printf("ExaDoneCopy\n");
537 if (exa->copy.tmp_pix) {
538 pScrn->pScreen->DestroyPixmap(exa->copy.tmp_pix);
539 exa->copy.tmp_pix = NULL;
541 exa->copy.src = NULL;
542 exa->copy.dst = NULL;
544 exa_debug_printf("ExaDoneCopy done\n");
550 picture_check_formats(struct exa_pixmap_priv *pSrc, PicturePtr pSrcPicture)
552 if (pSrc->picture_format == pSrcPicture->format)
555 if (pSrc->picture_format != PICT_a8r8g8b8)
558 /* pSrc->picture_format == PICT_a8r8g8b8 */
559 switch (pSrcPicture->format) {
564 /* just treat these two as x8... */
568 #ifdef PICT_TYPE_BGRA
571 return FALSE; /* does not support swizzleing the alpha channel yet */
572 case PICT_a2r10g10b10:
573 case PICT_x2r10g10b10:
574 case PICT_a2b10g10r10:
575 case PICT_x2b10g10r10:
584 /***********************************************************************
585 * Composite entrypoints
589 ExaCheckComposite(int op,
590 PicturePtr pSrcPicture, PicturePtr pMaskPicture,
591 PicturePtr pDstPicture)
593 ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPicture->pDrawable->pScreen);
594 modesettingPtr ms = modesettingPTR(pScrn);
595 struct exa_context *exa = ms->exa;
596 Bool accelerated = exa->accel && xorg_composite_accelerated(op,
601 exa_debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
602 op, pSrcPicture, pMaskPicture, pDstPicture, accelerated);
609 ExaPrepareComposite(int op, PicturePtr pSrcPicture,
610 PicturePtr pMaskPicture, PicturePtr pDstPicture,
611 PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
613 ScrnInfoPtr pScrn = xf86ScreenToScrn(pDst->drawable.pScreen);
614 modesettingPtr ms = modesettingPTR(pScrn);
615 struct exa_context *exa = ms->exa;
616 struct exa_pixmap_priv *priv;
621 exa_debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
622 op, pSrcPicture, pMaskPicture, pDstPicture);
623 exa_debug_printf("\tFormats: src(%s), mask(%s), dst(%s)\n",
624 pSrcPicture ? render_format_name(pSrcPicture->format) : "none",
625 pMaskPicture ? render_format_name(pMaskPicture->format) : "none",
626 pDstPicture ? render_format_name(pDstPicture->format) : "none");
629 XORG_FALLBACK("accel not enabled");
631 priv = exaGetPixmapDriverPrivate(pDst);
632 if (!priv || !priv->tex)
633 XORG_FALLBACK("pDst %s", !priv ? "!priv" : "!priv->tex");
635 if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
636 priv->tex->target, 0,
637 PIPE_BIND_RENDER_TARGET))
638 XORG_FALLBACK("pDst format: %s", util_format_name(priv->tex->format));
640 if (priv->picture_format != pDstPicture->format)
641 XORG_FALLBACK("pDst pic_format: %s != %s",
642 render_format_name(priv->picture_format),
643 render_format_name(pDstPicture->format));
646 priv = exaGetPixmapDriverPrivate(pSrc);
647 if (!priv || !priv->tex)
648 XORG_FALLBACK("pSrc %s", !priv ? "!priv" : "!priv->tex");
650 if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
651 priv->tex->target, 0,
652 PIPE_BIND_SAMPLER_VIEW))
653 XORG_FALLBACK("pSrc format: %s", util_format_name(priv->tex->format));
655 if (!picture_check_formats(priv, pSrcPicture))
656 XORG_FALLBACK("pSrc pic_format: %s != %s",
657 render_format_name(priv->picture_format),
658 render_format_name(pSrcPicture->format));
663 priv = exaGetPixmapDriverPrivate(pMask);
664 if (!priv || !priv->tex)
665 XORG_FALLBACK("pMask %s", !priv ? "!priv" : "!priv->tex");
667 if (!exa->scrn->is_format_supported(exa->scrn, priv->tex->format,
668 priv->tex->target, 0,
669 PIPE_BIND_SAMPLER_VIEW))
670 XORG_FALLBACK("pMask format: %s", util_format_name(priv->tex->format));
672 if (!picture_check_formats(priv, pMaskPicture))
673 XORG_FALLBACK("pMask pic_format: %s != %s",
674 render_format_name(priv->picture_format),
675 render_format_name(pMaskPicture->format));
678 return xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture,
680 pSrc ? exaGetPixmapDriverPrivate(pSrc) : NULL,
681 pMask ? exaGetPixmapDriverPrivate(pMask) : NULL,
682 exaGetPixmapDriverPrivate(pDst));
686 ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
687 int dstX, int dstY, int width, int height)
689 ScrnInfoPtr pScrn = xf86ScreenToScrn(pDst->drawable.pScreen);
690 modesettingPtr ms = modesettingPTR(pScrn);
691 struct exa_context *exa = ms->exa;
692 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDst);
694 exa_debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n",
695 srcX, srcY, maskX, maskY, dstX, dstY, width, height);
696 exa_debug_printf("\t Num bound samplers = %d\n",
697 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 = xf86ScreenToScrn(pPixmap->drawable.pScreen);
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 = calloc(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_resource_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_BIND_SCANOUT;
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_BIND_SHARED;
796 size_match( int width, int tex_width )
798 #if ROUND_UP_TEXTURES
799 if (width > tex_width)
802 if (width * 2 < tex_width)
807 return width == tex_width;
812 ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
813 int depth, int bitsPerPixel, int devKind,
816 ScreenPtr pScreen = pPixmap->drawable.pScreen;
817 ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
818 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
819 modesettingPtr ms = modesettingPTR(pScrn);
820 struct exa_context *exa = ms->exa;
822 if (!priv || pPixData)
826 debug_printf("%s pixmap %p sz %dx%dx%d devKind %d\n",
827 __FUNCTION__, pPixmap, width, height, bitsPerPixel, devKind);
830 debug_printf(" ==> old texture %dx%d\n",
837 depth = pPixmap->drawable.depth;
839 if (bitsPerPixel <= 0)
840 bitsPerPixel = pPixmap->drawable.bitsPerPixel;
843 width = pPixmap->drawable.width;
846 height = pPixmap->drawable.height;
848 if (width <= 0 || height <= 0 || depth <= 0)
851 miModifyPixmapHeader(pPixmap, width, height, depth,
852 bitsPerPixel, devKind, NULL);
855 priv->height = height;
857 /* Deal with screen resize */
858 if ((exa->accel || priv->flags) &&
860 !size_match(width, priv->tex->width0) ||
861 !size_match(height, priv->tex->height0) ||
862 priv->tex_flags != priv->flags)) {
863 struct pipe_resource *texture = NULL;
864 struct pipe_resource template;
866 memset(&template, 0, sizeof(template));
867 template.target = PIPE_TEXTURE_2D;
868 exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &priv->picture_format);
869 if (ROUND_UP_TEXTURES && priv->flags == 0) {
870 template.width0 = util_next_power_of_two(width);
871 template.height0 = util_next_power_of_two(height);
874 template.width0 = width;
875 template.height0 = height;
879 template.array_size = 1;
880 template.last_level = 0;
881 template.bind = PIPE_BIND_RENDER_TARGET | priv->flags;
882 priv->tex_flags = priv->flags;
883 texture = exa->scrn->resource_create(exa->scrn, &template);
886 struct pipe_box src_box;
887 u_box_origin_2d(min(width, texture->width0),
888 min(height, texture->height0),
890 exa->pipe->resource_copy_region(exa->pipe, texture,
896 pipe_resource_reference(&priv->tex, texture);
897 /* the texture we create has one reference */
898 pipe_resource_reference(&texture, NULL);
904 struct pipe_resource *
905 xorg_exa_get_texture(PixmapPtr pPixmap)
907 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
908 struct pipe_resource *tex = NULL;
909 pipe_resource_reference(&tex, priv->tex);
914 xorg_exa_set_texture(PixmapPtr pPixmap, struct pipe_resource *tex)
916 struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
918 int mask = PIPE_BIND_SHARED | PIPE_BIND_SCANOUT;
923 if (pPixmap->drawable.width != tex->width0 ||
924 pPixmap->drawable.height != tex->height0)
927 pipe_resource_reference(&priv->tex, tex);
928 priv->tex_flags = tex->bind & mask;
933 struct pipe_resource *
934 xorg_exa_create_root_texture(ScrnInfoPtr pScrn,
935 int width, int height,
936 int depth, int bitsPerPixel)
938 modesettingPtr ms = modesettingPTR(pScrn);
939 struct exa_context *exa = ms->exa;
940 struct pipe_resource template;
943 memset(&template, 0, sizeof(template));
944 template.target = PIPE_TEXTURE_2D;
945 exa_get_pipe_format(depth, &template.format, &bitsPerPixel, &dummy);
946 template.width0 = width;
947 template.height0 = height;
949 template.array_size = 1;
950 template.last_level = 0;
951 template.bind |= PIPE_BIND_RENDER_TARGET;
952 template.bind |= PIPE_BIND_SCANOUT;
953 template.bind |= PIPE_BIND_SHARED;
955 return exa->scrn->resource_create(exa->scrn, &template);
959 xorg_exa_close(ScrnInfoPtr pScrn)
961 modesettingPtr ms = modesettingPTR(pScrn);
962 struct exa_context *exa = ms->exa;
964 pipe_sampler_view_reference(&exa->bound_sampler_views[0], NULL);
965 pipe_sampler_view_reference(&exa->bound_sampler_views[1], NULL);
967 renderer_destroy(exa->renderer);
969 xorg_exa_finish(exa);
972 exa->pipe->destroy(exa->pipe);
974 /* Since this was shared be proper with the pointer */
977 exaDriverFini(pScrn->pScreen);
983 xorg_exa_init(ScrnInfoPtr pScrn, Bool accel)
985 modesettingPtr ms = modesettingPTR(pScrn);
986 struct exa_context *exa;
988 CustomizerPtr cust = ms->cust;
990 exa = calloc(1, sizeof(struct exa_context));
994 exa->scrn = ms->screen;
995 exa->pipe = exa->scrn->context_create(exa->scrn, NULL);
996 if (exa->pipe == NULL)
999 pExa = exaDriverAlloc();
1004 pExa->exa_major = 2;
1005 pExa->exa_minor = 2;
1006 pExa->memoryBase = 0;
1007 pExa->memorySize = 0;
1008 pExa->offScreenBase = 0;
1009 pExa->pixmapOffsetAlign = 0;
1010 pExa->pixmapPitchAlign = 1;
1011 pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
1012 #ifdef EXA_SUPPORTS_PREPARE_AUX
1013 pExa->flags |= EXA_SUPPORTS_PREPARE_AUX;
1015 #ifdef EXA_MIXED_PIXMAPS
1016 pExa->flags |= EXA_MIXED_PIXMAPS;
1019 pExa->maxX = pExa->maxY =
1020 1 << (exa->scrn->get_param(exa->scrn, PIPE_CAP_MAX_TEXTURE_2D_LEVELS) - 1);
1022 pExa->WaitMarker = ExaWaitMarker;
1023 pExa->MarkSync = ExaMarkSync;
1024 pExa->PrepareSolid = ExaPrepareSolid;
1025 pExa->Solid = ExaSolid;
1026 pExa->DoneSolid = ExaDoneSolid;
1027 pExa->PrepareCopy = ExaPrepareCopy;
1028 pExa->Copy = ExaCopy;
1029 pExa->DoneCopy = ExaDoneCopy;
1030 pExa->CheckComposite = ExaCheckComposite;
1031 pExa->PrepareComposite = ExaPrepareComposite;
1032 pExa->Composite = ExaComposite;
1033 pExa->DoneComposite = ExaDoneComposite;
1034 pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
1035 pExa->DownloadFromScreen = ExaDownloadFromScreen;
1036 pExa->UploadToScreen = ExaUploadToScreen;
1037 pExa->PrepareAccess = ExaPrepareAccess;
1038 pExa->FinishAccess = ExaFinishAccess;
1039 pExa->CreatePixmap = ExaCreatePixmap;
1040 pExa->DestroyPixmap = ExaDestroyPixmap;
1041 pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
1043 if (!exaDriverInit(pScrn->pScreen, pExa)) {
1047 /* Share context with DRI */
1048 ms->ctx = exa->pipe;
1049 if (cust && cust->winsys_context_throttle)
1050 cust->winsys_context_throttle(cust, ms->ctx, THROTTLE_RENDER);
1052 exa->renderer = renderer_create(exa->pipe);
1058 xorg_exa_close(pScrn);
1064 struct pipe_surface *
1065 xorg_gpu_surface(struct pipe_context *pipe, struct exa_pixmap_priv *priv)
1067 struct pipe_surface surf_tmpl;
1068 memset(&surf_tmpl, 0, sizeof(surf_tmpl));
1069 u_surface_default_template(&surf_tmpl, priv->tex,
1070 PIPE_BIND_RENDER_TARGET);
1072 return pipe->create_surface(pipe, priv->tex, &surf_tmpl);
1076 void xorg_exa_flush(struct exa_context *exa,
1077 struct pipe_fence_handle **fence)
1079 exa->pipe->flush(exa->pipe, fence);
1082 void xorg_exa_finish(struct exa_context *exa)
1084 struct pipe_fence_handle *fence = NULL;
1086 xorg_exa_flush(exa, &fence);
1088 exa->pipe->screen->fence_finish(exa->pipe->screen, fence,
1089 PIPE_TIMEOUT_INFINITE);
1090 exa->pipe->screen->fence_reference(exa->pipe->screen, &fence, NULL);