blob: a7db23ed4e1464f428e597b7b35f46f9c7b51404 [file] [log] [blame]
Robert Carr2047fae2016-11-28 14:09:09 -08001/*
2 * Copyright (C) 2016 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 "LayerVector.h"
18#include "Layer.h"
19
20namespace android {
Dan Stoza412903f2017-04-27 13:42:17 -070021
chaviwfd462612018-05-31 16:11:27 -070022LayerVector::LayerVector(const StateSet stateSet) : mStateSet(stateSet) {}
Dan Stoza412903f2017-04-27 13:42:17 -070023
chaviwfd462612018-05-31 16:11:27 -070024LayerVector::LayerVector(const LayerVector& rhs, const StateSet stateSet)
25 : SortedVector<sp<Layer>>(rhs), mStateSet(stateSet) {}
Robert Carr2047fae2016-11-28 14:09:09 -080026
Dan Stoza412903f2017-04-27 13:42:17 -070027LayerVector::~LayerVector() = default;
28
chaviwfd462612018-05-31 16:11:27 -070029// This operator override is needed to prevent mStateSet from getting copied over.
30LayerVector& LayerVector::operator=(const LayerVector& rhs) {
31 SortedVector::operator=(rhs);
32 return *this;
33}
34
Robert Carr2047fae2016-11-28 14:09:09 -080035int LayerVector::do_compare(const void* lhs, const void* rhs) const
36{
37 // sort layers per layer-stack, then by z-order and finally by sequence
38 const auto& l = *reinterpret_cast<const sp<Layer>*>(lhs);
39 const auto& r = *reinterpret_cast<const sp<Layer>*>(rhs);
40
Ady Abraham83729882018-12-07 12:26:48 -080041 const auto& [ls, lz] = l->getLayerStackAndZ(mStateSet);
42 const auto& [rs, rz] = r->getLayerStackAndZ(mStateSet);
chaviwfd462612018-05-31 16:11:27 -070043
Robert Carr2047fae2016-11-28 14:09:09 -080044 if (ls != rs)
Ivan Lozano80de6f32017-10-30 11:24:08 -070045 return (ls > rs) ? 1 : -1;
Robert Carr2047fae2016-11-28 14:09:09 -080046
Robert Carr2047fae2016-11-28 14:09:09 -080047 if (lz != rz)
Ivan Lozano80de6f32017-10-30 11:24:08 -070048 return (lz > rz) ? 1 : -1;
Robert Carr2047fae2016-11-28 14:09:09 -080049
Ivan Lozano80de6f32017-10-30 11:24:08 -070050 if (l->sequence == r->sequence)
51 return 0;
52
53 return (l->sequence > r->sequence) ? 1 : -1;
Robert Carr2047fae2016-11-28 14:09:09 -080054}
55
Dan Stoza412903f2017-04-27 13:42:17 -070056void LayerVector::traverseInZOrder(StateSet stateSet, const Visitor& visitor) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -070057 for (size_t i = 0; i < size(); i++) {
Robert Carrdb66e622017-04-10 16:55:57 -070058 const auto& layer = (*this)[i];
Ady Abraham83729882018-12-07 12:26:48 -080059 auto zOrderRelativeOf = layer->getZOrderRelativeOf(stateSet);
60 if (zOrderRelativeOf != nullptr) {
Robert Carrdb66e622017-04-10 16:55:57 -070061 continue;
62 }
Dan Stoza412903f2017-04-27 13:42:17 -070063 layer->traverseInZOrder(stateSet, visitor);
Robert Carr2047fae2016-11-28 14:09:09 -080064 }
65}
66
Dan Stoza412903f2017-04-27 13:42:17 -070067void LayerVector::traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const {
Robert Carr2047fae2016-11-28 14:09:09 -080068 for (auto i = static_cast<int64_t>(size()) - 1; i >= 0; i--) {
Robert Carrdb66e622017-04-10 16:55:57 -070069 const auto& layer = (*this)[i];
Ady Abraham83729882018-12-07 12:26:48 -080070 auto zOrderRelativeOf = layer->getZOrderRelativeOf(stateSet);
71 if (zOrderRelativeOf != nullptr) {
Robert Carrdb66e622017-04-10 16:55:57 -070072 continue;
73 }
Dan Stoza412903f2017-04-27 13:42:17 -070074 layer->traverseInReverseZOrder(stateSet, visitor);
Robert Carr2047fae2016-11-28 14:09:09 -080075 }
76}
77} // namespace android