| /* | |
| * Copyright 2025 The Android Open Source Project | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| #pragma once | |
| #include <functional> | |
| #include <map> | |
| #include <memory> | |
| #include <string> | |
| #include <vector> | |
| #include <ui/DisplayId.h> | |
| #include <ui/DisplayMap.h> | |
| #include "DisplayHardware/DisplayMode.h" | |
| namespace android::display { | |
| // Represents a single condition to be met for rejection. | |
| struct DebugDisplaySelector { | |
| enum class Type { All, External, Id }; | |
| Type type = Type::All; | |
| std::vector<uint64_t> ids; // For Type::Id | |
| }; | |
| struct DebugDisplayModeConstraint { | |
| DebugDisplaySelector selector; | |
| uint64_t maxPixelCount = 0; | |
| }; | |
| // Verifier implementation that checks if display mode changes violate any constraints. | |
| class DebugModeConstraintVerifier { | |
| public: | |
| DebugModeConstraintVerifier(std::vector<DebugDisplayModeConstraint> constraints, | |
| std::function<bool(PhysicalDisplayId)> isExternalDisplay) | |
| : mConstraints(std::move(constraints)), | |
| mIsExternalDisplay(std::move(isExternalDisplay)) {} | |
| // Returns true if the proposed mode changes are acceptable (do not violate constraints). | |
| // currentModes: List of current active modes for all displays. | |
| // proposedModes: List of mode changes being attempted (DisplayId -> NewMode). | |
| bool shouldAccept( | |
| const std::vector<std::pair<PhysicalDisplayId, DisplayModePtr>>& currentModes, | |
| const std::vector<std::pair<PhysicalDisplayId, DisplayModePtr>>& proposedModes) const; | |
| private: | |
| std::vector<DebugDisplayModeConstraint> mConstraints; | |
| std::function<bool(PhysicalDisplayId)> mIsExternalDisplay; | |
| }; | |
| // Parses a debug string configuration into constraints. | |
| // The string format is a semicolon-separated list of rules. | |
| // Each rule is a comma-separated list of key-value pairs. | |
| // Keys: | |
| // displays: "external", "id<ID>[+id<ID>...]", "all" (default: all) | |
| // max_pixel_count: "<NUMBER>[K|M|B]" (e.g. 8M, 1920000) | |
| // | |
| // Example: "displays=external,max_pixel_count=8M" | |
| class DebugModeRejectionParser { | |
| public: | |
| // Parses the debug string and returns a vector of constraints. | |
| static std::vector<DebugDisplayModeConstraint> parse(const std::string& debugString); | |
| }; | |
| } // namespace android::display |