blob: d72f65eb7a219e5ae90925e0687672b094b72e29 [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
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100062 status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
Vishnu Nair40fff5c2022-11-04 02:46:28 +000063 Vector<ComposerState>& state, const Vector<DisplayState>& displays,
64 uint32_t flags, const sp<IBinder>& applyToken,
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000065 InputWindowCommands commands, int64_t desiredPresentTime,
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000066 bool isAutoTimestamp,
67 const std::vector<client_cache_t>& uncacheBuffers,
Vishnu Nair40fff5c2022-11-04 02:46:28 +000068 bool hasListenerCallbacks,
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100069 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);
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000091 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(uncacheBuffers.size()));
92 for (const client_cache_t& uncacheBuffer : uncacheBuffers) {
93 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
94 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
95 }
chaviw308ddba2020-08-11 16:23:51 -070096 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070097
chaviw308ddba2020-08-11 16:23:51 -070098 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
99 for (const auto& [listener, callbackIds] : listenerCallbacks) {
100 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700101 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700102 }
103
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000104 SAFE_PARCEL(data.writeUint64, transactionId);
105
Robert Carr79dc06a2022-02-22 15:28:59 -0800106 if (flags & ISurfaceComposer::eOneWay) {
107 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
108 data, &reply, IBinder::FLAG_ONEWAY);
109 } else {
110 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
111 data, &reply);
112 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114};
115
Dan Stozad723bd72014-11-18 10:24:03 -0800116// Out-of-line virtual method definition to trigger vtable emission in this
117// translation unit (see clang warning -Wweak-vtables)
118BpSurfaceComposer::~BpSurfaceComposer() {}
119
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800120IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
121
122// ----------------------------------------------------------------------
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124status_t BnSurfaceComposer::onTransact(
125 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
126{
Huihong Luod3d8f8e2022-03-08 14:48:46 -0800127 switch (code) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700128 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700129 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800130
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000131 FrameTimelineInfo frameTimelineInfo;
Huihong Luo3bdef862022-03-03 11:57:19 -0800132 frameTimelineInfo.readFromParcel(&data);
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000133
chaviw308ddba2020-08-11 16:23:51 -0700134 uint32_t count = 0;
135 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700136 Vector<ComposerState> state;
137 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800138 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700139 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700140 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700141 state.add(s);
142 }
Dan Stozad723bd72014-11-18 10:24:03 -0800143
chaviw308ddba2020-08-11 16:23:51 -0700144 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700145 DisplayState d;
146 Vector<DisplayState> displays;
147 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800148 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700149 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700150 displays.add(d);
151 }
Dan Stozad723bd72014-11-18 10:24:03 -0800152
chaviw308ddba2020-08-11 16:23:51 -0700153 uint32_t stateFlags = 0;
154 SAFE_PARCEL(data.readUint32, &stateFlags);
155 sp<IBinder> applyToken;
156 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800157 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700158 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800159
chaviw308ddba2020-08-11 16:23:51 -0700160 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800161 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700162 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800163 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700164
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000165 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
166 std::vector<client_cache_t> uncacheBuffers(count);
chaviw308ddba2020-08-11 16:23:51 -0700167 sp<IBinder> tmpBinder;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000168 for (size_t i = 0; i < count; i++) {
169 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
170 uncacheBuffers[i].token = tmpBinder;
171 SAFE_PARCEL(data.readUint64, &uncacheBuffers[i].id);
172 }
Marissa Wall78b72202019-03-15 14:58:34 -0700173
chaviw308ddba2020-08-11 16:23:51 -0700174 bool hasListenerCallbacks = false;
175 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700176
Marissa Wall3dad52d2019-03-22 14:03:19 -0700177 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700178 int32_t listenersSize = 0;
179 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700180 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700181 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700182 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700183 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700184 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700185 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000186
187 uint64_t transactionId = -1;
188 SAFE_PARCEL(data.readUint64, &transactionId);
189
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000190 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
Chavi Weingartenc78f53c2023-04-14 18:50:53 +0000191 std::move(inputWindowCommands), desiredPresentTime,
192 isAutoTimestamp, uncacheBuffers, hasListenerCallbacks,
193 listenerCallbacks, transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -0700194 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700195 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700196 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700197 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199}
200
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800201} // namespace android