static force_inline void get_shifts (pixman_format_code_t format, int *a, int *r, int *g, int *b) { switch (PIXMAN_FORMAT_TYPE (format)) { case PIXMAN_TYPE_A: *b = 0; *g = 0; *r = 0; *a = 0; break; case PIXMAN_TYPE_ARGB: case PIXMAN_TYPE_ARGB_SRGB: *b = 0; *g = *b + PIXMAN_FORMAT_B (format); *r = *g + PIXMAN_FORMAT_G (format); *a = *r + PIXMAN_FORMAT_R (format); break; case PIXMAN_TYPE_ABGR: *r = 0; *g = *r + PIXMAN_FORMAT_R (format); *b = *g + PIXMAN_FORMAT_G (format); *a = *b + PIXMAN_FORMAT_B (format); break; case PIXMAN_TYPE_BGRA: /* With BGRA formats we start counting at the high end of the pixel */ *b = PIXMAN_FORMAT_BPP (format) - PIXMAN_FORMAT_B (format); *g = *b - PIXMAN_FORMAT_B (format); *r = *g - PIXMAN_FORMAT_G (format); *a = *r - PIXMAN_FORMAT_R (format); break; case PIXMAN_TYPE_RGBA: /* With BGRA formats we start counting at the high end of the pixel */ *r = PIXMAN_FORMAT_BPP (format) - PIXMAN_FORMAT_R (format); *g = *r - PIXMAN_FORMAT_R (format); *b = *g - PIXMAN_FORMAT_G (format); *a = *b - PIXMAN_FORMAT_B (format); break; default: assert (0); break; } }
PixelFormat qemu_pixelformat_from_pixman(pixman_format_code_t format) { PixelFormat pf; uint8_t bpp; bpp = pf.bits_per_pixel = PIXMAN_FORMAT_BPP(format); pf.bytes_per_pixel = PIXMAN_FORMAT_BPP(format) / 8; pf.depth = PIXMAN_FORMAT_DEPTH(format); pf.abits = PIXMAN_FORMAT_A(format); pf.rbits = PIXMAN_FORMAT_R(format); pf.gbits = PIXMAN_FORMAT_G(format); pf.bbits = PIXMAN_FORMAT_B(format); switch (PIXMAN_FORMAT_TYPE(format)) { case PIXMAN_TYPE_ARGB: pf.ashift = pf.bbits + pf.gbits + pf.rbits; pf.rshift = pf.bbits + pf.gbits; pf.gshift = pf.bbits; pf.bshift = 0; break; case PIXMAN_TYPE_ABGR: pf.ashift = pf.rbits + pf.gbits + pf.bbits; pf.bshift = pf.rbits + pf.gbits; pf.gshift = pf.rbits; pf.rshift = 0; break; case PIXMAN_TYPE_BGRA: pf.bshift = bpp - pf.bbits; pf.gshift = bpp - (pf.bbits + pf.gbits); pf.rshift = bpp - (pf.bbits + pf.gbits + pf.rbits); pf.ashift = 0; break; case PIXMAN_TYPE_RGBA: pf.rshift = bpp - pf.rbits; pf.gshift = bpp - (pf.rbits + pf.gbits); pf.bshift = bpp - (pf.rbits + pf.gbits + pf.bbits); pf.ashift = 0; break; default: g_assert_not_reached(); break; } pf.amax = (1 << pf.abits) - 1; pf.rmax = (1 << pf.rbits) - 1; pf.gmax = (1 << pf.gbits) - 1; pf.bmax = (1 << pf.bbits) - 1; pf.amask = pf.amax << pf.ashift; pf.rmask = pf.rmax << pf.rshift; pf.gmask = pf.gmax << pf.gshift; pf.bmask = pf.bmax << pf.bshift; return pf; }
cairo_bool_t _pixman_format_to_masks (pixman_format_code_t format, cairo_format_masks_t *masks) { int a, r, g, b; masks->bpp = PIXMAN_FORMAT_BPP (format); /* Number of bits in each channel */ a = PIXMAN_FORMAT_A (format); r = PIXMAN_FORMAT_R (format); g = PIXMAN_FORMAT_G (format); b = PIXMAN_FORMAT_B (format); switch (PIXMAN_FORMAT_TYPE (format)) { case PIXMAN_TYPE_ARGB: masks->alpha_mask = MASK (a) << (r + g + b); masks->red_mask = MASK (r) << (g + b); masks->green_mask = MASK (g) << (b); masks->blue_mask = MASK (b); return TRUE; case PIXMAN_TYPE_ABGR: masks->alpha_mask = MASK (a) << (b + g + r); masks->blue_mask = MASK (b) << (g + r); masks->green_mask = MASK (g) << (r); masks->red_mask = MASK (r); return TRUE; #ifdef PIXMAN_TYPE_BGRA case PIXMAN_TYPE_BGRA: masks->blue_mask = MASK (b) << (masks->bpp - b); masks->green_mask = MASK (g) << (masks->bpp - b - g); masks->red_mask = MASK (r) << (masks->bpp - b - g - r); masks->alpha_mask = MASK (a); return TRUE; #endif case PIXMAN_TYPE_A: masks->alpha_mask = MASK (a); masks->red_mask = 0; masks->green_mask = 0; masks->blue_mask = 0; return TRUE; case PIXMAN_TYPE_OTHER: case PIXMAN_TYPE_COLOR: case PIXMAN_TYPE_GRAY: case PIXMAN_TYPE_YUY2: case PIXMAN_TYPE_YV12: default: masks->alpha_mask = 0; masks->red_mask = 0; masks->green_mask = 0; masks->blue_mask = 0; return FALSE; } }
int main (int argc, char *argv[]) { bench_info_t binfo; pixman_filter_t filter = PIXMAN_FILTER_NEAREST; pixman_format_code_t src_format = PIXMAN_a8r8g8b8; pixman_format_code_t mask_format = 0; pixman_format_code_t dest_format = PIXMAN_a8r8g8b8; pixman_box32_t dest_box = { 0, 0, WIDTH, HEIGHT }; box_48_16_t transformed = { 0 }; int32_t xmin, ymin, xmax, ymax; uint32_t *src, *mask, *dest; binfo.op = PIXMAN_OP_SRC; binfo.mask_image = NULL; pixman_transform_init_identity (&binfo.transform); ++argv; if (*argv && (*argv)[0] == '-' && (*argv)[1] == 'n') { filter = PIXMAN_FILTER_NEAREST; ++argv; --argc; } if (*argv && (*argv)[0] == '-' && (*argv)[1] == 'b') { filter = PIXMAN_FILTER_BILINEAR; ++argv; --argc; } if (argc == 1 || !parse_arguments (argc, argv, &binfo.transform, &binfo.op, &src_format, &mask_format, &dest_format)) { printf ("Usage: affine-bench [-n] [-b] axx [axy] [ayx] [ayy] [combine type]\n"); printf (" [src format] [mask format] [dest format]\n"); printf (" -n : nearest scaling (default)\n"); printf (" -b : bilinear scaling\n"); printf (" axx : x_out:x_in factor\n"); printf (" axy : x_out:y_in factor (default 0)\n"); printf (" ayx : y_out:x_in factor (default 0)\n"); printf (" ayy : y_out:y_in factor (default 1)\n"); printf (" combine type : src, over, in etc (default src)\n"); printf (" src format : a8r8g8b8, r5g6b5 etc (default a8r8g8b8)\n"); printf (" mask format : as for src format, but no mask used if omitted\n"); printf (" dest format : as for src format (default a8r8g8b8)\n"); printf ("The output is a single number in megapixels/second.\n"); return EXIT_FAILURE; } /* Compute required extents for source and mask image so they qualify * for COVER fast paths and get the flags in pixman.c:analyze_extent(). * These computations are for FAST_PATH_SAMPLES_COVER_CLIP_BILINEAR, * but at the same time they also allow COVER_CLIP_NEAREST. */ compute_transformed_extents (&binfo.transform, &dest_box, &transformed); xmin = pixman_fixed_to_int (transformed.x1 - pixman_fixed_1 / 2); ymin = pixman_fixed_to_int (transformed.y1 - pixman_fixed_1 / 2); xmax = pixman_fixed_to_int (transformed.x2 + pixman_fixed_1 / 2); ymax = pixman_fixed_to_int (transformed.y2 + pixman_fixed_1 / 2); /* Note: * The upper limits can be reduced to the following when fetchers * are guaranteed to not access pixels with zero weight. This concerns * particularly all bilinear samplers. * * xmax = pixman_fixed_to_int (transformed.x2 + pixman_fixed_1 / 2 - pixman_fixed_e); * ymax = pixman_fixed_to_int (transformed.y2 + pixman_fixed_1 / 2 - pixman_fixed_e); * This is equivalent to subtracting 0.5 and rounding up, rather than * subtracting 0.5, rounding down and adding 1. */ binfo.src_x = -xmin; binfo.src_y = -ymin; /* Always over-allocate width by 64 pixels for all src, mask and dst, * so that we can iterate over an x-offset 0..63 in bench (). * This is similar to lowlevel-blt-bench, which uses the same method * to hit different cacheline misalignments. */ create_image (xmax - xmin + 64, ymax - ymin + 1, src_format, filter, &src, &binfo.src_image); if (mask_format) { create_image (xmax - xmin + 64, ymax - ymin + 1, mask_format, filter, &mask, &binfo.mask_image); if ((PIXMAN_FORMAT_R(mask_format) || PIXMAN_FORMAT_G(mask_format) || PIXMAN_FORMAT_B(mask_format))) { pixman_image_set_component_alpha (binfo.mask_image, 1); } } create_image (WIDTH + 64, HEIGHT, dest_format, filter, &dest, &binfo.dest_image); run_benchmark (&binfo); return EXIT_SUCCESS; }