framework/replay: disable AA accounting when comparing with no tolerance
[piglit.git] / tests / gbm / gbm-multi-plane.c
blob1debd60b69d794f2a2052392dcc1dbbbab4783ec
1 /* Copyright (c) 2021 Collabora Ltd
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
23 /**
24 * \file
25 * \brief Tests for libgbm.
28 #include <drm_fourcc.h>
29 #include <errno.h>
30 #include <fcntl.h>
31 #include <gbm.h>
32 #include <sys/stat.h>
33 #include <sys/types.h>
35 #include "piglit-util.h"
37 #define NUM_PLANES 3
38 #define WIDTH 512
39 #define HEIGHT 512
40 #define FORMAT GBM_FORMAT_R8
42 static bool
43 gem_handles_match(struct gbm_device *gbm, int fd, int old_handle)
45 bool match;
46 struct gbm_import_fd_data import = {
47 .width = WIDTH,
48 .height = HEIGHT,
49 .format = FORMAT,
50 .fd = fd,
52 struct gbm_bo *bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &import, 0);
53 if (!bo)
54 piglit_report_result(PIGLIT_FAIL);
56 match = gbm_bo_get_handle(bo).u32 == old_handle;
57 gbm_bo_destroy(bo);
59 return match;
62 int
63 main(int argc, char **argv)
65 int drm_fd;
66 char *nodename;
67 struct gbm_device *gbm;
68 struct gbm_bo *bos[NUM_PLANES];
69 struct gbm_bo *multi_plane_bo;
70 struct gbm_import_fd_modifier_data import_mod = {
71 .width = WIDTH,
72 .height = HEIGHT,
73 .format = GBM_FORMAT_YUV420,
74 .num_fds = NUM_PLANES,
75 .modifier = DRM_FORMAT_MOD_LINEAR,
78 /* Strip common piglit args. */
79 piglit_strip_arg(&argc, argv, "-fbo");
80 piglit_strip_arg(&argc, argv, "-auto");
82 nodename = getenv("WAFFLE_GBM_DEVICE");
83 if (!nodename)
84 nodename = "/dev/dri/renderD128";
85 drm_fd = open(nodename, O_RDWR);
86 if (drm_fd == -1) {
87 perror("Error opening render node");
88 piglit_report_result(PIGLIT_FAIL);
91 gbm = gbm_create_device(drm_fd);
92 if (!gbm)
93 piglit_report_result(PIGLIT_FAIL);
95 for (int i = 0; i < NUM_PLANES; i++) {
96 bos[i] = gbm_bo_create(gbm, WIDTH, HEIGHT, FORMAT,
97 GBM_BO_USE_RENDERING | GBM_BO_USE_LINEAR);
98 if (!bos[i])
99 piglit_report_result(PIGLIT_FAIL);
101 import_mod.fds[i] = gbm_bo_get_fd(bos[i]);
102 import_mod.strides[i] = gbm_bo_get_stride(bos[i]);
103 import_mod.offsets[i] = gbm_bo_get_offset(bos[i], 0);
106 multi_plane_bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD_MODIFIER,
107 &import_mod, 0);
108 if (!multi_plane_bo)
109 piglit_report_result(PIGLIT_FAIL);
111 for (int i = 0; i < NUM_PLANES; i++) {
112 int fd = gbm_bo_get_fd_for_plane(multi_plane_bo, i);
113 if (fd < 0)
114 piglit_report_result(PIGLIT_FAIL);
116 if (fcntl(fd, F_GETFL) == -1 && errno == EBADF)
117 piglit_report_result(PIGLIT_FAIL);
119 if (!gem_handles_match(gbm, fd, gbm_bo_get_handle(bos[i]).u32))
120 piglit_report_result(PIGLIT_FAIL);
122 if (import_mod.strides[i] != gbm_bo_get_stride_for_plane(multi_plane_bo, i))
123 piglit_report_result(PIGLIT_FAIL);
125 if (import_mod.offsets[i] != gbm_bo_get_offset(multi_plane_bo, i))
126 piglit_report_result(PIGLIT_FAIL);
129 piglit_report_result(PIGLIT_PASS);