+ /* init src box */
+ src_box = *src_box_in;
+
+ /* init dst box */
+ dst_box.x = dst_x;
+ dst_box.y = dst_y;
+ dst_box.z = dst_z;
+ dst_box.width = src_box.width;
+ dst_box.height = src_box.height;
+ dst_box.depth = src_box.depth;
+
+ src_bs = util_format_get_blocksize(src_format);
+ src_bw = util_format_get_blockwidth(src_format);
+ src_bh = util_format_get_blockheight(src_format);
+ dst_bs = util_format_get_blocksize(dst_format);
+ dst_bw = util_format_get_blockwidth(dst_format);
+ dst_bh = util_format_get_blockheight(dst_format);
+
+ /* Note: all box positions and sizes are in pixels */
+ if (src_bw > 1 && dst_bw == 1) {
+ /* Copy from compressed to uncompressed.
+ * Shrink dest box by the src block size.
+ */
+ dst_box.width /= src_bw;
+ dst_box.height /= src_bh;
+ }
+ else if (src_bw == 1 && dst_bw > 1) {
+ /* Copy from uncompressed to compressed.
+ * Expand dest box by the dest block size.
+ */
+ dst_box.width *= dst_bw;
+ dst_box.height *= dst_bh;
+ }
+ else {
+ /* compressed -> compressed or uncompressed -> uncompressed copy */
+ assert(src_bw == dst_bw);
+ assert(src_bh == dst_bh);
+ }
+
+ assert(src_bs == dst_bs);
+ if (src_bs != dst_bs) {
+ /* This can happen if we fail to do format checking before hand.
+ * Don't crash below.
+ */
+ return;
+ }
+
+ /* check that region boxes are block aligned */
+ assert(src_box.x % src_bw == 0);
+ assert(src_box.y % src_bh == 0);
+ assert(src_box.width % src_bw == 0 ||
+ src_box.x + src_box.width == u_minify(src->width0, src_level));
+ assert(src_box.height % src_bh == 0 ||
+ src_box.y + src_box.height == u_minify(src->height0, src_level));
+ assert(dst_box.x % dst_bw == 0);
+ assert(dst_box.y % dst_bh == 0);
+ assert(dst_box.width % dst_bw == 0 ||
+ dst_box.x + dst_box.width == u_minify(dst->width0, dst_level));
+ assert(dst_box.height % dst_bh == 0 ||
+ dst_box.y + dst_box.height == u_minify(dst->height0, dst_level));
+
+ /* check that region boxes are not out of bounds */
+ assert(src_box.x + src_box.width <= u_minify(src->width0, src_level));
+ assert(src_box.y + src_box.height <= u_minify(src->height0, src_level));
+ assert(dst_box.x + dst_box.width <= u_minify(dst->width0, dst_level));
+ assert(dst_box.y + dst_box.height <= u_minify(dst->height0, dst_level));
+
+ /* check that total number of src, dest bytes match */
+ assert((src_box.width / src_bw) * (src_box.height / src_bh) * src_bs ==
+ (dst_box.width / dst_bw) * (dst_box.height / dst_bh) * dst_bs);