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    enum class StateSet {
36        Invalid,
37        Current,
38        Drawing,
39    };
40
41    explicit LayerVector(const StateSet stateSet);
42    LayerVector(const LayerVector& rhs, const StateSet stateSet);
43    ~LayerVector() override;
44
45    LayerVector& operator=(const LayerVector& rhs);
46
47    // Sorts layer by layer-stack, Z order, and finally creation order (sequence).
48    int do_compare(const void* lhs, const void* rhs) const override;
49
50    using Visitor = std::function<void(Layer*)>;
51    void traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const;
52    void traverseInZOrder(StateSet stateSet, const Visitor& visitor) const;
53
54private:
55    const StateSet mStateSet;
56};
57}
58
59#endif /* ANDROID_SURFACE_FLINGER_LAYER_VECTOR_H_ */
60