2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-08-18 05:25:22 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-11 00:59:06 +03:00
|
|
|
#include <AK/Platform.h>
|
2022-07-16 08:33:17 +03:00
|
|
|
#include <AK/ScopeGuard.h>
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <fcntl.h>
|
2020-08-11 00:59:06 +03:00
|
|
|
#include <stddef.h>
|
2022-07-16 08:33:17 +03:00
|
|
|
#include <stdio.h>
|
2019-08-18 05:25:22 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/ioctl.h>
|
2022-07-16 08:33:17 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/sysmacros.h>
|
|
|
|
#include <unistd.h>
|
2019-08-18 05:25:22 +03:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2022-04-30 14:57:03 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_get_properties(int fd, GraphicsConnectorProperties* info)
|
2019-08-18 05:25:22 +03:00
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_GET_PROPERTIES, info);
|
2019-08-18 05:25:22 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:57:03 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_get_head_edid(int fd, GraphicsHeadEDID* info)
|
2022-01-01 08:02:55 +03:00
|
|
|
{
|
2022-07-16 08:33:17 +03:00
|
|
|
// FIXME: Optimize this function to get a minor number instead of a file descriptor.
|
|
|
|
struct stat display_connector_stat;
|
|
|
|
if (auto rc = fstat(fd, &display_connector_stat); rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
auto minor_number = minor(display_connector_stat.st_rdev);
|
|
|
|
|
|
|
|
auto edid_fd = open(String::formatted("/sys/devices/graphics/connectors/{}/edid", minor_number).characters(), O_RDONLY);
|
|
|
|
if (edid_fd < 0) {
|
|
|
|
return edid_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeGuard close_on_return([&]() {
|
|
|
|
close(edid_fd);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (auto rc = read(edid_fd, info->bytes, info->bytes_size); rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2022-01-01 08:02:55 +03:00
|
|
|
}
|
|
|
|
|
2022-06-10 14:16:28 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_set_responsible(int fd)
|
|
|
|
{
|
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_SET_RESPONSIBLE, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ALWAYS_INLINE int graphics_connector_unset_responsible(int fd)
|
|
|
|
{
|
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_UNSET_RESPONSIBLE, nullptr);
|
|
|
|
}
|
|
|
|
|
2022-04-30 14:54:46 +03:00
|
|
|
ALWAYS_INLINE int fb_get_head_vertical_offset_buffer(int fd, GraphicsHeadVerticalOffset* vertical_offset)
|
2019-08-18 05:25:22 +03:00
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_GET_HEAD_VERTICAL_OFFSET_BUFFER, vertical_offset);
|
2019-08-18 05:25:22 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:54:46 +03:00
|
|
|
ALWAYS_INLINE int fb_set_head_vertical_offset_buffer(int fd, GraphicsHeadVerticalOffset* vertical_offset)
|
2019-08-18 05:25:22 +03:00
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_SET_HEAD_VERTICAL_OFFSET_BUFFER, vertical_offset);
|
2019-08-18 05:25:22 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:57:03 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_set_head_mode_setting(int fd, GraphicsHeadModeSetting* mode_setting)
|
2022-04-29 17:56:24 +03:00
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_SET_HEAD_MODE_SETTING, mode_setting);
|
2022-04-29 17:56:24 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:57:03 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_set_safe_head_mode_setting(int fd)
|
2022-04-29 20:11:42 +03:00
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_SET_SAFE_HEAD_MODE_SETTING, nullptr);
|
2022-04-29 20:11:42 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 14:57:03 +03:00
|
|
|
ALWAYS_INLINE int graphics_connector_get_head_mode_setting(int fd, GraphicsHeadModeSetting* mode_setting)
|
2022-04-29 17:56:24 +03:00
|
|
|
{
|
2022-04-30 14:54:46 +03:00
|
|
|
GraphicsHeadModeSetting head_mode_setting;
|
2022-04-30 14:49:51 +03:00
|
|
|
if (auto rc = ioctl(fd, GRAPHICS_IOCTL_GET_HEAD_MODE_SETTING, &head_mode_setting); rc < 0)
|
2022-04-29 17:56:24 +03:00
|
|
|
return rc;
|
|
|
|
mode_setting->horizontal_stride = head_mode_setting.horizontal_stride;
|
|
|
|
mode_setting->pixel_clock_in_khz = head_mode_setting.pixel_clock_in_khz;
|
|
|
|
mode_setting->horizontal_active = head_mode_setting.horizontal_active;
|
|
|
|
mode_setting->horizontal_front_porch_pixels = head_mode_setting.horizontal_front_porch_pixels;
|
|
|
|
mode_setting->horizontal_sync_time_pixels = head_mode_setting.horizontal_sync_time_pixels;
|
|
|
|
mode_setting->horizontal_blank_pixels = head_mode_setting.horizontal_blank_pixels;
|
|
|
|
mode_setting->vertical_active = head_mode_setting.vertical_active;
|
|
|
|
mode_setting->vertical_front_porch_lines = head_mode_setting.vertical_front_porch_lines;
|
|
|
|
mode_setting->vertical_sync_time_lines = head_mode_setting.vertical_sync_time_lines;
|
|
|
|
mode_setting->vertical_blank_lines = head_mode_setting.vertical_blank_lines;
|
|
|
|
mode_setting->horizontal_offset = head_mode_setting.horizontal_offset;
|
|
|
|
mode_setting->vertical_offset = head_mode_setting.vertical_offset;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-03 21:43:35 +03:00
|
|
|
ALWAYS_INLINE int fb_flush_buffers(int fd, int index, FBRect const* rects, unsigned count)
|
2021-06-12 15:46:54 +03:00
|
|
|
{
|
2021-07-03 21:43:35 +03:00
|
|
|
FBFlushRects fb_flush_rects;
|
|
|
|
fb_flush_rects.buffer_index = index;
|
|
|
|
fb_flush_rects.count = count;
|
|
|
|
fb_flush_rects.rects = rects;
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_FLUSH_HEAD_BUFFERS, &fb_flush_rects);
|
2021-06-12 15:46:54 +03:00
|
|
|
}
|
|
|
|
|
2022-04-30 13:55:00 +03:00
|
|
|
ALWAYS_INLINE int fb_flush_head(int fd)
|
|
|
|
{
|
2022-04-30 14:49:51 +03:00
|
|
|
return ioctl(fd, GRAPHICS_IOCTL_FLUSH_HEAD, nullptr);
|
2022-04-30 13:55:00 +03:00
|
|
|
}
|
|
|
|
|
2019-08-18 05:25:22 +03:00
|
|
|
__END_DECLS
|