• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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-backend"
18 
19 #include "BackendManager.h"
20 
21 #include "utils/log.h"
22 #include "utils/properties.h"
23 
24 namespace android {
25 
26 // NOLINTNEXTLINE(cert-err58-cpp)
27 const std::vector<std::string> BackendManager::kClientDevices = {
28     "kirin",
29     "mediatek-drm",
30 };
31 
GetInstance()32 BackendManager &BackendManager::GetInstance() {
33   static BackendManager backend_manager;
34 
35   return backend_manager;
36 }
37 
RegisterBackend(const std::string & name,BackendConstructorT backend_constructor)38 int BackendManager::RegisterBackend(const std::string &name,
39                                     BackendConstructorT backend_constructor) {
40   available_backends_[name] = std::move(backend_constructor);
41   return 0;
42 }
43 
SetBackendForDisplay(HwcDisplay * display)44 int BackendManager::SetBackendForDisplay(HwcDisplay *display) {
45   std::string driver_name(display->GetPipe().device->GetName());
46   char backend_override[PROPERTY_VALUE_MAX];
47   property_get("vendor.hwc.backend_override", backend_override,
48                driver_name.c_str());
49   std::string backend_name(backend_override);
50 
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(),
55           display->GetPipe().connector->Get()->GetName().c_str(),
56           driver_name.c_str());
57     return -EINVAL;
58   }
59 
60   ALOGI("Backend '%s' for '%s' and driver '%s' was successfully set",
61         backend_name.c_str(),
62         display->GetPipe().connector->Get()->GetName().c_str(),
63         driver_name.c_str());
64 
65   return 0;
66 }
67 
GetBackendByName(std::string & name)68 std::unique_ptr<Backend> BackendManager::GetBackendByName(std::string &name) {
69   if (available_backends_.empty()) {
70     ALOGE("No backends are specified");
71     return nullptr;
72   }
73 
74   auto it = available_backends_.find(name);
75   if (it == available_backends_.end()) {
76     auto it = std::find(kClientDevices.begin(), kClientDevices.end(), name);
77     name = it == kClientDevices.end() ? "generic" : "client";
78   }
79 
80   return available_backends_[name]();
81 }
82 }  // namespace android
83