glamor_getspans.c 3.93 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Copyright © 2009 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Eric Anholt <eric@anholt.net>
 *
 */

#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#include "glamor_priv.h"

34 35 36 37 38
static Bool 
_glamor_get_spans(DrawablePtr drawable,
		  int wmax,
		  DDXPointPtr points, int *widths, int count, char *dst,
		  Bool fallback)
39
{
Zhigang Gong's avatar
Zhigang Gong committed
40 41 42 43 44 45 46 47 48 49 50 51
	PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
	GLenum format, type;
	int no_alpha, no_revert;
	glamor_screen_private *glamor_priv =
	    glamor_get_screen_private(drawable->pScreen);
	glamor_pixmap_private *pixmap_priv =
	    glamor_get_pixmap_private(pixmap);
	glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
	PixmapPtr temp_pixmap = NULL;
	int i;
	uint8_t *readpixels_dst = (uint8_t *) dst;
	int x_off, y_off;
52

53
	if (!pixmap_priv || !GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)) {
Zhigang Gong's avatar
Zhigang Gong committed
54 55 56
		glamor_fallback("pixmap has no fbo.\n");
		goto fail;
	}
57

Zhigang Gong's avatar
Zhigang Gong committed
58 59 60 61 62 63 64
	if (glamor_get_tex_format_type_from_pixmap(pixmap,
						   &format,
						   &type, &no_alpha,
						   &no_revert)) {
		glamor_fallback("unknown depth. %d \n", drawable->depth);
		goto fail;
	}
Eric Anholt's avatar
Eric Anholt committed
65

Zhigang Gong's avatar
Zhigang Gong committed
66 67
	glamor_set_destination_pixmap_priv_nc(pixmap_priv);
	glamor_validate_pixmap(pixmap);
68

Zhigang Gong's avatar
Zhigang Gong committed
69 70 71 72 73 74 75 76 77
	if (glamor_priv->gl_flavor == GLAMOR_GL_ES2) {
		/* XXX prepare whole pixmap is not efficient. */
		temp_pixmap =
		    glamor_es2_pixmap_read_prepare(pixmap, &format,
						   &type, no_alpha,
						   no_revert);
		pixmap_priv = glamor_get_pixmap_private(temp_pixmap);
		glamor_set_destination_pixmap_priv_nc(pixmap_priv);
	}
78

Zhigang Gong's avatar
Zhigang Gong committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	glamor_get_drawable_deltas(drawable, pixmap, &x_off, &y_off);
	for (i = 0; i < count; i++) {
		if (glamor_priv->yInverted) {
			dispatch->glReadPixels(points[i].x + x_off,
					       (points[i].y + y_off),
					       widths[i], 1, format,
					       type, readpixels_dst);
		} else {
			dispatch->glReadPixels(points[i].x + x_off,
					       pixmap->drawable.height -
					       1 - (points[i].y + y_off),
					       widths[i], 1, format,
					       type, readpixels_dst);
		}
		readpixels_dst +=
		    PixmapBytePad(widths[i], drawable->depth);
95
	}
Zhigang Gong's avatar
Zhigang Gong committed
96
	if (temp_pixmap)
97
		glamor_destroy_pixmap(temp_pixmap);
98
	return TRUE;
99

Zhigang Gong's avatar
Zhigang Gong committed
100
      fail:
101 102 103 104

	if (!fallback
	    && glamor_ddx_fallback_check_pixmap(drawable))
		return FALSE; 
Zhigang Gong's avatar
Zhigang Gong committed
105 106 107 108
	glamor_fallback("from %p (%c)\n", drawable,
			glamor_get_drawable_location(drawable));
	if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) {
		fbGetSpans(drawable, wmax, points, widths, count, dst);
109
		glamor_finish_access(drawable, GLAMOR_ACCESS_RO);
Zhigang Gong's avatar
Zhigang Gong committed
110
	}
111
	return TRUE;
112
}
113

114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
void
glamor_get_spans(DrawablePtr drawable,
		 int wmax,
		 DDXPointPtr points, int *widths, int count, char *dst)
{
	_glamor_get_spans(drawable, wmax, points, 
			  widths, count, dst, TRUE);
}

Bool
glamor_get_spans_nf(DrawablePtr drawable,
		    int wmax,
		    DDXPointPtr points, int *widths, int count, char *dst)
{
	return _glamor_get_spans(drawable, wmax, points, 
				 widths, count, dst, FALSE);
}