blob: 7ca62ea550f088d5febcb02c1f507ff9ddf5b777 [file] [log] [blame]
Ady Abraham838de062019-02-04 10:24:03 -08001/*
2 * Copyright 2019 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#pragma once
18
19#include <log/log.h>
20#include <vector>
21
22/*
23 * Used to represent the Display Configurations allowed to be set by SurfaceFlinger
24 */
25class AllowedDisplayConfigs {
26private:
27 // Defining ConstructorTag as private to prevent instantiating this class from outside
28 // while still allowing it to be constructed by std::make_unique
29 struct ConstructorTag {};
30
31public:
32 AllowedDisplayConfigs(ConstructorTag) {}
33
34 class Builder {
35 public:
36 Builder()
37 : mAllowedDisplayConfigs(std::make_unique<AllowedDisplayConfigs>(ConstructorTag{})) {}
38
39 std::unique_ptr<const AllowedDisplayConfigs> build() {
40 return std::move(mAllowedDisplayConfigs);
41 }
42
43 // add a config to the allowed config set
44 Builder& addConfig(int32_t config) {
45 mAllowedDisplayConfigs->addConfig(config);
46 return *this;
47 }
48
49 private:
50 std::unique_ptr<AllowedDisplayConfigs> mAllowedDisplayConfigs;
51 };
52
53 bool isConfigAllowed(int32_t config) const {
54 return (std::find(mConfigs.begin(), mConfigs.end(), config) != mConfigs.end());
55 }
56
Ady Abrahamd9b3ea62019-02-26 14:08:03 -080057 void getAllowedConfigs(std::vector<int32_t>* outConfigs) const {
58 if (outConfigs) {
59 *outConfigs = mConfigs;
60 }
61 }
62
Ady Abraham838de062019-02-04 10:24:03 -080063private:
64 // add a config to the allowed config set
65 void addConfig(int32_t config) { mConfigs.push_back(config); }
66
67 std::vector<int32_t> mConfigs;
68};