Thierry Reding | c13c504 | 2015-12-09 18:37:42 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2014 NVIDIA 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 | |
| 24 | #ifndef LIBKMS_TEST_H |
| 25 | #define LIBKMS_TEST_H |
| 26 | |
| 27 | #include <stdbool.h> |
| 28 | #include <stdint.h> |
| 29 | #include <stdlib.h> |
| 30 | |
| 31 | #include <xf86drmMode.h> |
| 32 | |
| 33 | struct kms_device { |
| 34 | int fd; |
| 35 | |
| 36 | struct kms_screen **screens; |
| 37 | unsigned int num_screens; |
| 38 | |
| 39 | struct kms_crtc **crtcs; |
| 40 | unsigned int num_crtcs; |
| 41 | |
| 42 | struct kms_plane **planes; |
| 43 | unsigned int num_planes; |
| 44 | }; |
| 45 | |
| 46 | struct kms_device *kms_device_open(int fd); |
| 47 | void kms_device_close(struct kms_device *device); |
| 48 | |
| 49 | struct kms_plane *kms_device_find_plane_by_type(struct kms_device *device, |
| 50 | uint32_t type, |
| 51 | unsigned int index); |
| 52 | |
| 53 | struct kms_crtc { |
| 54 | struct kms_device *device; |
| 55 | uint32_t id; |
| 56 | }; |
| 57 | |
| 58 | struct kms_crtc *kms_crtc_create(struct kms_device *device, uint32_t id); |
| 59 | void kms_crtc_free(struct kms_crtc *crtc); |
| 60 | |
| 61 | struct kms_framebuffer { |
| 62 | struct kms_device *device; |
| 63 | |
| 64 | unsigned int width; |
| 65 | unsigned int height; |
| 66 | unsigned int pitch; |
| 67 | uint32_t format; |
| 68 | size_t size; |
| 69 | |
| 70 | uint32_t handle; |
| 71 | uint32_t id; |
| 72 | |
| 73 | void *ptr; |
| 74 | }; |
| 75 | |
| 76 | struct kms_framebuffer *kms_framebuffer_create(struct kms_device *device, |
| 77 | unsigned int width, |
| 78 | unsigned int height, |
| 79 | uint32_t format); |
| 80 | void kms_framebuffer_free(struct kms_framebuffer *fb); |
| 81 | int kms_framebuffer_map(struct kms_framebuffer *fb, void **ptrp); |
| 82 | void kms_framebuffer_unmap(struct kms_framebuffer *fb); |
| 83 | |
| 84 | struct kms_screen { |
| 85 | struct kms_device *device; |
| 86 | bool connected; |
| 87 | uint32_t type; |
| 88 | uint32_t id; |
| 89 | |
| 90 | unsigned int width; |
| 91 | unsigned int height; |
| 92 | char *name; |
| 93 | |
| 94 | drmModeModeInfo mode; |
| 95 | }; |
| 96 | |
| 97 | struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id); |
| 98 | void kms_screen_free(struct kms_screen *screen); |
| 99 | |
| 100 | int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc, |
| 101 | struct kms_framebuffer *fb); |
| 102 | |
| 103 | struct kms_plane { |
| 104 | struct kms_device *device; |
| 105 | struct kms_crtc *crtc; |
| 106 | unsigned int type; |
| 107 | uint32_t id; |
| 108 | |
| 109 | uint32_t *formats; |
| 110 | unsigned int num_formats; |
| 111 | }; |
| 112 | |
| 113 | struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id); |
| 114 | void kms_plane_free(struct kms_plane *plane); |
| 115 | |
| 116 | int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb, |
| 117 | unsigned int x, unsigned int y); |
| 118 | bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format); |
| 119 | |
| 120 | #endif |