1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker // TODO(b/129481165): remove the #pragma below and fix conversion issues
18*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic push
19*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic ignored "-Wconversion"
20*38e8c45fSAndroid Build Coastguard Worker
21*38e8c45fSAndroid Build Coastguard Worker #include "LayerVector.h"
22*38e8c45fSAndroid Build Coastguard Worker #include "Layer.h"
23*38e8c45fSAndroid Build Coastguard Worker
24*38e8c45fSAndroid Build Coastguard Worker namespace android {
25*38e8c45fSAndroid Build Coastguard Worker
LayerVector(const StateSet stateSet)26*38e8c45fSAndroid Build Coastguard Worker LayerVector::LayerVector(const StateSet stateSet) : mStateSet(stateSet) {}
27*38e8c45fSAndroid Build Coastguard Worker
LayerVector(const LayerVector & rhs,const StateSet stateSet)28*38e8c45fSAndroid Build Coastguard Worker LayerVector::LayerVector(const LayerVector& rhs, const StateSet stateSet)
29*38e8c45fSAndroid Build Coastguard Worker : SortedVector<sp<Layer>>(rhs), mStateSet(stateSet) {}
30*38e8c45fSAndroid Build Coastguard Worker
31*38e8c45fSAndroid Build Coastguard Worker LayerVector::~LayerVector() = default;
32*38e8c45fSAndroid Build Coastguard Worker
33*38e8c45fSAndroid Build Coastguard Worker // This operator override is needed to prevent mStateSet from getting copied over.
operator =(const LayerVector & rhs)34*38e8c45fSAndroid Build Coastguard Worker LayerVector& LayerVector::operator=(const LayerVector& rhs) {
35*38e8c45fSAndroid Build Coastguard Worker SortedVector::operator=(rhs);
36*38e8c45fSAndroid Build Coastguard Worker return *this;
37*38e8c45fSAndroid Build Coastguard Worker }
38*38e8c45fSAndroid Build Coastguard Worker
do_compare(const void * lhs,const void * rhs) const39*38e8c45fSAndroid Build Coastguard Worker int LayerVector::do_compare(const void* lhs, const void* rhs) const
40*38e8c45fSAndroid Build Coastguard Worker {
41*38e8c45fSAndroid Build Coastguard Worker // sort layers per layer-stack, then by z-order and finally by sequence
42*38e8c45fSAndroid Build Coastguard Worker const auto& l = *reinterpret_cast<const sp<Layer>*>(lhs);
43*38e8c45fSAndroid Build Coastguard Worker const auto& r = *reinterpret_cast<const sp<Layer>*>(rhs);
44*38e8c45fSAndroid Build Coastguard Worker
45*38e8c45fSAndroid Build Coastguard Worker const auto& lState = l->getDrawingState();
46*38e8c45fSAndroid Build Coastguard Worker const auto& rState = r->getDrawingState();
47*38e8c45fSAndroid Build Coastguard Worker
48*38e8c45fSAndroid Build Coastguard Worker if (l->sequence == r->sequence)
49*38e8c45fSAndroid Build Coastguard Worker return 0;
50*38e8c45fSAndroid Build Coastguard Worker
51*38e8c45fSAndroid Build Coastguard Worker return (l->sequence > r->sequence) ? 1 : -1;
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker
54*38e8c45fSAndroid Build Coastguard Worker } // namespace android
55*38e8c45fSAndroid Build Coastguard Worker
56*38e8c45fSAndroid Build Coastguard Worker // TODO(b/129481165): remove the #pragma below and fix conversion issues
57*38e8c45fSAndroid Build Coastguard Worker #pragma clang diagnostic pop // ignored "-Wconversion"
58