blob: 7ba6ad3bfab64be06b1d205871d806f98afef473 [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 {
21LayerVector::LayerVector(const LayerVector& rhs) : SortedVector<sp<Layer>>(rhs) {
22}
23
24int LayerVector::do_compare(const void* lhs, const void* rhs) const
25{
26 // sort layers per layer-stack, then by z-order and finally by sequence
27 const auto& l = *reinterpret_cast<const sp<Layer>*>(lhs);
28 const auto& r = *reinterpret_cast<const sp<Layer>*>(rhs);
29
30 uint32_t ls = l->getCurrentState().layerStack;
31 uint32_t rs = r->getCurrentState().layerStack;
32 if (ls != rs)
33 return ls - rs;
34
35 uint32_t lz = l->getCurrentState().z;
36 uint32_t rz = r->getCurrentState().z;
37 if (lz != rz)
38 return lz - rz;
39
40 return l->sequence - r->sequence;
41}
42
43void LayerVector::traverseInZOrder(const std::function<void(Layer*)>& consume) const {
Robert Carr1f0a16a2016-10-24 16:27:39 -070044 for (size_t i = 0; i < size(); i++) {
45 (*this)[i]->traverseInZOrder(consume);
Robert Carr2047fae2016-11-28 14:09:09 -080046 }
47}
48
49void LayerVector::traverseInReverseZOrder(const std::function<void(Layer*)>& consume) const {
50 for (auto i = static_cast<int64_t>(size()) - 1; i >= 0; i--) {
Robert Carr1f0a16a2016-10-24 16:27:39 -070051 (*this)[i]->traverseInReverseZOrder(consume);
Robert Carr2047fae2016-11-28 14:09:09 -080052 }
53}
54} // namespace android