2 * Copyright (C) 2020 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-backend"
19 #include "BackendManager.h"
21 #include "utils/log.h"
22 #include "utils/properties.h"
26 // NOLINTNEXTLINE(cert-err58-cpp)
27 const std::vector<std::string> BackendManager::kClientDevices = {
32 BackendManager &BackendManager::GetInstance() {
33 static BackendManager backend_manager;
35 return backend_manager;
38 int BackendManager::RegisterBackend(const std::string &name,
39 BackendConstructorT backend_constructor) {
40 available_backends_[name] = std::move(backend_constructor);
44 int BackendManager::SetBackendForDisplay(HwcDisplay *display) {
45 std::string driver_name(display->drm()->GetName());
46 char backend_override[PROPERTY_VALUE_MAX];
47 property_get("vendor.hwc.backend_override", backend_override,
49 std::string backend_name(backend_override);
51 display->set_backend(GetBackendByName(backend_name));
52 if (display->backend() == nullptr) {
53 ALOGE("Failed to set backend '%s' for '%s' and driver '%s'",
54 backend_name.c_str(), display->connector()->GetName().c_str(),
59 ALOGI("Backend '%s' for '%s' and driver '%s' was successfully set",
60 backend_name.c_str(), display->connector()->GetName().c_str(),
66 std::unique_ptr<Backend> BackendManager::GetBackendByName(std::string &name) {
67 if (available_backends_.empty()) {
68 ALOGE("No backends are specified");
72 auto it = available_backends_.find(name);
73 if (it == available_backends_.end()) {
74 auto it = std::find(kClientDevices.begin(), kClientDevices.end(), name);
75 name = it == kClientDevices.end() ? "generic" : "client";
78 return available_backends_[name]();
80 } // namespace android