Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | namespace android { |
| 21 | LayerVector::LayerVector(const LayerVector& rhs) : SortedVector<sp<Layer>>(rhs) { |
| 22 | } |
| 23 | |
| 24 | int 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 | |
| 43 | void LayerVector::traverseInZOrder(const std::function<void(Layer*)>& consume) const { |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 44 | for (size_t i = 0; i < size(); i++) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame^] | 45 | const auto& layer = (*this)[i]; |
| 46 | if (layer->getDrawingState().zOrderRelativeOf != nullptr) { |
| 47 | continue; |
| 48 | } |
| 49 | layer->traverseInZOrder(consume); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | void LayerVector::traverseInReverseZOrder(const std::function<void(Layer*)>& consume) const { |
| 54 | for (auto i = static_cast<int64_t>(size()) - 1; i >= 0; i--) { |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame^] | 55 | const auto& layer = (*this)[i]; |
| 56 | if (layer->getDrawingState().zOrderRelativeOf != nullptr) { |
| 57 | continue; |
| 58 | } |
| 59 | layer->traverseInReverseZOrder(consume); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } // namespace android |