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"
51 #define DISABLE_ACCEL 1
58 exa_get_pipe_format(int depth
, enum pipe_format
*format
, int *bbp
)
62 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
;
66 *format
= PIPE_FORMAT_X8R8G8B8_UNORM
;
70 *format
= PIPE_FORMAT_R5G6B5_UNORM
;
74 *format
= PIPE_FORMAT_A1R5G5B5_UNORM
;
78 *format
= PIPE_FORMAT_I8_UNORM
;
83 *format
= PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
92 xorg_exa_init_state(struct exa_context
*exa
)
94 struct pipe_depth_stencil_alpha_state dsa
;
96 /* set common initial clip state */
97 memset(&dsa
, 0, sizeof(struct pipe_depth_stencil_alpha_state
));
98 cso_set_depth_stencil_alpha(exa
->cso
, &dsa
);
102 xorg_exa_common_done(struct exa_context
*exa
)
104 exa
->copy
.src
= NULL
;
105 exa
->copy
.dst
= NULL
;
106 exa
->has_solid_color
= FALSE
;
107 exa
->num_bound_samplers
= 0;
111 * Static exported EXA functions
115 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
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 PIPE_TRANSFER_READ_WRITE
,
213 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
215 pPix
->devPrivate
.ptr
=
216 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
217 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
);
288 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
291 if (!priv
|| !priv
->tex
)
294 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
296 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
313 return xorg_solid_bind_state(exa
, priv
, fg
);
318 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
320 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
321 modesettingPtr ms
= modesettingPTR(pScrn
);
322 struct exa_context
*exa
= ms
->exa
;
323 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
325 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
);
379 debug_printf("ExaPrepareCopy\n");
384 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
387 if (!priv
|| !src_priv
)
390 if (!exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
392 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0) ||
393 !exa
->scrn
->is_format_supported(exa
->scrn
, src_priv
->tex
->format
,
394 src_priv
->tex
->target
,
395 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
398 if (!priv
->tex
|| !src_priv
->tex
)
404 exa
->copy
.src
= src_priv
;
405 exa
->copy
.dst
= priv
;
415 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
416 int width
, int height
)
418 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
419 modesettingPtr ms
= modesettingPTR(pScrn
);
420 struct exa_context
*exa
= ms
->exa
;
421 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
);
426 debug_assert(priv
== exa
->copy
.dst
);
428 xorg_copy_pixmap(exa
, exa
->copy
.dst
, dstX
, dstY
,
429 exa
->copy
.src
, srcX
, srcY
,
434 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
435 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
436 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
438 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
439 modesettingPtr ms
= modesettingPTR(pScrn
);
440 struct exa_context
*exa
= ms
->exa
;
441 struct exa_pixmap_priv
*priv
;
443 debug_printf("ExaPrepareComposite\n");
445 priv
= exaGetPixmapDriverPrivate(pDst
);
446 if (!priv
|| !priv
->tex
||
447 !exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
449 PIPE_TEXTURE_USAGE_RENDER_TARGET
, 0))
453 priv
= exaGetPixmapDriverPrivate(pSrc
);
454 if (!priv
|| !priv
->tex
||
455 !exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
457 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
462 priv
= exaGetPixmapDriverPrivate(pMask
);
463 if (!priv
|| !priv
->tex
||
464 !exa
->scrn
->is_format_supported(exa
->scrn
, priv
->tex
->format
,
466 PIPE_TEXTURE_USAGE_SAMPLER
, 0))
474 return xorg_composite_bind_state(exa
, op
, pSrcPicture
, pMaskPicture
,
476 pSrc
? exaGetPixmapDriverPrivate(pSrc
) : NULL
,
477 pMask
? exaGetPixmapDriverPrivate(pMask
) : NULL
,
478 exaGetPixmapDriverPrivate(pDst
));
483 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
484 int dstX
, int dstY
, int width
, int height
)
486 ScrnInfoPtr pScrn
= xf86Screens
[pDst
->drawable
.pScreen
->myNum
];
487 modesettingPtr ms
= modesettingPTR(pScrn
);
488 struct exa_context
*exa
= ms
->exa
;
489 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pDst
);
491 debug_printf("\tExaComposite\n");
493 xorg_composite(exa
, priv
, srcX
, srcY
, maskX
, maskY
,
494 dstX
, dstY
, width
, height
);
498 ExaCheckComposite(int op
,
499 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
500 PicturePtr pDstPicture
)
502 boolean accelerated
= xorg_composite_accelerated(op
,
506 debug_printf("ExaCheckComposite(%d, %p, %p, %p) = %d\n",
507 op
, pSrcPicture
, pMaskPicture
, pDstPicture
, accelerated
);
512 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
514 struct exa_pixmap_priv
*priv
;
516 priv
= xcalloc(1, sizeof(struct exa_pixmap_priv
));
524 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
526 struct exa_pixmap_priv
*priv
= (struct exa_pixmap_priv
*)dPriv
;
531 pipe_texture_reference(&priv
->tex
, NULL
);
537 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
539 struct exa_pixmap_priv
*priv
;
541 priv
= exaGetPixmapDriverPrivate(pPixmap
);
553 xorg_exa_set_displayed_usage(PixmapPtr pPixmap
)
555 struct exa_pixmap_priv
*priv
;
556 priv
= exaGetPixmapDriverPrivate(pPixmap
);
559 FatalError("NO PIXMAP PRIVATE\n");
563 priv
->flags
|= PIPE_TEXTURE_USAGE_PRIMARY
;
569 xorg_exa_set_shared_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_DISPLAY_TARGET
;
585 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
, unsigned *stride_out
)
587 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
588 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
589 modesettingPtr ms
= modesettingPTR(pScrn
);
590 struct exa_pixmap_priv
*priv
;
595 FatalError("NO MS->EXA\n");
599 priv
= exaGetPixmapDriverPrivate(pPixmap
);
602 FatalError("NO PIXMAP PRIVATE\n");
606 ms
->api
->local_handle_from_texture(ms
->api
, ms
->screen
, priv
->tex
, &stride
, &handle
);
608 *stride_out
= stride
;
614 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
615 int depth
, int bitsPerPixel
, int devKind
,
618 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
619 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
620 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
621 modesettingPtr ms
= modesettingPTR(pScrn
);
622 struct exa_context
*exa
= ms
->exa
;
624 if (!priv
|| pPixData
)
628 depth
= pPixmap
->drawable
.depth
;
630 if (bitsPerPixel
<= 0)
631 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
634 width
= pPixmap
->drawable
.width
;
637 height
= pPixmap
->drawable
.height
;
639 if (width
<= 0 || height
<= 0 || depth
<= 0)
642 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
643 bitsPerPixel
, devKind
, NULL
);
645 /* Deal with screen resize */
647 (priv
->tex
->width
[0] != width
||
648 priv
->tex
->height
[0] != height
||
649 priv
->tex_flags
!= priv
->flags
)) {
650 struct pipe_texture
*texture
= NULL
;
652 #ifdef DRM_MODE_FEATURE_DIRTYFB
656 struct pipe_texture
template;
658 memset(&template, 0, sizeof(template));
659 template.target
= PIPE_TEXTURE_2D
;
660 exa_get_pipe_format(depth
, &template.format
, &bitsPerPixel
);
661 pf_get_block(template.format
, &template.block
);
662 template.width
[0] = width
;
663 template.height
[0] = height
;
664 template.depth
[0] = 1;
665 template.last_level
= 0;
666 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
| priv
->flags
;
667 priv
->tex_flags
= priv
->flags
;
668 texture
= exa
->scrn
->texture_create(exa
->scrn
, &template);
671 struct pipe_surface
*dst_surf
;
672 struct pipe_surface
*src_surf
;
674 dst_surf
= exa
->scrn
->get_tex_surface(
675 exa
->scrn
, texture
, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_WRITE
);
676 src_surf
= exa_gpu_surface(exa
, priv
);
677 exa
->pipe
->surface_copy(exa
->pipe
, dst_surf
, 0, 0, src_surf
,
678 0, 0, min(width
, texture
->width
[0]),
679 min(height
, texture
->height
[0]));
680 exa
->scrn
->tex_surface_destroy(dst_surf
);
681 exa
->scrn
->tex_surface_destroy(src_surf
);
682 } else if (pPixmap
->devPrivate
.ptr
) {
683 struct pipe_transfer
*transfer
;
685 if (priv
->map_count
!= 0)
686 FatalError("doing ExaModifyPixmapHeader on mapped buffer\n");
689 exa
->scrn
->get_tex_transfer(exa
->scrn
, texture
, 0, 0, 0,
691 0, 0, width
, height
);
692 util_copy_rect(exa
->scrn
->transfer_map(exa
->scrn
, transfer
),
693 &texture
->block
, transfer
->stride
, 0, 0,
694 width
, height
, pPixmap
->devPrivate
.ptr
,
695 pPixmap
->devKind
, 0, 0);
696 exa
->scrn
->transfer_unmap(exa
->scrn
, transfer
);
697 exa
->scrn
->tex_transfer_destroy(transfer
);
699 xfree(pPixmap
->devPrivate
.ptr
);
700 pPixmap
->devPrivate
.ptr
= NULL
;
703 #ifdef DRM_MODE_FEATURE_DIRTYFB
705 xfree(pPixmap
->devPrivate
.ptr
);
706 pPixmap
->devPrivate
.ptr
= xalloc(pPixmap
->drawable
.height
*
711 pipe_texture_reference(&priv
->tex
, texture
);
712 /* the texture we create has one reference */
713 pipe_texture_reference(&texture
, NULL
);
719 struct pipe_texture
*
720 xorg_exa_get_texture(PixmapPtr pPixmap
)
722 struct exa_pixmap_priv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
723 struct pipe_texture
*tex
= NULL
;
724 pipe_texture_reference(&tex
, priv
->tex
);
729 xorg_exa_close(ScrnInfoPtr pScrn
)
731 modesettingPtr ms
= modesettingPTR(pScrn
);
732 struct exa_context
*exa
= ms
->exa
;
733 struct pipe_constant_buffer
*vsbuf
= &exa
->vs_const_buffer
;
734 struct pipe_constant_buffer
*fsbuf
= &exa
->fs_const_buffer
;
737 xorg_shaders_destroy(exa
->shaders
);
740 if (vsbuf
&& vsbuf
->buffer
)
741 pipe_buffer_reference(&vsbuf
->buffer
, NULL
);
743 if (fsbuf
&& fsbuf
->buffer
)
744 pipe_buffer_reference(&fsbuf
->buffer
, NULL
);
747 cso_release_all(exa
->cso
);
748 cso_destroy_context(exa
->cso
);
752 exa
->pipe
->destroy(exa
->pipe
);
754 exaDriverFini(pScrn
->pScreen
);
760 xorg_exa_init(ScrnInfoPtr pScrn
)
762 modesettingPtr ms
= modesettingPTR(pScrn
);
763 struct exa_context
*exa
;
766 exa
= xcalloc(1, sizeof(struct exa_context
));
770 pExa
= exaDriverAlloc();
775 memset(pExa
, 0, sizeof(*pExa
));
779 pExa
->memoryBase
= 0;
780 pExa
->memorySize
= 0;
781 pExa
->offScreenBase
= 0;
782 pExa
->pixmapOffsetAlign
= 0;
783 pExa
->pixmapPitchAlign
= 1;
784 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
785 #ifdef EXA_SUPPORTS_PREPARE_AUX
786 pExa
->flags
|= EXA_SUPPORTS_PREPARE_AUX
;
788 #ifdef EXA_MIXED_PIXMAPS
789 pExa
->flags
|= EXA_MIXED_PIXMAPS
;
791 pExa
->maxX
= 8191; /* FIXME */
792 pExa
->maxY
= 8191; /* FIXME */
794 pExa
->WaitMarker
= ExaWaitMarker
;
795 pExa
->MarkSync
= ExaMarkSync
;
796 pExa
->PrepareSolid
= ExaPrepareSolid
;
797 pExa
->Solid
= ExaSolid
;
798 pExa
->DoneSolid
= ExaDone
;
799 pExa
->PrepareCopy
= ExaPrepareCopy
;
800 pExa
->Copy
= ExaCopy
;
801 pExa
->DoneCopy
= ExaDone
;
802 pExa
->CheckComposite
= ExaCheckComposite
;
803 pExa
->PrepareComposite
= ExaPrepareComposite
;
804 pExa
->Composite
= ExaComposite
;
805 pExa
->DoneComposite
= ExaDoneComposite
;
806 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
807 pExa
->DownloadFromScreen
= ExaDownloadFromScreen
;
808 pExa
->UploadToScreen
= ExaUploadToScreen
;
809 pExa
->PrepareAccess
= ExaPrepareAccess
;
810 pExa
->FinishAccess
= ExaFinishAccess
;
811 pExa
->CreatePixmap
= ExaCreatePixmap
;
812 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
813 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
815 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
819 exa
->scrn
= ms
->screen
;
820 exa
->pipe
= ms
->api
->create_context(ms
->api
, exa
->scrn
);
821 /* Share context with DRI */
824 exa
->cso
= cso_create_context(exa
->pipe
);
825 exa
->shaders
= xorg_shaders_create(exa
);
827 xorg_exa_init_state(exa
);
832 xorg_exa_close(pScrn
);
837 struct pipe_surface
*
838 exa_gpu_surface(struct exa_context
*exa
, struct exa_pixmap_priv
*priv
)
840 return exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
841 PIPE_BUFFER_USAGE_GPU_READ
|
842 PIPE_BUFFER_USAGE_GPU_WRITE
);
846 void xorg_exa_flush(struct exa_context
*exa
, uint pipeFlushFlags
,
847 struct pipe_fence_handle
**fence
)
849 exa
->pipe
->flush(exa
->pipe
, pipeFlushFlags
, fence
);
852 void xorg_exa_finish(struct exa_context
*exa
)
854 struct pipe_fence_handle
*fence
= NULL
;
856 xorg_exa_flush(exa
, PIPE_FLUSH_RENDER_CACHE
, &fence
);
858 exa
->pipe
->screen
->fence_finish(exa
->pipe
->screen
, fence
, 0);
859 exa
->pipe
->screen
->fence_reference(exa
->pipe
->screen
, &fence
, NULL
);