From 2b657d91d80a0a4d9fa2e390255ff87f51426b7c Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Sat, 22 Aug 2009 15:54:24 -0700 Subject: [PATCH] glamor: Add untested putimage support. --- glamor/Makefile.am | 1 + glamor/glamor_core.c | 10 --- glamor/glamor_priv.h | 5 ++ glamor/glamor_putimage.c | 129 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 10 deletions(-) create mode 100644 glamor/glamor_putimage.c diff --git a/glamor/Makefile.am b/glamor/Makefile.am index 3f5a2002b..43512f720 100644 --- a/glamor/Makefile.am +++ b/glamor/Makefile.am @@ -19,6 +19,7 @@ libglamor_la_SOURCES = \ glamor_fill.c \ glamor_fillspans.c \ glamor_getspans.c \ + glamor_putimage.c \ glamor_render.c \ glamor_tile.c \ glamor.h diff --git a/glamor/glamor_core.c b/glamor/glamor_core.c index ed6663e5c..ba73c0bd2 100644 --- a/glamor/glamor_core.c +++ b/glamor/glamor_core.c @@ -199,16 +199,6 @@ glamor_stipple(PixmapPtr pixmap, PixmapPtr stipple, glamor_solid_fail_region(pixmap, x, y, width, height); } -static void -glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, - int w, int h, int leftPad, int format, char *bits) -{ - PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); - - ErrorF("stub put_image depth %d\n", drawable->depth); - glamor_solid_fail_region(pixmap, x, y, w, h); -} - static void glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src, DDXPointPtr points, int *widths, int n, int sorted) diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index e8f486f27..74c1aea68 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -137,6 +137,11 @@ glamor_get_spans(DrawablePtr drawable, int nspans, char *dst_start); +/* glamor_putimage.c */ +void +glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, + int w, int h, int leftPad, int format, char *bits); + /* glamor_render.c */ void glamor_composite(CARD8 op, PicturePtr pSrc, diff --git a/glamor/glamor_putimage.c b/glamor/glamor_putimage.c new file mode 100644 index 000000000..2795d837e --- /dev/null +++ b/glamor/glamor_putimage.c @@ -0,0 +1,129 @@ +/* + * 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 + * + */ + + +/** @file glamor_putaimge.c + * + * XPutImage implementation + */ +#include "glamor_priv.h" + +void +glamor_put_image(DrawablePtr drawable, GCPtr gc, int depth, int x, int y, + int w, int h, int left_pad, int image_format, char *bits) +{ + PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable); + GLenum type, format; + RegionPtr clip; + BoxPtr pbox; + int nbox; + int bpp = drawable->bitsPerPixel; + int src_stride = PixmapBytePad(w, drawable->depth); + + if (gc->alu != GXcopy) { + ErrorF("putimage: non-copy alu\n"); + goto fail; + } + if (!glamor_pm_is_solid(drawable, gc->planemask)) { + ErrorF("putimage: non-solid planemask\n"); + goto fail; + } + if (image_format != ZPixmap) { + ErrorF("putimage: non-ZPixmap\n"); + goto fail; + } + if (bpp < 8) { + ErrorF("putimage: bad bpp: %d\n", bpp); + return; + } + + switch (drawable->depth) { + case 8: + format = GL_ALPHA; + type = GL_UNSIGNED_BYTE; + break; + case 24: + format = GL_RGB; + type = GL_UNSIGNED_BYTE; + break; + case 32: + format = GL_BGRA; + type = GL_UNSIGNED_INT_8_8_8_8_REV; + break; + default: + ErrorF("stub put_image depth %d\n", drawable->depth); + goto fail; + break; + } + + if (!glamor_set_destination_pixmap(pixmap)) { + fbPutImage(drawable, gc, depth, x, y, w, h, left_pad, + image_format, bits); + goto fail; + } + + x += drawable->x; + y += drawable->y; + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ROW_LENGTH, src_stride / (bpp / 8)); + clip = fbGetCompositeClip(gc); + for (nbox = REGION_NUM_RECTS(clip), + pbox = REGION_RECTS(clip); + nbox--; + pbox++) + { + int x1 = x; + int y1 = y; + int x2 = x + w; + int y2 = y + h; + char *src; + + if (x1 < pbox->x1) + x1 = pbox->x1; + if (y1 < pbox->y1) + y1 = pbox->y1; + if (x2 > pbox->x2) + x2 = pbox->x2; + if (y2 > pbox->y2) + y2 = pbox->y2; + if (x1 >= x2 || y1 >= y2) + continue; + + src = bits + (y1 - y) * src_stride + (x1 - x) * (bpp / 8); + glRasterPos2i(x1 + pixmap->screen_x, y1 + pixmap->screen_y); + glDrawPixels(x2 - x1, + y2 - y1, + format, type, + src); + } + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + return; + +fail: + glamor_solid_fail_region(pixmap, x, y, w, h); +}