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 "cso_cache/cso_context.h"
48 #include "util/u_rect.h"
52 #define DISABLE_ACCEL 0
59 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
63 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
67 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
71 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
75 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
79 *format
= PIPE_FORMAT_I8_UNORM
;
84 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
93 xorg_exa_init_state(struct exa_context
*exa
)
95 struct pipe_depth_stencil_alpha_state dsa
;
97 /* set common initial clip state */
98 memset(&dsa
, 0, sizeof(struct pipe_depth_stencil_alpha_state
));
99 cso_set_depth_stencil_alpha(exa
->cso
, &dsa
);
103 xorg_exa_common_done(struct exa_context
*exa
)
105 exa
->copy
.src
= NULL
;
106 exa
->copy
.dst
= NULL
;
107 exa
->has_solid_color
= FALSE
;
108 exa
->num_bound_samplers
= 0;
112 * Static exported EXA functions
116 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
121 ExaMarkSync(ScreenPtr pScreen
)
127 ExaDownloadFromScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *dst
,
130 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
131 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
132 modesettingPtr ms
= modesettingPTR(pScrn
);
133 struct exa_context
*exa
= ms
->exa
;
134 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
135 struct pipe_transfer
*transfer
;
137 if (!priv
|| !priv
->tex
)
140 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
141 PIPE_REFERENCED_FOR_WRITE
)
142 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
144 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
145 PIPE_TRANSFER_READ
, x
, y
, w
, h
);
149 util_copy_rect((unsigned char*)dst
, &priv
->tex
->block
, dst_pitch
, 0, 0,
150 w
, h
, exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
151 transfer
->stride
, 0, 0);
153 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
154 exa
->scrn
->tex_transfer_destroy(transfer
);
160 ExaUploadToScreen(PixmapPtr pPix
, int x
, int y
, int w
, int h
, char *src
,
163 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
164 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
165 modesettingPtr ms
= modesettingPTR(pScrn
);
166 struct exa_context
*exa
= ms
->exa
;
167 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPix
);
168 struct pipe_transfer
*transfer
;
170 if (!priv
|| !priv
->tex
)
173 transfer
= exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
174 PIPE_TRANSFER_WRITE
, x
, y
, w
, h
);
178 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
179 &priv
->tex
->block
, transfer
->stride
, 0, 0, w
, h
,
180 (unsigned char*)src
, src_pitch
, 0, 0);
182 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
183 exa
->scrn
->tex_transfer_destroy(transfer
);
189 ExaPrepareAccess(PixmapPtr pPix
, int index
)
191 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
192 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
193 modesettingPtr ms
= modesettingPTR(pScrn
);
194 struct exa_context
*exa
= ms
->exa
;
195 struct exa_pixmap_priv
*priv
;
197 priv
= exaGetPixmapDriverPrivate(pPix
);
205 if (priv
->map_count
== 0)
207 if (exa
->pipe
->is_texture_referenced(exa
->pipe
, priv
->tex
, 0, 0) &
208 PIPE_REFERENCED_FOR_WRITE
)
209 exa
->pipe
->flush(exa
->pipe
, 0, NULL
);
212 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
213 #ifdef EXA_MIXED_PIXMAPS
214 PIPE_TRANSFER_MAP_DIRECTLY
|
216 PIPE_TRANSFER_READ_WRITE
,
217 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
218 if (!priv
->map_transfer
)
221 pPix
->devPrivate
.ptr
=
222 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
223 pPix
->devKind
= priv
->map_transfer
->stride
;
232 ExaFinishAccess(PixmapPtr pPix
, int index
)
234 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
235 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
236 modesettingPtr ms
= modesettingPTR(pScrn
);
237 struct exa_context
*exa
= ms
->exa
;
238 struct exa_pixmap_priv
*priv
;
239 priv
= exaGetPixmapDriverPrivate(pPix
);
244 if (!priv
->map_transfer
)
247 if (--priv
->map_count
== 0) {
248 assert(priv
->map_transfer
);
249 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
250 exa
->scrn
->tex_transfer_destroy(priv
->map_transfer
);
251 priv
->map_transfer
= NULL
;
252 pPix
->devPrivate
.ptr
= NULL
;
257 ExaDone(PixmapPtr pPixmap
)
259 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
260 modesettingPtr ms
= modesettingPTR(pScrn
);
261 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
262 struct exa_context
*exa
= ms
->exa
;
268 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
270 xorg_exa_finish(exa
);
272 xorg_exa_common_done(exa
);
276 ExaDoneComposite(PixmapPtr pPixmap
)
278 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
279 modesettingPtr ms
= modesettingPTR(pScrn
);
280 struct exa_context
*exa
= ms
->exa
;
282 xorg_exa_common_done(exa
);
286 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
288 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
289 modesettingPtr ms
= modesettingPTR(pScrn
);
290 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
291 struct exa_context
*exa
= ms
->exa
;
294 debug_printf("ExaPrepareSolid(0x%x)\n", fg
);
297 XORG_FALLBACK("solid accle not enabled");
299 if (!priv
|| !priv
->tex
)
300 XORG_FALLBACK("solid !priv || !priv->tex");
302 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
303 XORG_FALLBACK("solid planeMask is not solid");
306 XORG_FALLBACK("solid not GXcopy");
308 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
310 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0)) {
311 XORG_FALLBACK("solid bad format %s", pf_name(priv
->tex
->format
));
321 return xorg_solid_bind_state(exa
, priv
, fg
);
326 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
328 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
329 modesettingPtr ms
= modesettingPTR(pScrn
);
330 struct exa_context
*exa
= ms
->exa
;
331 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
334 debug_printf("\tExaSolid(%d, %d, %d, %d)\n", x0
, y0
, x1
, y1
);
338 if (x0
== 0 && y0
== 0 &&
339 x1
== priv
->tex
->width
[0] &&
340 y1
== priv
->tex
->height
[0]) {
341 exa
->ctx
->clear(exa
->pipe
, PIPE_CLEAR_COLOR
,
342 exa
->solid_color
, 1., 0);
347 exa
->solid_color
[0] = 0.f
;
348 exa
->solid_color
[1] = 1.f
;
349 exa
->solid_color
[2] = 0.f
;
350 exa
->solid_color
[3] = 1.f
;
351 xorg_solid(exa
, priv
, 0, 0, 1024, 768);
352 exa
->solid_color
[0] = 1.f
;
353 exa
->solid_color
[1] = 0.f
;
354 exa
->solid_color
[2] = 0.f
;
355 exa
->solid_color
[3] = 1.f
;
356 xorg_solid(exa
, priv
, 0, 0, 300, 300);
357 xorg_solid(exa
, priv
, 300, 300, 350, 350);
358 xorg_solid(exa
, priv
, 350, 350, 500, 500);
360 xorg_solid(exa
, priv
,
361 priv
->tex
->width
[0] - 10,
362 priv
->tex
->height
[0] - 10,
364 priv
->tex
->height
[0]);
366 exa
->solid_color
[0] = 0.f
;
367 exa
->solid_color
[1] = 0.f
;
368 exa
->solid_color
[2] = 1.f
;
369 exa
->solid_color
[3] = 1.f
;
371 exa
->has_solid_color
= FALSE
;
372 ExaPrepareCopy(pPixmap
, pPixmap
, 0, 0, GXcopy
, 0xffffffff);
373 ExaCopy(pPixmap
, 0, 0, 50, 50, 500, 500);
375 xorg_solid(exa
, priv
, x0
, y0
, x1
, y1
) ;
380 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
381 int ydir
, int alu
, Pixel planeMask
)
383 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
384 modesettingPtr ms
= modesettingPTR(pScrn
);
385 struct exa_context
*exa
= ms
->exa
;
386 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
387 struct exa_pixmap_priv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
390 debug_printf("ExaPrepareCopy\n");
393 XORG_FALLBACK("copy accle not enabled");
395 if (!priv
|| !src_priv
)
396 XORG_FALLBACK("copy !priv || !src_priv");
398 if (!priv
->tex
|| !src_priv
->tex
)
399 XORG_FALLBACK("copy !priv->tex || !src_priv->tex");
401 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
402 XORG_FALLBACK("copy planeMask is not solid");
405 XORG_FALLBACK("copy alu not GXcopy");
407 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
409 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
410 XORG_FALLBACK("copy pDst format %s", pf_name(priv
->tex
->format
));
412 if (!exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
413 src_priv
->tex
->target
,
414 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
415 XORG_FALLBACK("copy pSrc format %s", pf_name(src_priv
->tex
->format
));
417 exa
->copy
.src
= src_priv
;
418 exa
->copy
.dst
= priv
;
428 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
429 int width
, int height
)
431 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
432 modesettingPtr ms
= modesettingPTR(pScrn
);
433 struct exa_context
*exa
= ms
->exa
;
434 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
437 debug_printf("\tExaCopy(srcx=%d, srcy=%d, dstX=%d, dstY=%d, w=%d, h=%d)\n",
438 srcX
, srcY
, dstX
, dstY
, width
, height
);
441 debug_assert(priv
== exa
->copy
.dst
);
443 xorg_copy_pixmap(exa
, exa
->copy
.dst
, dstX
, dstY
,
444 exa
->copy
.src
, srcX
, srcY
,
449 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
450 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
451 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
453 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
454 modesettingPtr ms
= modesettingPTR(pScrn
);
455 struct exa_context
*exa
= ms
->exa
;
456 struct exa_pixmap_priv
*priv
;
459 debug_printf("ExaPrepareComposite\n");
462 XORG_FALLBACK("comp accle not enabled");
464 priv
= exaGetPixmapDriverPrivate(pDst
);
465 if (!priv
|| !priv
->tex
)
466 XORG_FALLBACK("comp pDst %s", !priv
? "!priv" : "!priv->tex");
468 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
470 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
471 XORG_FALLBACK("copy pDst format: %s", pf_name(priv
->tex
->format
));
474 priv
= exaGetPixmapDriverPrivate(pSrc
);
475 if (!priv
|| !priv
->tex
)
476 XORG_FALLBACK("comp pSrc %s", !priv
? "!priv" : "!priv->tex");
478 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
480 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
481 XORG_FALLBACK("copy pSrc format: %s", pf_name(priv
->tex
->format
));
485 priv
= exaGetPixmapDriverPrivate(pMask
);
486 if (!priv
|| !priv
->tex
)
487 XORG_FALLBACK("comp pMask %s", !priv
? "!priv" : "!priv->tex");
489 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
491 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
492 XORG_FALLBACK("copy pMask format: %s", pf_name(priv
->tex
->format
));
499 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
501 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
502 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
503 exaGetPixmapDriverPrivate(pDst
));
508 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
509 int dstX
, int dstY
, int width
, int height
)
511 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
512 modesettingPtr ms
= modesettingPTR(pScrn
);
513 struct exa_context
*exa
= ms
->exa
;
514 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
517 debug_printf("\tExaComposite\n");
520 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
521 dstX
, dstY
, width
, height
);
525 ExaCheckComposite(int op
,
526 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
527 PicturePtr pDstPicture
)
529 boolean accelerated
= xorg_composite_accelerated(op
,
534 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
535 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
541 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
543 struct exa_pixmap_priv
*priv
;
545 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
553 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
555 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
560 pipe_texture_reference(&priv
->tex
, NULL
);
566 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
568 struct exa_pixmap_priv
*priv
;
570 priv
= exaGetPixmapDriverPrivate(pPixmap
);
582 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
584 struct exa_pixmap_priv
*priv
;
585 priv
= exaGetPixmapDriverPrivate(pPixmap
);
588 FatalError("NO PIXMAP PRIVATE\n");
592 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
598 xorg_exa_set_shared_usage(PixmapPtr pPixmap
)
600 struct exa_pixmap_priv
*priv
;
601 priv
= exaGetPixmapDriverPrivate(pPixmap
);
604 FatalError("NO PIXMAP PRIVATE\n");
608 priv
->flags
|= PIPE_TEXTURE_USAGE_DISPLAY_TARGET
;
614 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
616 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
617 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
618 modesettingPtr ms
= modesettingPTR(pScrn
);
619 struct exa_pixmap_priv
*priv
;
624 FatalError("NO MS->EXA\n");
628 priv
= exaGetPixmapDriverPrivate(pPixmap
);
631 FatalError("NO PIXMAP PRIVATE\n");
635 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
637 *stride_out
= stride
;
643 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
644 int depth
, int bitsPerPixel
, int devKind
,
647 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
648 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
649 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
650 modesettingPtr ms
= modesettingPTR(pScrn
);
651 struct exa_context
*exa
= ms
->exa
;
653 if (!priv
|| pPixData
)
657 depth
= pPixmap
->drawable
.depth
;
659 if (bitsPerPixel
<= 0)
660 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
663 width
= pPixmap
->drawable
.width
;
666 height
= pPixmap
->drawable
.height
;
668 if (width
<= 0 || height
<= 0 || depth
<= 0)
671 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
672 bitsPerPixel
, devKind
, NULL
);
674 /* Deal with screen resize */
676 (priv
->tex
->width
[0] != width
||
677 priv
->tex
->height
[0] != height
||
678 priv
->tex_flags
!= priv
->flags
)) {
679 struct pipe_texture
*texture
= NULL
;
680 struct pipe_texture
template;
682 memset(&template, 0, sizeof(template));
683 template.target
= PIPE_TEXTURE_2D
;
684 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
685 pf_get_block(template.format
, &template.block
);
686 template.width
[0] = width
;
687 template.height
[0] = height
;
688 template.depth
[0] = 1;
689 template.last_level
= 0;
690 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
691 priv
->tex_flags
= priv
->flags
;
692 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
695 struct pipe_surface
*dst_surf
;
696 struct pipe_surface
*src_surf
;
698 dst_surf
= exa
->scrn
->get_tex_surface(
699 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
700 src_surf
= exa_gpu_surface(exa
, priv
);
701 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
702 0, 0, min(width
, texture
->width
[0]),
703 min(height
, texture
->height
[0]));
704 exa
->scrn
->tex_surface_destroy(dst_surf
);
705 exa
->scrn
->tex_surface_destroy(src_surf
);
708 pipe_texture_reference(&priv
->tex
, texture
);
709 /* the texture we create has one reference */
710 pipe_texture_reference(&texture
, NULL
);
716 struct pipe_texture
*
717 xorg_exa_get_texture(PixmapPtr pPixmap
)
719 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
720 struct pipe_texture
*tex
= NULL
;
721 pipe_texture_reference(&tex
, priv
->tex
);
726 xorg_exa_close(ScrnInfoPtr pScrn
)
728 modesettingPtr ms
= modesettingPTR(pScrn
);
729 struct exa_context
*exa
= ms
->exa
;
730 struct pipe_constant_buffer
*vsbuf
= &exa
->vs_const_buffer
;
731 struct pipe_constant_buffer
*fsbuf
= &exa
->fs_const_buffer
;
734 xorg_shaders_destroy(exa
->shaders
);
737 if (vsbuf
&& vsbuf
->buffer
)
738 pipe_buffer_reference(&vsbuf
->buffer
, NULL
);
740 if (fsbuf
&& fsbuf
->buffer
)
741 pipe_buffer_reference(&fsbuf
->buffer
, NULL
);
744 cso_release_all(exa
->cso
);
745 cso_destroy_context(exa
->cso
);
749 exa
->pipe
->destroy(exa
->pipe
);
751 exaDriverFini(pScrn
->pScreen
);
757 xorg_exa_init(ScrnInfoPtr pScrn
)
759 modesettingPtr ms
= modesettingPTR(pScrn
);
760 struct exa_context
*exa
;
763 exa
= xcalloc(1, sizeof(struct exa_context
));
767 pExa
= exaDriverAlloc();
772 memset(pExa
, 0, sizeof(*pExa
));
776 pExa
->memoryBase
= 0;
777 pExa
->memorySize
= 0;
778 pExa
->offScreenBase
= 0;
779 pExa
->pixmapOffsetAlign
= 0;
780 pExa
->pixmapPitchAlign
= 1;
781 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
782 #ifdef EXA_SUPPORTS_PREPARE_AUX
783 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
785 #ifdef EXA_MIXED_PIXMAPS
786 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
788 pExa
->maxX
= 8191; /* FIXME */
789 pExa
->maxY
= 8191; /* FIXME */
791 pExa
->WaitMarker
= ExaWaitMarker
;
792 pExa
->MarkSync
= ExaMarkSync
;
793 pExa
->PrepareSolid
= ExaPrepareSolid
;
794 pExa
->Solid
= ExaSolid
;
795 pExa
->DoneSolid
= ExaDone
;
796 pExa
->PrepareCopy
= ExaPrepareCopy
;
797 pExa
->Copy
= ExaCopy
;
798 pExa
->DoneCopy
= ExaDone
;
799 pExa
->CheckComposite
= ExaCheckComposite
;
800 pExa
->PrepareComposite
= ExaPrepareComposite
;
801 pExa
->Composite
= ExaComposite
;
802 pExa
->DoneComposite
= ExaDoneComposite
;
803 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
804 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
805 pExa
->UploadToScreen
= ExaUploadToScreen
;
806 pExa
->PrepareAccess
= ExaPrepareAccess
;
807 pExa
->FinishAccess
= ExaFinishAccess
;
808 pExa
->CreatePixmap
= ExaCreatePixmap
;
809 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
810 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
812 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
816 exa
->scrn
= ms
->screen
;
817 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
818 /* Share context with DRI */
821 exa
->cso
= cso_create_context(exa
->pipe
);
822 exa
->shaders
= xorg_shaders_create(exa
);
824 xorg_exa_init_state(exa
);
829 xorg_exa_close(pScrn
);
834 struct pipe_surface
*
835 exa_gpu_surface(struct exa_context
*exa
, struct exa_pixmap_priv
*priv
)
837 return exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
838 PIPE_BUFFER_USAGE_GPU_READ
|
839 PIPE_BUFFER_USAGE_GPU_WRITE
);
843 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
844 struct pipe_fence_handle
**fence
)
846 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
849 void xorg_exa_finish(struct exa_context
*exa
)
851 struct pipe_fence_handle
*fence
= NULL
;
853 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
855 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
856 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);