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"
50 #define ACCEL_ENABLED TRUE
57 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
61 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
65 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
69 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
73 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
77 *format
= PIPE_FORMAT_A8_UNORM
;
82 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
91 xorg_exa_common_done(struct exa_context
*exa
)
95 exa
->has_solid_color
= FALSE
;
96 exa
->num_bound_samplers
= 0;
100 * Static exported EXA functions
104 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
109 ExaMarkSync(ScreenPtr pScreen
)
115 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
118 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
119 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
120 modesettingPtr ms
= modesettingPTR(pScrn
);
121 struct exa_context
*exa
= ms
->exa
;
122 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
123 struct pipe_transfer
*transfer
;
125 if (!priv
|| !priv
->tex
)
128 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
129 PIPE_REFERENCED_FOR_WRITE
)
130 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
132 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
133 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
137 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
138 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
139 transfer
->stride
, 0, 0);
141 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
142 exa
->scrn
->tex_transfer_destroy(transfer
);
148 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
151 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
152 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
153 modesettingPtr ms
= modesettingPTR(pScrn
);
154 struct exa_context
*exa
= ms
->exa
;
155 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
156 struct pipe_transfer
*transfer
;
158 if (!priv
|| !priv
->tex
)
161 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
162 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
166 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
167 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
168 (unsigned char*)src
, src_pitch
, 0, 0);
170 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
171 exa
->scrn
->tex_transfer_destroy(transfer
);
177 ExaPrepareAccess(PixmapPtr pPix
, int index
)
179 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
180 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
181 modesettingPtr ms
= modesettingPTR(pScrn
);
182 struct exa_context
*exa
= ms
->exa
;
183 struct exa_pixmap_priv
*priv
;
185 priv
= exaGetPixmapDriverPrivate(pPix
);
193 if (priv
->map_count
== 0)
195 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
196 PIPE_REFERENCED_FOR_WRITE
)
197 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
200 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
201 #ifdef EXA_MIXED_PIXMAPS
202 PIPE_TRANSFER_MAP_DIRECTLY
|
204 PIPE_TRANSFER_READ_WRITE
,
205 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
206 if (!priv
->map_transfer
)
207 #ifdef EXA_MIXED_PIXMAPS
210 FatalError("failed to create transfer\n");
213 pPix
->devPrivate
.ptr
=
214 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
215 pPix
->devKind
= priv
->map_transfer
->stride
;
224 ExaFinishAccess(PixmapPtr pPix
, int index
)
226 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
227 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
228 modesettingPtr ms
= modesettingPTR(pScrn
);
229 struct exa_context
*exa
= ms
->exa
;
230 struct exa_pixmap_priv
*priv
;
231 priv
= exaGetPixmapDriverPrivate(pPix
);
236 if (!priv
->map_transfer
)
239 if (--priv
->map_count
== 0) {
240 assert(priv
->map_transfer
);
241 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
242 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
243 priv
->map_transfer
= NULL
;
244 pPix
->devPrivate
.ptr
= NULL
;
249 ExaDone(PixmapPtr pPixmap
)
251 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
252 modesettingPtr ms
= modesettingPTR(pScrn
);
253 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
254 struct exa_context
*exa
= ms
->exa
;
260 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
262 xorg_exa_finish(exa
);
264 xorg_exa_common_done(exa
);
268 ExaDoneComposite(PixmapPtr pPixmap
)
270 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
271 modesettingPtr ms
= modesettingPTR(pScrn
);
272 struct exa_context
*exa
= ms
->exa
;
274 xorg_exa_common_done(exa
);
278 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
280 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
281 modesettingPtr ms
= modesettingPTR(pScrn
);
282 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
283 struct exa_context
*exa
= ms
->exa
;
286 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
289 XORG_FALLBACK("accle not enabled");
291 if (!priv
|| !priv
->tex
)
292 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
294 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
295 XORG_FALLBACK("planeMask is not solid");
298 XORG_FALLBACK("not GXcopy");
300 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
302 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
303 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
310 return ACCEL_ENABLED
&& xorg_solid_bind_state(exa
, priv
, fg
);
314 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
316 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
317 modesettingPtr ms
= modesettingPTR(pScrn
);
318 struct exa_context
*exa
= ms
->exa
;
319 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
322 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
326 if (x0
== 0 && y0
== 0 &&
327 x1
== priv
->tex
->width
[0] &&
328 y1
== priv
->tex
->height
[0]) {
329 exa
->ctx
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
,
330 exa
->solid_color
, 1., 0);
335 exa
->solid_color
[0] = 0.f
;
336 exa
->solid_color
[1] = 1.f
;
337 exa
->solid_color
[2] = 0.f
;
338 exa
->solid_color
[3] = 1.f
;
339 xorg_solid(exa
, priv
, 0, 0, 1024, 768);
340 exa
->solid_color
[0] = 1.f
;
341 exa
->solid_color
[1] = 0.f
;
342 exa
->solid_color
[2] = 0.f
;
343 exa
->solid_color
[3] = 1.f
;
344 xorg_solid(exa
, priv
, 0, 0, 300, 300);
345 xorg_solid(exa
, priv
, 300, 300, 350, 350);
346 xorg_solid(exa
, priv
, 350, 350, 500, 500);
348 xorg_solid(exa
, priv
,
349 priv
->tex
->width
[0] - 10,
350 priv
->tex
->height
[0] - 10,
352 priv
->tex
->height
[0]);
354 exa
->solid_color
[0] = 0.f
;
355 exa
->solid_color
[1] = 0.f
;
356 exa
->solid_color
[2] = 1.f
;
357 exa
->solid_color
[3] = 1.f
;
359 exa
->has_solid_color
= FALSE
;
360 ExaPrepareCopy(pPixmap
, pPixmap
, 0, 0, GXcopy
, 0xffffffff);
361 ExaCopy(pPixmap
, 0, 0, 50, 50, 500, 500);
363 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
368 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
369 int ydir
, int alu
, Pixel planeMask
)
371 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
372 modesettingPtr ms
= modesettingPTR(pScrn
);
373 struct exa_context
*exa
= ms
->exa
;
374 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
375 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
378 debug_printf("ExaPrepareCopy\n");
381 XORG_FALLBACK("accle not enabled");
383 if (!priv
|| !priv
->tex
)
384 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
386 if (!src_priv
|| !src_priv
->tex
)
387 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
389 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
390 XORG_FALLBACK("planeMask is not solid");
393 XORG_FALLBACK("alu not GXcopy");
395 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
397 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
398 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
400 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
401 src_priv
->tex
->target
,
402 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
403 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
405 exa
->copy
.src
= src_priv
;
406 exa
->copy
.dst
= priv
;
408 return ACCEL_ENABLED
;
412 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
413 int width
, int height
)
415 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
416 modesettingPtr ms
= modesettingPTR(pScrn
);
417 struct exa_context
*exa
= ms
->exa
;
418 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
421 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
422 srcX
, srcY
, dstX
, dstY
, width
, height
);
425 debug_assert(priv
== exa
->copy
.dst
);
427 renderer_copy_pixmap(exa
->renderer
, exa
->copy
.dst
, dstX
, dstY
,
428 exa
->copy
.src
, srcX
, srcY
,
433 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
434 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
435 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
437 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
438 modesettingPtr ms
= modesettingPTR(pScrn
);
439 struct exa_context
*exa
= ms
->exa
;
440 struct exa_pixmap_priv
*priv
;
443 debug_printf("ExaPrepareComposite\n");
446 XORG_FALLBACK("accle not enabled");
448 priv
= exaGetPixmapDriverPrivate(pDst
);
449 if (!priv
|| !priv
->tex
)
450 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
452 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
454 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
455 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
458 priv
= exaGetPixmapDriverPrivate(pSrc
);
459 if (!priv
|| !priv
->tex
)
460 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
462 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
464 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
465 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
469 priv
= exaGetPixmapDriverPrivate(pMask
);
470 if (!priv
|| !priv
->tex
)
471 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
473 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
475 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
476 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
479 return ACCEL_ENABLED
&&
480 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
482 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
483 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
484 exaGetPixmapDriverPrivate(pDst
));
488 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
489 int dstX
, int dstY
, int width
, int height
)
491 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
492 modesettingPtr ms
= modesettingPTR(pScrn
);
493 struct exa_context
*exa
= ms
->exa
;
494 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
497 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n", srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
500 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
501 dstX
, dstY
, width
, height
);
505 ExaCheckComposite(int op
,
506 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
507 PicturePtr pDstPicture
)
509 boolean accelerated
= xorg_composite_accelerated(op
,
514 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
515 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
517 return ACCEL_ENABLED
&& accelerated
;
521 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
523 struct exa_pixmap_priv
*priv
;
525 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
533 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
535 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
540 pipe_texture_reference(&priv
->tex
, NULL
);
546 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
548 struct exa_pixmap_priv
*priv
;
550 priv
= exaGetPixmapDriverPrivate(pPixmap
);
562 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
564 struct exa_pixmap_priv
*priv
;
565 priv
= exaGetPixmapDriverPrivate(pPixmap
);
568 FatalError("NO PIXMAP PRIVATE\n");
572 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
578 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
580 struct exa_pixmap_priv
*priv
;
581 priv
= exaGetPixmapDriverPrivate(pPixmap
);
584 FatalError("NO PIXMAP PRIVATE\n");
588 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
594 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
596 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
597 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
598 modesettingPtr ms
= modesettingPTR(pScrn
);
599 struct exa_pixmap_priv
*priv
;
604 FatalError("NO MS->EXA\n");
608 priv
= exaGetPixmapDriverPrivate(pPixmap
);
611 FatalError("NO PIXMAP PRIVATE\n");
615 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
617 *stride_out
= stride
;
623 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
624 int depth
, int bitsPerPixel
, int devKind
,
627 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
628 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
629 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
630 modesettingPtr ms
= modesettingPTR(pScrn
);
631 struct exa_context
*exa
= ms
->exa
;
633 if (!priv
|| pPixData
)
637 depth
= pPixmap
->drawable
.depth
;
639 if (bitsPerPixel
<= 0)
640 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
643 width
= pPixmap
->drawable
.width
;
646 height
= pPixmap
->drawable
.height
;
648 if (width
<= 0 || height
<= 0 || depth
<= 0)
651 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
652 bitsPerPixel
, devKind
, NULL
);
654 /* Deal with screen resize */
656 (priv
->tex
->width
[0] != width
||
657 priv
->tex
->height
[0] != height
||
658 priv
->tex_flags
!= priv
->flags
)) {
659 struct pipe_texture
*texture
= NULL
;
660 struct pipe_texture
template;
662 memset(&template, 0, sizeof(template));
663 template.target
= PIPE_TEXTURE_2D
;
664 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
665 pf_get_block(template.format
, &template.block
);
666 template.width
[0] = width
;
667 template.height
[0] = height
;
668 template.depth
[0] = 1;
669 template.last_level
= 0;
670 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
671 priv
->tex_flags
= priv
->flags
;
672 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
675 struct pipe_surface
*dst_surf
;
676 struct pipe_surface
*src_surf
;
678 dst_surf
= exa
->scrn
->get_tex_surface(
679 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
680 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
681 if (exa
->pipe
->surface_copy
) {
682 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
683 0, 0, min(width
, texture
->width
[0]),
684 min(height
, texture
->height
[0]));
686 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
687 0, 0, min(width
, texture
->width
[0]),
688 min(height
, texture
->height
[0]));
690 exa
->scrn
->tex_surface_destroy(dst_surf
);
691 exa
->scrn
->tex_surface_destroy(src_surf
);
694 pipe_texture_reference(&priv
->tex
, texture
);
695 /* the texture we create has one reference */
696 pipe_texture_reference(&texture
, NULL
);
702 struct pipe_texture
*
703 xorg_exa_get_texture(PixmapPtr pPixmap
)
705 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
706 struct pipe_texture
*tex
= NULL
;
707 pipe_texture_reference(&tex
, priv
->tex
);
712 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
714 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
716 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
721 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
722 pPixmap
->drawable
.height
!= tex
->height
[0])
725 pipe_texture_reference(&priv
->tex
, tex
);
726 priv
->tex_flags
= tex
->tex_usage
& mask
;
731 struct pipe_texture
*
732 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
733 int width
, int height
,
734 int depth
, int bitsPerPixel
)
736 modesettingPtr ms
= modesettingPTR(pScrn
);
737 struct exa_context
*exa
= ms
->exa
;
738 struct pipe_texture
template;
740 memset(&template, 0, sizeof(template));
741 template.target
= PIPE_TEXTURE_2D
;
742 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
743 pf_get_block(template.format
, &template.block
);
744 template.width
[0] = width
;
745 template.height
[0] = height
;
746 template.depth
[0] = 1;
747 template.last_level
= 0;
748 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
749 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
750 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
752 return exa
->scrn
->texture_create(exa
->scrn
, &template);
756 xorg_exa_close(ScrnInfoPtr pScrn
)
758 modesettingPtr ms
= modesettingPTR(pScrn
);
759 struct exa_context
*exa
= ms
->exa
;
761 renderer_destroy(exa
->renderer
);
764 exa
->pipe
->destroy(exa
->pipe
);
766 exaDriverFini(pScrn
->pScreen
);
772 xorg_exa_init(ScrnInfoPtr pScrn
)
774 modesettingPtr ms
= modesettingPTR(pScrn
);
775 struct exa_context
*exa
;
778 exa
= xcalloc(1, sizeof(struct exa_context
));
782 pExa
= exaDriverAlloc();
787 memset(pExa
, 0, sizeof(*pExa
));
791 pExa
->memoryBase
= 0;
792 pExa
->memorySize
= 0;
793 pExa
->offScreenBase
= 0;
794 pExa
->pixmapOffsetAlign
= 0;
795 pExa
->pixmapPitchAlign
= 1;
796 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
797 #ifdef EXA_SUPPORTS_PREPARE_AUX
798 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
800 #ifdef EXA_MIXED_PIXMAPS
801 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
803 pExa
->maxX
= 8191; /* FIXME */
804 pExa
->maxY
= 8191; /* FIXME */
806 pExa
->WaitMarker
= ExaWaitMarker
;
807 pExa
->MarkSync
= ExaMarkSync
;
808 pExa
->PrepareSolid
= ExaPrepareSolid
;
809 pExa
->Solid
= ExaSolid
;
810 pExa
->DoneSolid
= ExaDone
;
811 pExa
->PrepareCopy
= ExaPrepareCopy
;
812 pExa
->Copy
= ExaCopy
;
813 pExa
->DoneCopy
= ExaDone
;
814 pExa
->CheckComposite
= ExaCheckComposite
;
815 pExa
->PrepareComposite
= ExaPrepareComposite
;
816 pExa
->Composite
= ExaComposite
;
817 pExa
->DoneComposite
= ExaDoneComposite
;
818 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
819 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
820 pExa
->UploadToScreen
= ExaUploadToScreen
;
821 pExa
->PrepareAccess
= ExaPrepareAccess
;
822 pExa
->FinishAccess
= ExaFinishAccess
;
823 pExa
->CreatePixmap
= ExaCreatePixmap
;
824 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
825 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
827 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
831 exa
->scrn
= ms
->screen
;
832 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
833 /* Share context with DRI */
836 exa
->renderer
= renderer_create(exa
->pipe
);
841 xorg_exa_close(pScrn
);
846 struct pipe_surface
*
847 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
849 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
850 PIPE_BUFFER_USAGE_GPU_READ
|
851 PIPE_BUFFER_USAGE_GPU_WRITE
);
855 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
856 struct pipe_fence_handle
**fence
)
858 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
861 void xorg_exa_finish(struct exa_context
*exa
)
863 struct pipe_fence_handle
*fence
= NULL
;
865 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
867 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
868 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);