1f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu/* 2f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Copyright © 2007 Intel Corporation 3f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * 4f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Permission is hereby granted, free of charge, to any person obtaining a 5f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * copy of this software and associated documentation files (the "Software"), 6f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * to deal in the Software without restriction, including without limitation 7f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * and/or sell copies of the Software, and to permit persons to whom the 9f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Software is furnished to do so, subject to the following conditions: 10f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * 11f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * The above copyright notice and this permission notice (including the next 12f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * paragraph) shall be included in all copies or substantial portions of the 13f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Software. 14f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * 15f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * IN THE SOFTWARE. 22f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * 23f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Authors: 24f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Eric Anholt <eric@anholt.net> 25f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * 26f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu */ 27f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 28f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu#include "drmtest.h" 29f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 30f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryustatic void 31f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryuset_draw_cliprects_empty(int fd, int drawable) 32f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 33f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int ret; 34f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu struct drm_update_draw update; 35f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 36f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.handle = drawable; 37f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.type = DRM_DRAWABLE_CLIPRECTS; 38f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.num = 0; 39f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.data = 0; 40f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 41f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 42f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == 0); 43f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 44f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 45f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryustatic void 46f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryuset_draw_cliprects_empty_fail(int fd, int drawable) 47f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 48f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int ret; 49f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu struct drm_update_draw update; 50f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 51f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.handle = drawable; 52f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.type = DRM_DRAWABLE_CLIPRECTS; 53f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.num = 0; 54f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.data = 0; 55f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 56f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 57f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == -1 && errno == EINVAL); 58f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 59f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 60f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryustatic void 61f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryuset_draw_cliprects_2(int fd, int drawable) 62f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 63f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int ret; 64f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu struct drm_update_draw update; 65f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu drm_clip_rect_t rects[2]; 66f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 67f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[0].x1 = 0; 68f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[0].y1 = 0; 69f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[0].x2 = 10; 70f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[0].y2 = 10; 71f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 72f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[1].x1 = 10; 73f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[1].y1 = 10; 74f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[1].x2 = 20; 75f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rects[1].y2 = 20; 76f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 77f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.handle = drawable; 78f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.type = DRM_DRAWABLE_CLIPRECTS; 79f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.num = 2; 80f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu update.data = (unsigned long long)(uintptr_t)&rects; 81f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 82f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update); 83f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == 0); 84f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 85f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 86f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryustatic int add_drawable(int fd) 87f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 88f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu drm_draw_t drawarg; 89f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int ret; 90f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 91f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Create a drawable. 92f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * IOCTL_ADD_DRAW is RDWR, though it should really just be RD 93f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu */ 94f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu drawarg.handle = 0; 95f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg); 96f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == 0); 97f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu return drawarg.handle; 98f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 99f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 100f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryustatic int rm_drawable(int fd, int drawable, int fail) 101f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 102f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu drm_draw_t drawarg; 103f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int ret; 104f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 105f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Create a drawable. 106f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * IOCTL_ADD_DRAW is RDWR, though it should really just be RD 107f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu */ 108f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu drawarg.handle = drawable; 109f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg); 110f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu if (!fail) 111f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == 0); 112f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu else 113f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu assert(ret == -1 && errno == EINVAL); 114f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 115f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu return drawarg.handle; 116f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 117f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 118f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu/** 119f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * Tests drawable management: adding, removing, and updating the cliprects of 120f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu * drawables. 121f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu */ 122f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryuint main(int argc, char **argv) 123f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu{ 124f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu int fd, ret, d1, d2; 125f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 126f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu if (getuid() != 0) { 127f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu fprintf(stderr, "updatedraw test requires root, skipping\n"); 128f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu return 0; 129f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu } 130f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 131f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu fd = drm_open_any_master(); 132f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 133f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu d1 = add_drawable(fd); 134f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu d2 = add_drawable(fd); 135f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Do a series of cliprect updates */ 136f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu set_draw_cliprects_empty(fd, d1); 137f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu set_draw_cliprects_empty(fd, d2); 138f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu set_draw_cliprects_2(fd, d1); 139f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu set_draw_cliprects_empty(fd, d1); 140f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 141f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Remove our drawables */ 142f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rm_drawable(fd, d1, 0); 143f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rm_drawable(fd, d2, 0); 144f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 145f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Check that removing an unknown drawable returns error */ 146f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu rm_drawable(fd, 0x7fffffff, 1); 147f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 148f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu /* Attempt to set cliprects on a nonexistent drawable */ 149f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu set_draw_cliprects_empty_fail(fd, d1); 150f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu 151f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu close(fd); 152f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu return 0; 153f0352d4fde4ec179ffe04c3f834199d3bad36087Ho-Eun Ryu} 154