• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 #pragma once
18 
19 #include <android/gui/BnWindowInfosReportedListener.h>
20 #include <android/gui/IWindowInfosListener.h>
21 #include <android/gui/IWindowInfosReportedListener.h>
22 #include <binder/IBinder.h>
23 #include <ftl/small_map.h>
24 #include <utils/Mutex.h>
25 
26 namespace android {
27 
28 class SurfaceFlinger;
29 
30 class WindowInfosListenerInvoker : public IBinder::DeathRecipient {
31 public:
32     explicit WindowInfosListenerInvoker(SurfaceFlinger&);
33 
34     void addWindowInfosListener(sp<gui::IWindowInfosListener>);
35     void removeWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener);
36 
37     void windowInfosChanged(const std::vector<gui::WindowInfo>&,
38                             const std::vector<gui::DisplayInfo>&, bool shouldSync);
39 
40 protected:
41     void binderDied(const wp<IBinder>& who) override;
42 
43 private:
44     struct WindowInfosReportedListener;
45     void windowInfosReported();
46 
47     SurfaceFlinger& mFlinger;
48     std::mutex mListenersMutex;
49 
50     static constexpr size_t kStaticCapacity = 3;
51     ftl::SmallMap<wp<IBinder>, const sp<gui::IWindowInfosListener>, kStaticCapacity>
52             mWindowInfosListeners GUARDED_BY(mListenersMutex);
53 
54     sp<gui::IWindowInfosReportedListener> mWindowInfosReportedListener;
55     std::atomic<size_t> mCallbacksPending{0};
56 };
57 
58 } // namespace android
59