Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, |
| 22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | |
Jakob Bornecrantz | 5dbc1b3 | 2010-01-05 20:55:02 +0100 | [diff] [blame] | 29 | #include "config.h" |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 30 | #include <errno.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include "internal.h" |
| 34 | |
| 35 | int kms_create(int fd, struct kms_driver **out) |
| 36 | { |
Jakob Bornecrantz | d920fa9 | 2010-01-12 17:53:49 +0000 | [diff] [blame] | 37 | return linux_create(fd, out); |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int kms_get_prop(struct kms_driver *kms, unsigned key, unsigned *out) |
| 41 | { |
| 42 | switch (key) { |
Jakob Bornecrantz | 44a0e0a | 2010-01-23 01:41:49 +0000 | [diff] [blame] | 43 | case KMS_BO_TYPE: |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 44 | break; |
| 45 | default: |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | return kms->get_prop(kms, key, out); |
| 49 | } |
| 50 | |
Jakob Bornecrantz | 201f579 | 2009-12-04 16:06:42 +0100 | [diff] [blame] | 51 | int kms_destroy(struct kms_driver **kms) |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 52 | { |
Jakob Bornecrantz | 201f579 | 2009-12-04 16:06:42 +0100 | [diff] [blame] | 53 | if (!(*kms)) |
| 54 | return 0; |
| 55 | |
| 56 | free(*kms); |
| 57 | *kms = NULL; |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int kms_bo_create(struct kms_driver *kms, const unsigned *attr, struct kms_bo **out) |
| 62 | { |
| 63 | unsigned width = 0; |
| 64 | unsigned height = 0; |
Jakob Bornecrantz | 44a0e0a | 2010-01-23 01:41:49 +0000 | [diff] [blame] | 65 | enum kms_bo_type type = KMS_BO_TYPE_SCANOUT_X8R8G8B8; |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 66 | int i; |
| 67 | |
| 68 | for (i = 0; attr[i];) { |
| 69 | unsigned key = attr[i++]; |
| 70 | unsigned value = attr[i++]; |
| 71 | |
| 72 | switch (key) { |
| 73 | case KMS_WIDTH: |
| 74 | width = value; |
| 75 | break; |
| 76 | case KMS_HEIGHT: |
| 77 | height = value; |
| 78 | break; |
| 79 | case KMS_BO_TYPE: |
| 80 | type = value; |
| 81 | break; |
| 82 | default: |
| 83 | return EINVAL; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (width == 0 || height == 0) |
| 88 | return -EINVAL; |
| 89 | |
Jakob Bornecrantz | 44a0e0a | 2010-01-23 01:41:49 +0000 | [diff] [blame] | 90 | /* XXX sanity check type */ |
| 91 | |
| 92 | if (type == KMS_BO_TYPE_CURSOR_64X64_A8R8G8B8 && |
| 93 | (width != 64 || height != 64)) |
| 94 | return -EINVAL; |
| 95 | |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 96 | return kms->bo_create(kms, width, height, type, attr, out); |
| 97 | } |
| 98 | |
| 99 | int kms_bo_get_prop(struct kms_bo *bo, unsigned key, unsigned *out) |
| 100 | { |
| 101 | switch (key) { |
| 102 | case KMS_PITCH: |
| 103 | *out = bo->pitch; |
| 104 | break; |
| 105 | case KMS_HANDLE: |
| 106 | *out = bo->handle; |
| 107 | break; |
| 108 | default: |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | int kms_bo_map(struct kms_bo *bo, void **out) |
| 116 | { |
| 117 | return bo->kms->bo_map(bo, out); |
| 118 | } |
| 119 | |
| 120 | int kms_bo_unmap(struct kms_bo *bo) |
| 121 | { |
| 122 | return bo->kms->bo_unmap(bo); |
| 123 | } |
| 124 | |
Jakob Bornecrantz | 201f579 | 2009-12-04 16:06:42 +0100 | [diff] [blame] | 125 | int kms_bo_destroy(struct kms_bo **bo) |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 126 | { |
Jakob Bornecrantz | 201f579 | 2009-12-04 16:06:42 +0100 | [diff] [blame] | 127 | int ret; |
| 128 | |
| 129 | if (!(*bo)) |
| 130 | return 0; |
| 131 | |
| 132 | ret = (*bo)->kms->bo_destroy(*bo); |
| 133 | if (ret) |
| 134 | return ret; |
| 135 | |
| 136 | *bo = NULL; |
| 137 | return 0; |
Jakob Bornecrantz | 8c0571a | 2009-11-24 17:54:10 +0100 | [diff] [blame] | 138 | } |