blob: f18637df6f13f7fffdfc2b01d98b71ddb78686ef [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 Stratiienkoaa3cd542020-08-29 11:26:16 +030025#include "backend.h"
26#include "drmhwctwo.h"
27
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:
40 using backend_constructor_t = std::function<std::unique_ptr<Backend>()>;
41 static BackendManager &GetInstance();
42 int RegisterBackend(const std::string &name,
43 backend_constructor_t backend_constructor);
44 int SetBackendForDisplay(DrmHwcTwo::HwcDisplay *display);
45 std::unique_ptr<Backend> GetBackendByName(std::string &name);
46 HWC2::Error ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
47 uint32_t *num_types, uint32_t *num_requests);
48
49 private:
50 BackendManager() = default;
51
52 static const std::vector<std::string> client_devices_;
53
54 std::map<std::string, backend_constructor_t> available_backends_;
55};
56} // namespace android
57
58#endif