2 * Copyright © 2007 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 * Eric Anholt <eric@anholt.net>
31 set_draw_cliprects_empty(int fd, int drawable)
34 struct drm_update_draw update;
36 update.handle = drawable;
37 update.type = DRM_DRAWABLE_CLIPRECTS;
41 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
46 set_draw_cliprects_empty_fail(int fd, int drawable)
49 struct drm_update_draw update;
51 update.handle = drawable;
52 update.type = DRM_DRAWABLE_CLIPRECTS;
56 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
57 assert(ret == -1 && errno == EINVAL);
61 set_draw_cliprects_2(int fd, int drawable)
64 struct drm_update_draw update;
65 drm_clip_rect_t rects[2];
77 update.handle = drawable;
78 update.type = DRM_DRAWABLE_CLIPRECTS;
80 update.data = (unsigned long long)(uintptr_t)&rects;
82 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
86 static int add_drawable(int fd)
92 * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
95 ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg);
97 return drawarg.handle;
100 static int rm_drawable(int fd, int drawable, int fail)
105 /* Create a drawable.
106 * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
108 drawarg.handle = drawable;
109 ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
113 assert(ret == -1 && errno == EINVAL);
115 return drawarg.handle;
119 * Tests drawable management: adding, removing, and updating the cliprects of
122 int main(int argc, char **argv)
126 fd = drm_open_any_master();
128 d1 = add_drawable(fd);
129 d2 = add_drawable(fd);
130 /* Do a series of cliprect updates */
131 set_draw_cliprects_empty(fd, d1);
132 set_draw_cliprects_empty(fd, d2);
133 set_draw_cliprects_2(fd, d1);
134 set_draw_cliprects_empty(fd, d1);
136 /* Remove our drawables */
137 rm_drawable(fd, d1, 0);
138 rm_drawable(fd, d2, 0);
140 /* Check that removing an unknown drawable returns error */
141 rm_drawable(fd, 0x7fffffff, 1);
143 /* Attempt to set cliprects on a nonexistent drawable */
144 set_draw_cliprects_empty_fail(fd, d1);