blob: 80e512379f5cabcfbd6b75d490e81db35aa8e6f3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
Huihong Luo6fac5232021-11-22 16:05:23 -080020#include <android/gui/IDisplayEventConnection.h>
Huihong Luoecc1f902021-11-20 11:55:05 -080021#include <android/gui/IRegionSamplingListener.h>
Pablo Gamito6ee484d2020-07-30 14:26:28 +000022#include <android/gui/ITransactionTraceListener.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/IPCThreadState.h>
24#include <binder/IServiceManager.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080025#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080026#include <gui/IGraphicBufferProducer.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080027#include <gui/ISurfaceComposer.h>
28#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070029#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010030#include <private/gui/ParcelUtils.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080031#include <stdint.h>
32#include <sys/types.h>
Michael Wright28f24d02016-07-12 13:30:53 -070033#include <system/graphics.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010034#include <ui/DisplayMode.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070035#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080036#include <ui/DisplayState.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010037#include <ui/DynamicDisplayInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070038#include <ui/HdrCapabilities.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080039#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080040
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041// ---------------------------------------------------------------------------
42
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050043using namespace aidl::android::hardware::graphics;
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Huihong Luof5029222021-12-16 14:33:46 -080047using gui::DisplayCaptureArgs;
Huihong Luo6fac5232021-11-22 16:05:23 -080048using gui::IDisplayEventConnection;
Huihong Luoecc1f902021-11-20 11:55:05 -080049using gui::IRegionSamplingListener;
chaviw60c9d3e2021-06-04 12:52:17 -050050using gui::IWindowInfosListener;
Huihong Luof5029222021-12-16 14:33:46 -080051using gui::LayerCaptureArgs;
Peiyong Lin9f034472018-03-28 15:29:00 -070052using ui::ColorMode;
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
55{
56public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070057 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 : BpInterface<ISurfaceComposer>(impl)
59 {
60 }
61
Dan Stozad723bd72014-11-18 10:24:03 -080062 virtual ~BpSurfaceComposer();
63
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 Parcel data, reply;
67 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
68 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070069 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 }
71
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100072 status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
73 const Vector<ComposerState>& state,
74 const Vector<DisplayState>& displays, uint32_t flags,
75 const sp<IBinder>& applyToken, const InputWindowCommands& commands,
76 int64_t desiredPresentTime, bool isAutoTimestamp,
77 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
78 const std::vector<ListenerCallbacks>& listenerCallbacks,
79 uint64_t transactionId) override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 Parcel data, reply;
81 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080082
Huihong Luo3bdef862022-03-03 11:57:19 -080083 frameTimelineInfo.writeToParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100084
chaviw308ddba2020-08-11 16:23:51 -070085 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080086 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070087 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070088 }
Dan Stozad723bd72014-11-18 10:24:03 -080089
chaviw308ddba2020-08-11 16:23:51 -070090 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080091 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070092 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070093 }
Dan Stozad723bd72014-11-18 10:24:03 -080094
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(data.writeUint32, flags);
96 SAFE_PARCEL(data.writeStrongBinder, applyToken);
97 SAFE_PARCEL(commands.write, data);
98 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -080099 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
chaviw308ddba2020-08-11 16:23:51 -0700100 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
101 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
102 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700103
chaviw308ddba2020-08-11 16:23:51 -0700104 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
105 for (const auto& [listener, callbackIds] : listenerCallbacks) {
106 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700107 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700108 }
109
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000110 SAFE_PARCEL(data.writeUint64, transactionId);
111
Robert Carr79dc06a2022-02-22 15:28:59 -0800112 if (flags & ISurfaceComposer::eOneWay) {
113 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
114 data, &reply, IBinder::FLAG_ONEWAY);
115 } else {
116 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
117 data, &reply);
118 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 }
120
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000121 void bootFinished() override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122 Parcel data, reply;
123 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
124 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
125 }
126
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000127 sp<IDisplayEventConnection> createDisplayEventConnection(
128 VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) override {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800129 Parcel data, reply;
130 sp<IDisplayEventConnection> result;
131 int err = data.writeInterfaceToken(
132 ISurfaceComposer::getInterfaceDescriptor());
133 if (err != NO_ERROR) {
134 return result;
135 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700136 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham62f216c2020-10-13 19:07:23 -0700137 data.writeUint32(eventRegistration.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800138 err = remote()->transact(
139 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
140 data, &reply);
141 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000142 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800143 "transaction: %s (%d)", strerror(-err), -err);
144 return result;
145 }
146 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
147 return result;
148 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149};
150
Dan Stozad723bd72014-11-18 10:24:03 -0800151// Out-of-line virtual method definition to trigger vtable emission in this
152// translation unit (see clang warning -Wweak-vtables)
153BpSurfaceComposer::~BpSurfaceComposer() {}
154
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800155IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
156
157// ----------------------------------------------------------------------
158
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800159status_t BnSurfaceComposer::onTransact(
160 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
161{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162 switch(code) {
163 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700164 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800165 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700167 return NO_ERROR;
168 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700169 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700170 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800171
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000172 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800173 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000174
chaviw308ddba2020-08-11 16:23:51 -0700175 uint32_t count = 0;
176 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700177 Vector<ComposerState> state;
178 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800179 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700180 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700181 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700182 state.add(s);
183 }
Dan Stozad723bd72014-11-18 10:24:03 -0800184
chaviw308ddba2020-08-11 16:23:51 -0700185 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700186 DisplayState d;
187 Vector<DisplayState> displays;
188 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800189 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700190 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700191 displays.add(d);
192 }
Dan Stozad723bd72014-11-18 10:24:03 -0800193
chaviw308ddba2020-08-11 16:23:51 -0700194 uint32_t stateFlags = 0;
195 SAFE_PARCEL(data.readUint32, &stateFlags);
196 sp<IBinder> applyToken;
197 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800198 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700199 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800200
chaviw308ddba2020-08-11 16:23:51 -0700201 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800202 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700203 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800204 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700205
Marissa Wall947d34e2019-03-29 14:03:53 -0700206 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -0700207 sp<IBinder> tmpBinder;
208 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
209 uncachedBuffer.token = tmpBinder;
210 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -0700211
chaviw308ddba2020-08-11 16:23:51 -0700212 bool hasListenerCallbacks = false;
213 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700214
Marissa Wall3dad52d2019-03-22 14:03:19 -0700215 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700216 int32_t listenersSize = 0;
217 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700218 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700219 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700220 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700221 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700222 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700223 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000224
225 uint64_t transactionId = -1;
226 SAFE_PARCEL(data.readUint64, &transactionId);
227
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000228 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
229 inputWindowCommands, desiredPresentTime, isAutoTimestamp,
230 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
231 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -0700232 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800233 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700234 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700236 return NO_ERROR;
237 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800238 case CREATE_DISPLAY_EVENT_CONNECTION: {
239 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700240 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
Ady Abraham62f216c2020-10-13 19:07:23 -0700241 EventRegistrationFlags eventRegistration =
242 static_cast<EventRegistration>(data.readUint32());
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700243
244 sp<IDisplayEventConnection> connection(
Ady Abraham62f216c2020-10-13 19:07:23 -0700245 createDisplayEventConnection(vsyncSource, eventRegistration));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800246 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800247 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700248 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700249 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700250 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700251 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800252 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800253}
254
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800255} // namespace android