1 /*
2  * Copyright 2022 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_HWC_DISPLAYCHANGES_H
18 #define ANDROID_HWC_DISPLAYCHANGES_H
19 
20 #include <aidl/android/hardware/graphics/composer3/ChangedCompositionLayer.h>
21 #include <aidl/android/hardware/graphics/composer3/ChangedCompositionTypes.h>
22 #include <aidl/android/hardware/graphics/composer3/DisplayRequest.h>
23 
24 #include <optional>
25 
26 namespace aidl::android::hardware::graphics::composer3::impl {
27 
28 struct DisplayChanges {
29     std::optional<ChangedCompositionTypes> compositionChanges;
30     std::optional<DisplayRequest> displayRequestChanges;
31 
addLayerCompositionChangeDisplayChanges32     void addLayerCompositionChange(int64_t displayId, int64_t layerId,
33                                    Composition layerComposition) {
34         if (!compositionChanges) {
35             compositionChanges.emplace();
36             compositionChanges->display = displayId;
37         }
38 
39         ChangedCompositionLayer compositionChange;
40         compositionChange.layer = layerId;
41         compositionChange.composition = layerComposition;
42         compositionChanges->layers.emplace_back(std::move(compositionChange));
43     }
44 
clearLayerCompositionChangesDisplayChanges45     void clearLayerCompositionChanges() { compositionChanges.reset(); }
46 
hasAnyChangesDisplayChanges47     bool hasAnyChanges() const {
48         return compositionChanges.has_value() || displayRequestChanges.has_value();
49     }
50 
resetDisplayChanges51     void reset() {
52         compositionChanges.reset();
53         displayRequestChanges.reset();
54     }
55 };
56 
57 }  // namespace aidl::android::hardware::graphics::composer3::impl
58 
59 #endif