glamor_fillspans.c 3.09 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
/*
 * Copyright © 1998 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 Keith Packard not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Keith Packard makes no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL KEITH PACKARD 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.
 */

/** @file glamor_fillspans.c
 *
 * FillSpans implementation, taken from fb_fillsp.c
 */
#include "glamor_priv.h"

29 30
static Bool
_glamor_fill_spans(DrawablePtr drawable,
Zhigang Gong's avatar
Zhigang Gong committed
31
		  GCPtr gc,
32
		  int n, DDXPointPtr points, int *widths, int sorted, Bool fallback)
33
{
Zhigang Gong's avatar
Zhigang Gong committed
34 35 36 37 38
	DDXPointPtr ppt;
	int nbox;
	BoxPtr pbox;
	int x1, x2, y;
	RegionPtr pClip = fbGetCompositeClip(gc);
Zhigang Gong's avatar
Zhigang Gong committed
39 40 41 42
	glamor_screen_private *glamor_priv;
	Bool ret = FALSE;

	glamor_priv = glamor_get_screen_private(drawable->pScreen);
43

Zhigang Gong's avatar
Zhigang Gong committed
44 45
	if (gc->fillStyle != FillSolid && gc->fillStyle != FillTiled)
		goto fail;
46

47
	ppt = points;
Zhigang Gong's avatar
Zhigang Gong committed
48 49 50 51 52 53
	while (n--) {
		x1 = ppt->x;
		y = ppt->y;
		x2 = x1 + (int) *widths;
		ppt++;
		widths++;
54

Zhigang Gong's avatar
Zhigang Gong committed
55 56 57
		nbox = REGION_NUM_RECTS(pClip);
		pbox = REGION_RECTS(pClip);
		while (nbox--) {
58
			int real_x1 = x1, real_x2 = x2;
59

60 61
			if (real_x1 < pbox->x1)
				real_x1 = pbox->x1;
62

63 64
			if (real_x2 > pbox->x2)
				real_x2 = pbox->x2;
65

66 67 68 69 70
			if (real_x2 > real_x1 && pbox->y1 <= y && pbox->y2 > y) {
				if (!glamor_fill(drawable, gc, real_x1, y, 
						 real_x2 - real_x1, 1, fallback))
					goto fail;
			}
Zhigang Gong's avatar
Zhigang Gong committed
71 72 73
			pbox++;
		}
	}
Zhigang Gong's avatar
Zhigang Gong committed
74 75
	ret = TRUE;
	goto done;
76

Zhigang Gong's avatar
Zhigang Gong committed
77
fail:
78 79
	if (!fallback 
	    && glamor_ddx_fallback_check_pixmap(drawable)
Zhigang Gong's avatar
Zhigang Gong committed
80 81 82
	    && glamor_ddx_fallback_check_gc(gc)) {
		goto done;
	}
Zhigang Gong's avatar
Zhigang Gong committed
83 84 85 86 87 88 89 90
	glamor_fallback("to %p (%c)\n", drawable,
			glamor_get_drawable_location(drawable));
	if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
		if (glamor_prepare_access_gc(gc)) {
			fbFillSpans(drawable, gc, n, points, widths,
				    sorted);
			glamor_finish_access_gc(gc);
		}
91
		glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
92
	}
Zhigang Gong's avatar
Zhigang Gong committed
93 94 95 96
	ret = TRUE;

done:
	return ret;
97
}
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116


void
glamor_fill_spans(DrawablePtr drawable,
		  GCPtr gc,
		  int n, DDXPointPtr points, int *widths, int sorted)
{
	_glamor_fill_spans(drawable, gc, n, points, widths, sorted, TRUE);
}

Bool
glamor_fill_spans_nf(DrawablePtr drawable,
		     GCPtr gc,
		     int n, DDXPointPtr points, int *widths, int sorted)
{
	return _glamor_fill_spans(drawable, gc, n, points, widths, sorted, FALSE);
}