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
->transform
.has_src
= FALSE
;
96 exa
->transform
.has_mask
= FALSE
;
97 exa
->has_solid_color
= FALSE
;
98 exa
->num_bound_samplers
= 0;
102 * Static exported EXA functions
106 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
111 ExaMarkSync(ScreenPtr pScreen
)
117 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
120 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
121 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
122 modesettingPtr ms
= modesettingPTR(pScrn
);
123 struct exa_context
*exa
= ms
->exa
;
124 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
125 struct pipe_transfer
*transfer
;
127 if (!priv
|| !priv
->tex
)
130 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
131 PIPE_REFERENCED_FOR_WRITE
)
132 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
134 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
135 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
139 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
140 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
141 transfer
->stride
, 0, 0);
143 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
144 exa
->scrn
->tex_transfer_destroy(transfer
);
150 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
153 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
154 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
155 modesettingPtr ms
= modesettingPTR(pScrn
);
156 struct exa_context
*exa
= ms
->exa
;
157 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
158 struct pipe_transfer
*transfer
;
160 if (!priv
|| !priv
->tex
)
163 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
164 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
168 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
169 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
170 (unsigned char*)src
, src_pitch
, 0, 0);
172 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
173 exa
->scrn
->tex_transfer_destroy(transfer
);
179 ExaPrepareAccess(PixmapPtr pPix
, int index
)
181 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
182 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
183 modesettingPtr ms
= modesettingPTR(pScrn
);
184 struct exa_context
*exa
= ms
->exa
;
185 struct exa_pixmap_priv
*priv
;
187 priv
= exaGetPixmapDriverPrivate(pPix
);
195 if (priv
->map_count
== 0)
197 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
198 PIPE_REFERENCED_FOR_WRITE
)
199 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
202 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
203 #ifdef EXA_MIXED_PIXMAPS
204 PIPE_TRANSFER_MAP_DIRECTLY
|
206 PIPE_TRANSFER_READ_WRITE
,
207 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
208 if (!priv
->map_transfer
)
209 #ifdef EXA_MIXED_PIXMAPS
212 FatalError("failed to create transfer\n");
215 pPix
->devPrivate
.ptr
=
216 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
217 pPix
->devKind
= priv
->map_transfer
->stride
;
226 ExaFinishAccess(PixmapPtr pPix
, int index
)
228 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
229 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
230 modesettingPtr ms
= modesettingPTR(pScrn
);
231 struct exa_context
*exa
= ms
->exa
;
232 struct exa_pixmap_priv
*priv
;
233 priv
= exaGetPixmapDriverPrivate(pPix
);
238 if (!priv
->map_transfer
)
241 if (--priv
->map_count
== 0) {
242 assert(priv
->map_transfer
);
243 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
244 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
245 priv
->map_transfer
= NULL
;
246 pPix
->devPrivate
.ptr
= NULL
;
251 ExaDone(PixmapPtr pPixmap
)
253 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
254 modesettingPtr ms
= modesettingPTR(pScrn
);
255 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
256 struct exa_context
*exa
= ms
->exa
;
262 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
264 xorg_exa_finish(exa
);
266 xorg_exa_common_done(exa
);
270 ExaDoneComposite(PixmapPtr pPixmap
)
272 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
273 modesettingPtr ms
= modesettingPTR(pScrn
);
274 struct exa_context
*exa
= ms
->exa
;
276 xorg_exa_common_done(exa
);
280 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
282 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
283 modesettingPtr ms
= modesettingPTR(pScrn
);
284 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
285 struct exa_context
*exa
= ms
->exa
;
288 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
291 XORG_FALLBACK("accle not enabled");
293 if (!priv
|| !priv
->tex
)
294 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
296 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
297 XORG_FALLBACK("planeMask is not solid");
300 XORG_FALLBACK("not GXcopy");
302 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
304 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
305 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
312 return ACCEL_ENABLED
&& xorg_solid_bind_state(exa
, priv
, fg
);
316 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
318 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
319 modesettingPtr ms
= modesettingPTR(pScrn
);
320 struct exa_context
*exa
= ms
->exa
;
321 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
324 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
328 if (x0
== 0 && y0
== 0 &&
329 x1
== priv
->tex
->width
[0] &&
330 y1
== priv
->tex
->height
[0]) {
331 exa
->ctx
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
,
332 exa
->solid_color
, 1., 0);
337 exa
->solid_color
[0] = 0.f
;
338 exa
->solid_color
[1] = 1.f
;
339 exa
->solid_color
[2] = 0.f
;
340 exa
->solid_color
[3] = 1.f
;
341 xorg_solid(exa
, priv
, 0, 0, 1024, 768);
342 exa
->solid_color
[0] = 1.f
;
343 exa
->solid_color
[1] = 0.f
;
344 exa
->solid_color
[2] = 0.f
;
345 exa
->solid_color
[3] = 1.f
;
346 xorg_solid(exa
, priv
, 0, 0, 300, 300);
347 xorg_solid(exa
, priv
, 300, 300, 350, 350);
348 xorg_solid(exa
, priv
, 350, 350, 500, 500);
350 xorg_solid(exa
, priv
,
351 priv
->tex
->width
[0] - 10,
352 priv
->tex
->height
[0] - 10,
354 priv
->tex
->height
[0]);
356 exa
->solid_color
[0] = 0.f
;
357 exa
->solid_color
[1] = 0.f
;
358 exa
->solid_color
[2] = 1.f
;
359 exa
->solid_color
[3] = 1.f
;
361 exa
->has_solid_color
= FALSE
;
362 ExaPrepareCopy(pPixmap
, pPixmap
, 0, 0, GXcopy
, 0xffffffff);
363 ExaCopy(pPixmap
, 0, 0, 50, 50, 500, 500);
365 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
370 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
371 int ydir
, int alu
, Pixel planeMask
)
373 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
374 modesettingPtr ms
= modesettingPTR(pScrn
);
375 struct exa_context
*exa
= ms
->exa
;
376 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
377 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
380 debug_printf("ExaPrepareCopy\n");
383 XORG_FALLBACK("accle not enabled");
385 if (!priv
|| !priv
->tex
)
386 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
388 if (!src_priv
|| !src_priv
->tex
)
389 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
391 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
392 XORG_FALLBACK("planeMask is not solid");
395 XORG_FALLBACK("alu not GXcopy");
397 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
399 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
400 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
402 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
403 src_priv
->tex
->target
,
404 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
405 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
407 exa
->copy
.src
= src_priv
;
408 exa
->copy
.dst
= priv
;
410 return ACCEL_ENABLED
;
414 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
415 int width
, int height
)
417 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
418 modesettingPtr ms
= modesettingPTR(pScrn
);
419 struct exa_context
*exa
= ms
->exa
;
420 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
423 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
424 srcX
, srcY
, dstX
, dstY
, width
, height
);
427 debug_assert(priv
== exa
->copy
.dst
);
429 renderer_copy_pixmap(exa
->renderer
, exa
->copy
.dst
, dstX
, dstY
,
430 exa
->copy
.src
, srcX
, srcY
,
435 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
436 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
437 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
439 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
440 modesettingPtr ms
= modesettingPTR(pScrn
);
441 struct exa_context
*exa
= ms
->exa
;
442 struct exa_pixmap_priv
*priv
;
445 debug_printf("ExaPrepareComposite\n");
448 XORG_FALLBACK("accle not enabled");
450 priv
= exaGetPixmapDriverPrivate(pDst
);
451 if (!priv
|| !priv
->tex
)
452 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
454 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
456 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
457 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
460 priv
= exaGetPixmapDriverPrivate(pSrc
);
461 if (!priv
|| !priv
->tex
)
462 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
464 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
466 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
467 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
471 priv
= exaGetPixmapDriverPrivate(pMask
);
472 if (!priv
|| !priv
->tex
)
473 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
475 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
477 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
478 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
481 return ACCEL_ENABLED
&&
482 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
484 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
485 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
486 exaGetPixmapDriverPrivate(pDst
));
490 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
491 int dstX
, int dstY
, int width
, int height
)
493 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
494 modesettingPtr ms
= modesettingPTR(pScrn
);
495 struct exa_context
*exa
= ms
->exa
;
496 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
499 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n", srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
502 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
503 dstX
, dstY
, width
, height
);
507 ExaCheckComposite(int op
,
508 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
509 PicturePtr pDstPicture
)
511 boolean accelerated
= xorg_composite_accelerated(op
,
516 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
517 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
519 return ACCEL_ENABLED
&& accelerated
;
523 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
525 struct exa_pixmap_priv
*priv
;
527 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
535 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
537 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
542 pipe_texture_reference(&priv
->tex
, NULL
);
548 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
550 struct exa_pixmap_priv
*priv
;
552 priv
= exaGetPixmapDriverPrivate(pPixmap
);
564 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
566 struct exa_pixmap_priv
*priv
;
567 priv
= exaGetPixmapDriverPrivate(pPixmap
);
570 FatalError("NO PIXMAP PRIVATE\n");
574 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
580 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
582 struct exa_pixmap_priv
*priv
;
583 priv
= exaGetPixmapDriverPrivate(pPixmap
);
586 FatalError("NO PIXMAP PRIVATE\n");
590 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
596 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
598 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
599 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
600 modesettingPtr ms
= modesettingPTR(pScrn
);
601 struct exa_pixmap_priv
*priv
;
606 FatalError("NO MS->EXA\n");
610 priv
= exaGetPixmapDriverPrivate(pPixmap
);
613 FatalError("NO PIXMAP PRIVATE\n");
617 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
619 *stride_out
= stride
;
625 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
626 int depth
, int bitsPerPixel
, int devKind
,
629 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
630 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
631 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
632 modesettingPtr ms
= modesettingPTR(pScrn
);
633 struct exa_context
*exa
= ms
->exa
;
635 if (!priv
|| pPixData
)
639 depth
= pPixmap
->drawable
.depth
;
641 if (bitsPerPixel
<= 0)
642 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
645 width
= pPixmap
->drawable
.width
;
648 height
= pPixmap
->drawable
.height
;
650 if (width
<= 0 || height
<= 0 || depth
<= 0)
653 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
654 bitsPerPixel
, devKind
, NULL
);
656 /* Deal with screen resize */
658 (priv
->tex
->width
[0] != width
||
659 priv
->tex
->height
[0] != height
||
660 priv
->tex_flags
!= priv
->flags
)) {
661 struct pipe_texture
*texture
= NULL
;
662 struct pipe_texture
template;
664 memset(&template, 0, sizeof(template));
665 template.target
= PIPE_TEXTURE_2D
;
666 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
667 pf_get_block(template.format
, &template.block
);
668 template.width
[0] = width
;
669 template.height
[0] = height
;
670 template.depth
[0] = 1;
671 template.last_level
= 0;
672 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
673 priv
->tex_flags
= priv
->flags
;
674 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
677 struct pipe_surface
*dst_surf
;
678 struct pipe_surface
*src_surf
;
680 dst_surf
= exa
->scrn
->get_tex_surface(
681 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
682 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
683 if (exa
->pipe
->surface_copy
) {
684 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
685 0, 0, min(width
, texture
->width
[0]),
686 min(height
, texture
->height
[0]));
688 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
689 0, 0, min(width
, texture
->width
[0]),
690 min(height
, texture
->height
[0]));
692 exa
->scrn
->tex_surface_destroy(dst_surf
);
693 exa
->scrn
->tex_surface_destroy(src_surf
);
696 pipe_texture_reference(&priv
->tex
, texture
);
697 /* the texture we create has one reference */
698 pipe_texture_reference(&texture
, NULL
);
704 struct pipe_texture
*
705 xorg_exa_get_texture(PixmapPtr pPixmap
)
707 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
708 struct pipe_texture
*tex
= NULL
;
709 pipe_texture_reference(&tex
, priv
->tex
);
714 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
716 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
718 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
723 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
724 pPixmap
->drawable
.height
!= tex
->height
[0])
727 pipe_texture_reference(&priv
->tex
, tex
);
728 priv
->tex_flags
= tex
->tex_usage
& mask
;
733 struct pipe_texture
*
734 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
735 int width
, int height
,
736 int depth
, int bitsPerPixel
)
738 modesettingPtr ms
= modesettingPTR(pScrn
);
739 struct exa_context
*exa
= ms
->exa
;
740 struct pipe_texture
template;
742 memset(&template, 0, sizeof(template));
743 template.target
= PIPE_TEXTURE_2D
;
744 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
745 pf_get_block(template.format
, &template.block
);
746 template.width
[0] = width
;
747 template.height
[0] = height
;
748 template.depth
[0] = 1;
749 template.last_level
= 0;
750 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
751 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
752 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
754 return exa
->scrn
->texture_create(exa
->scrn
, &template);
758 xorg_exa_close(ScrnInfoPtr pScrn
)
760 modesettingPtr ms
= modesettingPTR(pScrn
);
761 struct exa_context
*exa
= ms
->exa
;
763 renderer_destroy(exa
->renderer
);
766 exa
->pipe
->destroy(exa
->pipe
);
768 exaDriverFini(pScrn
->pScreen
);
774 xorg_exa_init(ScrnInfoPtr pScrn
)
776 modesettingPtr ms
= modesettingPTR(pScrn
);
777 struct exa_context
*exa
;
780 exa
= xcalloc(1, sizeof(struct exa_context
));
784 pExa
= exaDriverAlloc();
789 memset(pExa
, 0, sizeof(*pExa
));
793 pExa
->memoryBase
= 0;
794 pExa
->memorySize
= 0;
795 pExa
->offScreenBase
= 0;
796 pExa
->pixmapOffsetAlign
= 0;
797 pExa
->pixmapPitchAlign
= 1;
798 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
799 #ifdef EXA_SUPPORTS_PREPARE_AUX
800 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
802 #ifdef EXA_MIXED_PIXMAPS
803 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
805 pExa
->maxX
= 8191; /* FIXME */
806 pExa
->maxY
= 8191; /* FIXME */
808 pExa
->WaitMarker
= ExaWaitMarker
;
809 pExa
->MarkSync
= ExaMarkSync
;
810 pExa
->PrepareSolid
= ExaPrepareSolid
;
811 pExa
->Solid
= ExaSolid
;
812 pExa
->DoneSolid
= ExaDone
;
813 pExa
->PrepareCopy
= ExaPrepareCopy
;
814 pExa
->Copy
= ExaCopy
;
815 pExa
->DoneCopy
= ExaDone
;
816 pExa
->CheckComposite
= ExaCheckComposite
;
817 pExa
->PrepareComposite
= ExaPrepareComposite
;
818 pExa
->Composite
= ExaComposite
;
819 pExa
->DoneComposite
= ExaDoneComposite
;
820 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
821 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
822 pExa
->UploadToScreen
= ExaUploadToScreen
;
823 pExa
->PrepareAccess
= ExaPrepareAccess
;
824 pExa
->FinishAccess
= ExaFinishAccess
;
825 pExa
->CreatePixmap
= ExaCreatePixmap
;
826 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
827 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
829 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
833 exa
->scrn
= ms
->screen
;
834 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
835 /* Share context with DRI */
838 exa
->renderer
= renderer_create(exa
->pipe
);
843 xorg_exa_close(pScrn
);
848 struct pipe_surface
*
849 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
851 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
852 PIPE_BUFFER_USAGE_GPU_READ
|
853 PIPE_BUFFER_USAGE_GPU_WRITE
);
857 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
858 struct pipe_fence_handle
**fence
)
860 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
863 void xorg_exa_finish(struct exa_context
*exa
)
865 struct pipe_fence_handle
*fence
= NULL
;
867 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
869 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
870 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);