blob: f848e4ffdef0b862c982b1592ec91a1c7b06da92 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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
Vishnu Nair217d8e62018-09-12 16:34:49 -070017#define LOG_TAG "LayerState"
18
Ady Abrahamdd5bfa92021-01-07 17:56:08 -080019#include <apex/window.h>
Garfield Tan8a3083e2018-12-03 13:21:07 -080020#include <inttypes.h>
21
Marin Shalamanovc5986772021-03-16 16:09:49 +010022#include <android/native_window.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/Parcel.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080024#include <gui/IGraphicBufferProducer.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000025#include <gui/ISurfaceComposerClient.h>
Robert Carr4cdc58f2017-08-23 14:22:20 -070026#include <gui/LayerState.h>
Marin Shalamanov3b1f7bc2021-03-16 15:51:53 +010027#include <private/gui/ParcelUtils.h>
Pablo Gamito11dcc222020-09-12 15:49:39 +000028#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
Steven Thomas62a4cf82020-01-31 12:04:03 -080030#include <cmath>
31
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032namespace android {
33
chaviw98318de2021-05-19 16:45:23 -050034using gui::FocusRequest;
35using gui::WindowInfoHandle;
36
Pablo Gamito11dcc222020-09-12 15:49:39 +000037layer_state_t::layer_state_t()
38 : what(0),
39 x(0),
40 y(0),
41 z(0),
42 w(0),
43 h(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000044 alpha(0),
45 flags(0),
46 mask(0),
47 reserved(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000048 cornerRadius(0.0f),
49 backgroundBlurRadius(0),
Pablo Gamito11dcc222020-09-12 15:49:39 +000050 transform(0),
51 transformToDisplayInverse(false),
52 crop(Rect::INVALID_RECT),
Pablo Gamito11dcc222020-09-12 15:49:39 +000053 dataspace(ui::Dataspace::UNKNOWN),
54 surfaceDamageRegion(),
55 api(-1),
56 colorTransform(mat4()),
57 bgColorAlpha(0),
58 bgColorDataspace(ui::Dataspace::UNKNOWN),
59 colorSpaceAgnostic(false),
60 shadowRadius(0.0f),
61 frameRateSelectionPriority(-1),
62 frameRate(0.0f),
63 frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
Marin Shalamanovc5986772021-03-16 16:09:49 +010064 changeFrameRateStrategy(ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS),
Pablo Gamito11dcc222020-09-12 15:49:39 +000065 fixedTransformHint(ui::Transform::ROT_INVALID),
Vishnu Nair1506b182021-02-22 14:35:15 -080066 autoRefresh(false),
Winson Chunga30f7c92021-06-29 15:42:56 -070067 isTrustedOverlay(false),
Vishnu Nair6bdec7d2021-05-10 15:01:13 -070068 bufferCrop(Rect::INVALID_RECT),
69 destinationFrame(Rect::INVALID_RECT),
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -070070 dropInputMode(gui::DropInputMode::NONE) {
Pablo Gamito11dcc222020-09-12 15:49:39 +000071 matrix.dsdx = matrix.dtdy = 1.0f;
72 matrix.dsdy = matrix.dtdx = 0.0f;
73 hdrMetadata.validTypes = 0;
74}
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076status_t layer_state_t::write(Parcel& output) const
77{
chaviw308ddba2020-08-11 16:23:51 -070078 SAFE_PARCEL(output.writeStrongBinder, surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +000079 SAFE_PARCEL(output.writeInt32, layerId);
chaviw308ddba2020-08-11 16:23:51 -070080 SAFE_PARCEL(output.writeUint64, what);
81 SAFE_PARCEL(output.writeFloat, x);
82 SAFE_PARCEL(output.writeFloat, y);
83 SAFE_PARCEL(output.writeInt32, z);
84 SAFE_PARCEL(output.writeUint32, w);
85 SAFE_PARCEL(output.writeUint32, h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -070086 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -070087 SAFE_PARCEL(output.writeFloat, alpha);
88 SAFE_PARCEL(output.writeUint32, flags);
89 SAFE_PARCEL(output.writeUint32, mask);
90 SAFE_PARCEL(matrix.write, output);
chaviw25714502021-02-11 10:01:08 -080091 SAFE_PARCEL(output.write, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +000092 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
Pablo Gamito11dcc222020-09-12 15:49:39 +000093 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
94 SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
chaviw308ddba2020-08-11 16:23:51 -070095 SAFE_PARCEL(output.writeFloat, color.r);
96 SAFE_PARCEL(output.writeFloat, color.g);
97 SAFE_PARCEL(output.writeFloat, color.b);
chaviw98318de2021-05-19 16:45:23 -050098 SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
chaviw308ddba2020-08-11 16:23:51 -070099 SAFE_PARCEL(output.write, transparentRegion);
100 SAFE_PARCEL(output.writeUint32, transform);
101 SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700102
chaviw308ddba2020-08-11 16:23:51 -0700103 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
104 SAFE_PARCEL(output.write, hdrMetadata);
105 SAFE_PARCEL(output.write, surfaceDamageRegion);
106 SAFE_PARCEL(output.writeInt32, api);
107
Marissa Wall61c58622018-07-18 10:12:20 -0700108 if (sidebandStream) {
chaviw308ddba2020-08-11 16:23:51 -0700109 SAFE_PARCEL(output.writeBool, true);
110 SAFE_PARCEL(output.writeNativeHandle, sidebandStream->handle());
Marissa Wall61c58622018-07-18 10:12:20 -0700111 } else {
chaviw308ddba2020-08-11 16:23:51 -0700112 SAFE_PARCEL(output.writeBool, false);
Marissa Wall61c58622018-07-18 10:12:20 -0700113 }
114
chaviw308ddba2020-08-11 16:23:51 -0700115 SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
116 SAFE_PARCEL(output.writeFloat, cornerRadius);
117 SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700118 SAFE_PARCEL(output.writeParcelable, metadata);
119 SAFE_PARCEL(output.writeFloat, bgColorAlpha);
120 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(bgColorDataspace));
121 SAFE_PARCEL(output.writeBool, colorSpaceAgnostic);
122 SAFE_PARCEL(output.writeVectorSize, listeners);
Valerie Hau9dab9732019-08-20 09:29:25 -0700123
124 for (auto listener : listeners) {
chaviw308ddba2020-08-11 16:23:51 -0700125 SAFE_PARCEL(output.writeStrongBinder, listener.transactionCompletedListener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700126 SAFE_PARCEL(output.writeParcelableVector, listener.callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700127 }
chaviw308ddba2020-08-11 16:23:51 -0700128 SAFE_PARCEL(output.writeFloat, shadowRadius);
129 SAFE_PARCEL(output.writeInt32, frameRateSelectionPriority);
130 SAFE_PARCEL(output.writeFloat, frameRate);
131 SAFE_PARCEL(output.writeByte, frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100132 SAFE_PARCEL(output.writeByte, changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700133 SAFE_PARCEL(output.writeUint32, fixedTransformHint);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800134 SAFE_PARCEL(output.writeBool, autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700135
136 SAFE_PARCEL(output.writeUint32, blurRegions.size());
137 for (auto region : blurRegions) {
138 SAFE_PARCEL(output.writeUint32, region.blurRadius);
139 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTL);
140 SAFE_PARCEL(output.writeFloat, region.cornerRadiusTR);
141 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBL);
142 SAFE_PARCEL(output.writeFloat, region.cornerRadiusBR);
143 SAFE_PARCEL(output.writeFloat, region.alpha);
144 SAFE_PARCEL(output.writeInt32, region.left);
145 SAFE_PARCEL(output.writeInt32, region.top);
146 SAFE_PARCEL(output.writeInt32, region.right);
147 SAFE_PARCEL(output.writeInt32, region.bottom);
148 }
John Reckcdb4ed72021-02-04 13:39:33 -0500149
150 SAFE_PARCEL(output.write, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500151 SAFE_PARCEL(output.write, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700152 SAFE_PARCEL(output.write, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700153 SAFE_PARCEL(output.writeBool, isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500154
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700155 SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dropInputMode));
chaviwba4320c2021-09-15 15:20:53 -0500156 SAFE_PARCEL(bufferData.write, output);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 return NO_ERROR;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158}
159
160status_t layer_state_t::read(const Parcel& input)
161{
chaviw308ddba2020-08-11 16:23:51 -0700162 SAFE_PARCEL(input.readNullableStrongBinder, &surface);
Pablo Gamitodbc31672020-09-01 18:28:58 +0000163 SAFE_PARCEL(input.readInt32, &layerId);
chaviw308ddba2020-08-11 16:23:51 -0700164 SAFE_PARCEL(input.readUint64, &what);
165 SAFE_PARCEL(input.readFloat, &x);
166 SAFE_PARCEL(input.readFloat, &y);
167 SAFE_PARCEL(input.readInt32, &z);
168 SAFE_PARCEL(input.readUint32, &w);
169 SAFE_PARCEL(input.readUint32, &h);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700170 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700171 SAFE_PARCEL(input.readFloat, &alpha);
Robert Carr2c358bf2018-08-08 15:58:15 -0700172
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800173 SAFE_PARCEL(input.readUint32, &flags);
chaviw308ddba2020-08-11 16:23:51 -0700174
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800175 SAFE_PARCEL(input.readUint32, &mask);
chaviw308ddba2020-08-11 16:23:51 -0700176
177 SAFE_PARCEL(matrix.read, input);
chaviw25714502021-02-11 10:01:08 -0800178 SAFE_PARCEL(input.read, crop);
Pablo Gamito11dcc222020-09-12 15:49:39 +0000179 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
chaviw308ddba2020-08-11 16:23:51 -0700180
Pablo Gamito11dcc222020-09-12 15:49:39 +0000181 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
182 SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
183
chaviw308ddba2020-08-11 16:23:51 -0700184 float tmpFloat = 0;
chaviw308ddba2020-08-11 16:23:51 -0700185 SAFE_PARCEL(input.readFloat, &tmpFloat);
186 color.r = tmpFloat;
187 SAFE_PARCEL(input.readFloat, &tmpFloat);
188 color.g = tmpFloat;
189 SAFE_PARCEL(input.readFloat, &tmpFloat);
190 color.b = tmpFloat;
chaviw98318de2021-05-19 16:45:23 -0500191 SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
Robert Carr2c358bf2018-08-08 15:58:15 -0700192
chaviw308ddba2020-08-11 16:23:51 -0700193 SAFE_PARCEL(input.read, transparentRegion);
194 SAFE_PARCEL(input.readUint32, &transform);
195 SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
chaviw308ddba2020-08-11 16:23:51 -0700196
Vishnu Nairf6eddb62021-01-27 22:02:11 -0800197 uint32_t tmpUint32 = 0;
chaviw308ddba2020-08-11 16:23:51 -0700198 SAFE_PARCEL(input.readUint32, &tmpUint32);
199 dataspace = static_cast<ui::Dataspace>(tmpUint32);
200
201 SAFE_PARCEL(input.read, hdrMetadata);
202 SAFE_PARCEL(input.read, surfaceDamageRegion);
203 SAFE_PARCEL(input.readInt32, &api);
chaviwba4320c2021-09-15 15:20:53 -0500204
205 bool tmpBool = false;
chaviw308ddba2020-08-11 16:23:51 -0700206 SAFE_PARCEL(input.readBool, &tmpBool);
207 if (tmpBool) {
Marissa Wall61c58622018-07-18 10:12:20 -0700208 sidebandStream = NativeHandle::create(input.readNativeHandle(), true);
209 }
210
chaviw308ddba2020-08-11 16:23:51 -0700211 SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
212 SAFE_PARCEL(input.readFloat, &cornerRadius);
213 SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
chaviw308ddba2020-08-11 16:23:51 -0700214 SAFE_PARCEL(input.readParcelable, &metadata);
Marissa Wallebc2c052019-01-16 19:16:55 -0800215
chaviw308ddba2020-08-11 16:23:51 -0700216 SAFE_PARCEL(input.readFloat, &bgColorAlpha);
217 SAFE_PARCEL(input.readUint32, &tmpUint32);
218 bgColorDataspace = static_cast<ui::Dataspace>(tmpUint32);
219 SAFE_PARCEL(input.readBool, &colorSpaceAgnostic);
Valerie Haued54efa2019-01-11 20:03:14 -0800220
chaviw308ddba2020-08-11 16:23:51 -0700221 int32_t numListeners = 0;
222 SAFE_PARCEL_READ_SIZE(input.readInt32, &numListeners, input.dataSize());
Valerie Hau9dab9732019-08-20 09:29:25 -0700223 listeners.clear();
224 for (int i = 0; i < numListeners; i++) {
chaviw308ddba2020-08-11 16:23:51 -0700225 sp<IBinder> listener;
Valerie Hau9dab9732019-08-20 09:29:25 -0700226 std::vector<CallbackId> callbackIds;
chaviw308ddba2020-08-11 16:23:51 -0700227 SAFE_PARCEL(input.readNullableStrongBinder, &listener);
Vishnu Nairfc46c1e2021-04-21 08:31:32 -0700228 SAFE_PARCEL(input.readParcelableVector, &callbackIds);
Valerie Hau9dab9732019-08-20 09:29:25 -0700229 listeners.emplace_back(listener, callbackIds);
230 }
chaviw308ddba2020-08-11 16:23:51 -0700231 SAFE_PARCEL(input.readFloat, &shadowRadius);
232 SAFE_PARCEL(input.readInt32, &frameRateSelectionPriority);
233 SAFE_PARCEL(input.readFloat, &frameRate);
234 SAFE_PARCEL(input.readByte, &frameRateCompatibility);
Marin Shalamanovc5986772021-03-16 16:09:49 +0100235 SAFE_PARCEL(input.readByte, &changeFrameRateStrategy);
chaviw308ddba2020-08-11 16:23:51 -0700236 SAFE_PARCEL(input.readUint32, &tmpUint32);
237 fixedTransformHint = static_cast<ui::Transform::RotationFlags>(tmpUint32);
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800238 SAFE_PARCEL(input.readBool, &autoRefresh);
Lucas Dupinc3800b82020-10-02 16:24:48 -0700239
240 uint32_t numRegions = 0;
241 SAFE_PARCEL(input.readUint32, &numRegions);
242 blurRegions.clear();
243 for (uint32_t i = 0; i < numRegions; i++) {
244 BlurRegion region;
245 SAFE_PARCEL(input.readUint32, &region.blurRadius);
246 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTL);
247 SAFE_PARCEL(input.readFloat, &region.cornerRadiusTR);
248 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBL);
249 SAFE_PARCEL(input.readFloat, &region.cornerRadiusBR);
250 SAFE_PARCEL(input.readFloat, &region.alpha);
251 SAFE_PARCEL(input.readInt32, &region.left);
252 SAFE_PARCEL(input.readInt32, &region.top);
253 SAFE_PARCEL(input.readInt32, &region.right);
254 SAFE_PARCEL(input.readInt32, &region.bottom);
255 blurRegions.push_back(region);
256 }
John Reckcdb4ed72021-02-04 13:39:33 -0500257
258 SAFE_PARCEL(input.read, stretchEffect);
chaviwf3f40fe2021-04-27 15:54:02 -0500259 SAFE_PARCEL(input.read, bufferCrop);
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700260 SAFE_PARCEL(input.read, destinationFrame);
Winson Chunga30f7c92021-06-29 15:42:56 -0700261 SAFE_PARCEL(input.readBool, &isTrustedOverlay);
John Reckcdb4ed72021-02-04 13:39:33 -0500262
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700263 uint32_t mode;
264 SAFE_PARCEL(input.readUint32, &mode);
265 dropInputMode = static_cast<gui::DropInputMode>(mode);
chaviwba4320c2021-09-15 15:20:53 -0500266 SAFE_PARCEL(bufferData.read, input);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800267 return NO_ERROR;
268}
269
Mathias Agopian698c0872011-06-28 19:09:31 -0700270status_t ComposerState::write(Parcel& output) const {
Mathias Agopian698c0872011-06-28 19:09:31 -0700271 return state.write(output);
272}
273
274status_t ComposerState::read(const Parcel& input) {
Mathias Agopian698c0872011-06-28 19:09:31 -0700275 return state.read(input);
276}
277
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700278DisplayState::DisplayState() = default;
Pablo Ceballos60d69222015-08-07 14:47:20 -0700279
Mathias Agopian8b33f032012-07-24 20:43:54 -0700280status_t DisplayState::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700281 SAFE_PARCEL(output.writeStrongBinder, token);
282 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(surface));
283 SAFE_PARCEL(output.writeUint32, what);
Evan Rosky2239b372021-05-20 13:43:47 -0700284 SAFE_PARCEL(output.writeUint32, flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700285 SAFE_PARCEL(output.writeUint32, layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700286 SAFE_PARCEL(output.writeUint32, toRotationInt(orientation));
287 SAFE_PARCEL(output.write, layerStackSpaceRect);
288 SAFE_PARCEL(output.write, orientedDisplaySpaceRect);
289 SAFE_PARCEL(output.writeUint32, width);
290 SAFE_PARCEL(output.writeUint32, height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700291 return NO_ERROR;
292}
293
294status_t DisplayState::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700295 SAFE_PARCEL(input.readStrongBinder, &token);
296 sp<IBinder> tmpBinder;
297 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
298 surface = interface_cast<IGraphicBufferProducer>(tmpBinder);
299
300 SAFE_PARCEL(input.readUint32, &what);
Evan Rosky2239b372021-05-20 13:43:47 -0700301 SAFE_PARCEL(input.readUint32, &flags);
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700302 SAFE_PARCEL(input.readUint32, &layerStack.id);
chaviw308ddba2020-08-11 16:23:51 -0700303 uint32_t tmpUint = 0;
304 SAFE_PARCEL(input.readUint32, &tmpUint);
305 orientation = ui::toRotation(tmpUint);
306
307 SAFE_PARCEL(input.read, layerStackSpaceRect);
308 SAFE_PARCEL(input.read, orientedDisplaySpaceRect);
309 SAFE_PARCEL(input.readUint32, &width);
310 SAFE_PARCEL(input.readUint32, &height);
Mathias Agopian8b33f032012-07-24 20:43:54 -0700311 return NO_ERROR;
312}
313
Robert Carr2c5f6d22017-09-26 12:30:35 -0700314void DisplayState::merge(const DisplayState& other) {
315 if (other.what & eSurfaceChanged) {
316 what |= eSurfaceChanged;
317 surface = other.surface;
318 }
319 if (other.what & eLayerStackChanged) {
320 what |= eLayerStackChanged;
321 layerStack = other.layerStack;
322 }
Evan Rosky2239b372021-05-20 13:43:47 -0700323 if (other.what & eFlagsChanged) {
324 what |= eFlagsChanged;
325 flags = other.flags;
326 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700327 if (other.what & eDisplayProjectionChanged) {
328 what |= eDisplayProjectionChanged;
329 orientation = other.orientation;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200330 layerStackSpaceRect = other.layerStackSpaceRect;
331 orientedDisplaySpaceRect = other.orientedDisplaySpaceRect;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700332 }
333 if (other.what & eDisplaySizeChanged) {
334 what |= eDisplaySizeChanged;
335 width = other.width;
336 height = other.height;
337 }
338}
339
340void layer_state_t::merge(const layer_state_t& other) {
341 if (other.what & ePositionChanged) {
342 what |= ePositionChanged;
343 x = other.x;
344 y = other.y;
345 }
346 if (other.what & eLayerChanged) {
347 what |= eLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700348 what &= ~eRelativeLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700349 z = other.z;
350 }
351 if (other.what & eSizeChanged) {
352 what |= eSizeChanged;
353 w = other.w;
354 h = other.h;
355 }
356 if (other.what & eAlphaChanged) {
357 what |= eAlphaChanged;
358 alpha = other.alpha;
359 }
360 if (other.what & eMatrixChanged) {
361 what |= eMatrixChanged;
362 matrix = other.matrix;
363 }
364 if (other.what & eTransparentRegionChanged) {
365 what |= eTransparentRegionChanged;
366 transparentRegion = other.transparentRegion;
367 }
368 if (other.what & eFlagsChanged) {
369 what |= eFlagsChanged;
Vishnu Nair996bc422019-07-16 14:15:33 -0700370 flags &= ~other.mask;
371 flags |= (other.flags & other.mask);
372 mask |= other.mask;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700373 }
374 if (other.what & eLayerStackChanged) {
375 what |= eLayerStackChanged;
376 layerStack = other.layerStack;
377 }
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700378 if (other.what & eCornerRadiusChanged) {
379 what |= eCornerRadiusChanged;
380 cornerRadius = other.cornerRadius;
381 }
Lucas Dupin19c8f0e2019-11-25 17:55:44 -0800382 if (other.what & eBackgroundBlurRadiusChanged) {
383 what |= eBackgroundBlurRadiusChanged;
384 backgroundBlurRadius = other.backgroundBlurRadius;
385 }
Lucas Dupinc3800b82020-10-02 16:24:48 -0700386 if (other.what & eBlurRegionsChanged) {
387 what |= eBlurRegionsChanged;
388 blurRegions = other.blurRegions;
389 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700390 if (other.what & eRelativeLayerChanged) {
391 what |= eRelativeLayerChanged;
chaviw32377582019-05-13 11:15:19 -0700392 what &= ~eLayerChanged;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700393 z = other.z;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000394 relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700395 }
396 if (other.what & eReparent) {
397 what |= eReparent;
Pablo Gamito11dcc222020-09-12 15:49:39 +0000398 parentSurfaceControlForChild = other.parentSurfaceControlForChild;
Robert Carr2c5f6d22017-09-26 12:30:35 -0700399 }
chaviwca27f252018-02-06 16:46:39 -0800400 if (other.what & eDestroySurface) {
401 what |= eDestroySurface;
402 }
Marissa Wall61c58622018-07-18 10:12:20 -0700403 if (other.what & eTransformChanged) {
404 what |= eTransformChanged;
405 transform = other.transform;
406 }
407 if (other.what & eTransformToDisplayInverseChanged) {
408 what |= eTransformToDisplayInverseChanged;
409 transformToDisplayInverse = other.transformToDisplayInverse;
410 }
411 if (other.what & eCropChanged) {
412 what |= eCropChanged;
413 crop = other.crop;
414 }
415 if (other.what & eBufferChanged) {
416 what |= eBufferChanged;
chaviwba4320c2021-09-15 15:20:53 -0500417 bufferData = other.bufferData;
Marissa Wall61c58622018-07-18 10:12:20 -0700418 }
419 if (other.what & eDataspaceChanged) {
420 what |= eDataspaceChanged;
421 dataspace = other.dataspace;
422 }
423 if (other.what & eHdrMetadataChanged) {
424 what |= eHdrMetadataChanged;
425 hdrMetadata = other.hdrMetadata;
426 }
427 if (other.what & eSurfaceDamageRegionChanged) {
428 what |= eSurfaceDamageRegionChanged;
429 surfaceDamageRegion = other.surfaceDamageRegion;
430 }
431 if (other.what & eApiChanged) {
432 what |= eApiChanged;
433 api = other.api;
434 }
435 if (other.what & eSidebandStreamChanged) {
436 what |= eSidebandStreamChanged;
437 sidebandStream = other.sidebandStream;
438 }
Peiyong Lind3788632018-09-18 16:01:31 -0700439 if (other.what & eColorTransformChanged) {
440 what |= eColorTransformChanged;
441 colorTransform = other.colorTransform;
442 }
Marissa Wall3dad52d2019-03-22 14:03:19 -0700443 if (other.what & eHasListenerCallbacksChanged) {
444 what |= eHasListenerCallbacksChanged;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700445 }
Robert Carr2c358bf2018-08-08 15:58:15 -0700446 if (other.what & eInputInfoChanged) {
447 what |= eInputInfoChanged;
chaviw98318de2021-05-19 16:45:23 -0500448 windowInfoHandle = new WindowInfoHandle(*other.windowInfoHandle);
Robert Carr2c358bf2018-08-08 15:58:15 -0700449 }
Valerie Haudd0b7572019-01-29 14:59:27 -0800450 if (other.what & eBackgroundColorChanged) {
451 what |= eBackgroundColorChanged;
452 color = other.color;
453 bgColorAlpha = other.bgColorAlpha;
454 bgColorDataspace = other.bgColorDataspace;
Valerie Haued54efa2019-01-11 20:03:14 -0800455 }
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800456 if (other.what & eMetadataChanged) {
457 what |= eMetadataChanged;
458 metadata.merge(other.metadata);
459 }
Vishnu Nairc97b8db2019-10-29 18:19:35 -0700460 if (other.what & eShadowRadiusChanged) {
461 what |= eShadowRadiusChanged;
462 shadowRadius = other.shadowRadius;
463 }
Ana Krulecc84d09b2019-11-02 23:10:29 +0100464 if (other.what & eFrameRateSelectionPriority) {
465 what |= eFrameRateSelectionPriority;
466 frameRateSelectionPriority = other.frameRateSelectionPriority;
467 }
Steven Thomas3172e202020-01-06 19:25:30 -0800468 if (other.what & eFrameRateChanged) {
469 what |= eFrameRateChanged;
470 frameRate = other.frameRate;
Steven Thomas62a4cf82020-01-31 12:04:03 -0800471 frameRateCompatibility = other.frameRateCompatibility;
Marin Shalamanovc5986772021-03-16 16:09:49 +0100472 changeFrameRateStrategy = other.changeFrameRateStrategy;
Steven Thomas3172e202020-01-06 19:25:30 -0800473 }
Vishnu Nair6213bd92020-05-08 17:42:25 -0700474 if (other.what & eFixedTransformHintChanged) {
475 what |= eFixedTransformHintChanged;
476 fixedTransformHint = other.fixedTransformHint;
477 }
Vishnu Naircf26a0a2020-11-13 12:56:20 -0800478 if (other.what & eAutoRefreshChanged) {
479 what |= eAutoRefreshChanged;
480 autoRefresh = other.autoRefresh;
481 }
Winson Chunga30f7c92021-06-29 15:42:56 -0700482 if (other.what & eTrustedOverlayChanged) {
483 what |= eTrustedOverlayChanged;
484 isTrustedOverlay = other.isTrustedOverlay;
485 }
John Reckc00c6692021-02-16 11:37:33 -0500486 if (other.what & eStretchChanged) {
487 what |= eStretchChanged;
488 stretchEffect = other.stretchEffect;
489 }
chaviwf3f40fe2021-04-27 15:54:02 -0500490 if (other.what & eBufferCropChanged) {
491 what |= eBufferCropChanged;
492 bufferCrop = other.bufferCrop;
493 }
Vishnu Nair6bdec7d2021-05-10 15:01:13 -0700494 if (other.what & eDestinationFrameChanged) {
495 what |= eDestinationFrameChanged;
496 destinationFrame = other.destinationFrame;
497 }
Vishnu Nair0e816872021-07-14 10:53:04 -0700498 if (other.what & eProducerDisconnect) {
499 what |= eProducerDisconnect;
500 }
Vishnu Nair9cf4a4d2021-09-17 12:16:08 -0700501 if (other.what & eDropInputModeChanged) {
502 what |= eDropInputModeChanged;
503 dropInputMode = other.dropInputMode;
504 }
Vishnu Nair217d8e62018-09-12 16:34:49 -0700505 if ((other.what & what) != other.what) {
506 ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? "
Vishnu Nair0e816872021-07-14 10:53:04 -0700507 "other.what=0x%" PRIX64 " what=0x%" PRIX64 " unmerged flags=0x%" PRIX64,
508 other.what, what, (other.what & what) ^ other.what);
Robert Carrd314f162018-08-15 13:12:42 -0700509 }
Robert Carr2c5f6d22017-09-26 12:30:35 -0700510}
Mathias Agopian8b33f032012-07-24 20:43:54 -0700511
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700512bool layer_state_t::hasBufferChanges() const {
chaviwba4320c2021-09-15 15:20:53 -0500513 return what & layer_state_t::eBufferChanged;
Vishnu Nairddf9b5c2021-03-29 18:53:41 -0700514}
515
Ady Abraham6e8e3642021-07-08 19:44:07 -0700516bool layer_state_t::hasValidBuffer() const {
chaviwba4320c2021-09-15 15:20:53 -0500517 return bufferData.buffer || bufferData.cachedBuffer.isValid();
Ady Abraham6e8e3642021-07-08 19:44:07 -0700518}
519
chaviw308ddba2020-08-11 16:23:51 -0700520status_t layer_state_t::matrix22_t::write(Parcel& output) const {
521 SAFE_PARCEL(output.writeFloat, dsdx);
522 SAFE_PARCEL(output.writeFloat, dtdx);
523 SAFE_PARCEL(output.writeFloat, dtdy);
524 SAFE_PARCEL(output.writeFloat, dsdy);
525 return NO_ERROR;
526}
527
528status_t layer_state_t::matrix22_t::read(const Parcel& input) {
529 SAFE_PARCEL(input.readFloat, &dsdx);
530 SAFE_PARCEL(input.readFloat, &dtdx);
531 SAFE_PARCEL(input.readFloat, &dtdy);
532 SAFE_PARCEL(input.readFloat, &dsdy);
533 return NO_ERROR;
534}
535
chaviw273171b2018-12-26 11:46:30 -0800536// ------------------------------- InputWindowCommands ----------------------------------------
537
Vishnu Naire798b472020-07-23 13:52:21 -0700538bool InputWindowCommands::merge(const InputWindowCommands& other) {
539 bool changes = false;
Vishnu Naire798b472020-07-23 13:52:21 -0700540 changes |= !other.focusRequests.empty();
541 focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
542 std::make_move_iterator(other.focusRequests.end()));
Vishnu Naire798b472020-07-23 13:52:21 -0700543 changes |= other.syncInputWindows && !syncInputWindows;
chaviwa911b102019-02-14 10:18:33 -0800544 syncInputWindows |= other.syncInputWindows;
Vishnu Naire798b472020-07-23 13:52:21 -0700545 return changes;
chaviw273171b2018-12-26 11:46:30 -0800546}
547
Vishnu Nair958da932020-08-21 17:12:37 -0700548bool InputWindowCommands::empty() const {
549 bool empty = true;
Vishnu Nair958da932020-08-21 17:12:37 -0700550 empty = focusRequests.empty() && !syncInputWindows;
Vishnu Nair958da932020-08-21 17:12:37 -0700551 return empty;
552}
553
chaviw273171b2018-12-26 11:46:30 -0800554void InputWindowCommands::clear() {
Vishnu Naire798b472020-07-23 13:52:21 -0700555 focusRequests.clear();
chaviwa911b102019-02-14 10:18:33 -0800556 syncInputWindows = false;
chaviw273171b2018-12-26 11:46:30 -0800557}
558
chaviw308ddba2020-08-11 16:23:51 -0700559status_t InputWindowCommands::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700560 SAFE_PARCEL(output.writeParcelableVector, focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700561 SAFE_PARCEL(output.writeBool, syncInputWindows);
562 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800563}
564
chaviw308ddba2020-08-11 16:23:51 -0700565status_t InputWindowCommands::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700566 SAFE_PARCEL(input.readParcelableVector, &focusRequests);
chaviw308ddba2020-08-11 16:23:51 -0700567 SAFE_PARCEL(input.readBool, &syncInputWindows);
568 return NO_ERROR;
chaviw273171b2018-12-26 11:46:30 -0800569}
570
Marin Shalamanovc5986772021-03-16 16:09:49 +0100571bool ValidateFrameRate(float frameRate, int8_t compatibility, int8_t changeFrameRateStrategy,
572 const char* inFunctionName, bool privileged) {
Steven Thomas62a4cf82020-01-31 12:04:03 -0800573 const char* functionName = inFunctionName != nullptr ? inFunctionName : "call";
574 int floatClassification = std::fpclassify(frameRate);
575 if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) {
576 ALOGE("%s failed - invalid frame rate %f", functionName, frameRate);
577 return false;
578 }
579
580 if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT &&
Ady Abrahamdd5bfa92021-01-07 17:56:08 -0800581 compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE &&
582 (!privileged || compatibility != ANATIVEWINDOW_FRAME_RATE_EXACT)) {
583 ALOGE("%s failed - invalid compatibility value %d privileged: %s", functionName,
584 compatibility, privileged ? "yes" : "no");
Steven Thomas62a4cf82020-01-31 12:04:03 -0800585 return false;
586 }
587
Marin Shalamanovc5986772021-03-16 16:09:49 +0100588 if (changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS &&
589 changeFrameRateStrategy != ANATIVEWINDOW_CHANGE_FRAME_RATE_ALWAYS) {
590 ALOGE("%s failed - invalid change frame rate strategy value %d", functionName,
591 changeFrameRateStrategy);
592 }
593
Steven Thomas62a4cf82020-01-31 12:04:03 -0800594 return true;
595}
596
chaviw618c42d2020-07-24 15:25:08 -0700597// ----------------------------------------------------------------------------
598
599status_t CaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700600 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(pixelFormat));
601 SAFE_PARCEL(output.write, sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -0800602 SAFE_PARCEL(output.writeFloat, frameScaleX);
603 SAFE_PARCEL(output.writeFloat, frameScaleY);
chaviw308ddba2020-08-11 16:23:51 -0700604 SAFE_PARCEL(output.writeBool, captureSecureLayers);
605 SAFE_PARCEL(output.writeInt32, uid);
Peiyong Lincd261472020-10-06 18:05:25 -0700606 SAFE_PARCEL(output.writeInt32, static_cast<int32_t>(dataspace));
Peiyong Lin05cc0112020-10-14 16:16:37 -0700607 SAFE_PARCEL(output.writeBool, allowProtected);
chaviw17ac24b2021-01-28 18:50:05 -0800608 SAFE_PARCEL(output.writeBool, grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700609 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700610}
611
612status_t CaptureArgs::read(const Parcel& input) {
Peiyong Lincd261472020-10-06 18:05:25 -0700613 int32_t value = 0;
614 SAFE_PARCEL(input.readInt32, &value);
615 pixelFormat = static_cast<ui::PixelFormat>(value);
chaviw308ddba2020-08-11 16:23:51 -0700616 SAFE_PARCEL(input.read, sourceCrop);
chaviw17ac24b2021-01-28 18:50:05 -0800617 SAFE_PARCEL(input.readFloat, &frameScaleX);
618 SAFE_PARCEL(input.readFloat, &frameScaleY);
chaviw308ddba2020-08-11 16:23:51 -0700619 SAFE_PARCEL(input.readBool, &captureSecureLayers);
620 SAFE_PARCEL(input.readInt32, &uid);
Peiyong Lincd261472020-10-06 18:05:25 -0700621 SAFE_PARCEL(input.readInt32, &value);
622 dataspace = static_cast<ui::Dataspace>(value);
Peiyong Lin05cc0112020-10-14 16:16:37 -0700623 SAFE_PARCEL(input.readBool, &allowProtected);
chaviw17ac24b2021-01-28 18:50:05 -0800624 SAFE_PARCEL(input.readBool, &grayscale);
chaviw308ddba2020-08-11 16:23:51 -0700625 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700626}
627
628status_t DisplayCaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700629 SAFE_PARCEL(CaptureArgs::write, output);
chaviw618c42d2020-07-24 15:25:08 -0700630
chaviw308ddba2020-08-11 16:23:51 -0700631 SAFE_PARCEL(output.writeStrongBinder, displayToken);
632 SAFE_PARCEL(output.writeUint32, width);
633 SAFE_PARCEL(output.writeUint32, height);
634 SAFE_PARCEL(output.writeBool, useIdentityTransform);
635 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700636}
637
638status_t DisplayCaptureArgs::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700639 SAFE_PARCEL(CaptureArgs::read, input);
chaviw618c42d2020-07-24 15:25:08 -0700640
chaviw308ddba2020-08-11 16:23:51 -0700641 SAFE_PARCEL(input.readStrongBinder, &displayToken);
642 SAFE_PARCEL(input.readUint32, &width);
643 SAFE_PARCEL(input.readUint32, &height);
644 SAFE_PARCEL(input.readBool, &useIdentityTransform);
645 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700646}
647
648status_t LayerCaptureArgs::write(Parcel& output) const {
chaviw308ddba2020-08-11 16:23:51 -0700649 SAFE_PARCEL(CaptureArgs::write, output);
chaviw618c42d2020-07-24 15:25:08 -0700650
chaviw308ddba2020-08-11 16:23:51 -0700651 SAFE_PARCEL(output.writeStrongBinder, layerHandle);
652 SAFE_PARCEL(output.writeInt32, excludeHandles.size());
chaviw618c42d2020-07-24 15:25:08 -0700653 for (auto el : excludeHandles) {
chaviw308ddba2020-08-11 16:23:51 -0700654 SAFE_PARCEL(output.writeStrongBinder, el);
chaviw618c42d2020-07-24 15:25:08 -0700655 }
chaviw308ddba2020-08-11 16:23:51 -0700656 SAFE_PARCEL(output.writeBool, childrenOnly);
657 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700658}
659
660status_t LayerCaptureArgs::read(const Parcel& input) {
chaviw308ddba2020-08-11 16:23:51 -0700661 SAFE_PARCEL(CaptureArgs::read, input);
chaviw618c42d2020-07-24 15:25:08 -0700662
chaviw308ddba2020-08-11 16:23:51 -0700663 SAFE_PARCEL(input.readStrongBinder, &layerHandle);
chaviw618c42d2020-07-24 15:25:08 -0700664
George Burgess IV4d7aceb2020-07-30 10:01:56 -0700665 int32_t numExcludeHandles = 0;
chaviw308ddba2020-08-11 16:23:51 -0700666 SAFE_PARCEL_READ_SIZE(input.readInt32, &numExcludeHandles, input.dataSize());
chaviw618c42d2020-07-24 15:25:08 -0700667 excludeHandles.reserve(numExcludeHandles);
668 for (int i = 0; i < numExcludeHandles; i++) {
669 sp<IBinder> binder;
chaviw308ddba2020-08-11 16:23:51 -0700670 SAFE_PARCEL(input.readStrongBinder, &binder);
chaviw618c42d2020-07-24 15:25:08 -0700671 excludeHandles.emplace(binder);
672 }
673
chaviw308ddba2020-08-11 16:23:51 -0700674 SAFE_PARCEL(input.readBool, &childrenOnly);
675 return NO_ERROR;
chaviw618c42d2020-07-24 15:25:08 -0700676}
677
chaviwba4320c2021-09-15 15:20:53 -0500678status_t BufferData::write(Parcel& output) const {
679 SAFE_PARCEL(output.writeInt32, flags.get());
680
681 if (buffer) {
682 SAFE_PARCEL(output.writeBool, true);
683 SAFE_PARCEL(output.write, *buffer);
684 } else {
685 SAFE_PARCEL(output.writeBool, false);
686 }
687
688 if (acquireFence) {
689 SAFE_PARCEL(output.writeBool, true);
690 SAFE_PARCEL(output.write, *acquireFence);
691 } else {
692 SAFE_PARCEL(output.writeBool, false);
693 }
694
695 SAFE_PARCEL(output.writeUint64, frameNumber);
696 SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(releaseBufferListener));
697 SAFE_PARCEL(output.writeStrongBinder, releaseBufferEndpoint);
698
699 SAFE_PARCEL(output.writeStrongBinder, cachedBuffer.token.promote());
700 SAFE_PARCEL(output.writeUint64, cachedBuffer.id);
701
702 return NO_ERROR;
703}
704
705status_t BufferData::read(const Parcel& input) {
706 int32_t tmpInt32;
707 SAFE_PARCEL(input.readInt32, &tmpInt32);
708 flags = Flags<BufferDataChange>(tmpInt32);
709
710 bool tmpBool = false;
711 SAFE_PARCEL(input.readBool, &tmpBool);
712 if (tmpBool) {
713 buffer = new GraphicBuffer();
714 SAFE_PARCEL(input.read, *buffer);
715 }
716
717 SAFE_PARCEL(input.readBool, &tmpBool);
718 if (tmpBool) {
719 acquireFence = new Fence();
720 SAFE_PARCEL(input.read, *acquireFence);
721 }
722
723 SAFE_PARCEL(input.readUint64, &frameNumber);
724
725 sp<IBinder> tmpBinder = nullptr;
726 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
727 if (tmpBinder) {
728 releaseBufferListener = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
729 }
730 SAFE_PARCEL(input.readNullableStrongBinder, &releaseBufferEndpoint);
731
732 tmpBinder = nullptr;
733 SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
734 cachedBuffer.token = tmpBinder;
735 SAFE_PARCEL(input.readUint64, &cachedBuffer.id);
736
737 return NO_ERROR;
738}
739
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800740}; // namespace android