summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alevy@redhat.com>2012-07-20 19:53:18 +0300
committerAlon Levy <alevy@redhat.com>2012-10-25 12:44:52 +0200
commit3e966d91807ff1f5498c591db3c715ce4b383dde (patch)
tree472dc319dc9b9990cd5e69192e455c7438e4acb9
parent8fcda22b59ef2437486c9c1a9192a667c91eb26d (diff)
qxl/tests: execbuffer with relocations (draw_copy)
-rw-r--r--tests/qxl/qxl.c85
1 files changed, 63 insertions, 22 deletions
diff --git a/tests/qxl/qxl.c b/tests/qxl/qxl.c
index 4794d97f..daee5fd5 100644
--- a/tests/qxl/qxl.c
+++ b/tests/qxl/qxl.c
@@ -39,7 +39,7 @@ int qxl_open_fd(void)
}
enum {
- ALLOC_ONLY,
+ ALLOC_ONLY = 0,
ALLOC_DEALLOC,
COMMAND,
RELOC_COMMAND,
@@ -171,8 +171,22 @@ void command(int fd)
}
}
+static int verbose = 1;
+
#define INSIDE(x, y, top, left, bottom, right) ((x) >= (left) && (x) <= (right) && (y) >= (top) && (y) <= (bottom))
+uint64_t area(uint64_t width, uint64_t height, uint64_t top, uint64_t left,
+ uint64_t bottom, uint64_t right, uint64_t incol, uint64_t outcol)
+{
+ uint64_t area = width * height;
+ uint64_t inarea = (bottom - top + 1) * (right - left + 1);
+
+ if (verbose)
+ printf("(%d - %d + 1) (%d - %d + 1) %d\n", bottom, top, right, left,
+ inarea);
+ return incol * inarea + outcol * (area - inarea);
+}
+
void reloc_command(int fd)
{
/* also a number of commands in a single exec_buffer */
@@ -181,62 +195,89 @@ void reloc_command(int fd)
struct drm_qxl_reloc r[2];
QXLDrawable drawable = {0};
int ret;
- int width = 64;
- int height = 64;
- int stride = 4 * width;
- int bitmap_size = stride * height;
uint64_t image_handle;
uint32_t *bitmap;
QXLImage *qxl_image;
int x, y;
+ int width = 64;
+ int height = 64;
+ int stride = 4 * width;
+ int bitmap_size = stride * height;
+ int bo_size = sizeof(*qxl_image) + bitmap_size;
+ //uint32_t col[4] = {1, 0, 4, 2};
+ uint32_t col[4] = {0xff0000, 0x00f000, 0x000f00, 0x0000ff};
- image_handle = qxl_alloc(fd, sizeof(*qxl_image) + bitmap_size);
- qxl_image = qxl_mmap(fd, image_handle, bitmap_size);
+ image_handle = qxl_alloc(fd, bo_size);
+ qxl_image = qxl_mmap(fd, image_handle, bo_size);
+ if (verbose) {
+ printf("%s: qxl_mmap returned %llx (handle %d, length %d)\n",
+ __FUNCTION__, qxl_image, image_handle, bitmap_size);
+ }
if (!qxl_image) {
return;
}
bitmap = (uint32_t *)&qxl_image[1];
for (y = 0 ; y < height; ++y) {
for (x = 0 ; x < width; ++x) {
- *bitmap++ = (INSIDE(x, y, 8, 8, 32, 32) ? 0xff0000 : 0x00f000) |
- (INSIDE(x, y, 24, 24, 54, 54) ? 0x000f00 : 0x0000ff);
+ *bitmap++ = (INSIDE(x, y, 8, 8, 32, 32) ? col[0] : col[1]) |
+ (INSIDE(x, y, 24, 24, 48, 48) ? col[2] : col[3]);
}
}
+ /* check that the memory looks like it should */
+ {
+ uint64_t sum = 0;
+ uint64_t expected_sum;
+ bitmap = (uint32_t *)&qxl_image[1];
+ for (y = 0 ; y < height; ++y) {
+ for (x = 0 ; x < width; ++x) {
+ sum += *bitmap++;
+ }
+ }
+ expected_sum = area(width, height, 8, 8, 32, 32, col[0], col[1]) +
+ area(width, height, 24, 24, 48, 48, col[2], col[3]);
+ if (verbose)
+ printf("%lld, %lld, %lld\n", sum, expected_sum, sum - expected_sum);
+ }
+
qxl_image->descriptor.id = 1234;
qxl_image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
qxl_image->descriptor.flags = 0;
qxl_image->descriptor.width = width;
qxl_image->descriptor.height = height;
- qxl_image->bitmap.x = 0;
- qxl_image->bitmap.y = 0;
+ qxl_image->bitmap.x = width;
+ qxl_image->bitmap.y = height;
qxl_image->bitmap.stride = stride;
qxl_image->bitmap.palette = 0;
qxl_image->bitmap.flags = QXL_BITMAP_DIRECT;
- qxl_image->bitmap.data = 0xdead;
+ qxl_image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
+ qxl_image->bitmap.data = 0xdeadbeed; /* filled in by relocation */
r[1].src_handle = image_handle;
r[1].src_offset = offsetof(QXLImage, bitmap.data);
r[1].dst_handle = image_handle;
r[1].dst_offset = sizeof(QXLImage);
drawable.surface_id = 0;
- drawable.type = QXL_DRAW_OPAQUE;
+ drawable.type = QXL_DRAW_COPY;
drawable.effect = QXL_EFFECT_OPAQUE;
drawable.self_bitmap = 0;
+ set_rect(&drawable.self_bitmap_area, 0, 0, 0, 0);
drawable.mm_time = 0;
drawable.surfaces_dest[0] = -1;
drawable.surfaces_dest[1] = -1;
drawable.surfaces_dest[2] = -1;
set_rect(&drawable.bbox, 0, 0, height, width);
- // Opaque specific
- drawable.u.opaque.scale_mode = SPICE_IMAGE_SCALE_MODE_NEAREST;
- drawable.u.opaque.src_bitmap = 0xdead;
- drawable.u.opaque.brush.type = SPICE_BRUSH_TYPE_SOLID;
- drawable.u.opaque.brush.u.color = 0x00ff77ff;
- drawable.u.opaque.rop_descriptor = SPICE_ROPD_OP_PUT;
- drawable.u.opaque.mask.bitmap = 0;
- set_rect(&drawable.u.opaque.src_area, 0, 0, 64, 64);
+ drawable.clip.type = SPICE_CLIP_TYPE_NONE;
+ // Copy specific
+ drawable.u.copy.scale_mode = SPICE_IMAGE_SCALE_MODE_INTERPOLATE;
+ drawable.u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
+ drawable.u.copy.mask.bitmap = 0;
+ drawable.u.copy.mask.pos.x = 0;
+ drawable.u.copy.mask.bitmap = 0;
+ drawable.u.copy.mask.flags = 0;
+ set_rect(&drawable.u.copy.src_area, 0, 0, width, height);
+ drawable.u.copy.src_bitmap = 0xdeadbeed; /* filled in by relocation */
// Relocation for src_bitmap
r[0].src_handle = 0; // TODO - special constant for CMD_BO
- r[0].src_offset = offsetof(QXLDrawable, u.opaque.src_bitmap);
+ r[0].src_offset = offsetof(QXLDrawable, u.copy.src_bitmap);
r[0].dst_handle = image_handle;
r[0].dst_offset = 0;
c.type = QXL_CMD_DRAW;