blob: c3b33cb595d19e73f4e5a302b3f937c455daa947 [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>
28#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070029#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010030#include <private/gui/ParcelUtils.h>
Alec Mouriadebf5c2021-01-05 12:57:36 -080031#include <stdint.h>
32#include <sys/types.h>
Michael Wright28f24d02016-07-12 13:30:53 -070033#include <system/graphics.h>
Marin Shalamanova7fe3042021-01-29 21:02:08 +010034#include <ui/DisplayMode.h>
Lajos Molnar67d8bd62014-09-11 14:58:45 -070035#include <ui/DisplayStatInfo.h>
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080036#include <ui/DisplayState.h>
Marin Shalamanov228f46b2021-01-28 21:11:45 +010037#include <ui/DynamicDisplayInfo.h>
Dan Stozac4f471e2016-03-24 09:31:08 -070038#include <ui/HdrCapabilities.h>
Jamie Gennis134f0422011-03-08 12:18:54 -080039#include <utils/Log.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080040
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080041// ---------------------------------------------------------------------------
42
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -050043using namespace aidl::android::hardware::graphics;
44
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045namespace android {
46
Huihong Luof5029222021-12-16 14:33:46 -080047using gui::DisplayCaptureArgs;
Huihong Luo6fac5232021-11-22 16:05:23 -080048using gui::IDisplayEventConnection;
Huihong Luoecc1f902021-11-20 11:55:05 -080049using gui::IRegionSamplingListener;
chaviw60c9d3e2021-06-04 12:52:17 -050050using gui::IWindowInfosListener;
Huihong Luof5029222021-12-16 14:33:46 -080051using gui::LayerCaptureArgs;
Peiyong Lin9f034472018-03-28 15:29:00 -070052using ui::ColorMode;
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054class BpSurfaceComposer : public BpInterface<ISurfaceComposer>
55{
56public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070057 explicit BpSurfaceComposer(const sp<IBinder>& impl)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058 : BpInterface<ISurfaceComposer>(impl)
59 {
60 }
61
Dan Stozad723bd72014-11-18 10:24:03 -080062 virtual ~BpSurfaceComposer();
63
Mathias Agopian7e27f052010-05-28 14:22:23 -070064 virtual sp<ISurfaceComposerClient> createConnection()
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 Parcel data, reply;
67 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
68 remote()->transact(BnSurfaceComposer::CREATE_CONNECTION, data, &reply);
Mathias Agopian7e27f052010-05-28 14:22:23 -070069 return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 }
71
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100072 status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo,
73 const Vector<ComposerState>& state,
74 const Vector<DisplayState>& displays, uint32_t flags,
75 const sp<IBinder>& applyToken, const InputWindowCommands& commands,
76 int64_t desiredPresentTime, bool isAutoTimestamp,
77 const client_cache_t& uncacheBuffer, bool hasListenerCallbacks,
78 const std::vector<ListenerCallbacks>& listenerCallbacks,
79 uint64_t transactionId) override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080 Parcel data, reply;
81 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080082
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -100083 SAFE_PARCEL(frameTimelineInfo.write, data);
84
chaviw308ddba2020-08-11 16:23:51 -070085 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(state.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080086 for (const auto& s : state) {
chaviw308ddba2020-08-11 16:23:51 -070087 SAFE_PARCEL(s.write, data);
Mathias Agopian698c0872011-06-28 19:09:31 -070088 }
Dan Stozad723bd72014-11-18 10:24:03 -080089
chaviw308ddba2020-08-11 16:23:51 -070090 SAFE_PARCEL(data.writeUint32, static_cast<uint32_t>(displays.size()));
Dan Stozad723bd72014-11-18 10:24:03 -080091 for (const auto& d : displays) {
chaviw308ddba2020-08-11 16:23:51 -070092 SAFE_PARCEL(d.write, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -070093 }
Dan Stozad723bd72014-11-18 10:24:03 -080094
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(data.writeUint32, flags);
96 SAFE_PARCEL(data.writeStrongBinder, applyToken);
97 SAFE_PARCEL(commands.write, data);
98 SAFE_PARCEL(data.writeInt64, desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -080099 SAFE_PARCEL(data.writeBool, isAutoTimestamp);
chaviw308ddba2020-08-11 16:23:51 -0700100 SAFE_PARCEL(data.writeStrongBinder, uncacheBuffer.token.promote());
101 SAFE_PARCEL(data.writeUint64, uncacheBuffer.id);
102 SAFE_PARCEL(data.writeBool, hasListenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700103
chaviw308ddba2020-08-11 16:23:51 -0700104 SAFE_PARCEL(data.writeVectorSize, listenerCallbacks);
105 for (const auto& [listener, callbackIds] : listenerCallbacks) {
106 SAFE_PARCEL(data.writeStrongBinder, listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700107 SAFE_PARCEL(data.writeParcelableVector, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700108 }
109
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000110 SAFE_PARCEL(data.writeUint64, transactionId);
111
Robert Carr79dc06a2022-02-22 15:28:59 -0800112 if (flags & ISurfaceComposer::eOneWay) {
113 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
114 data, &reply, IBinder::FLAG_ONEWAY);
115 } else {
116 return remote()->transact(BnSurfaceComposer::SET_TRANSACTION_STATE,
117 data, &reply);
118 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800119 }
120
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000121 void bootFinished() override {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122 Parcel data, reply;
123 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
124 remote()->transact(BnSurfaceComposer::BOOT_FINISHED, data, &reply);
125 }
126
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000127 bool authenticateSurfaceTexture(
128 const sp<IGraphicBufferProducer>& bufferProducer) const override {
Jamie Gennis134f0422011-03-08 12:18:54 -0800129 Parcel data, reply;
130 int err = NO_ERROR;
131 err = data.writeInterfaceToken(
132 ISurfaceComposer::getInterfaceDescriptor());
133 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000134 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis134f0422011-03-08 12:18:54 -0800135 "interface descriptor: %s (%d)", strerror(-err), -err);
136 return false;
137 }
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800138 err = data.writeStrongBinder(IInterface::asBinder(bufferProducer));
Jamie Gennis134f0422011-03-08 12:18:54 -0800139 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000140 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error writing "
Jamie Gennis582270d2011-08-17 18:19:00 -0700141 "strong binder to parcel: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800142 return false;
143 }
144 err = remote()->transact(BnSurfaceComposer::AUTHENTICATE_SURFACE, data,
145 &reply);
146 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000147 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700148 "performing transaction: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800149 return false;
150 }
151 int32_t result = 0;
152 err = reply.readInt32(&result);
153 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000154 ALOGE("ISurfaceComposer::authenticateSurfaceTexture: error "
Jamie Gennis582270d2011-08-17 18:19:00 -0700155 "retrieving result: %s (%d)", strerror(-err), -err);
Jamie Gennis134f0422011-03-08 12:18:54 -0800156 return false;
157 }
158 return result != 0;
159 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800160
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000161 sp<IDisplayEventConnection> createDisplayEventConnection(
162 VsyncSource vsyncSource, EventRegistrationFlags eventRegistration) override {
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800163 Parcel data, reply;
164 sp<IDisplayEventConnection> result;
165 int err = data.writeInterfaceToken(
166 ISurfaceComposer::getInterfaceDescriptor());
167 if (err != NO_ERROR) {
168 return result;
169 }
Jorim Jaggib1e2f8d2017-06-08 15:43:59 -0700170 data.writeInt32(static_cast<int32_t>(vsyncSource));
Ady Abraham62f216c2020-10-13 19:07:23 -0700171 data.writeUint32(eventRegistration.get());
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800172 err = remote()->transact(
173 BnSurfaceComposer::CREATE_DISPLAY_EVENT_CONNECTION,
174 data, &reply);
175 if (err != NO_ERROR) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000176 ALOGE("ISurfaceComposer::createDisplayEventConnection: error performing "
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800177 "transaction: %s (%d)", strerror(-err), -err);
178 return result;
179 }
180 result = interface_cast<IDisplayEventConnection>(reply.readStrongBinder());
181 return result;
182 }
Colin Cross8e533062012-06-07 13:17:52 -0700183
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000184 status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
185 uint64_t timestamp,
186 DisplayedFrameStats* outStats) const override {
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700187 if (!outStats) return BAD_VALUE;
188
189 Parcel data, reply;
190 data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
191 data.writeStrongBinder(display);
192 data.writeUint64(maxFrames);
193 data.writeUint64(timestamp);
194
195 status_t result =
196 remote()->transact(BnSurfaceComposer::GET_DISPLAYED_CONTENT_SAMPLE, data, &reply);
197
198 if (result != NO_ERROR) {
199 return result;
200 }
201
202 result = reply.readUint64(&outStats->numFrames);
203 if (result != NO_ERROR) {
204 return result;
205 }
206
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800207 result = reply.readUint64Vector(&outStats->component_0_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700208 if (result != NO_ERROR) {
209 return result;
210 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800211 result = reply.readUint64Vector(&outStats->component_1_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700212 if (result != NO_ERROR) {
213 return result;
214 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800215 result = reply.readUint64Vector(&outStats->component_2_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700216 if (result != NO_ERROR) {
217 return result;
218 }
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800219 result = reply.readUint64Vector(&outStats->component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700220 return result;
221 }
Peiyong Lin3c2791e2019-01-14 17:05:18 -0800222
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000223 status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor,
224 float lightPosY, float lightPosZ, float lightRadius) override {
Vishnu Nairb13bb952019-11-15 10:24:08 -0800225 Parcel data, reply;
226 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
227 if (error != NO_ERROR) {
228 ALOGE("setGlobalShadowSettings: failed to write interface token: %d", error);
229 return error;
230 }
231
232 std::vector<float> shadowConfig = {ambientColor.r, ambientColor.g, ambientColor.b,
233 ambientColor.a, spotColor.r, spotColor.g,
234 spotColor.b, spotColor.a, lightPosY,
235 lightPosZ, lightRadius};
236
237 error = data.writeFloatVector(shadowConfig);
238 if (error != NO_ERROR) {
239 ALOGE("setGlobalShadowSettings: failed to write shadowConfig: %d", error);
240 return error;
241 }
242
243 error = remote()->transact(BnSurfaceComposer::SET_GLOBAL_SHADOW_SETTINGS, data, &reply,
244 IBinder::FLAG_ONEWAY);
245 if (error != NO_ERROR) {
246 ALOGE("setGlobalShadowSettings: failed to transact: %d", error);
247 return error;
248 }
249 return NO_ERROR;
250 }
Steven Thomas62a4cf82020-01-31 12:04:03 -0800251
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500252 status_t getDisplayDecorationSupport(
253 const sp<IBinder>& displayToken,
254 std::optional<common::DisplayDecorationSupport>* outSupport) const override {
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500255 Parcel data, reply;
256 status_t error = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
257 if (error != NO_ERROR) {
258 ALOGE("getDisplayDecorationSupport: failed to write interface token: %d", error);
259 return error;
260 }
261 error = data.writeStrongBinder(displayToken);
262 if (error != NO_ERROR) {
263 ALOGE("getDisplayDecorationSupport: failed to write display token: %d", error);
264 return error;
265 }
266 error = remote()->transact(BnSurfaceComposer::GET_DISPLAY_DECORATION_SUPPORT, data, &reply);
267 if (error != NO_ERROR) {
268 ALOGE("getDisplayDecorationSupport: failed to transact: %d", error);
269 return error;
270 }
271 bool support;
272 error = reply.readBool(&support);
273 if (error != NO_ERROR) {
274 ALOGE("getDisplayDecorationSupport: failed to read support: %d", error);
275 return error;
276 }
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500277
278 if (support) {
279 int32_t format, alphaInterpretation;
280 error = reply.readInt32(&format);
281 if (error != NO_ERROR) {
282 ALOGE("getDisplayDecorationSupport: failed to read format: %d", error);
283 return error;
284 }
285 error = reply.readInt32(&alphaInterpretation);
286 if (error != NO_ERROR) {
287 ALOGE("getDisplayDecorationSupport: failed to read alphaInterpretation: %d", error);
288 return error;
289 }
290 outSupport->emplace();
291 outSupport->value().format = static_cast<common::PixelFormat>(format);
292 outSupport->value().alphaInterpretation =
293 static_cast<common::AlphaInterpretation>(alphaInterpretation);
294 } else {
295 outSupport->reset();
296 }
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500297 return NO_ERROR;
298 }
299
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000300 status_t setFrameRate(const sp<IGraphicBufferProducer>& surface, float frameRate,
Marin Shalamanovc5986772021-03-16 16:09:49 +0100301 int8_t compatibility, int8_t changeFrameRateStrategy) override {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800302 Parcel data, reply;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100303 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
304 SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(surface));
305 SAFE_PARCEL(data.writeFloat, frameRate);
306 SAFE_PARCEL(data.writeByte, compatibility);
307 SAFE_PARCEL(data.writeByte, changeFrameRateStrategy);
Steven Thomas62a4cf82020-01-31 12:04:03 -0800308
Marin Shalamanovc5986772021-03-16 16:09:49 +0100309 status_t err = remote()->transact(BnSurfaceComposer::SET_FRAME_RATE, data, &reply);
Steven Thomas62a4cf82020-01-31 12:04:03 -0800310 if (err != NO_ERROR) {
311 ALOGE("setFrameRate: failed to transact: %s (%d)", strerror(-err), err);
312 return err;
313 }
Steven Thomasd4071902020-03-24 16:02:53 -0700314
315 return reply.readInt32();
316 }
317
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000318 status_t setFrameTimelineInfo(const sp<IGraphicBufferProducer>& surface,
319 const FrameTimelineInfo& frameTimelineInfo) override {
Ady Abraham74e17562020-08-24 18:18:19 -0700320 Parcel data, reply;
321 status_t err = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
322 if (err != NO_ERROR) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000323 ALOGE("%s: failed writing interface token: %s (%d)", __func__, strerror(-err), -err);
Ady Abraham74e17562020-08-24 18:18:19 -0700324 return err;
325 }
326
327 err = data.writeStrongBinder(IInterface::asBinder(surface));
328 if (err != NO_ERROR) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000329 ALOGE("%s: failed writing strong binder: %s (%d)", __func__, strerror(-err), -err);
Ady Abraham74e17562020-08-24 18:18:19 -0700330 return err;
331 }
332
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000333 SAFE_PARCEL(frameTimelineInfo.write, data);
Ady Abraham74e17562020-08-24 18:18:19 -0700334
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000335 err = remote()->transact(BnSurfaceComposer::SET_FRAME_TIMELINE_INFO, data, &reply);
Ady Abraham74e17562020-08-24 18:18:19 -0700336 if (err != NO_ERROR) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000337 ALOGE("%s: failed to transact: %s (%d)", __func__, strerror(-err), err);
Ady Abraham74e17562020-08-24 18:18:19 -0700338 return err;
339 }
340
341 return reply.readInt32();
342 }
Pablo Gamito6ee484d2020-07-30 14:26:28 +0000343
Andy Yu2ae6b6b2021-11-18 14:51:06 -0800344 status_t setOverrideFrameRate(uid_t uid, float frameRate) override {
345 Parcel data, reply;
346 SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
347 SAFE_PARCEL(data.writeUint32, uid);
348 SAFE_PARCEL(data.writeFloat, frameRate);
349
350 status_t err = remote()->transact(BnSurfaceComposer::SET_OVERRIDE_FRAME_RATE, data, &reply);
351 if (err != NO_ERROR) {
352 ALOGE("setOverrideFrameRate: failed to transact %s (%d)", strerror(-err), err);
353 return err;
354 }
355
356 return NO_ERROR;
357 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800358};
359
Dan Stozad723bd72014-11-18 10:24:03 -0800360// Out-of-line virtual method definition to trigger vtable emission in this
361// translation unit (see clang warning -Wweak-vtables)
362BpSurfaceComposer::~BpSurfaceComposer() {}
363
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800364IMPLEMENT_META_INTERFACE(SurfaceComposer, "android.ui.ISurfaceComposer");
365
366// ----------------------------------------------------------------------
367
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800368status_t BnSurfaceComposer::onTransact(
369 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
370{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800371 switch(code) {
372 case CREATE_CONNECTION: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700373 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800374 sp<IBinder> b = IInterface::asBinder(createConnection());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800375 reply->writeStrongBinder(b);
Jesse Hall6c913be2013-08-08 12:15:49 -0700376 return NO_ERROR;
377 }
Mathias Agopian698c0872011-06-28 19:09:31 -0700378 case SET_TRANSACTION_STATE: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700379 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -0800380
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000381 FrameTimelineInfo frameTimelineInfo;
382 SAFE_PARCEL(frameTimelineInfo.read, data);
383
chaviw308ddba2020-08-11 16:23:51 -0700384 uint32_t count = 0;
385 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian698c0872011-06-28 19:09:31 -0700386 Vector<ComposerState> state;
387 state.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800388 for (size_t i = 0; i < count; i++) {
Marissa Wallc837b5e2018-10-12 10:04:44 -0700389 ComposerState s;
chaviw308ddba2020-08-11 16:23:51 -0700390 SAFE_PARCEL(s.read, data);
Mathias Agopian698c0872011-06-28 19:09:31 -0700391 state.add(s);
392 }
Dan Stozad723bd72014-11-18 10:24:03 -0800393
chaviw308ddba2020-08-11 16:23:51 -0700394 SAFE_PARCEL_READ_SIZE(data.readUint32, &count, data.dataSize());
Mathias Agopian8b33f032012-07-24 20:43:54 -0700395 DisplayState d;
396 Vector<DisplayState> displays;
397 displays.setCapacity(count);
Dan Stozad723bd72014-11-18 10:24:03 -0800398 for (size_t i = 0; i < count; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700399 SAFE_PARCEL(d.read, data);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700400 displays.add(d);
401 }
Dan Stozad723bd72014-11-18 10:24:03 -0800402
chaviw308ddba2020-08-11 16:23:51 -0700403 uint32_t stateFlags = 0;
404 SAFE_PARCEL(data.readUint32, &stateFlags);
405 sp<IBinder> applyToken;
406 SAFE_PARCEL(data.readStrongBinder, &applyToken);
chaviw273171b2018-12-26 11:46:30 -0800407 InputWindowCommands inputWindowCommands;
chaviw308ddba2020-08-11 16:23:51 -0700408 SAFE_PARCEL(inputWindowCommands.read, data);
Marissa Wall17b4e452018-12-26 16:32:34 -0800409
chaviw308ddba2020-08-11 16:23:51 -0700410 int64_t desiredPresentTime = 0;
Ady Abrahamf0c56492020-12-17 18:04:15 -0800411 bool isAutoTimestamp = true;
chaviw308ddba2020-08-11 16:23:51 -0700412 SAFE_PARCEL(data.readInt64, &desiredPresentTime);
Ady Abrahamf0c56492020-12-17 18:04:15 -0800413 SAFE_PARCEL(data.readBool, &isAutoTimestamp);
Marissa Wall78b72202019-03-15 14:58:34 -0700414
Marissa Wall947d34e2019-03-29 14:03:53 -0700415 client_cache_t uncachedBuffer;
chaviw308ddba2020-08-11 16:23:51 -0700416 sp<IBinder> tmpBinder;
417 SAFE_PARCEL(data.readNullableStrongBinder, &tmpBinder);
418 uncachedBuffer.token = tmpBinder;
419 SAFE_PARCEL(data.readUint64, &uncachedBuffer.id);
Marissa Wall78b72202019-03-15 14:58:34 -0700420
chaviw308ddba2020-08-11 16:23:51 -0700421 bool hasListenerCallbacks = false;
422 SAFE_PARCEL(data.readBool, &hasListenerCallbacks);
Valerie Hau9dab9732019-08-20 09:29:25 -0700423
Marissa Wall3dad52d2019-03-22 14:03:19 -0700424 std::vector<ListenerCallbacks> listenerCallbacks;
chaviw308ddba2020-08-11 16:23:51 -0700425 int32_t listenersSize = 0;
426 SAFE_PARCEL_READ_SIZE(data.readInt32, &listenersSize, data.dataSize());
Marissa Wall3dad52d2019-03-22 14:03:19 -0700427 for (int32_t i = 0; i < listenersSize; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700428 SAFE_PARCEL(data.readStrongBinder, &tmpBinder);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700429 std::vector<CallbackId> callbackIds;
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700430 SAFE_PARCEL(data.readParcelableVector, &callbackIds);
chaviw308ddba2020-08-11 16:23:51 -0700431 listenerCallbacks.emplace_back(tmpBinder, callbackIds);
Marissa Wall3dad52d2019-03-22 14:03:19 -0700432 }
Pablo Gamito7eb7ee72020-08-05 10:57:05 +0000433
434 uint64_t transactionId = -1;
435 SAFE_PARCEL(data.readUint64, &transactionId);
436
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000437 return setTransactionState(frameTimelineInfo, state, displays, stateFlags, applyToken,
438 inputWindowCommands, desiredPresentTime, isAutoTimestamp,
439 uncachedBuffer, hasListenerCallbacks, listenerCallbacks,
440 transactionId);
Jesse Hall6c913be2013-08-08 12:15:49 -0700441 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800442 case BOOT_FINISHED: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700443 CHECK_INTERFACE(ISurfaceComposer, data, reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444 bootFinished();
Jesse Hall6c913be2013-08-08 12:15:49 -0700445 return NO_ERROR;
446 }
Jamie Gennis134f0422011-03-08 12:18:54 -0800447 case AUTHENTICATE_SURFACE: {
448 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Andy McFadden2adaf042012-12-18 09:49:45 -0800449 sp<IGraphicBufferProducer> bufferProducer =
450 interface_cast<IGraphicBufferProducer>(data.readStrongBinder());
451 int32_t result = authenticateSurfaceTexture(bufferProducer) ? 1 : 0;
Jamie Gennis134f0422011-03-08 12:18:54 -0800452 reply->writeInt32(result);
Jesse Hall6c913be2013-08-08 12:15:49 -0700453 return NO_ERROR;
454 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800455 case CREATE_DISPLAY_EVENT_CONNECTION: {
456 CHECK_INTERFACE(ISurfaceComposer, data, reply);
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700457 auto vsyncSource = static_cast<ISurfaceComposer::VsyncSource>(data.readInt32());
Ady Abraham62f216c2020-10-13 19:07:23 -0700458 EventRegistrationFlags eventRegistration =
459 static_cast<EventRegistration>(data.readUint32());
Ady Abraham0f4a1b12019-06-04 16:04:04 -0700460
461 sp<IDisplayEventConnection> connection(
Ady Abraham62f216c2020-10-13 19:07:23 -0700462 createDisplayEventConnection(vsyncSource, eventRegistration));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800463 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800464 return NO_ERROR;
Jesse Hall6c913be2013-08-08 12:15:49 -0700465 }
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700466 case GET_DISPLAYED_CONTENT_SAMPLE: {
467 CHECK_INTERFACE(ISurfaceComposer, data, reply);
468
469 sp<IBinder> display = data.readStrongBinder();
470 uint64_t maxFrames = 0;
471 uint64_t timestamp = 0;
472
473 status_t result = data.readUint64(&maxFrames);
474 if (result != NO_ERROR) {
475 ALOGE("getDisplayedContentSample failure in reading max frames: %d", result);
476 return result;
477 }
478
479 result = data.readUint64(&timestamp);
480 if (result != NO_ERROR) {
481 ALOGE("getDisplayedContentSample failure in reading timestamp: %d", result);
482 return result;
483 }
484
485 DisplayedFrameStats stats;
486 result = getDisplayedContentSample(display, maxFrames, timestamp, &stats);
487 if (result == NO_ERROR) {
488 reply->writeUint64(stats.numFrames);
Kevin DuBois1d4c6a62018-12-12 13:59:46 -0800489 reply->writeUint64Vector(stats.component_0_sample);
490 reply->writeUint64Vector(stats.component_1_sample);
491 reply->writeUint64Vector(stats.component_2_sample);
492 reply->writeUint64Vector(stats.component_3_sample);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700493 }
494 return result;
495 }
Vishnu Nairb13bb952019-11-15 10:24:08 -0800496 case SET_GLOBAL_SHADOW_SETTINGS: {
497 CHECK_INTERFACE(ISurfaceComposer, data, reply);
498
499 std::vector<float> shadowConfig;
500 status_t error = data.readFloatVector(&shadowConfig);
501 if (error != NO_ERROR || shadowConfig.size() != 11) {
502 ALOGE("setGlobalShadowSettings: failed to read shadowConfig: %d", error);
503 return error;
504 }
505
506 half4 ambientColor = {shadowConfig[0], shadowConfig[1], shadowConfig[2],
507 shadowConfig[3]};
508 half4 spotColor = {shadowConfig[4], shadowConfig[5], shadowConfig[6], shadowConfig[7]};
509 float lightPosY = shadowConfig[8];
510 float lightPosZ = shadowConfig[9];
511 float lightRadius = shadowConfig[10];
512 return setGlobalShadowSettings(ambientColor, spotColor, lightPosY, lightPosZ,
513 lightRadius);
514 }
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500515 case GET_DISPLAY_DECORATION_SUPPORT: {
516 CHECK_INTERFACE(ISurfaceComposer, data, reply);
517 sp<IBinder> displayToken;
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500518 SAFE_PARCEL(data.readNullableStrongBinder, &displayToken);
519 std::optional<common::DisplayDecorationSupport> support;
520 auto error = getDisplayDecorationSupport(displayToken, &support);
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500521 if (error != NO_ERROR) {
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500522 ALOGE("getDisplayDecorationSupport failed with error %d", error);
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500523 return error;
524 }
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500525 reply->writeBool(support.has_value());
526 if (support) {
527 reply->writeInt32(static_cast<int32_t>(support.value().format));
528 reply->writeInt32(static_cast<int32_t>(support.value().alphaInterpretation));
529 }
Leon Scroggins IIIe5cff632021-12-29 11:53:36 -0500530 return error;
531 }
Steven Thomas62a4cf82020-01-31 12:04:03 -0800532 case SET_FRAME_RATE: {
533 CHECK_INTERFACE(ISurfaceComposer, data, reply);
534 sp<IBinder> binder;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100535 SAFE_PARCEL(data.readStrongBinder, &binder);
536
Steven Thomas62a4cf82020-01-31 12:04:03 -0800537 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
538 if (!surface) {
Marin Shalamanovc5986772021-03-16 16:09:49 +0100539 ALOGE("setFrameRate: failed to cast to IGraphicBufferProducer");
540 return BAD_VALUE;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800541 }
542 float frameRate;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100543 SAFE_PARCEL(data.readFloat, &frameRate);
544
Steven Thomas62a4cf82020-01-31 12:04:03 -0800545 int8_t compatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100546 SAFE_PARCEL(data.readByte, &compatibility);
547
548 int8_t changeFrameRateStrategy;
549 SAFE_PARCEL(data.readByte, &changeFrameRateStrategy);
550
551 status_t result =
552 setFrameRate(surface, frameRate, compatibility, changeFrameRateStrategy);
Steven Thomas62a4cf82020-01-31 12:04:03 -0800553 reply->writeInt32(result);
554 return NO_ERROR;
555 }
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000556 case SET_FRAME_TIMELINE_INFO: {
Ady Abraham74e17562020-08-24 18:18:19 -0700557 CHECK_INTERFACE(ISurfaceComposer, data, reply);
558 sp<IBinder> binder;
559 status_t err = data.readStrongBinder(&binder);
560 if (err != NO_ERROR) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000561 ALOGE("setFrameTimelineInfo: failed to read strong binder: %s (%d)", strerror(-err),
562 -err);
Ady Abraham74e17562020-08-24 18:18:19 -0700563 return err;
564 }
565 sp<IGraphicBufferProducer> surface = interface_cast<IGraphicBufferProducer>(binder);
566 if (!surface) {
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000567 ALOGE("setFrameTimelineInfo: failed to cast to IGraphicBufferProducer: %s (%d)",
Ady Abraham74e17562020-08-24 18:18:19 -0700568 strerror(-err), -err);
569 return err;
570 }
Ady Abraham74e17562020-08-24 18:18:19 -0700571
Siarhei Vishniakoufc434ac2021-01-13 10:28:00 -1000572 FrameTimelineInfo frameTimelineInfo;
573 SAFE_PARCEL(frameTimelineInfo.read, data);
574
575 status_t result = setFrameTimelineInfo(surface, frameTimelineInfo);
Ady Abraham74e17562020-08-24 18:18:19 -0700576 reply->writeInt32(result);
577 return NO_ERROR;
578 }
Andy Yu2ae6b6b2021-11-18 14:51:06 -0800579 case SET_OVERRIDE_FRAME_RATE: {
580 CHECK_INTERFACE(ISurfaceComposer, data, reply);
581
582 uid_t uid;
583 SAFE_PARCEL(data.readUint32, &uid);
584
585 float frameRate;
586 SAFE_PARCEL(data.readFloat, &frameRate);
587
588 return setOverrideFrameRate(uid, frameRate);
589 }
Jesse Hall6c913be2013-08-08 12:15:49 -0700590 default: {
Mathias Agopian83c04462009-05-22 19:00:22 -0700591 return BBinder::onTransact(code, data, reply, flags);
Jesse Hall6c913be2013-08-08 12:15:49 -0700592 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800593 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800594}
595
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800596} // namespace android