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#ifndef ANDROID_SURFACE_FLINGER_LAYER_VECTOR_H
18#define ANDROID_SURFACE_FLINGER_LAYER_VECTOR_H
19
20#include <utils/SortedVector.h>
21#include <utils/RefBase.h>
22
23#include <functional>
24
25namespace android {
26class Layer;
27
28/*
29 * Used by the top-level SurfaceFlinger state and individual layers
30 * to track layers they own sorted according to Z-order. Provides traversal
31 * functions for traversing all owned layers, and their descendents.
32 */
33class LayerVector : public SortedVector<sp<Layer>> {
34public:
35    LayerVector();
36    LayerVector(const LayerVector& rhs);
37    ~LayerVector() override;
38
39    enum class StateSet {
40        Invalid,
41        Current,
42        Drawing,
43    };
44
45    // Sorts layer by layer-stack, Z order, and finally creation order (sequence).
46    int do_compare(const void* lhs, const void* rhs) const override;
47
48    using Visitor = std::function<void(Layer*)>;
49    void traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const;
50    void traverseInZOrder(StateSet stateSet, const Visitor& visitor) const;
51};
52}
53
54#endif /* ANDROID_SURFACE_FLINGER_LAYER_VECTOR_H_ */
55