#include "xorg_composite.h"
+#include <cso_cache/cso_context.h>
+
+#include <pipe/p_inlines.h>
+
struct xorg_composite_blend {
int op:8;
return FALSE;
}
+static void
+bind_framebuffer_state(struct exa_context *exa, PicturePtr pDstPicture,
+ struct exa_pixmap_priv *pDst)
+{
+ unsigned i;
+ struct pipe_framebuffer_state state;
+ struct pipe_surface *surface = exa_gpu_surface(exa, pDst);
+ memset(&state, 0, sizeof(struct pipe_framebuffer_state));
+
+ state.width = pDstPicture->pDrawable->width;
+ state.height = pDstPicture->pDrawable->height;
+
+ state.nr_cbufs = 1;
+ state.cbufs[0] = surface;
+ for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
+ state.cbufs[i] = 0;
+
+ /* currently we don't use depth/stencil */
+ state.zsbuf = 0;
+
+ cso_set_framebuffer(exa->cso, &state);
+}
+
+enum AxisOrientation {
+ Y0_BOTTOM,
+ Y0_TOP
+};
+
+static void
+set_viewport(struct exa_context *exa, int width, int height,
+ enum AxisOrientation orientation)
+{
+ struct pipe_viewport_state viewport;
+ float y_scale = (orientation == Y0_BOTTOM) ? -2.f : 2.f;
+
+ viewport.scale[0] = width / 2.f;
+ viewport.scale[1] = height / y_scale;
+ viewport.scale[2] = 1.0;
+ viewport.scale[3] = 1.0;
+ viewport.translate[0] = width / 2.f;
+ viewport.translate[1] = height / 2.f;
+ viewport.translate[2] = 0.0;
+ viewport.translate[3] = 0.0;
+
+ cso_set_viewport(exa->cso, &viewport);
+}
+
+static void
+bind_viewport_state(struct exa_context *exa, PicturePtr pDstPicture)
+{
+ const int param_bytes = 8 * sizeof(float);
+ int width = pDstPicture->pDrawable->width;
+ int height = pDstPicture->pDrawable->height;
+ float vs_consts[8] = {
+ 2.f/width, 2.f/height, 1, 1,
+ -1, -1, 0, 0
+ };
+ struct pipe_constant_buffer *cbuf = &exa->vs_const_buffer;
+
+ set_viewport(exa, width, height, Y0_BOTTOM);
+
+ pipe_buffer_reference(&cbuf->buffer, NULL);
+ cbuf->buffer = pipe_buffer_create(exa->ctx->screen, 16,
+ PIPE_BUFFER_USAGE_CONSTANT,
+ param_bytes);
+
+ if (cbuf->buffer) {
+ pipe_buffer_write(exa->ctx->screen, cbuf->buffer,
+ 0, param_bytes, vs_consts);
+ }
+ exa->ctx->set_constant_buffer(exa->ctx, PIPE_SHADER_VERTEX, 0, cbuf);
+}
+
+static void
+bind_blend_state()
+{
+}
+
+static void
+bind_rasterizer_state()
+{
+}
+
+static void
+bind_shaders()
+{
+}
+
+
boolean xorg_composite_bind_state(struct exa_context *exa,
int op,
PicturePtr pSrcPicture,
PicturePtr pMaskPicture,
- PicturePtr pDstPicture)
+ PicturePtr pDstPicture,
+ struct exa_pixmap_priv *pSrc,
+ struct exa_pixmap_priv *pMask,
+ struct exa_pixmap_priv *pDst)
{
+ bind_framebuffer_state(exa, pDstPicture, pDst);
+ bind_viewport_state(exa, pDstPicture);
+ bind_blend_state();
+ bind_rasterizer_state();
+ bind_shaders();
+
return FALSE;
}
modesettingPtr ms = modesettingPTR(pScrn);
struct exa_context *exa = ms->exa;
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
- struct pipe_surface *surf =
- exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ struct pipe_surface *surf = exa_gpu_surface(exa, priv);
exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
priv->color);
if (!exa->ctx || !exa->ctx->surface_copy)
return FALSE;
- priv->src_surf =
- exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ priv->src_surf = exa_gpu_surface(exa, src_priv);
return TRUE;
}
modesettingPtr ms = modesettingPTR(pScrn);
struct exa_context *exa = ms->exa;
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
- struct pipe_surface *surf =
- exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
- PIPE_BUFFER_USAGE_GPU_READ |
- PIPE_BUFFER_USAGE_GPU_WRITE);
+ struct pipe_surface *surf = exa_gpu_surface(exa, priv);
exa->ctx->surface_copy(exa->ctx, surf, dstX, dstY, priv->src_surf,
srcX, srcY, width, height);
struct exa_context *exa = ms->exa;
return xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture,
- pDstPicture);
+ pDstPicture,
+ exaGetPixmapDriverPrivate(pSrc),
+ exaGetPixmapDriverPrivate(pMask),
+ exaGetPixmapDriverPrivate(pDst));
}
static void
struct pipe_texture *
xorg_exa_get_texture(PixmapPtr pPixmap)
{
- struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
- struct pipe_texture *tex = NULL;
- pipe_texture_reference(&tex, priv->tex);
- return tex;
+ struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
+ struct pipe_texture *tex = NULL;
+ pipe_texture_reference(&tex, priv->tex);
+ return tex;
}
void
xorg_exa_close(ScrnInfoPtr pScrn)
{
- modesettingPtr ms = modesettingPTR(pScrn);
- struct exa_context *exa = ms->exa;
+ modesettingPtr ms = modesettingPTR(pScrn);
+ struct exa_context *exa = ms->exa;
+ struct pipe_constant_buffer *vsbuf = &exa->vs_const_buffer;
+ struct pipe_constant_buffer *fsbuf = &exa->fs_const_buffer;
- if (exa->shaders) {
- xorg_shaders_destroy(exa->shaders);
- }
+ if (exa->shaders) {
+ xorg_shaders_destroy(exa->shaders);
+ }
- if (exa->cso) {
- cso_release_all(exa->cso);
- cso_destroy_context(exa->cso);
- }
+ if (vsbuf && vsbuf->buffer)
+ pipe_buffer_reference(&vsbuf->buffer, NULL);
+
+ if (fsbuf && fsbuf->buffer)
+ pipe_buffer_reference(&fsbuf->buffer, NULL);
+
+ if (exa->cso) {
+ cso_release_all(exa->cso);
+ cso_destroy_context(exa->cso);
+ }
- if (exa->ctx)
- exa->ctx->destroy(exa->ctx);
+ if (exa->ctx)
+ exa->ctx->destroy(exa->ctx);
- exaDriverFini(pScrn->pScreen);
- xfree(exa);
- ms->exa = NULL;
+ exaDriverFini(pScrn->pScreen);
+ xfree(exa);
+ ms->exa = NULL;
}
void *
xorg_exa_init(ScrnInfoPtr pScrn)
{
- modesettingPtr ms = modesettingPTR(pScrn);
- struct exa_context *exa;
- ExaDriverPtr pExa;
-
- exa = xcalloc(1, sizeof(struct exa_context));
- if (!exa)
- return NULL;
-
- pExa = exaDriverAlloc();
- if (!pExa) {
- goto out_err;
- }
-
- memset(pExa, 0, sizeof(*pExa));
-
- pExa->exa_major = 2;
- pExa->exa_minor = 2;
- pExa->memoryBase = 0;
- pExa->memorySize = 0;
- pExa->offScreenBase = 0;
- pExa->pixmapOffsetAlign = 0;
- pExa->pixmapPitchAlign = 1;
- pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
- pExa->maxX = 8191; /* FIXME */
- pExa->maxY = 8191; /* FIXME */
-
- pExa->WaitMarker = ExaWaitMarker;
- pExa->MarkSync = ExaMarkSync;
- pExa->PrepareSolid = ExaPrepareSolid;
- pExa->Solid = ExaSolid;
- pExa->DoneSolid = ExaDone;
- pExa->PrepareCopy = ExaPrepareCopy;
- pExa->Copy = ExaCopy;
- pExa->DoneCopy = ExaDone;
- pExa->CheckComposite = ExaCheckComposite;
- pExa->PrepareComposite = ExaPrepareComposite;
- pExa->Composite = ExaComposite;
- pExa->DoneComposite = ExaDoneComposite;
- pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
- pExa->PrepareAccess = ExaPrepareAccess;
- pExa->FinishAccess = ExaFinishAccess;
- pExa->CreatePixmap = ExaCreatePixmap;
- pExa->DestroyPixmap = ExaDestroyPixmap;
- pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
-
- if (!exaDriverInit(pScrn->pScreen, pExa)) {
- goto out_err;
- }
-
- exa->scrn = ms->screen;
- exa->ctx = ms->api->create_context(ms->api, exa->scrn);
- /* Share context with DRI */
- ms->ctx = exa->ctx;
-
- exa->cso = cso_create_context(exa->ctx);
- exa->shaders = xorg_shaders_create(exa);
-
- return (void *)exa;
+ modesettingPtr ms = modesettingPTR(pScrn);
+ struct exa_context *exa;
+ ExaDriverPtr pExa;
+
+ exa = xcalloc(1, sizeof(struct exa_context));
+ if (!exa)
+ return NULL;
+
+ pExa = exaDriverAlloc();
+ if (!pExa) {
+ goto out_err;
+ }
+
+ memset(pExa, 0, sizeof(*pExa));
+
+ pExa->exa_major = 2;
+ pExa->exa_minor = 2;
+ pExa->memoryBase = 0;
+ pExa->memorySize = 0;
+ pExa->offScreenBase = 0;
+ pExa->pixmapOffsetAlign = 0;
+ pExa->pixmapPitchAlign = 1;
+ pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
+ pExa->maxX = 8191; /* FIXME */
+ pExa->maxY = 8191; /* FIXME */
+
+ pExa->WaitMarker = ExaWaitMarker;
+ pExa->MarkSync = ExaMarkSync;
+ pExa->PrepareSolid = ExaPrepareSolid;
+ pExa->Solid = ExaSolid;
+ pExa->DoneSolid = ExaDone;
+ pExa->PrepareCopy = ExaPrepareCopy;
+ pExa->Copy = ExaCopy;
+ pExa->DoneCopy = ExaDone;
+ pExa->CheckComposite = ExaCheckComposite;
+ pExa->PrepareComposite = ExaPrepareComposite;
+ pExa->Composite = ExaComposite;
+ pExa->DoneComposite = ExaDoneComposite;
+ pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
+ pExa->PrepareAccess = ExaPrepareAccess;
+ pExa->FinishAccess = ExaFinishAccess;
+ pExa->CreatePixmap = ExaCreatePixmap;
+ pExa->DestroyPixmap = ExaDestroyPixmap;
+ pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
+
+ if (!exaDriverInit(pScrn->pScreen, pExa)) {
+ goto out_err;
+ }
+
+ exa->scrn = ms->screen;
+ exa->ctx = ms->api->create_context(ms->api, exa->scrn);
+ /* Share context with DRI */
+ ms->ctx = exa->ctx;
+
+ exa->cso = cso_create_context(exa->ctx);
+ exa->shaders = xorg_shaders_create(exa);
+
+ return (void *)exa;
+
+out_err:
+ xorg_exa_close(pScrn);
+
+ return NULL;
+}
- out_err:
- xorg_exa_close(pScrn);
+struct pipe_surface *
+exa_gpu_surface(struct exa_context *exa, struct exa_pixmap_priv *priv)
+{
+ return exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+ PIPE_BUFFER_USAGE_GPU_READ |
+ PIPE_BUFFER_USAGE_GPU_WRITE);
- return NULL;
}
-/* vim: set sw=4 ts=8 sts=4: */