2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "drmproperty.h"
18 #include "drmresources.h"
24 #include <xf86drmMode.h>
28 DrmProperty::DrmPropertyEnum::DrmPropertyEnum(drm_mode_property_enum *e)
29 : value_(e->value), name_(e->name) {
32 DrmProperty::DrmPropertyEnum::~DrmPropertyEnum() {
35 DrmProperty::DrmProperty(drmModePropertyPtr p, uint64_t value)
36 : id_(0), type_(DRM_PROPERTY_TYPE_INVALID), flags_(0), name_("") {
40 DrmProperty::DrmProperty()
42 type_(DRM_PROPERTY_TYPE_INVALID),
48 DrmProperty::~DrmProperty() {
51 void DrmProperty::Init(drmModePropertyPtr p, uint64_t value) {
57 for (int i = 0; i < p->count_values; ++i)
58 values_.push_back(p->values[i]);
60 for (int i = 0; i < p->count_enums; ++i)
61 enums_.push_back(DrmPropertyEnum(&p->enums[i]));
63 for (int i = 0; i < p->count_blobs; ++i)
64 blob_ids_.push_back(p->blob_ids[i]);
66 if (flags_ & DRM_MODE_PROP_RANGE)
67 type_ = DRM_PROPERTY_TYPE_INT;
68 else if (flags_ & DRM_MODE_PROP_ENUM)
69 type_ = DRM_PROPERTY_TYPE_ENUM;
70 else if (flags_ & DRM_MODE_PROP_OBJECT)
71 type_ = DRM_PROPERTY_TYPE_OBJECT;
74 uint32_t DrmProperty::id() const {
78 std::string DrmProperty::name() const {
82 int DrmProperty::value(uint64_t *value) const {
83 if (values_.size() == 0)
87 case DRM_PROPERTY_TYPE_INT:
91 case DRM_PROPERTY_TYPE_ENUM:
92 if (value_ >= enums_.size())
95 *value = enums_[value_].value_;
98 case DRM_PROPERTY_TYPE_OBJECT: