blob: 751cb78f0ed16c2e0f25358701411267df6b07de [file] [log] [blame]
Matvii Zorinef3c7972020-08-11 15:15:44 +03001/*
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#ifndef ANDROID_BACKEND_MANAGER_H
18#define ANDROID_BACKEND_MANAGER_H
19
Matvii Zorinef3c7972020-08-11 15:15:44 +030020#include <functional>
21#include <map>
22#include <string>
23#include <vector>
24
Roman Stratiienko13cc3662020-08-29 21:35:39 +030025#include "Backend.h"
Roman Stratiienkoaa3cd542020-08-29 11:26:16 +030026
Roman Stratiienkof815d382021-12-30 19:23:14 +020027// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
Matvii Zorinef3c7972020-08-11 15:15:44 +030028#define REGISTER_BACKEND(name_str_, backend_) \
29 static int \
30 backend = BackendManager::GetInstance() \
31 .RegisterBackend(name_str_, \
32 []() -> std::unique_ptr<Backend> { \
33 return std::make_unique<backend_>(); \
34 });
35
36namespace android {
37
38class BackendManager {
39 public:
Roman Stratiienkof815d382021-12-30 19:23:14 +020040 using BackendConstructorT = std::function<std::unique_ptr<Backend>()>;
Matvii Zorinef3c7972020-08-11 15:15:44 +030041 static BackendManager &GetInstance();
42 int RegisterBackend(const std::string &name,
Roman Stratiienkof815d382021-12-30 19:23:14 +020043 BackendConstructorT backend_constructor);
Roman Stratiienko3627beb2022-01-04 16:02:55 +020044 int SetBackendForDisplay(HwcDisplay *display);
Matvii Zorinef3c7972020-08-11 15:15:44 +030045 std::unique_ptr<Backend> GetBackendByName(std::string &name);
Roman Stratiienko3627beb2022-01-04 16:02:55 +020046 HWC2::Error ValidateDisplay(HwcDisplay *display, uint32_t *num_types,
47 uint32_t *num_requests);
Matvii Zorinef3c7972020-08-11 15:15:44 +030048
49 private:
50 BackendManager() = default;
51
Roman Stratiienkoe2f2c922021-02-13 10:57:47 +020052 static const std::vector<std::string> kClientDevices;
Matvii Zorinef3c7972020-08-11 15:15:44 +030053
Roman Stratiienkof815d382021-12-30 19:23:14 +020054 std::map<std::string, BackendConstructorT> available_backends_;
Matvii Zorinef3c7972020-08-11 15:15:44 +030055};
56} // namespace android
57
58#endif