Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 17 | #define LOG_TAG "hwc-resource-manager" |
| 18 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 19 | #include "ResourceManager.h" |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 20 | |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 21 | #include <fcntl.h> |
Matvii Zorin | ec75ccd | 2020-07-17 12:08:45 +0300 | [diff] [blame] | 22 | #include <sys/stat.h> |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 23 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 24 | #include <sstream> |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 25 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 26 | #include "bufferinfo/BufferInfoGetter.h" |
Roman Stratiienko | d518a05 | 2021-02-25 19:15:14 +0200 | [diff] [blame] | 27 | #include "utils/log.h" |
Roman Stratiienko | d21071f | 2021-03-09 21:56:50 +0200 | [diff] [blame] | 28 | #include "utils/properties.h" |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 29 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 30 | namespace android { |
| 31 | |
Roman Stratiienko | 123cdb0 | 2021-09-29 12:47:00 +0300 | [diff] [blame] | 32 | ResourceManager::ResourceManager() : num_displays_(0) { |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 33 | } |
| 34 | |
| 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. |
Jason Macnak | f1af957 | 2020-08-20 11:49:51 -0700 | [diff] [blame] | 39 | int path_len = property_get("vendor.hwc.drm.device", path_pattern, |
| 40 | "/dev/dri/card%"); |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 41 | int ret = 0; |
| 42 | if (path_pattern[path_len - 1] != '%') { |
| 43 | ret = AddDrmDevice(std::string(path_pattern)); |
| 44 | } else { |
| 45 | path_pattern[path_len - 1] = '\0'; |
| 46 | for (int idx = 0; !ret; ++idx) { |
| 47 | std::ostringstream path; |
| 48 | path << path_pattern << idx; |
Matvii Zorin | ec75ccd | 2020-07-17 12:08:45 +0300 | [diff] [blame] | 49 | |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 50 | struct stat buf {}; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 51 | if (stat(path.str().c_str(), &buf)) |
Matvii Zorin | ec75ccd | 2020-07-17 12:08:45 +0300 | [diff] [blame] | 52 | break; |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 53 | |
Roman Stratiienko | 56f4adc | 2021-09-29 12:47:12 +0300 | [diff] [blame^] | 54 | if (DrmDevice::IsKMSDev(path.str().c_str())) |
Matvii Zorin | ec75ccd | 2020-07-17 12:08:45 +0300 | [diff] [blame] | 55 | ret = AddDrmDevice(path.str()); |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | if (!num_displays_) { |
| 60 | ALOGE("Failed to initialize any displays"); |
| 61 | return ret ? -EINVAL : ret; |
| 62 | } |
| 63 | |
Roman Stratiienko | 65f2ba8 | 2019-12-20 17:04:01 +0200 | [diff] [blame] | 64 | char scale_with_gpu[PROPERTY_VALUE_MAX]; |
Jason Macnak | f1af957 | 2020-08-20 11:49:51 -0700 | [diff] [blame] | 65 | property_get("vendor.hwc.drm.scale_with_gpu", scale_with_gpu, "0"); |
Roman Stratiienko | 65f2ba8 | 2019-12-20 17:04:01 +0200 | [diff] [blame] | 66 | scale_with_gpu_ = bool(strncmp(scale_with_gpu, "0", 1)); |
| 67 | |
Roman Stratiienko | b2e9fe2 | 2020-10-03 10:52:36 +0300 | [diff] [blame] | 68 | if (!BufferInfoGetter::GetInstance()) { |
| 69 | ALOGE("Failed to initialize BufferInfoGetter"); |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
Roman Stratiienko | 123cdb0 | 2021-09-29 12:47:00 +0300 | [diff] [blame] | 73 | return 0; |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Roman Stratiienko | 8666dc9 | 2021-02-09 17:49:55 +0200 | [diff] [blame] | 76 | int ResourceManager::AddDrmDevice(const std::string &path) { |
| 77 | auto drm = std::make_unique<DrmDevice>(); |
Roman Stratiienko | b3b5c1e | 2021-02-15 13:44:19 +0200 | [diff] [blame] | 78 | int displays_added = 0; |
| 79 | int ret = 0; |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 80 | std::tie(ret, displays_added) = drm->Init(path.c_str(), num_displays_); |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 81 | drms_.push_back(std::move(drm)); |
| 82 | num_displays_ += displays_added; |
| 83 | return ret; |
| 84 | } |
| 85 | |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 86 | DrmDevice *ResourceManager::GetDrmDevice(int display) { |
| 87 | for (auto &drm : drms_) { |
| 88 | if (drm->HandlesDisplay(display)) |
| 89 | return drm.get(); |
| 90 | } |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 91 | return nullptr; |
Alexandru Gheorghe | c546358 | 2018-03-27 15:52:02 +0100 | [diff] [blame] | 92 | } |
Sean Paul | f72cccd | 2018-08-27 13:59:08 -0400 | [diff] [blame] | 93 | } // namespace android |