[PATCH 04/16] glamor: Replace fallback preparation code

Eric Anholt eric at anholt.net
Wed Apr 2 12:32:13 PDT 2014


Keith Packard <keithp at keithp.com> writes:

> These offer a simpler and more efficient means for temporarily
> transitioning to CPU-accessible memory for fallback implementations.

> diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c
> new file mode 100644
> index 0000000..97029f9
> --- /dev/null
> +++ b/glamor/glamor_prepare.c
> @@ -0,0 +1,241 @@
> +/*
> + * Copyright © 2014 Keith Packard
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include "glamor_priv.h"
> +#include "glamor_prepare.h"
> +#include "glamor_transfer.h"
> +
> +/*
> + * Make a pixmap ready to draw with fb by
> + * creating a PBO large enough for the whole object
> + * and downloading all of the FBOs into it.
> + */
> +
> +static Bool
> +glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
> +{
> +    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
> +    int gl_access, gl_usage;
> +    RegionRec region;
> +
> +    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(priv))
> +        return TRUE;
> +
> +    RegionInit(&region, box, 1);
> +
> +    /* See if it's already mapped */
> +    if (pixmap->devPrivate.ptr) {
> +        /*
> +         * Someone else has mapped this pixmap;
> +         * we'll assume that it's directly mapped
> +         * by a lower level driver
> +         */
> +        if (!priv->base.prepared)
> +            return TRUE;
> +
> +        /* In X, multiple Drawables can be stored in the same Pixmap (such as
> +         * each individual window in a non-composited screen pixmap, or the
> +         * reparented window contents inside the window-manager-decorated window
> +         * pixmap on a composited screen).
> +         *
> +         * As a result, when doing a series of mappings for a fallback, we may
> +         * need to add more boxes to the set of data we've downloaded, as we go.
> +         */
> +        RegionSubtract(&region, &region, &priv->base.pbo_region);
> +        if (!RegionNotEmpty(&region))
> +            return TRUE;
> +
> +        if (access == GLAMOR_ACCESS_RW)
> +            FatalError("attempt to remap buffer as writable");
> +
> +        glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->base.pbo);
> +        glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
> +
> +    } else {
> +        RegionInit(&priv->base.pbo_region, box, 1);
> +
> +        if (priv->base.pbo == 0)
> +            glGenBuffers(1, &priv->base.pbo);
> +
> +        if (access == GLAMOR_ACCESS_RW)
> +            gl_usage = GL_DYNAMIC_DRAW;
> +        else
> +            gl_usage = GL_STREAM_READ;
> +
> +        glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->base.pbo);
> +        glBufferData(GL_PIXEL_PACK_BUFFER, pixmap->devKind * pixmap->drawable.height, NULL, gl_usage);
> +        priv->base.map_access = access;
> +    }
> +
> +    glamor_download_boxes(pixmap, RegionRects(&region), RegionNumRects(&region),
> +                          0, 0, 0, 0, NULL, pixmap->devKind);
> +
> +    RegionUninit(&region);
> +
> +    if (priv->base.map_access == GLAMOR_ACCESS_RW)
> +        gl_access = GL_READ_WRITE;
> +    else
> +        gl_access = GL_READ_ONLY;
> +
> +    pixmap->devPrivate.ptr = glMapBuffer(GL_PIXEL_PACK_BUFFER, gl_access);
> +    glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

GLES2 only allows WRITE_ONLY in the glMapBuffer interface (and only when
GL_OES_mapbuffer is available), which the old path avoided.  I think
your change just totally breaks fallbacks in gles2.

I noticed this when going to delete the code you made dead by this
patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20140402/1db6b19a/attachment.sig>


More information about the xorg-devel mailing list