2 * Copyright © 2014 NVIDIA Corporation
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:
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
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
27 #include "libkms-test.h"
29 static int kms_plane_probe(struct kms_plane *plane)
31 struct kms_device *device = plane->device;
32 drmModeObjectPropertiesPtr props;
36 p = drmModeGetPlane(device->fd, plane->id);
40 /* TODO: allow dynamic assignment to CRTCs */
41 if (p->crtc_id == 0) {
42 for (i = 0; i < device->num_crtcs; i++) {
43 if (p->possible_crtcs & (1 << i)) {
44 p->crtc_id = device->crtcs[i]->id;
50 for (i = 0; i < device->num_crtcs; i++) {
51 if (device->crtcs[i]->id == p->crtc_id) {
52 plane->crtc = device->crtcs[i];
57 plane->formats = calloc(p->count_formats, sizeof(uint32_t));
58 if (!plane->formats) {
63 for (i = 0; i < p->count_formats; i++)
64 plane->formats[i] = p->formats[i];
66 plane->num_formats = p->count_formats;
70 props = drmModeObjectGetProperties(device->fd, plane->id,
71 DRM_MODE_OBJECT_PLANE);
75 for (i = 0; i < props->count_props; i++) {
76 drmModePropertyPtr prop;
78 prop = drmModeGetProperty(device->fd, props->props[i]);
80 if (strcmp(prop->name, "type") == 0)
81 plane->type = props->prop_values[i];
83 drmModeFreeProperty(prop);
87 drmModeFreeObjectProperties(props);
92 struct kms_plane *kms_plane_create(struct kms_device *device, uint32_t id)
94 struct kms_plane *plane;
96 plane = calloc(1, sizeof(*plane));
100 plane->device = device;
103 kms_plane_probe(plane);
108 void kms_plane_free(struct kms_plane *plane)
113 int kms_plane_set(struct kms_plane *plane, struct kms_framebuffer *fb,
114 unsigned int x, unsigned int y)
116 struct kms_device *device = plane->device;
119 err = drmModeSetPlane(device->fd, plane->id, plane->crtc->id, fb->id,
120 0, x, y, fb->width, fb->height, 0 << 16,
121 0 << 16, fb->width << 16, fb->height << 16);
128 bool kms_plane_supports_format(struct kms_plane *plane, uint32_t format)
132 for (i = 0; i < plane->num_formats; i++)
133 if (plane->formats[i] == format)