blob: 269936858a8c41a4149eb62eebe0cd14da46f13c [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>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/IPCThreadState.h>
23#include <binder/IServiceManager.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080024#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080025#include <gui/IGraphicBufferProducer.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080026#include <gui/ISurfaceComposer.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070027#include <gui/LayerState.h>
Ady Abraham07d03c42023-09-27 19:15:08 -070028#include <gui/SchedulingPolicy.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
Pablo Gamito23780be2023-04-18 08:30:00 +000063 status_t setTransactionState(
64 const FrameTimelineInfo& frameTimelineInfo, Vector<ComposerState>& state,
Patrick Williamsa69ae942024-07-24 17:11:19 +000065 Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken,
Pablo Gamito23780be2023-04-18 08:30:00 +000066 InputWindowCommands commands, int64_t desiredPresentTime, bool isAutoTimestamp,
67 const std::vector<client_cache_t>& uncacheBuffers, bool hasListenerCallbacks,
68 const std::vector<ListenerCallbacks>& listenerCallbacks, uint64_t transactionId,
69 const std::vector<uint64_t>& mergedTransactionIds) override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 Parcel data, reply;
71 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080072
Huihong Luo3bdef862022-03-03 11:57:19 -080073 frameTimelineInfo.writeToParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100074
chaviw308ddba2020-08-11 16:23:51 -070075 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080076 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070077 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070078 }
Dan Stozad723bd72014-11-18 10:24:03 -080079
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080081 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070082 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070083 }
Dan Stozad723bd72014-11-18 10:24:03 -080084
chaviw308ddba2020-08-11 16:23:51 -070085 SAFE_PARCEL(data.writeUint32, flags);
86 SAFE_PARCEL(data.writeStrongBinder, applyToken);
87 SAFE_PARCEL(commands.write, data);
88 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -080089 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000090 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size()));
91 for (const client_cache_t& uncacheBuffer : uncacheBuffers) {
92 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
93 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
94 }
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070096
chaviw308ddba2020-08-11 16:23:51 -070097 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
98 for (const auto& [listener, callbackIds] : listenerCallbacks) {
99 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700100 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700101 }
102
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000103 SAFE_PARCEL(data.writeUint64, transactionId);
104
Pablo Gamito23780be2023-04-18 08:30:00 +0000105 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
106 for (auto mergedTransactionId : mergedTransactionIds) {
107 SAFE_PARCEL(data.writeUint64, mergedTransactionId);
108 }
109
Robert Carr79dc06a2022-02-22 15:28:59 -0800110 if (flags & ISurfaceComposer::eOneWay) {
111 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
112 data, &reply, IBinder::FLAG_ONEWAY);
113 } else {
114 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
115 data, &reply);
116 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118};
119
Dan Stozad723bd72014-11-18 10:24:03 -0800120// Out-of-line virtual method definition to trigger vtable emission in this
121// translation unit (see clang warning -Wweak-vtables)
122BpSurfaceComposer::~BpSurfaceComposer() {}
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
125
126// ----------------------------------------------------------------------
127
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128status_t BnSurfaceComposer::onTransact(
129 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
130{
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800131 switch (code) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700132 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700133 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800134
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000135 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800136 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000137
chaviw308ddba2020-08-11 16:23:51 -0700138 uint32_t count = 0;
139 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700140 Vector<ComposerState> state;
141 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800142 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700143 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700144 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700145 state.add(s);
146 }
Dan Stozad723bd72014-11-18 10:24:03 -0800147
chaviw308ddba2020-08-11 16:23:51 -0700148 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700149 DisplayState d;
150 Vector<DisplayState> displays;
151 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800152 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700153 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700154 displays.add(d);
155 }
Dan Stozad723bd72014-11-18 10:24:03 -0800156
chaviw308ddba2020-08-11 16:23:51 -0700157 uint32_t stateFlags = 0;
158 SAFE_PARCEL(data.readUint32, &stateFlags);
159 sp<IBinder> applyToken;
160 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800161 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700162 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800163
chaviw308ddba2020-08-11 16:23:51 -0700164 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800165 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700166 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800167 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700168
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000169 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
170 std::vector<client_cache_t> uncacheBuffers(count);
chaviw308ddba2020-08-11 16:23:51 -0700171 sp<IBinder> tmpBinder;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000172 for (size_t i = 0; i < count; i++) {
173 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
174 uncacheBuffers[i].token = tmpBinder;
175 SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
176 }
Marissa Wall78b72202019-03-15 14:58:34 -0700177
chaviw308ddba2020-08-11 16:23:51 -0700178 bool hasListenerCallbacks = false;
179 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700180
Marissa Wall3dad52d2019-03-22 14:03:19 -0700181 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700182 int32_t listenersSize = 0;
183 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700184 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700185 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700186 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700187 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700188 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700189 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000190
191 uint64_t transactionId = -1;
192 SAFE_PARCEL(data.readUint64, &transactionId);
193
Pablo Gamito23780be2023-04-18 08:30:00 +0000194 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
195 std::vector<uint64_t> mergedTransactions(count);
196 for (size_t i = 0; i < count; i++) {
197 SAFE_PARCEL(data.readUint64, &mergedTransactions[i]);
198 }
199
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000200 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
Chavi Weingartenc78f53c2023-04-14 18:50:53 +0000201 std::move(inputWindowCommands), desiredPresentTime,
202 isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
Pablo Gamito23780be2023-04-18 08:30:00 +0000203 listenerCallbacks, transactionId, mergedTransactions);
Jesse Hall6c913be2013-08-08 12:15:49 -0700204 }
Ady Abraham07d03c42023-09-27 19:15:08 -0700205 case GET_SCHEDULING_POLICY: {
206 gui::SchedulingPolicy policy;
207 const auto status = gui::getSchedulingPolicy(&policy);
208 if (!status.isOk()) {
209 return status.exceptionCode();
210 }
211
212 SAFE_PARCEL(reply->writeInt32, policy.policy);
213 SAFE_PARCEL(reply->writeInt32, policy.priority);
214 return NO_ERROR;
215 }
216
Jesse Hall6c913be2013-08-08 12:15:49 -0700217 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700218 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700219 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800220 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800221}
222
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800223} // namespace android