blob: af64b3bd329960ae38aafb8cdcd8c46cf8ec1ccd [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 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111};
112
Dan Stozad723bd72014-11-18 10:24:03 -0800113// Out-of-line virtual method definition to trigger vtable emission in this
114// translation unit (see clang warning -Wweak-vtables)
115BpSurfaceComposer::~BpSurfaceComposer() {}
116
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800117IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
118
119// ----------------------------------------------------------------------
120
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121status_t BnSurfaceComposer::onTransact(
122 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
123{
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800124 switch (code) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700125 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700126 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800127
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000128 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800129 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000130
chaviw308ddba2020-08-11 16:23:51 -0700131 uint32_t count = 0;
132 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700133 Vector<ComposerState> state;
134 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800135 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700136 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700137 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700138 state.add(s);
139 }
Dan Stozad723bd72014-11-18 10:24:03 -0800140
chaviw308ddba2020-08-11 16:23:51 -0700141 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700142 DisplayState d;
143 Vector<DisplayState> displays;
144 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800145 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700146 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700147 displays.add(d);
148 }
Dan Stozad723bd72014-11-18 10:24:03 -0800149
chaviw308ddba2020-08-11 16:23:51 -0700150 uint32_t stateFlags = 0;
151 SAFE_PARCEL(data.readUint32, &stateFlags);
152 sp<IBinder> applyToken;
153 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800154 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700155 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800156
chaviw308ddba2020-08-11 16:23:51 -0700157 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800158 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700159 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800160 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700161
Marissa Wall947d34e2019-03-29 14:03:53 -0700162 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -0700163 sp<IBinder> tmpBinder;
164 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
165 uncachedBuffer.token = tmpBinder;
166 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -0700167
chaviw308ddba2020-08-11 16:23:51 -0700168 bool hasListenerCallbacks = false;
169 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700170
Marissa Wall3dad52d2019-03-22 14:03:19 -0700171 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700172 int32_t listenersSize = 0;
173 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700174 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700175 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700176 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700177 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700178 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700179 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000180
181 uint64_t transactionId = -1;
182 SAFE_PARCEL(data.readUint64, &transactionId);
183
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000184 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
185 inputWindowCommands, desiredPresentTime, isAutoTimestamp,
186 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
187 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -0700188 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700189 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700190 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700191 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193}
194
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800195} // namespace android