Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 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 | |
Roman Stratiienko | bde9566 | 2022-12-10 20:27:58 +0200 | [diff] [blame] | 17 | #pragma once |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 18 | |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 19 | #include <functional> |
| 20 | #include <map> |
| 21 | #include <string> |
| 22 | #include <vector> |
| 23 | |
Roman Stratiienko | 13cc366 | 2020-08-29 21:35:39 +0300 | [diff] [blame] | 24 | #include "Backend.h" |
Roman Stratiienko | aa3cd54 | 2020-08-29 11:26:16 +0300 | [diff] [blame] | 25 | |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 26 | // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 27 | #define REGISTER_BACKEND(name_str_, backend_) \ |
| 28 | static int \ |
| 29 | backend = BackendManager::GetInstance() \ |
| 30 | .RegisterBackend(name_str_, \ |
| 31 | []() -> std::unique_ptr<Backend> { \ |
| 32 | return std::make_unique<backend_>(); \ |
| 33 | }); |
| 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | class BackendManager { |
| 38 | public: |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 39 | using BackendConstructorT = std::function<std::unique_ptr<Backend>()>; |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 40 | static BackendManager &GetInstance(); |
| 41 | int RegisterBackend(const std::string &name, |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 42 | BackendConstructorT backend_constructor); |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 43 | int SetBackendForDisplay(HwcDisplay *display); |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 44 | std::unique_ptr<Backend> GetBackendByName(std::string &name); |
Roman Stratiienko | 3627beb | 2022-01-04 16:02:55 +0200 | [diff] [blame] | 45 | HWC2::Error ValidateDisplay(HwcDisplay *display, uint32_t *num_types, |
| 46 | uint32_t *num_requests); |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | BackendManager() = default; |
| 50 | |
Roman Stratiienko | e2f2c92 | 2021-02-13 10:57:47 +0200 | [diff] [blame] | 51 | static const std::vector<std::string> kClientDevices; |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 52 | |
Roman Stratiienko | f815d38 | 2021-12-30 19:23:14 +0200 | [diff] [blame] | 53 | std::map<std::string, BackendConstructorT> available_backends_; |
Matvii Zorin | ef3c797 | 2020-08-11 15:15:44 +0300 | [diff] [blame] | 54 | }; |
| 55 | } // namespace android |