blob: d9fdb37d17709a66e3ec94ee1c05228b4ac5998d [file] [log] [blame]
Sean Paul6a55e9f2015-04-30 15:31:06 -04001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Roman Stratiienko13cc3662020-08-29 21:35:39 +030017#include "DrmMode.h"
18
Roman Stratiienkod518a052021-02-25 19:15:14 +020019#include <cstring>
20
Roman Stratiienko13cc3662020-08-29 21:35:39 +030021#include "DrmDevice.h"
Sean Paul6a55e9f2015-04-30 15:31:06 -040022
Sean Paul6a55e9f2015-04-30 15:31:06 -040023namespace android {
24
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020025DrmMode::DrmMode(drmModeModeInfoPtr m) : mode_(*m){};
Sean Paul6a55e9f2015-04-30 15:31:06 -040026
Sean Paul6a55e9f2015-04-30 15:31:06 -040027bool DrmMode::operator==(const drmModeModeInfo &m) const {
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020028 return memcmp(&m, &mode_, offsetof(drmModeModeInfo, name)) == 0;
Sean Paul6a55e9f2015-04-30 15:31:06 -040029}
Roman Stratiienko40b374b2021-10-22 18:13:09 +030030
Drew Davenporte60540f2025-02-07 12:18:43 -070031bool DrmMode::SameSize(const DrmMode &mode) const {
32 return (mode_.vdisplay == mode.mode_.vdisplay) &&
33 (mode_.hdisplay == mode.mode_.hdisplay);
34}
35
Roman Stratiienko40b374b2021-10-22 18:13:09 +030036auto DrmMode::CreateModeBlob(const DrmDevice &drm)
37 -> DrmModeUserPropertyBlobUnique {
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020038 struct drm_mode_modeinfo drm_mode = {};
39 /* drm_mode_modeinfo and drmModeModeInfo should be identical
40 * At least libdrm does the same memcpy in drmModeAttachMode();
41 */
42 memcpy(&drm_mode, &mode_, sizeof(struct drm_mode_modeinfo));
Roman Stratiienko40b374b2021-10-22 18:13:09 +030043
44 return drm.RegisterUserPropertyBlob(&drm_mode,
Roman Stratiienkodf3120f2022-12-07 23:10:55 +020045 sizeof(struct drm_mode_modeinfo));
Roman Stratiienko40b374b2021-10-22 18:13:09 +030046}
47
Sean Paulf72cccd2018-08-27 13:59:08 -040048} // namespace android