1 /* 2 * Copyright 2007 Intel Corporation 3 * 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: 10 * 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 13 * Software. 14 * 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 21 * IN THE SOFTWARE. 22 * 23 * Authors: 24 * Eric Anholt <eric (at) anholt.net> 25 * 26 */ 27 28 #include <sys/ioctl.h> 29 #include "drmtest.h" 30 31 static void 32 set_draw_cliprects_empty(int fd, int drawable) 33 { 34 int ret; 35 struct drm_update_draw update; 36 37 update.handle = drawable; 38 update.type = DRM_DRAWABLE_CLIPRECTS; 39 update.num = 0; 40 update.data = 0; 41 42 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 43 assert(ret == 0); 44 } 45 46 static void 47 set_draw_cliprects_empty_fail(int fd, int drawable) 48 { 49 int ret; 50 struct drm_update_draw update; 51 52 update.handle = drawable; 53 update.type = DRM_DRAWABLE_CLIPRECTS; 54 update.num = 0; 55 update.data = 0; 56 57 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 58 assert(ret == -1 && errno == EINVAL); 59 } 60 61 static void 62 set_draw_cliprects_2(int fd, int drawable) 63 { 64 int ret; 65 struct drm_update_draw update; 66 drm_clip_rect_t rects[2]; 67 68 rects[0].x1 = 0; 69 rects[0].y1 = 0; 70 rects[0].x2 = 10; 71 rects[0].y2 = 10; 72 73 rects[1].x1 = 10; 74 rects[1].y1 = 10; 75 rects[1].x2 = 20; 76 rects[1].y2 = 20; 77 78 update.handle = drawable; 79 update.type = DRM_DRAWABLE_CLIPRECTS; 80 update.num = 2; 81 update.data = (unsigned long long)(uintptr_t)&rects; 82 83 ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 84 assert(ret == 0); 85 } 86 87 static int add_drawable(int fd) 88 { 89 drm_draw_t drawarg; 90 int ret; 91 92 /* Create a drawable. 93 * IOCTL_ADD_DRAW is RDWR, though it should really just be RD 94 */ 95 drawarg.handle = 0; 96 ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg); 97 assert(ret == 0); 98 return drawarg.handle; 99 } 100 101 static int rm_drawable(int fd, int drawable, int fail) 102 { 103 drm_draw_t drawarg; 104 int ret; 105 106 /* Create a drawable. 107 * IOCTL_ADD_DRAW is RDWR, though it should really just be RD 108 */ 109 drawarg.handle = drawable; 110 ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg); 111 if (!fail) 112 assert(ret == 0); 113 else 114 assert(ret == -1 && errno == EINVAL); 115 116 return drawarg.handle; 117 } 118 119 /** 120 * Tests drawable management: adding, removing, and updating the cliprects of 121 * drawables. 122 */ 123 int main(int argc, char **argv) 124 { 125 int fd, d1, d2; 126 127 if (getuid() != 0) { 128 fprintf(stderr, "updatedraw test requires root, skipping\n"); 129 return 0; 130 } 131 132 fd = drm_open_any_master(); 133 134 d1 = add_drawable(fd); 135 d2 = add_drawable(fd); 136 /* Do a series of cliprect updates */ 137 set_draw_cliprects_empty(fd, d1); 138 set_draw_cliprects_empty(fd, d2); 139 set_draw_cliprects_2(fd, d1); 140 set_draw_cliprects_empty(fd, d1); 141 142 /* Remove our drawables */ 143 rm_drawable(fd, d1, 0); 144 rm_drawable(fd, d2, 0); 145 146 /* Check that removing an unknown drawable returns error */ 147 rm_drawable(fd, 0x7fffffff, 1); 148 149 /* Attempt to set cliprects on a nonexistent drawable */ 150 set_draw_cliprects_empty_fail(fd, d1); 151 152 close(fd); 153 return 0; 154 } 155