15b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis/**************************************************************************
25b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
35b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Copyright 2009, VMware, Inc.
45b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * All Rights Reserved.
55b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
65b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
75b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Permission is hereby granted, free of charge, to any person obtaining a
85b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * copy of this software and associated documentation files (the
95b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * "Software"), to deal in the Software without restriction, including
105b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * without limitation the rights to use, copy, modify, merge, publish,
115b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * distribute, sub license, and/or sell copies of the Software, and to
125b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * permit persons to whom the Software is furnished to do so, subject to
135b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * the following conditions:
145b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
155b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * The above copyright notice and this permission notice (including the
165b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * next paragraph) shall be included in all copies or substantial portions
175b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * of the Software.
185b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
195b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
205b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
215b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
225b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
235b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
245b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
255b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
265b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
275b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis **************************************************************************/
285b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
291570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis/* TODO:
301570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis *
3198aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke * xshm / EGLImage:
321570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis *
331570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis * Allow the loaders to use the XSHM extension. It probably requires callbacks
34625e024b186829f199458679921916971a5b00cbGeorge Sapountzis * for createImage/destroyImage similar to DRI2 getBuffers.
351570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis */
361570e30b487018f056af4d0b5ca83a889f9ce721George Sapountzis
37a24fc90703f62d286031cb2ee8f625ef728243fdGeorge Sapountzis#include "util/u_format.h"
385b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "util/u_memory.h"
395b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "util/u_inlines.h"
405b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "pipe/p_context.h"
41625e024b186829f199458679921916971a5b00cbGeorge Sapountzis#include "state_tracker/drisw_api.h"
4298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke#include "state_tracker/st_context.h"
435b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
445b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "dri_screen.h"
455b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "dri_context.h"
465b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis#include "dri_drawable.h"
475b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
48cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob BornecrantzDEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", FALSE);
49cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantzstatic boolean swrast_no_present = FALSE;
505b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
515b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic INLINE void
5298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzkeget_drawable_info(__DRIdrawable *dPriv, int *x, int *y, int *w, int *h)
535b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
545b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   __DRIscreen *sPriv = dPriv->driScreenPriv;
555b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
565b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
575b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   loader->getDrawableInfo(dPriv,
5898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                           x, y, w, h,
595b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis                           dPriv->loaderPrivate);
605b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
615b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
625b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic INLINE void
63625e024b186829f199458679921916971a5b00cbGeorge Sapountzisput_image(__DRIdrawable *dPriv, void *data, unsigned width, unsigned height)
645b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
655b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   __DRIscreen *sPriv = dPriv->driScreenPriv;
665b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
675b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
685b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
69625e024b186829f199458679921916971a5b00cbGeorge Sapountzis                    0, 0, width, height,
705b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis                    data, dPriv->loaderPrivate);
715b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
725b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
730c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzisstatic INLINE void
740c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzisget_image(__DRIdrawable *dPriv, int x, int y, int width, int height, void *data)
750c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis{
760c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   __DRIscreen *sPriv = dPriv->driScreenPriv;
770c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
780c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis
790c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   loader->getImage(dPriv,
800c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis                    x, y, width, height,
810c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis                    data, dPriv->loaderPrivate);
820c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis}
830c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis
84ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantzstatic void
85625e024b186829f199458679921916971a5b00cbGeorge Sapountzisdrisw_update_drawable_info(struct dri_drawable *drawable)
865b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
87625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   __DRIdrawable *dPriv = drawable->dPriv;
8898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   int x, y;
89625e024b186829f199458679921916971a5b00cbGeorge Sapountzis
9098aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   get_drawable_info(dPriv, &x, &y, &dPriv->w, &dPriv->h);
915b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
925b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
93625e024b186829f199458679921916971a5b00cbGeorge Sapountzisstatic void
94625e024b186829f199458679921916971a5b00cbGeorge Sapountzisdrisw_put_image(struct dri_drawable *drawable,
95625e024b186829f199458679921916971a5b00cbGeorge Sapountzis                void *data, unsigned width, unsigned height)
96625e024b186829f199458679921916971a5b00cbGeorge Sapountzis{
97625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   __DRIdrawable *dPriv = drawable->dPriv;
98625e024b186829f199458679921916971a5b00cbGeorge Sapountzis
99625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   put_image(dPriv, data, width, height);
100625e024b186829f199458679921916971a5b00cbGeorge Sapountzis}
101625e024b186829f199458679921916971a5b00cbGeorge Sapountzis
1025b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic INLINE void
1035b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisdrisw_present_texture(__DRIdrawable *dPriv,
104287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell                      struct pipe_resource *ptex)
1055b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
1065b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   struct dri_drawable *drawable = dri_drawable(dPriv);
1075b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   struct dri_screen *screen = dri_screen(drawable->sPriv);
1085b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
109cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz   if (swrast_no_present)
110cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz      return;
111cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz
1124c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger   screen->base.screen->flush_frontbuffer(screen->base.screen, ptex, 0, 0, drawable);
1135b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
1145b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1155b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic INLINE void
1165b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisdrisw_invalidate_drawable(__DRIdrawable *dPriv)
1175b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
1185b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   struct dri_drawable *drawable = dri_drawable(dPriv);
1195b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1205b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   drawable->texture_stamp = dPriv->lastStamp - 1;
1215b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
122ac8fdbc1c723afb19eeaba5457ba78d0bf33b8d4Thomas Hellstrom   p_atomic_inc(&drawable->base.stamp);
1235b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
1245b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1255b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic INLINE void
1265b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisdrisw_copy_to_front(__DRIdrawable * dPriv,
127287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell                    struct pipe_resource *ptex)
1285b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
1295b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   drisw_present_texture(dPriv, ptex);
1305b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1315b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   drisw_invalidate_drawable(dPriv);
1325b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
1335b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1345b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis/*
1355b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Backend functions for st_framebuffer interface and swap_buffers.
1365b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis */
1375b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1382e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzisstatic void
139625e024b186829f199458679921916971a5b00cbGeorge Sapountzisdrisw_swap_buffers(__DRIdrawable *dPriv)
1405b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
141a66b391edf746a5eb0cb4aad1ff2e546df00a11dJakob Bornecrantz   struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
142625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   struct dri_drawable *drawable = dri_drawable(dPriv);
143287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   struct pipe_resource *ptex;
1445b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1455b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (!ctx)
1465b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      return;
1475b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
148625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
1495b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1505b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (ptex) {
151421235d42ad9921fd45332ec7b33bcee5c1ad33dLauri Kasanen      if (ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
152421235d42ad9921fd45332ec7b33bcee5c1ad33dLauri Kasanen         pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
153421235d42ad9921fd45332ec7b33bcee5c1ad33dLauri Kasanen
1547e02303497237cde958c28608477d0c355a8038bMarek Olšák      ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL);
155625e024b186829f199458679921916971a5b00cbGeorge Sapountzis
156625e024b186829f199458679921916971a5b00cbGeorge Sapountzis      drisw_copy_to_front(dPriv, ptex);
1575b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   }
1585b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
1595b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
160ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantzstatic void
161625e024b186829f199458679921916971a5b00cbGeorge Sapountzisdrisw_flush_frontbuffer(struct dri_drawable *drawable,
162625e024b186829f199458679921916971a5b00cbGeorge Sapountzis                        enum st_attachment_type statt)
1635b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
164a66b391edf746a5eb0cb4aad1ff2e546df00a11dJakob Bornecrantz   struct dri_context *ctx = dri_get_current(drawable->sPriv);
165287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   struct pipe_resource *ptex;
1665b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1675b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (!ctx)
1685b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      return;
1695b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
170625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   ptex = drawable->textures[statt];
1715b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1725b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (ptex) {
173625e024b186829f199458679921916971a5b00cbGeorge Sapountzis      drisw_copy_to_front(ctx->dPriv, ptex);
1745b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   }
1755b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
1765b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1775b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis/**
1785b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Allocate framebuffer attachments.
1795b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis *
1805b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * During fixed-size operation, the function keeps allocating new attachments
1815b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * as they are requested. Unused attachments are not removed, not until the
1825b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * framebuffer is resized or destroyed.
1835b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis */
184ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantzstatic void
1855b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisdrisw_allocate_textures(struct dri_drawable *drawable,
186ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz                        const enum st_attachment_type *statts,
187ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz                        unsigned count)
1885b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
1895b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   struct dri_screen *screen = dri_screen(drawable->sPriv);
190287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell   struct pipe_resource templ;
1915b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   unsigned width, height;
1925b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   boolean resized;
1935270deaab682c938e360f0d3b52f35b4027db858nobled   unsigned i;
1945b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1955b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   width  = drawable->dPriv->w;
1965b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   height = drawable->dPriv->h;
1975b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
1985b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   resized = (drawable->old_w != width ||
1995b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis              drawable->old_h != height);
2005b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2015b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   /* remove outdated textures */
2025b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (resized) {
2035b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
204287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell         pipe_resource_reference(&drawable->textures[i], NULL);
2055b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   }
2065b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2075b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   memset(&templ, 0, sizeof(templ));
2084a5acc0ec7d6d94ea2a73b3d8ee498f75e929a1cLuca Barbieri   templ.target = screen->target;
2095b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   templ.width0 = width;
2105b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   templ.height0 = height;
2115b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   templ.depth0 = 1;
2124c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger   templ.array_size = 1;
2135b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   templ.last_level = 0;
2145b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2155270deaab682c938e360f0d3b52f35b4027db858nobled   for (i = 0; i < count; i++) {
2165b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      enum pipe_format format;
217ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      unsigned bind;
2185b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2195b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      /* the texture already exists or not requested */
220ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      if (drawable->textures[statts[i]])
2215b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis         continue;
222ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz
223ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      dri_drawable_get_format(drawable, statts[i], &format, &bind);
224ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz
225cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz      /* if we don't do any present, no need for display targets */
226cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz      if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !swrast_no_present)
227ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz         bind |= PIPE_BIND_DISPLAY_TARGET;
228ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz
229ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      if (format == PIPE_FORMAT_NONE)
230ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz         continue;
231ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz
232ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      templ.format = format;
233ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      templ.bind = bind;
234ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz
235ea6a52a1f8e7fd72b5506218c31e58088131f1f5Jakob Bornecrantz      drawable->textures[statts[i]] =
2361372a8f90dc64350e4ac29dbb8c5feb88bc83cd1Jakob Bornecrantz         screen->base.screen->resource_create(screen->base.screen, &templ);
2375b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   }
2385b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2395b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   drawable->old_w = width;
2405b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   drawable->old_h = height;
2415b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
2425b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
24398aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzkestatic void
24498aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzkedrisw_update_tex_buffer(struct dri_drawable *drawable,
24598aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                        struct dri_context *ctx,
24698aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                        struct pipe_resource *res)
24798aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke{
24898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   __DRIdrawable *dPriv = drawable->dPriv;
2490c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis
2500c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   struct st_context *st_ctx = (struct st_context *)ctx->st;
2510c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   struct pipe_context *pipe = st_ctx->pipe;
25298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   struct pipe_transfer *transfer;
25398aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   char *map;
2540c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   int x, y, w, h;
25598aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   int ximage_stride, line;
256d6c5ad52b2473064f0b3e031a2e1b59480c68c43Dave Airlie   int cpp = util_format_get_blocksize(res->format);
25798aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
25898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   get_drawable_info(dPriv, &x, &y, &w, &h);
25998aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
26098aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   transfer = pipe_get_transfer(pipe, res,
26198aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                                0, 0, // level, layer,
26298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                                PIPE_TRANSFER_WRITE,
26398aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke                                x, y, w, h);
26498aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   map = pipe_transfer_map(pipe, transfer);
26598aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
26698aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   /* Copy the Drawable content to the mapped texture buffer */
2670c425ac18c56ea3315fcb0fdeecfa3685a52f4baGeorge Sapountzis   get_image(dPriv, x, y, w, h, map);
26898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
269d6c5ad52b2473064f0b3e031a2e1b59480c68c43Dave Airlie   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels. */
270d6c5ad52b2473064f0b3e031a2e1b59480c68c43Dave Airlie   ximage_stride = w * cpp;
27198aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   for (line = h-1; line; --line) {
27298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke      memmove(&map[line * transfer->stride],
27398aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke              &map[line * ximage_stride],
27498aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke              ximage_stride);
27598aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   }
27698aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
27798aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   pipe_transfer_unmap(pipe, transfer);
27898aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   pipe_transfer_destroy(pipe, transfer);
27998aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke}
28098aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke
2815b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis/*
2825b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis * Backend function for init_screen.
2835b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis */
2845b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
2855b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisstatic const __DRIextension *drisw_screen_extensions[] = {
2862b64886c8122227ffa2d86abb9b4a5d79d1e2451Adam Jackson   &driTexBufferExtension.base,
2875b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   NULL
2885b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis};
2895b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
290625e024b186829f199458679921916971a5b00cbGeorge Sapountzisstatic struct drisw_loader_funcs drisw_lf = {
291625e024b186829f199458679921916971a5b00cbGeorge Sapountzis   .put_image = drisw_put_image
292625e024b186829f199458679921916971a5b00cbGeorge Sapountzis};
293625e024b186829f199458679921916971a5b00cbGeorge Sapountzis
2942e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzisstatic const __DRIconfig **
2955b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisdrisw_init_screen(__DRIscreen * sPriv)
2965b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis{
2975b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis   const __DRIconfig **configs;
2985b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   struct dri_screen *screen;
29939c81dada01585a6030f03d215842a1a2ae87d86Jakob Bornecrantz   struct pipe_screen *pscreen;
3005b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
3015b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   screen = CALLOC_STRUCT(dri_screen);
3025b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   if (!screen)
3035b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      return NULL;
3045b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
3055b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   screen->sPriv = sPriv;
3065b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   screen->fd = -1;
3075b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis
308cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz   swrast_no_present = debug_get_option_swrast_no_present();
309cc09dc2773a729ab361c58ea5fc70ff070d0b1d2Jakob Bornecrantz
310875a757ddd103722cfe9a2b21035024aa5a23d32George Sapountzis   sPriv->driverPrivate = (void *)screen;
3115b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   sPriv->extensions = drisw_screen_extensions;
3125b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
31353c57191c5f24d3620e2e4ce95dd12b5c6e9109bJakob Bornecrantz   pscreen = drisw_create_screen(&drisw_lf);
31439c81dada01585a6030f03d215842a1a2ae87d86Jakob Bornecrantz   /* dri_init_screen_helper checks pscreen for us */
31539c81dada01585a6030f03d215842a1a2ae87d86Jakob Bornecrantz
31639c81dada01585a6030f03d215842a1a2ae87d86Jakob Bornecrantz   configs = dri_init_screen_helper(screen, pscreen, 32);
3175b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis   if (!configs)
3185b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis      goto fail;
3195b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
3205b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis   return configs;
3215b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzisfail:
3225b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis   dri_destroy_screen_helper(screen);
3235b07257fdbb5a93f432b8eaf3a41f39b26bdb1f3George Sapountzis   FREE(screen);
3245b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis   return NULL;
3255b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis}
3265b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis
327873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzisstatic boolean
328873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzisdrisw_create_buffer(__DRIscreen * sPriv,
329873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis                    __DRIdrawable * dPriv,
330d3491e775fb07f891463b2185d74bbad62f3ed24Kristian Høgsberg                    const struct gl_config * visual, boolean isPixmap)
331873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis{
332873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   struct dri_drawable *drawable = NULL;
333873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis
334873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap))
335873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis      return FALSE;
336873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis
337873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   drawable = dPriv->driverPrivate;
338873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis
339873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   drawable->allocate_textures = drisw_allocate_textures;
340873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   drawable->update_drawable_info = drisw_update_drawable_info;
341873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   drawable->flush_frontbuffer = drisw_flush_frontbuffer;
34298aa2a8f725e44aec8bd998fe436a134e94f13bbBenjamin Franzke   drawable->update_tex_buffer = drisw_update_tex_buffer;
343873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis
344873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   return TRUE;
345873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis}
346873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis
3472e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis/**
3482e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis * DRI driver virtual function table.
3492e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis *
3502e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis * DRI versions differ in their implementation of init_screen and swap_buffers.
3512e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis */
3522e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzisconst struct __DriverAPIRec driDriverAPI = {
353873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   .InitScreen = drisw_init_screen,
3542e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .DestroyScreen = dri_destroy_screen,
3552e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .CreateContext = dri_create_context,
3562e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .DestroyContext = dri_destroy_context,
357873ddf547d5aeb68f37a172d73131c6bc51101f6George Sapountzis   .CreateBuffer = drisw_create_buffer,
3582e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .DestroyBuffer = dri_destroy_buffer,
3597192c37294964b3f6e1551469f161593ec8f851dGeorge Sapountzis   .SwapBuffers = drisw_swap_buffers,
3602e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .MakeCurrent = dri_make_current,
3612e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis   .UnbindContext = dri_unbind_context,
3622e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis};
3632e4ad14a525f4028f0e0a93de2f8db785df33fb7George Sapountzis
3641fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis/* This is the table of extensions that the loader will dlsym() for. */
3651fbfc22d8560c9d900832147f504ff64c64358deGeorge SapountzisPUBLIC const __DRIextension *__driDriverExtensions[] = {
3661fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis    &driCoreExtension.base,
3671fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis    &driSWRastExtension.base,
3681fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis    NULL
3691fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis};
3701fbfc22d8560c9d900832147f504ff64c64358deGeorge Sapountzis
3715b75e12f9165c890fd14b22983d6289be8f20abcGeorge Sapountzis/* vim: set sw=3 ts=8 sts=3 expandtab: */
372