void PixmanBitmap::FlipBlit(int x, int y, Bitmap* _src, Rect src_rect, bool horizontal, bool vertical) { if (!horizontal && !vertical) { Blit(x, y, _src, src_rect, 255); return; } PixmanBitmap* src = (PixmanBitmap*) _src; pixman_transform_t xform; pixman_transform_init_scale(&xform, pixman_int_to_fixed(horizontal ? -1 : 1), pixman_int_to_fixed(vertical ? -1 : 1)); pixman_transform_translate((pixman_transform_t*) NULL, &xform, pixman_int_to_fixed(horizontal ? src_rect.width : 0), pixman_int_to_fixed(vertical ? src_rect.height : 0)); pixman_image_set_transform(bitmap, &xform); pixman_image_composite32(PIXMAN_OP_SRC, src->bitmap, (pixman_image_t*) NULL, bitmap, src_rect.x, src_rect.y, 0, 0, x, y, src_rect.width, src_rect.height); pixman_transform_init_identity(&xform); pixman_image_set_transform(bitmap, &xform); RefreshCallback(); }
Bitmap* PixmanBitmap::Resample(int scale_w, int scale_h, const Rect& src_rect) { PixmanBitmap *dst = new PixmanBitmap(scale_w, scale_h, GetTransparent()); double zoom_x = (double)src_rect.width / scale_w; double zoom_y = (double)src_rect.height / scale_h; pixman_transform_t xform; pixman_transform_init_scale(&xform, pixman_double_to_fixed(zoom_x), pixman_double_to_fixed(zoom_y)); pixman_image_set_transform(bitmap, &xform); pixman_image_composite32(PIXMAN_OP_SRC, bitmap, (pixman_image_t*) NULL, dst->bitmap, src_rect.x, src_rect.y, 0, 0, 0, 0, scale_w, scale_h); pixman_transform_init_identity(&xform); pixman_image_set_transform(bitmap, &xform); return dst; }
void PixmanBitmap::Blit2x(Rect dst_rect, Bitmap* _src, Rect src_rect) { PixmanBitmap* src = (PixmanBitmap*) _src; pixman_transform_t xform; pixman_transform_init_scale(&xform, pixman_double_to_fixed(0.5), pixman_double_to_fixed(0.5)); pixman_image_set_transform(src->bitmap, &xform); pixman_image_composite32(PIXMAN_OP_SRC, src->bitmap, (pixman_image_t*) NULL, bitmap, src_rect.x, src_rect.y, 0, 0, dst_rect.x, dst_rect.y, dst_rect.width, dst_rect.height); pixman_transform_init_identity(&xform); pixman_image_set_transform(src->bitmap, &xform); RefreshCallback(); }
void PixmanBitmap::StretchBlit(Rect dst_rect, Bitmap* _src, Rect src_rect, int opacity) { if (opacity < 0) return; PixmanBitmap* src = (PixmanBitmap*) _src; pixman_image_t* mask = (pixman_image_t*) NULL; if (opacity < 255) { pixman_color_t tcolor = {0, 0, 0, opacity << 8}; mask = pixman_image_create_solid_fill(&tcolor); } double zoom_x = (double)src_rect.width / dst_rect.width; double zoom_y = (double)src_rect.height / dst_rect.height; pixman_transform_t xform; pixman_transform_init_scale(&xform, pixman_double_to_fixed(zoom_x), pixman_double_to_fixed(zoom_y)); pixman_image_set_transform(src->bitmap, &xform); pixman_image_composite32(PIXMAN_OP_OVER, src->bitmap, mask, bitmap, src_rect.x / zoom_x, src_rect.y / zoom_y, 0, 0, dst_rect.x, dst_rect.y, dst_rect.width, dst_rect.height); pixman_transform_init_identity(&xform); pixman_image_set_transform(src->bitmap, &xform); if (mask != NULL) pixman_image_unref(mask); RefreshCallback(); }
/** * Helper function to implement video blit, handling clipping, damage, etc.. * * TODO: move to EXA? */ int OMAPVidCopyArea(DrawablePtr pSrcDraw, BoxPtr pSrcBox, DrawablePtr pOsdDraw, BoxPtr pOsdBox, DrawablePtr pDstDraw, BoxPtr pDstBox, OMAPPutTextureImageProc PutTextureImage, void *closure, RegionPtr clipBoxes) { ScreenPtr pScreen = pDstDraw->pScreen; ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; PixmapPtr pSrcPix = draw2pix(pSrcDraw); PixmapPtr pOsdPix = draw2pix(pOsdDraw); PixmapPtr pDstPix = draw2pix(pDstDraw); pixman_fixed_t sx, sy, tx, ty; pixman_transform_t srcxfrm; BoxPtr pbox; int nbox, dx, dy, ret = Success; #ifdef COMPOSITE DEBUG_MSG("--> %dx%d, %dx%d", pDstPix->screen_x, pDstPix->screen_y, pDstDraw->x, pDstDraw->y); /* Convert screen coords to pixmap coords */ if (pDstPix->screen_x || pDstPix->screen_y) { RegionTranslate(clipBoxes, -pDstPix->screen_x, -pDstPix->screen_y); } dx = pDstPix->screen_x; dy = pDstPix->screen_y; #else dx = 0; dy = 0; #endif /* the clip-region gives coordinates in dst's coord space.. generate * a transform that can be used to work backwards from dst->src coord * space: */ sx = ((pixman_fixed_48_16_t) (pSrcBox->x2 - pSrcBox->x1) << 16) / (pDstBox->x2 - pDstBox->x1); sy = ((pixman_fixed_48_16_t) (pSrcBox->y2 - pSrcBox->y1) << 16) / (pDstBox->y2 - pDstBox->y1); tx = ((pixman_fixed_48_16_t)(pDstBox->x1 - pSrcBox->x1 - dx) << 16); ty = ((pixman_fixed_48_16_t)(pDstBox->y1 - pSrcBox->y1 - dy) << 16); pixman_transform_init_scale(&srcxfrm, sx, sy); pixman_transform_translate(NULL, &srcxfrm, tx, ty); // TODO generate transform for osd as well pbox = RegionRects(clipBoxes); nbox = RegionNumRects(clipBoxes); while (nbox--) { RegionRec damage; BoxRec dstb = *pbox; BoxRec srcb = *pbox; BoxRec osdb = *pbox; pixman_transform_bounds(&srcxfrm, &srcb); //pixman_transform_bounds(&osdxfrm, &osdb); DEBUG_MSG("%d,%d %d,%d -> %d,%d %d,%d", srcb.x1, srcb.y1, srcb.x2, srcb.y2, dstb.x1, dstb.y1, dstb.x2, dstb.y2); ret = PutTextureImage(pSrcPix, &srcb, pOsdPix, &osdb, pDstPix, &dstb, closure); if (ret != Success) { break; } RegionInit(&damage, &dstb, 1); #ifdef COMPOSITE /* Convert screen coords to pixmap coords */ if (pDstPix->screen_x || pDstPix->screen_y) { RegionTranslate(&damage, pDstPix->screen_x, pDstPix->screen_y); } #endif DamageRegionAppend(pDstDraw, &damage); RegionUninit(&damage); pbox++; } DamageRegionProcessPending(pDstDraw); return ret; }
/* * Composite operation with pseudorandom images */ uint32_t test_composite (int testnum, int verbose) { int i; pixman_image_t * src_img; pixman_image_t * dst_img; pixman_transform_t transform; pixman_region16_t clip; int src_width, src_height; int dst_width, dst_height; int src_stride, dst_stride; int src_x, src_y; int dst_x, dst_y; int src_bpp; int dst_bpp; int w, h; pixman_fixed_t scale_x = 65536, scale_y = 65536; pixman_fixed_t translate_x = 0, translate_y = 0; int op; int repeat = 0; int src_fmt, dst_fmt; uint32_t * srcbuf; uint32_t * dstbuf; uint32_t crc32; lcg_srand (testnum); src_bpp = (lcg_rand_n (2) == 0) ? 2 : 4; dst_bpp = (lcg_rand_n (2) == 0) ? 2 : 4; op = (lcg_rand_n (2) == 0) ? PIXMAN_OP_SRC : PIXMAN_OP_OVER; src_width = lcg_rand_n (MAX_SRC_WIDTH) + 1; src_height = lcg_rand_n (MAX_SRC_HEIGHT) + 1; dst_width = lcg_rand_n (MAX_DST_WIDTH) + 1; dst_height = lcg_rand_n (MAX_DST_HEIGHT) + 1; src_stride = src_width * src_bpp + lcg_rand_n (MAX_STRIDE) * src_bpp; dst_stride = dst_width * dst_bpp + lcg_rand_n (MAX_STRIDE) * dst_bpp; if (src_stride & 3) src_stride += 2; if (dst_stride & 3) dst_stride += 2; src_x = -(src_width / 4) + lcg_rand_n (src_width * 3 / 2); src_y = -(src_height / 4) + lcg_rand_n (src_height * 3 / 2); dst_x = -(dst_width / 4) + lcg_rand_n (dst_width * 3 / 2); dst_y = -(dst_height / 4) + lcg_rand_n (dst_height * 3 / 2); w = lcg_rand_n (dst_width * 3 / 2 - dst_x); h = lcg_rand_n (dst_height * 3 / 2 - dst_y); srcbuf = (uint32_t *)malloc (src_stride * src_height); dstbuf = (uint32_t *)malloc (dst_stride * dst_height); for (i = 0; i < src_stride * src_height; i++) *((uint8_t *)srcbuf + i) = lcg_rand_n (256); for (i = 0; i < dst_stride * dst_height; i++) *((uint8_t *)dstbuf + i) = lcg_rand_n (256); src_fmt = src_bpp == 4 ? (lcg_rand_n (2) == 0 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8) : PIXMAN_r5g6b5; dst_fmt = dst_bpp == 4 ? (lcg_rand_n (2) == 0 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8) : PIXMAN_r5g6b5; src_img = pixman_image_create_bits ( src_fmt, src_width, src_height, srcbuf, src_stride); dst_img = pixman_image_create_bits ( dst_fmt, dst_width, dst_height, dstbuf, dst_stride); image_endian_swap (src_img, src_bpp * 8); image_endian_swap (dst_img, dst_bpp * 8); if (lcg_rand_n (8) > 0) { scale_x = -32768 * 3 + lcg_rand_N (65536 * 5); scale_y = -32768 * 3 + lcg_rand_N (65536 * 5); translate_x = lcg_rand_N (65536); translate_y = lcg_rand_N (65536); pixman_transform_init_scale (&transform, scale_x, scale_y); pixman_transform_translate (&transform, NULL, translate_x, translate_y); pixman_image_set_transform (src_img, &transform); } switch (lcg_rand_n (4)) { case 0: repeat = PIXMAN_REPEAT_NONE; break; case 1: repeat = PIXMAN_REPEAT_NORMAL; break; case 2: repeat = PIXMAN_REPEAT_PAD; break; case 3: repeat = PIXMAN_REPEAT_REFLECT; break; default: break; } pixman_image_set_repeat (src_img, repeat); if (lcg_rand_n (2)) pixman_image_set_filter (src_img, PIXMAN_FILTER_NEAREST, NULL, 0); else pixman_image_set_filter (src_img, PIXMAN_FILTER_BILINEAR, NULL, 0); if (verbose) { printf ("src_fmt=%08X, dst_fmt=%08X\n", src_fmt, dst_fmt); printf ("op=%d, scale_x=%d, scale_y=%d, repeat=%d\n", op, scale_x, scale_y, repeat); printf ("translate_x=%d, translate_y=%d\n", translate_x, translate_y); printf ("src_width=%d, src_height=%d, dst_width=%d, dst_height=%d\n", src_width, src_height, dst_width, dst_height); printf ("src_x=%d, src_y=%d, dst_x=%d, dst_y=%d\n", src_x, src_y, dst_x, dst_y); printf ("w=%d, h=%d\n", w, h); } if (lcg_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = lcg_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = lcg_rand_n (src_width); clip_boxes[i].y1 = lcg_rand_n (src_height); clip_boxes[i].x2 = clip_boxes[i].x1 + lcg_rand_n (src_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + lcg_rand_n (src_height - clip_boxes[i].y1); if (verbose) { printf ("source clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (src_img, &clip); pixman_image_set_source_clipping (src_img, 1); pixman_region_fini (&clip); } if (lcg_rand_n (8) == 0) { pixman_box16_t clip_boxes[2]; int n = lcg_rand_n (2) + 1; for (i = 0; i < n; i++) { clip_boxes[i].x1 = lcg_rand_n (dst_width); clip_boxes[i].y1 = lcg_rand_n (dst_height); clip_boxes[i].x2 = clip_boxes[i].x1 + lcg_rand_n (dst_width - clip_boxes[i].x1); clip_boxes[i].y2 = clip_boxes[i].y1 + lcg_rand_n (dst_height - clip_boxes[i].y1); if (verbose) { printf ("destination clip box: [%d,%d-%d,%d]\n", clip_boxes[i].x1, clip_boxes[i].y1, clip_boxes[i].x2, clip_boxes[i].y2); } } pixman_region_init_rects (&clip, clip_boxes, n); pixman_image_set_clip_region (dst_img, &clip); pixman_region_fini (&clip); } pixman_image_composite (op, src_img, NULL, dst_img, src_x, src_y, 0, 0, dst_x, dst_y, w, h); if (dst_fmt == PIXMAN_x8r8g8b8) { /* ignore unused part */ for (i = 0; i < dst_stride * dst_height / 4; i++) dstbuf[i] &= 0xFFFFFF; } image_endian_swap (dst_img, dst_bpp * 8); if (verbose) { int j; for (i = 0; i < dst_height; i++) { for (j = 0; j < dst_stride; j++) printf ("%02X ", *((uint8_t *)dstbuf + i * dst_stride + j)); printf ("\n"); } } pixman_image_unref (src_img); pixman_image_unref (dst_img); crc32 = compute_crc32 (0, dstbuf, dst_stride * dst_height); free (srcbuf); free (dstbuf); return crc32; }
/* * We have a source image filled with solid color, set NORMAL or PAD repeat, * and some transform which results in nearest neighbour scaling. * * The expected result is either that the destination image filled with this solid * color or, if the transformation is such that we can't composite anything at * all, that nothing has changed in the destination. * * The surrounding memory of the source image is a different solid color so that * we are sure to get failures if we access it. */ static int run_test (int32_t dst_width, int32_t dst_height, int32_t src_width, int32_t src_height, int32_t src_x, int32_t src_y, int32_t scale_x, int32_t scale_y, pixman_filter_t filter, pixman_repeat_t repeat) { pixman_image_t * src_img; pixman_image_t * dst_img; pixman_transform_t transform; uint32_t * srcbuf; uint32_t * dstbuf; pixman_box32_t box = { 0, 0, src_width, src_height }; pixman_color_t color_cc = { 0xcccc, 0xcccc, 0xcccc, 0xcccc }; int result; int i; static const pixman_fixed_t kernel[] = { #define D(f) (pixman_double_to_fixed (f) + 0x0001) pixman_int_to_fixed (5), pixman_int_to_fixed (5), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0), D(1/25.0) }; result = 0; srcbuf = (uint32_t *)malloc ((src_width + 10) * (src_height + 10) * 4); dstbuf = (uint32_t *)malloc (dst_width * dst_height * 4); memset (srcbuf, 0x88, src_width * src_height * 4); memset (dstbuf, 0x33, dst_width * dst_height * 4); src_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, src_width, src_height, srcbuf + (src_width + 10) * 5 + 5, (src_width + 10) * 4); pixman_image_fill_boxes (PIXMAN_OP_SRC, src_img, &color_cc, 1, &box); dst_img = pixman_image_create_bits ( PIXMAN_a8r8g8b8, dst_width, dst_height, dstbuf, dst_width * 4); pixman_transform_init_scale (&transform, scale_x, scale_y); pixman_image_set_transform (src_img, &transform); pixman_image_set_repeat (src_img, repeat); if (filter == PIXMAN_FILTER_CONVOLUTION) pixman_image_set_filter (src_img, filter, kernel, 27); else pixman_image_set_filter (src_img, filter, NULL, 0); pixman_image_composite (PIXMAN_OP_SRC, src_img, NULL, dst_img, src_x, src_y, 0, 0, 0, 0, dst_width, dst_height); pixman_image_unref (src_img); pixman_image_unref (dst_img); for (i = 0; i < dst_width * dst_height; i++) { if (dstbuf[i] != 0xCCCCCCCC && dstbuf[i] != 0x33333333) { result = 1; break; } } free (srcbuf); free (dstbuf); return result; }