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
)
108 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
109 modesettingPtr ms
= modesettingPTR(pScrn
);
110 struct exa_context
*exa
= ms
->exa
;
113 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
115 xorg_exa_finish(exa
);
120 ExaMarkSync(ScreenPtr pScreen
)
126 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
129 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
130 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
131 modesettingPtr ms
= modesettingPTR(pScrn
);
132 struct exa_context
*exa
= ms
->exa
;
133 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
134 struct pipe_transfer
*transfer
;
136 if (!priv
|| !priv
->tex
)
139 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
140 PIPE_REFERENCED_FOR_WRITE
)
141 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
143 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
144 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
148 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
149 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
150 transfer
->stride
, 0, 0);
152 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
153 exa
->scrn
->tex_transfer_destroy(transfer
);
159 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
162 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
163 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
164 modesettingPtr ms
= modesettingPTR(pScrn
);
165 struct exa_context
*exa
= ms
->exa
;
166 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
167 struct pipe_transfer
*transfer
;
169 if (!priv
|| !priv
->tex
)
172 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
173 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
177 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
178 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
179 (unsigned char*)src
, src_pitch
, 0, 0);
181 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
182 exa
->scrn
->tex_transfer_destroy(transfer
);
188 ExaPrepareAccess(PixmapPtr pPix
, int index
)
190 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
191 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
192 modesettingPtr ms
= modesettingPTR(pScrn
);
193 struct exa_context
*exa
= ms
->exa
;
194 struct exa_pixmap_priv
*priv
;
196 priv
= exaGetPixmapDriverPrivate(pPix
);
204 if (priv
->map_count
== 0)
206 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
207 PIPE_REFERENCED_FOR_WRITE
)
208 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
211 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
212 #ifdef EXA_MIXED_PIXMAPS
213 PIPE_TRANSFER_MAP_DIRECTLY
|
215 PIPE_TRANSFER_READ_WRITE
,
216 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
217 if (!priv
->map_transfer
)
218 #ifdef EXA_MIXED_PIXMAPS
221 FatalError("failed to create transfer\n");
224 pPix
->devPrivate
.ptr
=
225 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
226 pPix
->devKind
= priv
->map_transfer
->stride
;
235 ExaFinishAccess(PixmapPtr pPix
, int index
)
237 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
238 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
239 modesettingPtr ms
= modesettingPTR(pScrn
);
240 struct exa_context
*exa
= ms
->exa
;
241 struct exa_pixmap_priv
*priv
;
242 priv
= exaGetPixmapDriverPrivate(pPix
);
247 if (!priv
->map_transfer
)
250 if (--priv
->map_count
== 0) {
251 assert(priv
->map_transfer
);
252 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
253 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
254 priv
->map_transfer
= NULL
;
255 pPix
->devPrivate
.ptr
= NULL
;
260 ExaDone(PixmapPtr pPixmap
)
262 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
263 modesettingPtr ms
= modesettingPTR(pScrn
);
264 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
265 struct exa_context
*exa
= ms
->exa
;
270 xorg_exa_common_done(exa
);
274 ExaDoneComposite(PixmapPtr pPixmap
)
276 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
277 modesettingPtr ms
= modesettingPTR(pScrn
);
278 struct exa_context
*exa
= ms
->exa
;
280 xorg_exa_common_done(exa
);
284 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
286 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
287 modesettingPtr ms
= modesettingPTR(pScrn
);
288 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
289 struct exa_context
*exa
= ms
->exa
;
292 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
295 XORG_FALLBACK("accle not enabled");
297 if (!priv
|| !priv
->tex
)
298 XORG_FALLBACK("%s", !priv
? "!priv" : "!priv->tex");
300 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
301 XORG_FALLBACK("planeMask is not solid");
304 XORG_FALLBACK("not GXcopy");
306 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
308 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
309 XORG_FALLBACK("format %s", pf_name(priv
->tex
->format
));
316 return ACCEL_ENABLED
&& xorg_solid_bind_state(exa
, priv
, fg
);
320 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
322 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
323 modesettingPtr ms
= modesettingPTR(pScrn
);
324 struct exa_context
*exa
= ms
->exa
;
325 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
328 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
332 if (x0
== 0 && y0
== 0 &&
333 x1
== priv
->tex
->width
[0] &&
334 y1
== priv
->tex
->height
[0]) {
335 exa
->ctx
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
,
336 exa
->solid_color
, 1., 0);
341 exa
->solid_color
[0] = 0.f
;
342 exa
->solid_color
[1] = 1.f
;
343 exa
->solid_color
[2] = 0.f
;
344 exa
->solid_color
[3] = 1.f
;
345 xorg_solid(exa
, priv
, 0, 0, 1024, 768);
346 exa
->solid_color
[0] = 1.f
;
347 exa
->solid_color
[1] = 0.f
;
348 exa
->solid_color
[2] = 0.f
;
349 exa
->solid_color
[3] = 1.f
;
350 xorg_solid(exa
, priv
, 0, 0, 300, 300);
351 xorg_solid(exa
, priv
, 300, 300, 350, 350);
352 xorg_solid(exa
, priv
, 350, 350, 500, 500);
354 xorg_solid(exa
, priv
,
355 priv
->tex
->width
[0] - 10,
356 priv
->tex
->height
[0] - 10,
358 priv
->tex
->height
[0]);
360 exa
->solid_color
[0] = 0.f
;
361 exa
->solid_color
[1] = 0.f
;
362 exa
->solid_color
[2] = 1.f
;
363 exa
->solid_color
[3] = 1.f
;
365 exa
->has_solid_color
= FALSE
;
366 ExaPrepareCopy(pPixmap
, pPixmap
, 0, 0, GXcopy
, 0xffffffff);
367 ExaCopy(pPixmap
, 0, 0, 50, 50, 500, 500);
369 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
374 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
375 int ydir
, int alu
, Pixel planeMask
)
377 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
378 modesettingPtr ms
= modesettingPTR(pScrn
);
379 struct exa_context
*exa
= ms
->exa
;
380 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
381 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
384 debug_printf("ExaPrepareCopy\n");
387 XORG_FALLBACK("accle not enabled");
389 if (!priv
|| !priv
->tex
)
390 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
392 if (!src_priv
|| !src_priv
->tex
)
393 XORG_FALLBACK("pSrc %s", !src_priv
? "!priv" : "!priv->tex");
395 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
396 XORG_FALLBACK("planeMask is not solid");
399 XORG_FALLBACK("alu not GXcopy");
401 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
403 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
404 XORG_FALLBACK("pDst format %s", pf_name(priv
->tex
->format
));
406 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
407 src_priv
->tex
->target
,
408 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
409 XORG_FALLBACK("pSrc format %s", pf_name(src_priv
->tex
->format
));
411 exa
->copy
.src
= src_priv
;
412 exa
->copy
.dst
= priv
;
414 return ACCEL_ENABLED
;
418 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
419 int width
, int height
)
421 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
422 modesettingPtr ms
= modesettingPTR(pScrn
);
423 struct exa_context
*exa
= ms
->exa
;
424 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
427 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
428 srcX
, srcY
, dstX
, dstY
, width
, height
);
431 debug_assert(priv
== exa
->copy
.dst
);
433 renderer_copy_pixmap(exa
->renderer
, exa
->copy
.dst
, dstX
, dstY
,
434 exa
->copy
.src
, srcX
, srcY
,
439 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
440 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
441 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
443 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
444 modesettingPtr ms
= modesettingPTR(pScrn
);
445 struct exa_context
*exa
= ms
->exa
;
446 struct exa_pixmap_priv
*priv
;
449 debug_printf("ExaPrepareComposite(%d, src=0x%p, mask=0x%p, dst=0x%p)\n",
450 op
, pSrcPicture
, pMaskPicture
, pDstPicture
);
453 XORG_FALLBACK("accle not enabled");
455 priv
= exaGetPixmapDriverPrivate(pDst
);
456 if (!priv
|| !priv
->tex
)
457 XORG_FALLBACK("pDst %s", !priv
? "!priv" : "!priv->tex");
459 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
461 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
462 XORG_FALLBACK("pDst format: %s", pf_name(priv
->tex
->format
));
465 priv
= exaGetPixmapDriverPrivate(pSrc
);
466 if (!priv
|| !priv
->tex
)
467 XORG_FALLBACK("pSrc %s", !priv
? "!priv" : "!priv->tex");
469 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
471 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
472 XORG_FALLBACK("pSrc format: %s", pf_name(priv
->tex
->format
));
476 priv
= exaGetPixmapDriverPrivate(pMask
);
477 if (!priv
|| !priv
->tex
)
478 XORG_FALLBACK("pMask %s", !priv
? "!priv" : "!priv->tex");
480 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
482 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
483 XORG_FALLBACK("pMask format: %s", pf_name(priv
->tex
->format
));
486 return ACCEL_ENABLED
&&
487 xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
489 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
490 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
491 exaGetPixmapDriverPrivate(pDst
));
495 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
496 int dstX
, int dstY
, int width
, int height
)
498 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
499 modesettingPtr ms
= modesettingPTR(pScrn
);
500 struct exa_context
*exa
= ms
->exa
;
501 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
504 debug_printf("\tExaComposite(src[%d,%d], mask=[%d, %d], dst=[%d, %d], dim=[%d, %d])\n", srcX
, srcY
, maskX
, maskY
, dstX
, dstY
, width
, height
);
507 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
508 dstX
, dstY
, width
, height
);
512 ExaCheckComposite(int op
,
513 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
514 PicturePtr pDstPicture
)
516 boolean accelerated
= xorg_composite_accelerated(op
,
521 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
522 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
524 return ACCEL_ENABLED
&& accelerated
;
528 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
530 struct exa_pixmap_priv
*priv
;
532 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
540 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
542 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
547 pipe_texture_reference(&priv
->tex
, NULL
);
553 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
555 struct exa_pixmap_priv
*priv
;
557 priv
= exaGetPixmapDriverPrivate(pPixmap
);
569 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
571 struct exa_pixmap_priv
*priv
;
572 priv
= exaGetPixmapDriverPrivate(pPixmap
);
575 FatalError("NO PIXMAP PRIVATE\n");
579 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
585 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
587 struct exa_pixmap_priv
*priv
;
588 priv
= exaGetPixmapDriverPrivate(pPixmap
);
591 FatalError("NO PIXMAP PRIVATE\n");
595 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
601 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
603 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
604 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
605 modesettingPtr ms
= modesettingPTR(pScrn
);
606 struct exa_pixmap_priv
*priv
;
611 FatalError("NO MS->EXA\n");
615 priv
= exaGetPixmapDriverPrivate(pPixmap
);
618 FatalError("NO PIXMAP PRIVATE\n");
622 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
624 *stride_out
= stride
;
630 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
631 int depth
, int bitsPerPixel
, int devKind
,
634 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
635 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
636 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
637 modesettingPtr ms
= modesettingPTR(pScrn
);
638 struct exa_context
*exa
= ms
->exa
;
640 if (!priv
|| pPixData
)
644 depth
= pPixmap
->drawable
.depth
;
646 if (bitsPerPixel
<= 0)
647 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
650 width
= pPixmap
->drawable
.width
;
653 height
= pPixmap
->drawable
.height
;
655 if (width
<= 0 || height
<= 0 || depth
<= 0)
658 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
659 bitsPerPixel
, devKind
, NULL
);
661 /* Deal with screen resize */
663 (priv
->tex
->width
[0] != width
||
664 priv
->tex
->height
[0] != height
||
665 priv
->tex_flags
!= priv
->flags
)) {
666 struct pipe_texture
*texture
= NULL
;
667 struct pipe_texture
template;
669 memset(&template, 0, sizeof(template));
670 template.target
= PIPE_TEXTURE_2D
;
671 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
672 pf_get_block(template.format
, &template.block
);
673 template.width
[0] = width
;
674 template.height
[0] = height
;
675 template.depth
[0] = 1;
676 template.last_level
= 0;
677 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
678 priv
->tex_flags
= priv
->flags
;
679 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
682 struct pipe_surface
*dst_surf
;
683 struct pipe_surface
*src_surf
;
685 dst_surf
= exa
->scrn
->get_tex_surface(
686 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
687 src_surf
= xorg_gpu_surface(exa
->pipe
->screen
, priv
);
688 if (exa
->pipe
->surface_copy
) {
689 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
690 0, 0, min(width
, texture
->width
[0]),
691 min(height
, texture
->height
[0]));
693 util_surface_copy(exa
->pipe
, FALSE
, dst_surf
, 0, 0, src_surf
,
694 0, 0, min(width
, texture
->width
[0]),
695 min(height
, texture
->height
[0]));
697 exa
->scrn
->tex_surface_destroy(dst_surf
);
698 exa
->scrn
->tex_surface_destroy(src_surf
);
701 pipe_texture_reference(&priv
->tex
, texture
);
702 /* the texture we create has one reference */
703 pipe_texture_reference(&texture
, NULL
);
709 struct pipe_texture
*
710 xorg_exa_get_texture(PixmapPtr pPixmap
)
712 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
713 struct pipe_texture
*tex
= NULL
;
714 pipe_texture_reference(&tex
, priv
->tex
);
719 xorg_exa_set_texture(PixmapPtr pPixmap
, struct pipe_texture
*tex
)
721 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
723 int mask
= PIPE_TEXTURE_USAGE_PRIMARY
| PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
728 if (pPixmap
->drawable
.width
!= tex
->width
[0] ||
729 pPixmap
->drawable
.height
!= tex
->height
[0])
732 pipe_texture_reference(&priv
->tex
, tex
);
733 priv
->tex_flags
= tex
->tex_usage
& mask
;
738 struct pipe_texture
*
739 xorg_exa_create_root_texture(ScrnInfoPtr pScrn
,
740 int width
, int height
,
741 int depth
, int bitsPerPixel
)
743 modesettingPtr ms
= modesettingPTR(pScrn
);
744 struct exa_context
*exa
= ms
->exa
;
745 struct pipe_texture
template;
747 memset(&template, 0, sizeof(template));
748 template.target
= PIPE_TEXTURE_2D
;
749 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
750 pf_get_block(template.format
, &template.block
);
751 template.width
[0] = width
;
752 template.height
[0] = height
;
753 template.depth
[0] = 1;
754 template.last_level
= 0;
755 template.tex_usage
|= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
756 template.tex_usage
|= PIPE_TEXTURE_USAGE_PRIMARY
;
757 template.tex_usage
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
759 return exa
->scrn
->texture_create(exa
->scrn
, &template);
763 xorg_exa_close(ScrnInfoPtr pScrn
)
765 modesettingPtr ms
= modesettingPTR(pScrn
);
766 struct exa_context
*exa
= ms
->exa
;
768 renderer_destroy(exa
->renderer
);
771 exa
->pipe
->destroy(exa
->pipe
);
773 exaDriverFini(pScrn
->pScreen
);
779 xorg_exa_init(ScrnInfoPtr pScrn
)
781 modesettingPtr ms
= modesettingPTR(pScrn
);
782 struct exa_context
*exa
;
785 exa
= xcalloc(1, sizeof(struct exa_context
));
789 pExa
= exaDriverAlloc();
794 memset(pExa
, 0, sizeof(*pExa
));
798 pExa
->memoryBase
= 0;
799 pExa
->memorySize
= 0;
800 pExa
->offScreenBase
= 0;
801 pExa
->pixmapOffsetAlign
= 0;
802 pExa
->pixmapPitchAlign
= 1;
803 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
804 #ifdef EXA_SUPPORTS_PREPARE_AUX
805 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
807 #ifdef EXA_MIXED_PIXMAPS
808 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
810 pExa
->maxX
= 8191; /* FIXME */
811 pExa
->maxY
= 8191; /* FIXME */
813 pExa
->WaitMarker
= ExaWaitMarker
;
814 pExa
->MarkSync
= ExaMarkSync
;
815 pExa
->PrepareSolid
= ExaPrepareSolid
;
816 pExa
->Solid
= ExaSolid
;
817 pExa
->DoneSolid
= ExaDone
;
818 pExa
->PrepareCopy
= ExaPrepareCopy
;
819 pExa
->Copy
= ExaCopy
;
820 pExa
->DoneCopy
= ExaDone
;
821 pExa
->CheckComposite
= ExaCheckComposite
;
822 pExa
->PrepareComposite
= ExaPrepareComposite
;
823 pExa
->Composite
= ExaComposite
;
824 pExa
->DoneComposite
= ExaDoneComposite
;
825 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
826 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
827 pExa
->UploadToScreen
= ExaUploadToScreen
;
828 pExa
->PrepareAccess
= ExaPrepareAccess
;
829 pExa
->FinishAccess
= ExaFinishAccess
;
830 pExa
->CreatePixmap
= ExaCreatePixmap
;
831 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
832 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
834 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
838 exa
->scrn
= ms
->screen
;
839 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
840 /* Share context with DRI */
843 exa
->renderer
= renderer_create(exa
->pipe
);
848 xorg_exa_close(pScrn
);
853 struct pipe_surface
*
854 xorg_gpu_surface(struct pipe_screen
*scrn
, struct exa_pixmap_priv
*priv
)
856 return scrn
->get_tex_surface(scrn
, priv
->tex
, 0, 0, 0,
857 PIPE_BUFFER_USAGE_GPU_READ
|
858 PIPE_BUFFER_USAGE_GPU_WRITE
);
862 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
863 struct pipe_fence_handle
**fence
)
865 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
868 void xorg_exa_finish(struct exa_context
*exa
)
870 struct pipe_fence_handle
*fence
= NULL
;
872 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
874 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
875 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);