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 #define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
35 //#include "xf86_OSproc.h"
36 #include "xorg_tracker.h"
38 //#include "pipe/p_winsys.h"
39 #include "pipe/p_format.h"
40 #include "pipe/p_context.h"
41 #include "pipe/p_state.h"
42 #include "pipe/p_inlines.h"
47 struct pipe_context
*ctx
;
48 struct pipe_screen
*scrn
;
54 struct pipe_texture
*tex
;
56 struct pipe_surface
*src_surf
; /* for copies */
57 struct pipe_transfer
*map_transfer
;
64 static enum pipe_format
65 exa_get_pipe_format(int depth
)
69 return PIPE_FORMAT_A8R8G8B8_UNORM
;
71 return PIPE_FORMAT_X8R8G8B8_UNORM
;
73 return PIPE_FORMAT_R5G6B5_UNORM
;
75 return PIPE_FORMAT_A1R5G5B5_UNORM
;
79 return PIPE_FORMAT_A8R8G8B8_UNORM
; /* bad bad bad */
87 * Static exported EXA functions
91 ExaWaitMarker(ScreenPtr pScreen
, int marker
)
96 ExaMarkSync(ScreenPtr pScreen
)
102 ExaPrepareAccess(PixmapPtr pPix
, int index
)
104 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
105 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
106 modesettingPtr ms
= modesettingPTR(pScrn
);
107 //PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
108 struct exa_entity
*exa
= ms
->exa
;
109 struct PixmapPriv
*priv
;
112 priv
= exaGetPixmapDriverPrivate(pPix
);
121 exa
->scrn
->get_tex_transfer(exa
->scrn
, priv
->tex
, 0, 0, 0,
122 PIPE_TRANSFER_READ_WRITE
,
123 0, 0, priv
->tex
->width
[0], priv
->tex
->height
[0]);
125 pPix
->devPrivate
.ptr
=
126 exa
->scrn
->transfer_map(exa
->scrn
, priv
->map_transfer
);
127 pPix
->devKind
= priv
->map_transfer
->stride
;
134 ExaFinishAccess(PixmapPtr pPix
, int index
)
136 ScreenPtr pScreen
= pPix
->drawable
.pScreen
;
137 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
138 modesettingPtr ms
= modesettingPTR(pScrn
);
139 struct exa_entity
*exa
= ms
->exa
;
140 struct PixmapPriv
*priv
;
141 priv
= exaGetPixmapDriverPrivate(pPix
);
146 if (!priv
->map_transfer
)
149 exa
->scrn
->transfer_unmap(exa
->scrn
, priv
->map_transfer
);
150 pipe_transfer_reference(&priv
->map_transfer
, NULL
);
155 ExaDone(PixmapPtr pPixmap
)
157 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
158 modesettingPtr ms
= modesettingPTR(pScrn
);
159 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
160 struct exa_entity
*exa
= ms
->exa
;
166 exa
->scrn
->tex_surface_release(exa
->scrn
, &priv
->src_surf
);
167 priv
->src_surf
= NULL
;
171 ExaDoneComposite(PixmapPtr pPixmap
)
177 ExaPrepareSolid(PixmapPtr pPixmap
, int alu
, Pixel planeMask
, Pixel fg
)
179 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
180 modesettingPtr ms
= modesettingPTR(pScrn
);
181 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
182 struct exa_entity
*exa
= ms
->exa
;
187 if (pPixmap
->drawable
.depth
< 15)
190 if (!EXA_PM_IS_SOLID(&pPixmap
->drawable
, planeMask
))
193 if (!priv
|| !priv
->tex
)
199 if (!exa
->ctx
|| !exa
->ctx
->surface_fill
)
208 ExaSolid(PixmapPtr pPixmap
, int x0
, int y0
, int x1
, int y1
)
210 ScrnInfoPtr pScrn
= xf86Screens
[pPixmap
->drawable
.pScreen
->myNum
];
211 modesettingPtr ms
= modesettingPTR(pScrn
);
212 struct exa_entity
*exa
= ms
->exa
;
213 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
214 struct pipe_surface
*surf
=
215 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
216 PIPE_BUFFER_USAGE_GPU_READ
|
217 PIPE_BUFFER_USAGE_GPU_WRITE
);
219 exa
->ctx
->surface_fill(exa
->ctx
, surf
, x0
, y0
, x1
- x0
, y1
- y0
,
222 exa
->scrn
->tex_surface_release(exa
->scrn
, &surf
);
226 ExaPrepareCopy(PixmapPtr pSrcPixmap
, PixmapPtr pDstPixmap
, int xdir
,
227 int ydir
, int alu
, Pixel planeMask
)
229 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
230 modesettingPtr ms
= modesettingPTR(pScrn
);
231 struct exa_entity
*exa
= ms
->exa
;
232 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
233 struct PixmapPriv
*src_priv
= exaGetPixmapDriverPrivate(pSrcPixmap
);
241 if (pSrcPixmap
->drawable
.depth
< 15 || pDstPixmap
->drawable
.depth
< 15)
244 if (!EXA_PM_IS_SOLID(&pSrcPixmap
->drawable
, planeMask
))
247 if (!priv
|| !src_priv
)
250 if (!priv
->tex
|| !src_priv
->tex
)
253 if (!exa
->ctx
|| !exa
->ctx
->surface_copy
)
257 exa
->scrn
->get_tex_surface(exa
->scrn
, src_priv
->tex
, 0, 0, 0,
258 PIPE_BUFFER_USAGE_GPU_READ
|
259 PIPE_BUFFER_USAGE_GPU_WRITE
);
265 ExaCopy(PixmapPtr pDstPixmap
, int srcX
, int srcY
, int dstX
, int dstY
,
266 int width
, int height
)
268 ScrnInfoPtr pScrn
= xf86Screens
[pDstPixmap
->drawable
.pScreen
->myNum
];
269 modesettingPtr ms
= modesettingPTR(pScrn
);
270 struct exa_entity
*exa
= ms
->exa
;
271 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pDstPixmap
);
272 struct pipe_surface
*surf
=
273 exa
->scrn
->get_tex_surface(exa
->scrn
, priv
->tex
, 0, 0, 0,
274 PIPE_BUFFER_USAGE_GPU_READ
|
275 PIPE_BUFFER_USAGE_GPU_WRITE
);
277 exa
->ctx
->surface_copy(exa
->ctx
, 0, surf
, dstX
, dstY
, priv
->src_surf
,
278 srcX
, srcY
, width
, height
);
279 exa
->scrn
->tex_surface_release(exa
->scrn
, &surf
);
283 ExaPrepareComposite(int op
, PicturePtr pSrcPicture
,
284 PicturePtr pMaskPicture
, PicturePtr pDstPicture
,
285 PixmapPtr pSrc
, PixmapPtr pMask
, PixmapPtr pDst
)
292 ExaUploadToScreen(PixmapPtr pDst
, int x
, int y
, int w
, int h
, char *src
,
302 ExaComposite(PixmapPtr pDst
, int srcX
, int srcY
, int maskX
, int maskY
,
303 int dstX
, int dstY
, int width
, int height
)
308 ExaCheckComposite(int op
,
309 PicturePtr pSrcPicture
, PicturePtr pMaskPicture
,
310 PicturePtr pDstPicture
)
316 ExaCreatePixmap(ScreenPtr pScreen
, int size
, int align
)
318 struct PixmapPriv
*priv
;
320 priv
= xcalloc(1, sizeof(struct PixmapPriv
));
328 ExaDestroyPixmap(ScreenPtr pScreen
, void *dPriv
)
330 struct PixmapPriv
*priv
= (struct PixmapPriv
*)dPriv
;
331 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
332 modesettingPtr ms
= modesettingPTR(pScrn
);
333 struct exa_entity
*exa
= ms
->exa
;
339 ms
->screen
->texture_release(exa
->scrn
, &priv
->tex
);
345 ExaPixmapIsOffscreen(PixmapPtr pPixmap
)
347 struct PixmapPriv
*priv
;
349 priv
= exaGetPixmapDriverPrivate(pPixmap
);
361 xorg_exa_get_pixmap_handle(PixmapPtr pPixmap
)
363 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
364 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
365 modesettingPtr ms
= modesettingPTR(pScrn
);
366 struct PixmapPriv
*priv
;
367 struct pipe_buffer
*buffer
= NULL
;
372 FatalError("NO MS->EXA\n");
376 priv
= exaGetPixmapDriverPrivate(pPixmap
);
379 FatalError("NO PIXMAP PRIVATE\n");
383 drm_api_hooks
.buffer_from_texture(priv
->tex
, &buffer
, &stride
);
384 drm_api_hooks
.handle_from_buffer(ms
->screen
, buffer
, &handle
);
385 pipe_buffer_reference(ms
->screen
, &buffer
, NULL
);
390 ExaModifyPixmapHeader(PixmapPtr pPixmap
, int width
, int height
,
391 int depth
, int bitsPerPixel
, int devKind
,
394 ScreenPtr pScreen
= pPixmap
->drawable
.pScreen
;
395 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
396 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
397 modesettingPtr ms
= modesettingPTR(pScrn
);
398 //PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
399 struct exa_entity
*exa
= ms
->exa
;
405 depth
= pPixmap
->drawable
.depth
;
407 if (bitsPerPixel
<= 0)
408 bitsPerPixel
= pPixmap
->drawable
.bitsPerPixel
;
411 width
= pPixmap
->drawable
.width
;
414 height
= pPixmap
->drawable
.height
;
416 if (width
<= 0 || height
<= 0 || depth
<= 0)
419 miModifyPixmapHeader(pPixmap
, width
, height
, depth
,
420 bitsPerPixel
, devKind
, NULL
);
422 /* Deal with screen resize */
423 if (priv
->tex
&& (priv
->tex
->width
[0] != width
|| priv
->tex
->height
[0] != height
)) {
424 pipe_texture_reference(&priv
->tex
, NULL
);
428 struct pipe_texture
template;
430 memset(&template, 0, sizeof(template));
431 template.target
= PIPE_TEXTURE_2D
;
432 template.compressed
= 0;
433 template.format
= exa_get_pipe_format(depth
);
434 pf_get_block(template.format
, &template.block
);
435 template.width
[0] = width
;
436 template.height
[0] = height
;
437 template.depth
[0] = 1;
438 template.last_level
= 0;
439 template.tex_usage
= PIPE_TEXTURE_USAGE_RENDER_TARGET
;
440 priv
->tex
= exa
->scrn
->texture_create(exa
->scrn
, &template);
446 struct pipe_texture
*
447 xorg_exa_get_texture(PixmapPtr pPixmap
)
449 struct PixmapPriv
*priv
= exaGetPixmapDriverPrivate(pPixmap
);
450 struct pipe_texture
*tex
= NULL
;
451 pipe_texture_reference(&tex
, priv
->tex
);
456 xorg_exa_close(ScrnInfoPtr pScrn
)
458 modesettingPtr ms
= modesettingPTR(pScrn
);
459 struct exa_entity
*exa
= ms
->exa
;
462 exa
->ctx
->destroy(exa
->ctx
);
464 exaDriverFini(pScrn
->pScreen
);
470 xorg_exa_init(ScrnInfoPtr pScrn
)
472 modesettingPtr ms
= modesettingPTR(pScrn
);
473 struct exa_entity
*exa
;
476 exa
= xcalloc(1, sizeof(struct exa_entity
));
480 pExa
= exaDriverAlloc();
485 memset(pExa
, 0, sizeof(*pExa
));
488 pExa
->memoryBase
= 0;
489 pExa
->memorySize
= 0;
490 pExa
->offScreenBase
= 0;
491 pExa
->pixmapOffsetAlign
= 0;
492 pExa
->pixmapPitchAlign
= 1;
493 pExa
->flags
= EXA_OFFSCREEN_PIXMAPS
| EXA_HANDLES_PIXMAPS
;
494 pExa
->maxX
= 8191; /* FIXME */
495 pExa
->maxY
= 8191; /* FIXME */
496 pExa
->WaitMarker
= ExaWaitMarker
;
497 pExa
->MarkSync
= ExaMarkSync
;
498 pExa
->PrepareSolid
= ExaPrepareSolid
;
499 pExa
->Solid
= ExaSolid
;
500 pExa
->DoneSolid
= ExaDone
;
501 pExa
->PrepareCopy
= ExaPrepareCopy
;
502 pExa
->Copy
= ExaCopy
;
503 pExa
->DoneCopy
= ExaDone
;
504 pExa
->CheckComposite
= ExaCheckComposite
;
505 pExa
->PrepareComposite
= ExaPrepareComposite
;
506 pExa
->Composite
= ExaComposite
;
507 pExa
->DoneComposite
= ExaDoneComposite
;
508 pExa
->PixmapIsOffscreen
= ExaPixmapIsOffscreen
;
509 pExa
->PrepareAccess
= ExaPrepareAccess
;
510 pExa
->FinishAccess
= ExaFinishAccess
;
511 //pExa->UploadToScreen = ExaUploadToScreen;
512 pExa
->UploadToScreen
= NULL
;
513 pExa
->CreatePixmap
= ExaCreatePixmap
;
514 pExa
->DestroyPixmap
= ExaDestroyPixmap
;
515 pExa
->ModifyPixmapHeader
= ExaModifyPixmapHeader
;
517 if (!exaDriverInit(pScrn
->pScreen
, pExa
)) {
521 exa
->scrn
= ms
->screen
;
522 exa
->ctx
= drm_api_hooks
.create_context(exa
->scrn
);
523 /* Share context with DRI */
529 xorg_exa_close(pScrn
);
534 /* vim: set sw=4 ts=8 sts=4: */