Brian Lindahl | f5fdff8 | 2024-11-01 09:28:47 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2024 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 | #include "ActivePictureUpdater.h" |
| 18 | |
| 19 | #include <algorithm> |
| 20 | |
| 21 | #include "Layer.h" |
| 22 | #include "LayerFE.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | void ActivePictureUpdater::onLayerComposed(const Layer& layer, const LayerFE& layerFE, |
| 27 | const CompositionResult& result) { |
| 28 | if (result.wasPictureProfileCommitted) { |
| 29 | gui::ActivePicture picture; |
| 30 | picture.layerId = int32_t(layer.sequence); |
| 31 | picture.ownerUid = int32_t(layer.getOwnerUid()); |
| 32 | // TODO(b/337330263): Why does LayerFE coming from SF have a null composition state? |
| 33 | if (layerFE.getCompositionState()) { |
| 34 | picture.pictureProfileId = layerFE.getCompositionState()->pictureProfileHandle.getId(); |
| 35 | } else { |
| 36 | picture.pictureProfileId = result.pictureProfileHandle.getId(); |
| 37 | } |
| 38 | mNewActivePictures.push_back(picture); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | bool ActivePictureUpdater::updateAndHasChanged() { |
| 43 | bool hasChanged = true; |
| 44 | if (mNewActivePictures.size() == mOldActivePictures.size()) { |
| 45 | auto compare = [](const gui::ActivePicture& lhs, const gui::ActivePicture& rhs) -> int { |
| 46 | if (lhs.layerId == rhs.layerId) { |
| 47 | return lhs.pictureProfileId < rhs.pictureProfileId; |
| 48 | } |
| 49 | return lhs.layerId < rhs.layerId; |
| 50 | }; |
| 51 | std::sort(mNewActivePictures.begin(), mNewActivePictures.end(), compare); |
| 52 | if (std::equal(mNewActivePictures.begin(), mNewActivePictures.end(), |
| 53 | mOldActivePictures.begin())) { |
| 54 | hasChanged = false; |
| 55 | } |
| 56 | } |
| 57 | std::swap(mOldActivePictures, mNewActivePictures); |
| 58 | mNewActivePictures.resize(0); |
| 59 | return hasChanged; |
| 60 | } |
| 61 | |
| 62 | const std::vector<gui::ActivePicture>& ActivePictureUpdater::getActivePictures() const { |
| 63 | return mOldActivePictures; |
| 64 | } |
| 65 | |
| 66 | } // namespace android |