• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 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 // tag as surfaceflinger
18 #define LOG_TAG "SurfaceFlinger"
19 
20 #include <android/gui/IDisplayEventConnection.h>
21 #include <android/gui/IRegionSamplingListener.h>
22 #include <binder/IPCThreadState.h>
23 #include <binder/IServiceManager.h>
24 #include <binder/Parcel.h>
25 #include <gui/IGraphicBufferProducer.h>
26 #include <gui/ISurfaceComposer.h>
27 #include <gui/LayerState.h>
28 #include <private/gui/ParcelUtils.h>
29 #include <stdint.h>
30 #include <sys/types.h>
31 #include <system/graphics.h>
32 #include <ui/DisplayMode.h>
33 #include <ui/DisplayStatInfo.h>
34 #include <ui/DisplayState.h>
35 #include <ui/DynamicDisplayInfo.h>
36 #include <ui/HdrCapabilities.h>
37 #include <utils/Log.h>
38 
39 // ---------------------------------------------------------------------------
40 
41 using namespace aidl::android::hardware::graphics;
42 
43 namespace android {
44 
45 using gui::DisplayCaptureArgs;
46 using gui::IDisplayEventConnection;
47 using gui::IRegionSamplingListener;
48 using gui::IWindowInfosListener;
49 using gui::LayerCaptureArgs;
50 using ui::ColorMode;
51 
52 class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
53 {
54 public:
BpSurfaceComposer(const sp<IBinder> & impl)55     explicit BpSurfaceComposer(const sp<IBinder>& impl)
56         : BpInterface<ISurfaceComposer>(impl)
57     {
58     }
59 
60     virtual ~BpSurfaceComposer();
61 
setTransactionState(const FrameTimelineInfo & frameTimelineInfo,Vector<ComposerState> & state,const Vector<DisplayState> & displays,uint32_t flags,const sp<IBinder> & applyToken,InputWindowCommands commands,int64_t desiredPresentTime,bool isAutoTimestamp,const std::vector<client_cache_t> & uncacheBuffers,bool hasListenerCallbacks,const std::vector<ListenerCallbacks> & listenerCallbacks,uint64_t transactionId,const std::vector<uint64_t> & mergedTransactionIds)62     status_t setTransactionState(
63             const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
64             const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
65             InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp,
66             const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks,
67             const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId,
68             const std::vector<uint64_t>& mergedTransactionIds) override {
69         Parcel data, reply;
70         data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
71 
72         frameTimelineInfo.writeToParcel(&data);
73 
74         SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
75         for (const auto& s : state) {
76             SAFE_PARCEL(s.write, data);
77         }
78 
79         SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
80         for (const auto& d : displays) {
81             SAFE_PARCEL(d.write, data);
82         }
83 
84         SAFE_PARCEL(data.writeUint32, flags);
85         SAFE_PARCEL(data.writeStrongBinder, applyToken);
86         SAFE_PARCEL(commands.write, data);
87         SAFE_PARCEL(data.writeInt64, desiredPresentTime);
88         SAFE_PARCEL(data.writeBool, isAutoTimestamp);
89         SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size()));
90         for (const client_cache_t& uncacheBuffer : uncacheBuffers) {
91             SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
92             SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
93         }
94         SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
95 
96         SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
97         for (const auto& [listener, callbackIds] : listenerCallbacks) {
98             SAFE_PARCEL(data.writeStrongBinder, listener);
99             SAFE_PARCEL(data.writeParcelableVector, callbackIds);
100         }
101 
102         SAFE_PARCEL(data.writeUint64, transactionId);
103 
104         SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
105         for (auto mergedTransactionId : mergedTransactionIds) {
106             SAFE_PARCEL(data.writeUint64, mergedTransactionId);
107         }
108 
109         if (flags & ISurfaceComposer::eOneWay) {
110             return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
111                     data, &reply, IBinder::FLAG_ONEWAY);
112         } else {
113             return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
114                     data, &reply);
115         }
116     }
117 };
118 
119 // Out-of-line virtual method definition to trigger vtable emission in this
120 // translation unit (see clang warning -Wweak-vtables)
~BpSurfaceComposer()121 BpSurfaceComposer::~BpSurfaceComposer() {}
122 
123 IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
124 
125 // ----------------------------------------------------------------------
126 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)127 status_t BnSurfaceComposer::onTransact(
128     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
129 {
130     switch (code) {
131         case SET_TRANSACTION_STATE: {
132             CHECK_INTERFACE(ISurfaceComposer, data, reply);
133 
134             FrameTimelineInfo frameTimelineInfo;
135             frameTimelineInfo.readFromParcel(&data);
136 
137             uint32_t count = 0;
138             SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
139             Vector<ComposerState> state;
140             state.setCapacity(count);
141             for (size_t i = 0; i < count; i++) {
142                 ComposerState s;
143                 SAFE_PARCEL(s.read, data);
144                 state.add(s);
145             }
146 
147             SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
148             DisplayState d;
149             Vector<DisplayState> displays;
150             displays.setCapacity(count);
151             for (size_t i = 0; i < count; i++) {
152                 SAFE_PARCEL(d.read, data);
153                 displays.add(d);
154             }
155 
156             uint32_t stateFlags = 0;
157             SAFE_PARCEL(data.readUint32, &stateFlags);
158             sp<IBinder> applyToken;
159             SAFE_PARCEL(data.readStrongBinder, &applyToken);
160             InputWindowCommands inputWindowCommands;
161             SAFE_PARCEL(inputWindowCommands.read, data);
162 
163             int64_t desiredPresentTime = 0;
164             bool isAutoTimestamp = true;
165             SAFE_PARCEL(data.readInt64, &desiredPresentTime);
166             SAFE_PARCEL(data.readBool, &isAutoTimestamp);
167 
168             SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
169             std::vector<client_cache_t> uncacheBuffers(count);
170             sp<IBinder> tmpBinder;
171             for (size_t i = 0; i < count; i++) {
172                 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
173                 uncacheBuffers[i].token = tmpBinder;
174                 SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
175             }
176 
177             bool hasListenerCallbacks = false;
178             SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
179 
180             std::vector<ListenerCallbacks> listenerCallbacks;
181             int32_t listenersSize = 0;
182             SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
183             for (int32_t i = 0; i < listenersSize; i++) {
184                 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
185                 std::vector<CallbackId> callbackIds;
186                 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
187                 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
188             }
189 
190             uint64_t transactionId = -1;
191             SAFE_PARCEL(data.readUint64, &transactionId);
192 
193             SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
194             std::vector<uint64_t> mergedTransactions(count);
195             for (size_t i = 0; i < count; i++) {
196                 SAFE_PARCEL(data.readUint64, &mergedTransactions[i]);
197             }
198 
199             return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
200                                        std::move(inputWindowCommands), desiredPresentTime,
201                                        isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
202                                        listenerCallbacks, transactionId, mergedTransactions);
203         }
204         default: {
205             return BBinder::onTransact(code, data, reply, flags);
206         }
207     }
208 }
209 
210 } // namespace android
211