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 #include <errno.h> 25 #include <string.h> 26 27 #include "libkms-test.h" 28 29 static void kms_screen_probe(struct kms_screen *screen) 30 { 31 struct kms_device *device = screen->device; 32 drmModeConnector *con; 33 34 con = drmModeGetConnector(device->fd, screen->id); 35 if (!con) 36 return; 37 38 screen->type = con->connector_type; 39 40 if (con->connection == DRM_MODE_CONNECTED) 41 screen->connected = true; 42 else 43 screen->connected = false; 44 45 if (con->modes) 46 memcpy(&screen->mode, &con->modes[0], sizeof(drmModeModeInfo)); 47 48 screen->width = screen->mode.hdisplay; 49 screen->height = screen->mode.vdisplay; 50 51 drmModeFreeConnector(con); 52 } 53 54 struct kms_screen *kms_screen_create(struct kms_device *device, uint32_t id) 55 { 56 struct kms_screen *screen; 57 58 screen = calloc(1, sizeof(*screen)); 59 if (!screen) 60 return NULL; 61 62 screen->device = device; 63 screen->id = id; 64 65 kms_screen_probe(screen); 66 67 return screen; 68 } 69 70 void kms_screen_free(struct kms_screen *screen) 71 { 72 if (screen) 73 free(screen->name); 74 75 free(screen); 76 } 77 78 int kms_screen_set(struct kms_screen *screen, struct kms_crtc *crtc, 79 struct kms_framebuffer *fb) 80 { 81 struct kms_device *device = screen->device; 82 int err; 83 84 err = drmModeSetCrtc(device->fd, crtc->id, fb->id, 0, 0, &screen->id, 85 1, &screen->mode); 86 if (err < 0) 87 return -errno; 88 89 return 0; 90 } 91