2 * Copyright (C) 2018 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 #define LOG_TAG "hwc-resource-manager"
19 #include "ResourceManager.h"
26 #include "bufferinfo/BufferInfoGetter.h"
27 #include "utils/log.h"
28 #include "utils/properties.h"
32 ResourceManager::ResourceManager() : num_displays_(0) {
35 int ResourceManager::Init() {
36 char path_pattern[PROPERTY_VALUE_MAX];
37 // Could be a valid path or it can have at the end of it the wildcard %
38 // which means that it will try open all devices until an error is met.
39 int path_len = property_get("vendor.hwc.drm.device", path_pattern,
42 if (path_pattern[path_len - 1] != '%') {
43 ret = AddDrmDevice(std::string(path_pattern));
45 path_pattern[path_len - 1] = '\0';
46 for (int idx = 0; !ret; ++idx) {
47 std::ostringstream path;
48 path << path_pattern << idx;
51 if (stat(path.str().c_str(), &buf))
54 if (IsKMSDev(path.str().c_str()))
55 ret = AddDrmDevice(path.str());
60 ALOGE("Failed to initialize any displays");
61 return ret ? -EINVAL : ret;
64 char scale_with_gpu[PROPERTY_VALUE_MAX];
65 property_get("vendor.hwc.drm.scale_with_gpu", scale_with_gpu, "0");
66 scale_with_gpu_ = bool(strncmp(scale_with_gpu, "0", 1));
68 if (!BufferInfoGetter::GetInstance()) {
69 ALOGE("Failed to initialize BufferInfoGetter");
76 int ResourceManager::AddDrmDevice(const std::string &path) {
77 auto drm = std::make_unique<DrmDevice>();
78 int displays_added = 0;
80 std::tie(ret, displays_added) = drm->Init(path.c_str(), num_displays_);
81 drms_.push_back(std::move(drm));
82 num_displays_ += displays_added;
86 bool ResourceManager::IsKMSDev(const char *path) {
87 auto fd = UniqueFd(open(path, O_RDWR | O_CLOEXEC));
92 auto res = MakeDrmModeResUnique(fd.Get());
97 bool is_kms = res->count_crtcs > 0 && res->count_connectors > 0 &&
98 res->count_encoders > 0;
103 DrmDevice *ResourceManager::GetDrmDevice(int display) {
104 for (auto &drm : drms_) {
105 if (drm->HandlesDisplay(display))
110 } // namespace android