| /* | |
| * Copyright 2024 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 <set> | |
| #include <unordered_map> | |
| #include <unordered_set> | |
| #include <vector> | |
| namespace android::adpf { | |
| // Maintains a bi-directional mapping between ADPF Session IDs and SurfaceFlinger Layer IDs. | |
| // This allows querying which layers are monitored by a given ADPF session and which ADPF sessions | |
| // monitor a given SurfaceFlinger layer. | |
| class SessionLayerMap { | |
| public: | |
| // Inform the SessionLayerMap about dead sessions | |
| void notifySessionsDied(const std::vector<int32_t>& sessions); | |
| // Inform the SessionLayerMap about dead layers | |
| void notifyLayersDied(const std::vector<int32_t>& layers); | |
| // Associate a session with a specific set of layer ids | |
| bool bindSessionIDToLayers(const int32_t sessionId, std::vector<int32_t> layerIds); | |
| // Get the set of sessions that are mapped to a specific layer id | |
| std::vector<int32_t> getAssociatedSessions(const int32_t layerId) const; | |
| // Find out whether a given layer should be tracked | |
| bool isLayerRelevant(const int32_t layerId) const; | |
| // Gets the set of layers that changed. This clears the internal update state tracking. | |
| std::vector<int32_t> extractUpdatedLayers(); | |
| // Is there any active mapping between sessions and layers currently | |
| bool isIdle() const; | |
| private: | |
| void unbindSessionFromLayer(const int32_t layerId, const int32_t sessionId); | |
| void unbindLayerFromSession(const int32_t layerId, const int32_t sessionId); | |
| std::unordered_map<int32_t, std::vector<int32_t>> mSessionToLayers; | |
| std::unordered_map<int32_t, std::vector<int32_t>> mLayerToSessions; | |
| std::vector<int32_t> mUpdatedLayers; | |
| }; | |
| } // namespace android::adpf |