2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Damien Lespiau <damien.lespiau@intel.com>
25 * Xiang, Haihao <haihao.xiang@intel.com>
29 * This file is a basic test for the media_fill() function, a very simple
30 * workload for the Media pipeline.
36 #include <sys/ioctl.h>
45 #include "ioctl_wrappers.h"
47 #include "intel_bufmgr.h"
48 #include "intel_batchbuffer.h"
50 #include "intel_chipset.h"
53 #define STRIDE (WIDTH)
55 #define SIZE (HEIGHT*STRIDE)
63 drm_intel_bufmgr *bufmgr;
64 uint8_t linear[WIDTH * HEIGHT];
67 static void scratch_buf_init(data_t *data, struct igt_buf *buf,
68 int width, int height, int stride, uint8_t color)
73 bo = drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096);
74 for (i = 0; i < width * height; i++)
75 data->linear[i] = color;
76 gem_write(data->drm_fd, bo->handle, 0, data->linear,
77 sizeof(data->linear));
81 buf->tiling = I915_TILING_NONE;
86 scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
91 gem_read(data->drm_fd, buf->bo->handle, 0,
92 data->linear, sizeof(data->linear));
93 val = data->linear[y * WIDTH + x];
94 igt_assert_f(val == color,
95 "Expected 0x%02x, found 0x%02x at (%d,%d)\n",
102 struct intel_batchbuffer *batch = NULL;
104 igt_media_fillfunc_t media_fill = NULL;
107 data.drm_fd = drm_open_any_render();
108 data.devid = intel_get_drm_devid(data.drm_fd);
110 data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
111 igt_assert(data.bufmgr);
113 media_fill = igt_get_media_fillfunc(data.devid);
115 igt_require_f(media_fill,
116 "no media-fill function\n");
118 batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
121 scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, COLOR_C4);
123 for (i = 0; i < WIDTH; i++) {
124 for (j = 0; j < HEIGHT; j++) {
125 scratch_buf_check(&data, &dst, i, j, COLOR_C4);
130 &dst, 0, 0, WIDTH / 2, HEIGHT / 2,
133 for (i = 0; i < WIDTH; i++) {
134 for (j = 0; j < HEIGHT; j++) {
135 if (i < WIDTH / 2 && j < HEIGHT / 2)
136 scratch_buf_check(&data, &dst, i, j, COLOR_4C);
138 scratch_buf_check(&data, &dst, i, j, COLOR_C4);