Back to index

libdrm  2.4.37
main.c
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
00021  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
00022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
00023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
00024  * USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00028 
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include "xf86drm.h"
00032 #include "libkms.h"
00033 
00034 #define CHECK_RET_RETURN(ret, str) \
00035        if (ret < 0) { \
00036               printf("%s: %s (%s)\n", __func__, str, strerror(-ret)); \
00037               return ret; \
00038        }
00039 
00040 int test_bo(struct kms_driver *kms)
00041 {
00042        struct kms_bo *bo;
00043        int ret;
00044        unsigned attrs[7] = {
00045               KMS_WIDTH, 1024,
00046               KMS_HEIGHT, 768,
00047               KMS_BO_TYPE, KMS_BO_TYPE_SCANOUT_X8R8G8B8,
00048               KMS_TERMINATE_PROP_LIST,
00049        };
00050 
00051        ret = kms_bo_create(kms, attrs, &bo);
00052        CHECK_RET_RETURN(ret, "Could not create bo");
00053 
00054        kms_bo_destroy(&bo);
00055 
00056        return 0;
00057 }
00058 
00059 char *drivers[] = {
00060        "i915",
00061        "radeon",
00062        "nouveau",
00063        "vmwgfx",
00064        NULL
00065 };
00066 
00067 int main(int argc, char** argv)
00068 {
00069        struct kms_driver *kms;
00070        int ret, fd, i;
00071 
00072        for (i = 0, fd = -1; fd < 0 && drivers[i]; i++)
00073               fd = drmOpen(drivers[i], NULL);
00074        CHECK_RET_RETURN(fd, "Could not open device");
00075 
00076        ret = kms_create(fd, &kms);
00077        CHECK_RET_RETURN(ret, "Failed to create kms driver");
00078 
00079        ret = test_bo(kms);
00080        if (ret)
00081               goto err;
00082 
00083        printf("%s: All ok!\n", __func__);
00084 
00085        kms_destroy(&kms);
00086        return 0;
00087 
00088 err:
00089        kms_destroy(&kms);
00090        return ret;
00091 }