The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Nair | 217d8e6 | 2018-09-12 16:34:49 -0700 | [diff] [blame] | 17 | #define LOG_TAG "LayerState" |
| 18 | |
Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 19 | #include <inttypes.h> |
| 20 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/Errors.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 23 | #include <gui/ISurfaceComposerClient.h> |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 24 | #include <gui/IGraphicBufferProducer.h> |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 25 | #include <gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 27 | #include <cmath> |
| 28 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | status_t layer_state_t::write(Parcel& output) const |
| 32 | { |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 33 | output.writeStrongBinder(surface); |
Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 34 | output.writeUint64(what); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 35 | output.writeFloat(x); |
| 36 | output.writeFloat(y); |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 37 | output.writeInt32(z); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 38 | output.writeUint32(w); |
| 39 | output.writeUint32(h); |
| 40 | output.writeUint32(layerStack); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 41 | output.writeFloat(alpha); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 42 | output.writeUint32(flags); |
| 43 | output.writeUint32(mask); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 44 | *reinterpret_cast<layer_state_t::matrix22_t *>( |
| 45 | output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix; |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 46 | output.write(crop_legacy); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 47 | output.writeStrongBinder(barrierHandle_legacy); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 48 | output.writeStrongBinder(reparentHandle); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 49 | output.writeUint64(frameNumber_legacy); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 50 | output.writeInt32(overrideScalingMode); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 51 | output.writeStrongBinder(IInterface::asBinder(barrierGbp_legacy)); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 52 | output.writeStrongBinder(relativeLayerHandle); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 53 | output.writeStrongBinder(parentHandleForChild); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 54 | output.writeFloat(color.r); |
| 55 | output.writeFloat(color.g); |
| 56 | output.writeFloat(color.b); |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 57 | #ifndef NO_INPUT |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 58 | inputHandle->writeToParcel(&output); |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 59 | #endif |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 60 | output.write(transparentRegion); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 61 | output.writeUint32(transform); |
| 62 | output.writeBool(transformToDisplayInverse); |
| 63 | output.write(crop); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 64 | output.write(orientedDisplaySpaceRect); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 65 | if (buffer) { |
| 66 | output.writeBool(true); |
| 67 | output.write(*buffer); |
| 68 | } else { |
| 69 | output.writeBool(false); |
| 70 | } |
| 71 | if (acquireFence) { |
| 72 | output.writeBool(true); |
| 73 | output.write(*acquireFence); |
| 74 | } else { |
| 75 | output.writeBool(false); |
| 76 | } |
| 77 | output.writeUint32(static_cast<uint32_t>(dataspace)); |
| 78 | output.write(hdrMetadata); |
| 79 | output.write(surfaceDamageRegion); |
| 80 | output.writeInt32(api); |
| 81 | if (sidebandStream) { |
| 82 | output.writeBool(true); |
| 83 | output.writeNativeHandle(sidebandStream->handle()); |
| 84 | } else { |
| 85 | output.writeBool(false); |
| 86 | } |
| 87 | |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 88 | memcpy(output.writeInplace(16 * sizeof(float)), |
| 89 | colorTransform.asArray(), 16 * sizeof(float)); |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 90 | output.writeFloat(cornerRadius); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 91 | output.writeUint32(backgroundBlurRadius); |
Steven Moreland | 9d4ce9b | 2019-07-17 15:23:38 -0700 | [diff] [blame] | 92 | output.writeStrongBinder(cachedBuffer.token.promote()); |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 93 | output.writeUint64(cachedBuffer.id); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 94 | output.writeParcelable(metadata); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 95 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 96 | output.writeFloat(bgColorAlpha); |
| 97 | output.writeUint32(static_cast<uint32_t>(bgColorDataspace)); |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 98 | output.writeBool(colorSpaceAgnostic); |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 99 | |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 100 | auto err = output.writeVectorSize(listeners); |
| 101 | if (err) { |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | for (auto listener : listeners) { |
| 106 | err = output.writeStrongBinder(listener.transactionCompletedListener); |
| 107 | if (err) { |
| 108 | return err; |
| 109 | } |
| 110 | err = output.writeInt64Vector(listener.callbackIds); |
| 111 | if (err) { |
| 112 | return err; |
| 113 | } |
| 114 | } |
Vishnu Nair | 440992f | 2019-12-09 19:53:19 -0800 | [diff] [blame] | 115 | output.writeFloat(shadowRadius); |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 116 | output.writeInt32(frameRateSelectionPriority); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 117 | output.writeFloat(frameRate); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 118 | output.writeByte(frameRateCompatibility); |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 119 | output.writeUint32(fixedTransformHint); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 120 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | status_t layer_state_t::read(const Parcel& input) |
| 124 | { |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 125 | surface = input.readStrongBinder(); |
Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 126 | what = input.readUint64(); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 127 | x = input.readFloat(); |
| 128 | y = input.readFloat(); |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 129 | z = input.readInt32(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 130 | w = input.readUint32(); |
| 131 | h = input.readUint32(); |
| 132 | layerStack = input.readUint32(); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 133 | alpha = input.readFloat(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 134 | flags = static_cast<uint8_t>(input.readUint32()); |
| 135 | mask = static_cast<uint8_t>(input.readUint32()); |
Michael Lentine | 8afa1c4 | 2014-10-31 11:10:13 -0700 | [diff] [blame] | 136 | const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t)); |
| 137 | if (matrix_data) { |
| 138 | matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data); |
| 139 | } else { |
| 140 | return BAD_VALUE; |
| 141 | } |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 142 | input.read(crop_legacy); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 143 | barrierHandle_legacy = input.readStrongBinder(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 144 | reparentHandle = input.readStrongBinder(); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 145 | frameNumber_legacy = input.readUint64(); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 146 | overrideScalingMode = input.readInt32(); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 147 | barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(input.readStrongBinder()); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 148 | relativeLayerHandle = input.readStrongBinder(); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 149 | parentHandleForChild = input.readStrongBinder(); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 150 | color.r = input.readFloat(); |
| 151 | color.g = input.readFloat(); |
| 152 | color.b = input.readFloat(); |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 153 | |
| 154 | #ifndef NO_INPUT |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 155 | inputHandle->readFromParcel(&input); |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 156 | #endif |
| 157 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 158 | input.read(transparentRegion); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 159 | transform = input.readUint32(); |
| 160 | transformToDisplayInverse = input.readBool(); |
| 161 | input.read(crop); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 162 | input.read(orientedDisplaySpaceRect); |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 163 | buffer = new GraphicBuffer(); |
| 164 | if (input.readBool()) { |
| 165 | input.read(*buffer); |
| 166 | } |
| 167 | acquireFence = new Fence(); |
| 168 | if (input.readBool()) { |
| 169 | input.read(*acquireFence); |
| 170 | } |
| 171 | dataspace = static_cast<ui::Dataspace>(input.readUint32()); |
| 172 | input.read(hdrMetadata); |
| 173 | input.read(surfaceDamageRegion); |
| 174 | api = input.readInt32(); |
| 175 | if (input.readBool()) { |
| 176 | sidebandStream = NativeHandle::create(input.readNativeHandle(), true); |
| 177 | } |
| 178 | |
Denis Hsu | 8f3da5e | 2020-07-15 09:31:21 +0800 | [diff] [blame] | 179 | const void* color_transform_data = input.readInplace(16 * sizeof(float)); |
| 180 | if (color_transform_data) { |
| 181 | colorTransform = mat4(static_cast<const float*>(color_transform_data)); |
| 182 | } else { |
| 183 | return BAD_VALUE; |
| 184 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 185 | cornerRadius = input.readFloat(); |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 186 | backgroundBlurRadius = input.readUint32(); |
Steven Moreland | 9d4ce9b | 2019-07-17 15:23:38 -0700 | [diff] [blame] | 187 | cachedBuffer.token = input.readStrongBinder(); |
Marissa Wall | 947d34e | 2019-03-29 14:03:53 -0700 | [diff] [blame] | 188 | cachedBuffer.id = input.readUint64(); |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 189 | input.readParcelable(&metadata); |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 190 | |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 191 | bgColorAlpha = input.readFloat(); |
| 192 | bgColorDataspace = static_cast<ui::Dataspace>(input.readUint32()); |
Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 193 | colorSpaceAgnostic = input.readBool(); |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 194 | |
Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 195 | int32_t numListeners = input.readInt32(); |
| 196 | listeners.clear(); |
| 197 | for (int i = 0; i < numListeners; i++) { |
| 198 | auto listener = input.readStrongBinder(); |
| 199 | std::vector<CallbackId> callbackIds; |
| 200 | input.readInt64Vector(&callbackIds); |
| 201 | listeners.emplace_back(listener, callbackIds); |
| 202 | } |
Vishnu Nair | 440992f | 2019-12-09 19:53:19 -0800 | [diff] [blame] | 203 | shadowRadius = input.readFloat(); |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 204 | frameRateSelectionPriority = input.readInt32(); |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 205 | frameRate = input.readFloat(); |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 206 | frameRateCompatibility = input.readByte(); |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 207 | fixedTransformHint = static_cast<ui::Transform::RotationFlags>(input.readUint32()); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | return NO_ERROR; |
| 209 | } |
| 210 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 211 | status_t ComposerState::write(Parcel& output) const { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 212 | return state.write(output); |
| 213 | } |
| 214 | |
| 215 | status_t ComposerState::read(const Parcel& input) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 216 | return state.read(input); |
| 217 | } |
| 218 | |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 219 | DisplayState::DisplayState() |
| 220 | : what(0), |
| 221 | layerStack(0), |
| 222 | layerStackSpaceRect(Rect::EMPTY_RECT), |
| 223 | orientedDisplaySpaceRect(Rect::EMPTY_RECT), |
| 224 | width(0), |
| 225 | height(0) {} |
Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 226 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 227 | status_t DisplayState::write(Parcel& output) const { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 228 | output.writeStrongBinder(token); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 229 | output.writeStrongBinder(IInterface::asBinder(surface)); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 230 | output.writeUint32(what); |
| 231 | output.writeUint32(layerStack); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 232 | output.writeUint32(toRotationInt(orientation)); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 233 | output.write(layerStackSpaceRect); |
| 234 | output.write(orientedDisplaySpaceRect); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 235 | output.writeUint32(width); |
| 236 | output.writeUint32(height); |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 237 | return NO_ERROR; |
| 238 | } |
| 239 | |
| 240 | status_t DisplayState::read(const Parcel& input) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 241 | token = input.readStrongBinder(); |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 242 | surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 243 | what = input.readUint32(); |
| 244 | layerStack = input.readUint32(); |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 245 | orientation = ui::toRotation(input.readUint32()); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 246 | input.read(layerStackSpaceRect); |
| 247 | input.read(orientedDisplaySpaceRect); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 248 | width = input.readUint32(); |
| 249 | height = input.readUint32(); |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 250 | return NO_ERROR; |
| 251 | } |
| 252 | |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 253 | void DisplayState::merge(const DisplayState& other) { |
| 254 | if (other.what & eSurfaceChanged) { |
| 255 | what |= eSurfaceChanged; |
| 256 | surface = other.surface; |
| 257 | } |
| 258 | if (other.what & eLayerStackChanged) { |
| 259 | what |= eLayerStackChanged; |
| 260 | layerStack = other.layerStack; |
| 261 | } |
| 262 | if (other.what & eDisplayProjectionChanged) { |
| 263 | what |= eDisplayProjectionChanged; |
| 264 | orientation = other.orientation; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 265 | layerStackSpaceRect = other.layerStackSpaceRect; |
| 266 | orientedDisplaySpaceRect = other.orientedDisplaySpaceRect; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 267 | } |
| 268 | if (other.what & eDisplaySizeChanged) { |
| 269 | what |= eDisplaySizeChanged; |
| 270 | width = other.width; |
| 271 | height = other.height; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void layer_state_t::merge(const layer_state_t& other) { |
| 276 | if (other.what & ePositionChanged) { |
| 277 | what |= ePositionChanged; |
| 278 | x = other.x; |
| 279 | y = other.y; |
| 280 | } |
| 281 | if (other.what & eLayerChanged) { |
| 282 | what |= eLayerChanged; |
chaviw | 3237758 | 2019-05-13 11:15:19 -0700 | [diff] [blame] | 283 | what &= ~eRelativeLayerChanged; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 284 | z = other.z; |
| 285 | } |
| 286 | if (other.what & eSizeChanged) { |
| 287 | what |= eSizeChanged; |
| 288 | w = other.w; |
| 289 | h = other.h; |
| 290 | } |
| 291 | if (other.what & eAlphaChanged) { |
| 292 | what |= eAlphaChanged; |
| 293 | alpha = other.alpha; |
| 294 | } |
| 295 | if (other.what & eMatrixChanged) { |
| 296 | what |= eMatrixChanged; |
| 297 | matrix = other.matrix; |
| 298 | } |
| 299 | if (other.what & eTransparentRegionChanged) { |
| 300 | what |= eTransparentRegionChanged; |
| 301 | transparentRegion = other.transparentRegion; |
| 302 | } |
| 303 | if (other.what & eFlagsChanged) { |
| 304 | what |= eFlagsChanged; |
Vishnu Nair | 996bc42 | 2019-07-16 14:15:33 -0700 | [diff] [blame] | 305 | flags &= ~other.mask; |
| 306 | flags |= (other.flags & other.mask); |
| 307 | mask |= other.mask; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 308 | } |
| 309 | if (other.what & eLayerStackChanged) { |
| 310 | what |= eLayerStackChanged; |
| 311 | layerStack = other.layerStack; |
| 312 | } |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 313 | if (other.what & eCropChanged_legacy) { |
| 314 | what |= eCropChanged_legacy; |
| 315 | crop_legacy = other.crop_legacy; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 316 | } |
Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 317 | if (other.what & eCornerRadiusChanged) { |
| 318 | what |= eCornerRadiusChanged; |
| 319 | cornerRadius = other.cornerRadius; |
| 320 | } |
Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 321 | if (other.what & eBackgroundBlurRadiusChanged) { |
| 322 | what |= eBackgroundBlurRadiusChanged; |
| 323 | backgroundBlurRadius = other.backgroundBlurRadius; |
| 324 | } |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 325 | if (other.what & eDeferTransaction_legacy) { |
| 326 | what |= eDeferTransaction_legacy; |
| 327 | barrierHandle_legacy = other.barrierHandle_legacy; |
| 328 | barrierGbp_legacy = other.barrierGbp_legacy; |
| 329 | frameNumber_legacy = other.frameNumber_legacy; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 330 | } |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 331 | if (other.what & eOverrideScalingModeChanged) { |
| 332 | what |= eOverrideScalingModeChanged; |
| 333 | overrideScalingMode = other.overrideScalingMode; |
| 334 | } |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 335 | if (other.what & eReparentChildren) { |
| 336 | what |= eReparentChildren; |
| 337 | reparentHandle = other.reparentHandle; |
| 338 | } |
| 339 | if (other.what & eDetachChildren) { |
| 340 | what |= eDetachChildren; |
| 341 | } |
| 342 | if (other.what & eRelativeLayerChanged) { |
| 343 | what |= eRelativeLayerChanged; |
chaviw | 3237758 | 2019-05-13 11:15:19 -0700 | [diff] [blame] | 344 | what &= ~eLayerChanged; |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 345 | z = other.z; |
| 346 | relativeLayerHandle = other.relativeLayerHandle; |
| 347 | } |
| 348 | if (other.what & eReparent) { |
| 349 | what |= eReparent; |
| 350 | parentHandleForChild = other.parentHandleForChild; |
| 351 | } |
chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 352 | if (other.what & eDestroySurface) { |
| 353 | what |= eDestroySurface; |
| 354 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 355 | if (other.what & eTransformChanged) { |
| 356 | what |= eTransformChanged; |
| 357 | transform = other.transform; |
| 358 | } |
| 359 | if (other.what & eTransformToDisplayInverseChanged) { |
| 360 | what |= eTransformToDisplayInverseChanged; |
| 361 | transformToDisplayInverse = other.transformToDisplayInverse; |
| 362 | } |
| 363 | if (other.what & eCropChanged) { |
| 364 | what |= eCropChanged; |
| 365 | crop = other.crop; |
| 366 | } |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 367 | if (other.what & eFrameChanged) { |
| 368 | what |= eFrameChanged; |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame^] | 369 | orientedDisplaySpaceRect = other.orientedDisplaySpaceRect; |
Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 370 | } |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 371 | if (other.what & eBufferChanged) { |
| 372 | what |= eBufferChanged; |
| 373 | buffer = other.buffer; |
| 374 | } |
| 375 | if (other.what & eAcquireFenceChanged) { |
| 376 | what |= eAcquireFenceChanged; |
| 377 | acquireFence = other.acquireFence; |
| 378 | } |
| 379 | if (other.what & eDataspaceChanged) { |
| 380 | what |= eDataspaceChanged; |
| 381 | dataspace = other.dataspace; |
| 382 | } |
| 383 | if (other.what & eHdrMetadataChanged) { |
| 384 | what |= eHdrMetadataChanged; |
| 385 | hdrMetadata = other.hdrMetadata; |
| 386 | } |
| 387 | if (other.what & eSurfaceDamageRegionChanged) { |
| 388 | what |= eSurfaceDamageRegionChanged; |
| 389 | surfaceDamageRegion = other.surfaceDamageRegion; |
| 390 | } |
| 391 | if (other.what & eApiChanged) { |
| 392 | what |= eApiChanged; |
| 393 | api = other.api; |
| 394 | } |
| 395 | if (other.what & eSidebandStreamChanged) { |
| 396 | what |= eSidebandStreamChanged; |
| 397 | sidebandStream = other.sidebandStream; |
| 398 | } |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 399 | if (other.what & eColorTransformChanged) { |
| 400 | what |= eColorTransformChanged; |
| 401 | colorTransform = other.colorTransform; |
| 402 | } |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 403 | if (other.what & eHasListenerCallbacksChanged) { |
| 404 | what |= eHasListenerCallbacksChanged; |
Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 405 | } |
Robert Carr | d314f16 | 2018-08-15 13:12:42 -0700 | [diff] [blame] | 406 | |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 407 | #ifndef NO_INPUT |
| 408 | if (other.what & eInputInfoChanged) { |
| 409 | what |= eInputInfoChanged; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 410 | inputHandle = new InputWindowHandle(*other.inputHandle); |
Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 411 | } |
| 412 | #endif |
| 413 | |
Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 414 | if (other.what & eCachedBufferChanged) { |
| 415 | what |= eCachedBufferChanged; |
| 416 | cachedBuffer = other.cachedBuffer; |
| 417 | } |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 418 | if (other.what & eBackgroundColorChanged) { |
| 419 | what |= eBackgroundColorChanged; |
| 420 | color = other.color; |
| 421 | bgColorAlpha = other.bgColorAlpha; |
| 422 | bgColorDataspace = other.bgColorDataspace; |
Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 423 | } |
Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 424 | if (other.what & eMetadataChanged) { |
| 425 | what |= eMetadataChanged; |
| 426 | metadata.merge(other.metadata); |
| 427 | } |
Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 428 | if (other.what & eShadowRadiusChanged) { |
| 429 | what |= eShadowRadiusChanged; |
| 430 | shadowRadius = other.shadowRadius; |
| 431 | } |
Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 432 | if (other.what & eFrameRateSelectionPriority) { |
| 433 | what |= eFrameRateSelectionPriority; |
| 434 | frameRateSelectionPriority = other.frameRateSelectionPriority; |
| 435 | } |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 436 | if (other.what & eFrameRateChanged) { |
| 437 | what |= eFrameRateChanged; |
| 438 | frameRate = other.frameRate; |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 439 | frameRateCompatibility = other.frameRateCompatibility; |
Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 440 | } |
Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 441 | if (other.what & eFixedTransformHintChanged) { |
| 442 | what |= eFixedTransformHintChanged; |
| 443 | fixedTransformHint = other.fixedTransformHint; |
| 444 | } |
Vishnu Nair | 217d8e6 | 2018-09-12 16:34:49 -0700 | [diff] [blame] | 445 | if ((other.what & what) != other.what) { |
| 446 | ALOGE("Unmerged SurfaceComposer Transaction properties. LayerState::merge needs updating? " |
Garfield Tan | 8a3083e | 2018-12-03 13:21:07 -0800 | [diff] [blame] | 447 | "other.what=0x%" PRIu64 " what=0x%" PRIu64, |
Vishnu Nair | 217d8e6 | 2018-09-12 16:34:49 -0700 | [diff] [blame] | 448 | other.what, what); |
Robert Carr | d314f16 | 2018-08-15 13:12:42 -0700 | [diff] [blame] | 449 | } |
Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 450 | } |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 451 | |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 452 | // ------------------------------- InputWindowCommands ---------------------------------------- |
| 453 | |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 454 | bool InputWindowCommands::merge(const InputWindowCommands& other) { |
| 455 | bool changes = false; |
| 456 | #ifndef NO_INPUT |
| 457 | changes |= !other.focusRequests.empty(); |
| 458 | focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()), |
| 459 | std::make_move_iterator(other.focusRequests.end())); |
| 460 | #endif |
| 461 | changes |= other.syncInputWindows && !syncInputWindows; |
chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 462 | syncInputWindows |= other.syncInputWindows; |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 463 | return changes; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void InputWindowCommands::clear() { |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 467 | #ifndef NO_INPUT |
| 468 | focusRequests.clear(); |
| 469 | #endif |
chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 470 | syncInputWindows = false; |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void InputWindowCommands::write(Parcel& output) const { |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 474 | #ifndef NO_INPUT |
| 475 | output.writeParcelableVector(focusRequests); |
| 476 | #endif |
chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 477 | output.writeBool(syncInputWindows); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void InputWindowCommands::read(const Parcel& input) { |
Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 481 | #ifndef NO_INPUT |
| 482 | input.readParcelableVector(&focusRequests); |
| 483 | #endif |
chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 484 | syncInputWindows = input.readBool(); |
chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 487 | bool ValidateFrameRate(float frameRate, int8_t compatibility, const char* inFunctionName) { |
| 488 | const char* functionName = inFunctionName != nullptr ? inFunctionName : "call"; |
| 489 | int floatClassification = std::fpclassify(frameRate); |
| 490 | if (frameRate < 0 || floatClassification == FP_INFINITE || floatClassification == FP_NAN) { |
| 491 | ALOGE("%s failed - invalid frame rate %f", functionName, frameRate); |
| 492 | return false; |
| 493 | } |
| 494 | |
| 495 | if (compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT && |
| 496 | compatibility != ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_FIXED_SOURCE) { |
| 497 | ALOGE("%s failed - invalid compatibility value %d", functionName, compatibility); |
| 498 | return false; |
| 499 | } |
| 500 | |
| 501 | return true; |
| 502 | } |
| 503 | |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 504 | // ---------------------------------------------------------------------------- |
| 505 | |
| 506 | status_t CaptureArgs::write(Parcel& output) const { |
| 507 | status_t status = output.writeInt32(static_cast<int32_t>(pixelFormat)) ?: |
| 508 | output.write(sourceCrop) ?: |
| 509 | output.writeFloat(frameScale) ?: |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 510 | output.writeBool(captureSecureLayers) ?: |
| 511 | output.writeInt32(uid); |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 512 | return status; |
| 513 | } |
| 514 | |
| 515 | status_t CaptureArgs::read(const Parcel& input) { |
George Burgess IV | 4d7aceb | 2020-07-30 10:01:56 -0700 | [diff] [blame] | 516 | int32_t format = 0; |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 517 | status_t status = input.readInt32(&format) ?: |
| 518 | input.read(sourceCrop) ?: |
| 519 | input.readFloat(&frameScale) ?: |
chaviw | 4b9d5e1 | 2020-08-04 18:30:35 -0700 | [diff] [blame] | 520 | input.readBool(&captureSecureLayers) ?: |
| 521 | input.readInt32(&uid); |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 522 | |
| 523 | pixelFormat = static_cast<ui::PixelFormat>(format); |
| 524 | return status; |
| 525 | } |
| 526 | |
| 527 | status_t DisplayCaptureArgs::write(Parcel& output) const { |
| 528 | status_t status = CaptureArgs::write(output); |
| 529 | |
| 530 | status |= output.writeStrongBinder(displayToken) ?: |
| 531 | output.writeUint32(width) ?: |
| 532 | output.writeUint32(height) ?: |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 533 | output.writeBool(useIdentityTransform); |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 534 | return status; |
| 535 | } |
| 536 | |
| 537 | status_t DisplayCaptureArgs::read(const Parcel& input) { |
| 538 | status_t status = CaptureArgs::read(input); |
| 539 | |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 540 | status |= input.readStrongBinder(&displayToken) ?: |
| 541 | input.readUint32(&width) ?: |
| 542 | input.readUint32(&height) ?: |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 543 | input.readBool(&useIdentityTransform); |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 544 | return status; |
| 545 | } |
| 546 | |
| 547 | status_t LayerCaptureArgs::write(Parcel& output) const { |
| 548 | status_t status = CaptureArgs::write(output); |
| 549 | |
| 550 | status |= output.writeStrongBinder(layerHandle); |
| 551 | status |= output.writeInt32(excludeHandles.size()); |
| 552 | for (auto el : excludeHandles) { |
| 553 | status |= output.writeStrongBinder(el); |
| 554 | } |
| 555 | status |= output.writeBool(childrenOnly); |
| 556 | return status; |
| 557 | } |
| 558 | |
| 559 | status_t LayerCaptureArgs::read(const Parcel& input) { |
| 560 | status_t status = CaptureArgs::read(input); |
| 561 | |
| 562 | status |= input.readStrongBinder(&layerHandle); |
| 563 | |
George Burgess IV | 4d7aceb | 2020-07-30 10:01:56 -0700 | [diff] [blame] | 564 | int32_t numExcludeHandles = 0; |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 565 | status |= input.readInt32(&numExcludeHandles); |
| 566 | excludeHandles.reserve(numExcludeHandles); |
| 567 | for (int i = 0; i < numExcludeHandles; i++) { |
| 568 | sp<IBinder> binder; |
| 569 | status |= input.readStrongBinder(&binder); |
| 570 | excludeHandles.emplace(binder); |
| 571 | } |
| 572 | |
| 573 | status |= input.readBool(&childrenOnly); |
| 574 | return status; |
| 575 | } |
| 576 | |
| 577 | status_t ScreenCaptureResults::write(Parcel& output) const { |
| 578 | status_t status = output.write(*buffer) ?: |
| 579 | output.writeBool(capturedSecureLayers) ?: |
| 580 | output.writeUint32(static_cast<uint32_t>(capturedDataspace)); |
| 581 | return status; |
| 582 | } |
| 583 | |
| 584 | status_t ScreenCaptureResults::read(const Parcel& input) { |
| 585 | buffer = new GraphicBuffer(); |
George Burgess IV | 4d7aceb | 2020-07-30 10:01:56 -0700 | [diff] [blame] | 586 | uint32_t dataspace = 0; |
chaviw | 618c42d | 2020-07-24 15:25:08 -0700 | [diff] [blame] | 587 | status_t status = input.read(*buffer) ?: |
| 588 | input.readBool(&capturedSecureLayers) ?: |
| 589 | input.readUint32(&dataspace); |
| 590 | |
| 591 | capturedDataspace = static_cast<ui::Dataspace>(dataspace); |
| 592 | |
| 593 | return status; |
| 594 | } |
| 595 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | }; // namespace android |