blob: 54e50b50ac254b400db84d4688a1c75979f5f65e [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>
Robert Carr4cdc58f2017-08-23 14:22:20 -070028#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010029#include <private/gui/ParcelUtils.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080030#include <stdint.h>
31#include <sys/types.h>
Michael Wright28f24d02016-07-12 13:30:53 -070032#include <system/graphics.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010033#include <ui/DisplayMode.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070034#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080035#include <ui/DisplayState.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010036#include <ui/DynamicDisplayInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070037#include <ui/HdrCapabilities.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080038#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080039
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040// ---------------------------------------------------------------------------
41
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050042using namespace aidl::android::hardware::graphics;
43
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044namespace android {
45
Huihong Luof5029222021-12-16 14:33:46 -080046using gui::DisplayCaptureArgs;
Huihong Luo6fac5232021-11-22 16:05:23 -080047using gui::IDisplayEventConnection;
Huihong Luoecc1f902021-11-20 11:55:05 -080048using gui::IRegionSamplingListener;
chaviw60c9d3e2021-06-04 12:52:17 -050049using gui::IWindowInfosListener;
Huihong Luof5029222021-12-16 14:33:46 -080050using gui::LayerCaptureArgs;
Peiyong Lin9f034472018-03-28 15:29:00 -070051using ui::ColorMode;
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
54{
55public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070056 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 : BpInterface<ISurfaceComposer>(impl)
58 {
59 }
60
Dan Stozad723bd72014-11-18 10:24:03 -080061 virtual ~BpSurfaceComposer();
62
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100063 status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
64 const Vector<ComposerState>& state,
65 const Vector<DisplayState>& displays, uint32_t flags,
66 const sp<IBinder>& applyToken, const InputWindowCommands& commands,
67 int64_t desiredPresentTime, bool isAutoTimestamp,
68 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
69 const std::vector<ListenerCallbacks>& listenerCallbacks,
70 uint64_t transactionId) override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 Parcel data, reply;
72 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080073
Huihong Luo3bdef862022-03-03 11:57:19 -080074 frameTimelineInfo.writeToParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100075
chaviw308ddba2020-08-11 16:23:51 -070076 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080077 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070078 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070079 }
Dan Stozad723bd72014-11-18 10:24:03 -080080
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080082 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070083 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070084 }
Dan Stozad723bd72014-11-18 10:24:03 -080085
chaviw308ddba2020-08-11 16:23:51 -070086 SAFE_PARCEL(data.writeUint32, flags);
87 SAFE_PARCEL(data.writeStrongBinder, applyToken);
88 SAFE_PARCEL(commands.write, data);
89 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -080090 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
chaviw308ddba2020-08-11 16:23:51 -070091 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
92 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
93 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070094
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
96 for (const auto& [listener, callbackIds] : listenerCallbacks) {
97 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070098 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -070099 }
100
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000101 SAFE_PARCEL(data.writeUint64, transactionId);
102
Robert Carr79dc06a2022-02-22 15:28:59 -0800103 if (flags & ISurfaceComposer::eOneWay) {
104 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
105 data, &reply, IBinder::FLAG_ONEWAY);
106 } else {
107 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
108 data, &reply);
109 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 }
111
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000112 void bootFinished() override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 Parcel data, reply;
114 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
115 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
116 }
117
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000118 sp<IDisplayEventConnection> createDisplayEventConnection(
119 VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) override {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800120 Parcel data, reply;
121 sp<IDisplayEventConnection> result;
122 int err = data.writeInterfaceToken(
123 ISurfaceComposer::getInterfaceDescriptor());
124 if (err != NO_ERROR) {
125 return result;
126 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700127 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham62f216c2020-10-13 19:07:23 -0700128 data.writeUint32(eventRegistration.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800129 err = remote()->transact(
130 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
131 data, &reply);
132 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000133 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800134 "transaction: %s (%d)", strerror(-err), -err);
135 return result;
136 }
137 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
138 return result;
139 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140};
141
Dan Stozad723bd72014-11-18 10:24:03 -0800142// Out-of-line virtual method definition to trigger vtable emission in this
143// translation unit (see clang warning -Wweak-vtables)
144BpSurfaceComposer::~BpSurfaceComposer() {}
145
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
147
148// ----------------------------------------------------------------------
149
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150status_t BnSurfaceComposer::onTransact(
151 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
152{
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800153 switch (code) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700154 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700155 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800156
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000157 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800158 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000159
chaviw308ddba2020-08-11 16:23:51 -0700160 uint32_t count = 0;
161 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700162 Vector<ComposerState> state;
163 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800164 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700165 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700166 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700167 state.add(s);
168 }
Dan Stozad723bd72014-11-18 10:24:03 -0800169
chaviw308ddba2020-08-11 16:23:51 -0700170 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700171 DisplayState d;
172 Vector<DisplayState> displays;
173 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800174 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700175 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700176 displays.add(d);
177 }
Dan Stozad723bd72014-11-18 10:24:03 -0800178
chaviw308ddba2020-08-11 16:23:51 -0700179 uint32_t stateFlags = 0;
180 SAFE_PARCEL(data.readUint32, &stateFlags);
181 sp<IBinder> applyToken;
182 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800183 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700184 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800185
chaviw308ddba2020-08-11 16:23:51 -0700186 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800187 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700188 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800189 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700190
Marissa Wall947d34e2019-03-29 14:03:53 -0700191 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -0700192 sp<IBinder> tmpBinder;
193 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
194 uncachedBuffer.token = tmpBinder;
195 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -0700196
chaviw308ddba2020-08-11 16:23:51 -0700197 bool hasListenerCallbacks = false;
198 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700199
Marissa Wall3dad52d2019-03-22 14:03:19 -0700200 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700201 int32_t listenersSize = 0;
202 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700203 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700204 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700205 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700206 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700207 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700208 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000209
210 uint64_t transactionId = -1;
211 SAFE_PARCEL(data.readUint64, &transactionId);
212
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000213 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
214 inputWindowCommands, desiredPresentTime, isAutoTimestamp,
215 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
216 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -0700217 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800218 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700219 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700221 return NO_ERROR;
222 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800223 case CREATE_DISPLAY_EVENT_CONNECTION: {
224 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700225 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
Ady Abraham62f216c2020-10-13 19:07:23 -0700226 EventRegistrationFlags eventRegistration =
227 static_cast<EventRegistration>(data.readUint32());
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700228
229 sp<IDisplayEventConnection> connection(
Ady Abraham62f216c2020-10-13 19:07:23 -0700230 createDisplayEventConnection(vsyncSource, eventRegistration));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800231 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800232 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700233 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700234 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700235 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700236 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800237 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800238}
239
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800240} // namespace android