Back to index

libdrm  2.4.37
updatedraw.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2007 Intel Corporation
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice (including the next
00012  * paragraph) shall be included in all copies or substantial portions of the
00013  * Software.
00014  *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00021  * IN THE SOFTWARE.
00022  *
00023  * Authors:
00024  *    Eric Anholt <eric@anholt.net>
00025  *
00026  */
00027 
00028 #include "drmtest.h"
00029 
00030 static void
00031 set_draw_cliprects_empty(int fd, int drawable)
00032 {
00033        int ret;
00034        struct drm_update_draw update;
00035 
00036        update.handle = drawable;
00037        update.type = DRM_DRAWABLE_CLIPRECTS;
00038        update.num = 0;
00039        update.data = 0;
00040 
00041        ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
00042        assert(ret == 0);
00043 }
00044 
00045 static void
00046 set_draw_cliprects_empty_fail(int fd, int drawable)
00047 {
00048        int ret;
00049        struct drm_update_draw update;
00050 
00051        update.handle = drawable;
00052        update.type = DRM_DRAWABLE_CLIPRECTS;
00053        update.num = 0;
00054        update.data = 0;
00055 
00056        ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
00057        assert(ret == -1 && errno == EINVAL);
00058 }
00059 
00060 static void
00061 set_draw_cliprects_2(int fd, int drawable)
00062 {
00063        int ret;
00064        struct drm_update_draw update;
00065        drm_clip_rect_t rects[2];
00066 
00067        rects[0].x1 = 0;
00068        rects[0].y1 = 0;
00069        rects[0].x2 = 10;
00070        rects[0].y2 = 10;
00071 
00072        rects[1].x1 = 10;
00073        rects[1].y1 = 10;
00074        rects[1].x2 = 20;
00075        rects[1].y2 = 20;
00076 
00077        update.handle = drawable;
00078        update.type = DRM_DRAWABLE_CLIPRECTS;
00079        update.num = 2;
00080        update.data = (unsigned long long)(uintptr_t)&rects;
00081 
00082        ret = ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update);
00083        assert(ret == 0);
00084 }
00085 
00086 static int add_drawable(int fd)
00087 {
00088        drm_draw_t drawarg;
00089        int ret;
00090 
00091        /* Create a drawable.
00092         * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
00093         */
00094        drawarg.handle = 0;
00095        ret = ioctl(fd, DRM_IOCTL_ADD_DRAW, &drawarg);
00096        assert(ret == 0);
00097        return drawarg.handle;
00098 }
00099 
00100 static int rm_drawable(int fd, int drawable, int fail)
00101 {
00102        drm_draw_t drawarg;
00103        int ret;
00104 
00105        /* Create a drawable.
00106         * IOCTL_ADD_DRAW is RDWR, though it should really just be RD
00107         */
00108        drawarg.handle = drawable;
00109        ret = ioctl(fd, DRM_IOCTL_RM_DRAW, &drawarg);
00110        if (!fail)
00111               assert(ret == 0);
00112        else
00113               assert(ret == -1 && errno == EINVAL);
00114 
00115        return drawarg.handle;
00116 }
00117 
00122 int main(int argc, char **argv)
00123 {
00124        int fd, ret, d1, d2;
00125 
00126        if (getuid() != 0) {
00127               fprintf(stderr, "updatedraw test requires root, skipping\n");
00128               return 0;
00129        }
00130 
00131        fd = drm_open_any_master();
00132 
00133        d1 = add_drawable(fd);
00134        d2 = add_drawable(fd);
00135        /* Do a series of cliprect updates */
00136        set_draw_cliprects_empty(fd, d1);
00137        set_draw_cliprects_empty(fd, d2);
00138        set_draw_cliprects_2(fd, d1);
00139        set_draw_cliprects_empty(fd, d1);
00140 
00141        /* Remove our drawables */
00142        rm_drawable(fd, d1, 0);
00143        rm_drawable(fd, d2, 0);
00144 
00145        /* Check that removing an unknown drawable returns error */
00146        rm_drawable(fd, 0x7fffffff, 1);
00147 
00148        /* Attempt to set cliprects on a nonexistent drawable */
00149        set_draw_cliprects_empty_fail(fd, d1);
00150 
00151        close(fd);
00152        return 0;
00153 }