blob: 88d7711bb8e0e4d0c8640f1919791f05be8fa5fa [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#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:
Dan Stoza412903f2017-04-27 13:42:17 -070035 enum class StateSet {
36 Invalid,
37 Current,
38 Drawing,
39 };
40
chaviwfd462612018-05-31 16:11:27 -070041 explicit LayerVector(const StateSet stateSet);
42 LayerVector(const LayerVector& rhs, const StateSet stateSet);
43 ~LayerVector() override;
44
45 LayerVector& operator=(const LayerVector& rhs);
46
Robert Carr2047fae2016-11-28 14:09:09 -080047 // 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
Dan Stoza412903f2017-04-27 13:42:17 -070050 using Visitor = std::function<void(Layer*)>;
51 void traverseInReverseZOrder(StateSet stateSet, const Visitor& visitor) const;
52 void traverseInZOrder(StateSet stateSet, const Visitor& visitor) const;
chaviwfd462612018-05-31 16:11:27 -070053
54private:
55 const StateSet mStateSet;
Robert Carr2047fae2016-11-28 14:09:09 -080056};
57}
58
59#endif /* ANDROID_SURFACE_FLINGER_LAYER_VECTOR_H_ */