blob: b526a6c92cabdcbdab7f560552e1f08dfbb98b0d [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>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010028#include <private/gui/ParcelUtils.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080029#include <stdint.h>
30#include <sys/types.h>
Michael Wright28f24d02016-07-12 13:30:53 -070031#include <system/graphics.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010032#include <ui/DisplayMode.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070033#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080034#include <ui/DisplayState.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010035#include <ui/DynamicDisplayInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070036#include <ui/HdrCapabilities.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080037#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080038
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039// ---------------------------------------------------------------------------
40
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050041using namespace aidl::android::hardware::graphics;
42
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043namespace android {
44
Huihong Luof5029222021-12-16 14:33:46 -080045using gui::DisplayCaptureArgs;
Huihong Luo6fac5232021-11-22 16:05:23 -080046using gui::IDisplayEventConnection;
Huihong Luoecc1f902021-11-20 11:55:05 -080047using gui::IRegionSamplingListener;
chaviw60c9d3e2021-06-04 12:52:17 -050048using gui::IWindowInfosListener;
Huihong Luof5029222021-12-16 14:33:46 -080049using gui::LayerCaptureArgs;
Peiyong Lin9f034472018-03-28 15:29:00 -070050using ui::ColorMode;
51
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
53{
54public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070055 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056 : BpInterface<ISurfaceComposer>(impl)
57 {
58 }
59
Dan Stozad723bd72014-11-18 10:24:03 -080060 virtual ~BpSurfaceComposer();
61
Pablo Gamito23780be2023-04-18 08:30:00 +000062 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 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 Parcel data, reply;
70 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080071
Huihong Luo3bdef862022-03-03 11:57:19 -080072 frameTimelineInfo.writeToParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100073
chaviw308ddba2020-08-11 16:23:51 -070074 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080075 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070076 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070077 }
Dan Stozad723bd72014-11-18 10:24:03 -080078
chaviw308ddba2020-08-11 16:23:51 -070079 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080080 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070081 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070082 }
Dan Stozad723bd72014-11-18 10:24:03 -080083
chaviw308ddba2020-08-11 16:23:51 -070084 SAFE_PARCEL(data.writeUint32, flags);
85 SAFE_PARCEL(data.writeStrongBinder, applyToken);
86 SAFE_PARCEL(commands.write, data);
87 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -080088 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000089 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 }
chaviw308ddba2020-08-11 16:23:51 -070094 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070095
chaviw308ddba2020-08-11 16:23:51 -070096 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
97 for (const auto& [listener, callbackIds] : listenerCallbacks) {
98 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070099 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700100 }
101
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000102 SAFE_PARCEL(data.writeUint64, transactionId);
103
Pablo Gamito23780be2023-04-18 08:30:00 +0000104 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(mergedTransactionIds.size()));
105 for (auto mergedTransactionId : mergedTransactionIds) {
106 SAFE_PARCEL(data.writeUint64, mergedTransactionId);
107 }
108
Robert Carr79dc06a2022-02-22 15:28:59 -0800109 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 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117};
118
Dan Stozad723bd72014-11-18 10:24:03 -0800119// Out-of-line virtual method definition to trigger vtable emission in this
120// translation unit (see clang warning -Wweak-vtables)
121BpSurfaceComposer::~BpSurfaceComposer() {}
122
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
124
125// ----------------------------------------------------------------------
126
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127status_t BnSurfaceComposer::onTransact(
128 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
129{
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800130 switch (code) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700131 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700132 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800133
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000134 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800135 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000136
chaviw308ddba2020-08-11 16:23:51 -0700137 uint32_t count = 0;
138 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700139 Vector<ComposerState> state;
140 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800141 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700142 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700143 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700144 state.add(s);
145 }
Dan Stozad723bd72014-11-18 10:24:03 -0800146
chaviw308ddba2020-08-11 16:23:51 -0700147 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700148 DisplayState d;
149 Vector<DisplayState> displays;
150 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800151 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700152 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700153 displays.add(d);
154 }
Dan Stozad723bd72014-11-18 10:24:03 -0800155
chaviw308ddba2020-08-11 16:23:51 -0700156 uint32_t stateFlags = 0;
157 SAFE_PARCEL(data.readUint32, &stateFlags);
158 sp<IBinder> applyToken;
159 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800160 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700161 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800162
chaviw308ddba2020-08-11 16:23:51 -0700163 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800164 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700165 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800166 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700167
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000168 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
169 std::vector<client_cache_t> uncacheBuffers(count);
chaviw308ddba2020-08-11 16:23:51 -0700170 sp<IBinder> tmpBinder;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000171 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 }
Marissa Wall78b72202019-03-15 14:58:34 -0700176
chaviw308ddba2020-08-11 16:23:51 -0700177 bool hasListenerCallbacks = false;
178 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700179
Marissa Wall3dad52d2019-03-22 14:03:19 -0700180 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700181 int32_t listenersSize = 0;
182 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700183 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700184 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700185 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700186 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700187 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700188 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000189
190 uint64_t transactionId = -1;
191 SAFE_PARCEL(data.readUint64, &transactionId);
192
Pablo Gamito23780be2023-04-18 08:30:00 +0000193 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
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000199 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
Chavi Weingartenc78f53c2023-04-14 18:50:53 +0000200 std::move(inputWindowCommands), desiredPresentTime,
201 isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
Pablo Gamito23780be2023-04-18 08:30:00 +0000202 listenerCallbacks, transactionId, mergedTransactions);
Jesse Hall6c913be2013-08-08 12:15:49 -0700203 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700204 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700205 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700206 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800207 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208}
209
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800210} // namespace android