Ady Abraham | 838de06 | 2019-02-04 10:24:03 -0800 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 25 | class AllowedDisplayConfigs { |
| 26 | private: |
| 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 | |
| 31 | public: |
| 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 | |
| 57 | private: |
| 58 | // add a config to the allowed config set |
| 59 | void addConfig(int32_t config) { mConfigs.push_back(config); } |
| 60 | |
| 61 | std::vector<int32_t> mConfigs; |
| 62 | }; |