LayerVector.h 1.8 KB

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