| 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 |  | 
|  | 17 | #include <utils/Errors.h> | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 18 | #include <binder/Parcel.h> | 
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 19 | #include <gui/ISurfaceComposerClient.h> | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 20 | #include <gui/IGraphicBufferProducer.h> | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 21 | #include <gui/LayerState.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 |  | 
|  | 23 | namespace android { | 
|  | 24 |  | 
|  | 25 | status_t layer_state_t::write(Parcel& output) const | 
|  | 26 | { | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 27 | output.writeStrongBinder(surface); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 28 | output.writeUint32(what); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 29 | output.writeFloat(x); | 
|  | 30 | output.writeFloat(y); | 
| Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 31 | output.writeInt32(z); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 32 | output.writeUint32(w); | 
|  | 33 | output.writeUint32(h); | 
|  | 34 | output.writeUint32(layerStack); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 35 | output.writeFloat(alpha); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 36 | output.writeUint32(flags); | 
|  | 37 | output.writeUint32(mask); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 38 | *reinterpret_cast<layer_state_t::matrix22_t *>( | 
|  | 39 | output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix; | 
|  | 40 | output.write(crop); | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 41 | output.write(finalCrop); | 
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 42 | output.writeStrongBinder(barrierHandle); | 
| Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 43 | output.writeStrongBinder(reparentHandle); | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 44 | output.writeUint64(frameNumber); | 
| Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 45 | output.writeInt32(overrideScalingMode); | 
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 46 | output.writeStrongBinder(IInterface::asBinder(barrierGbp)); | 
| Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 47 | output.writeStrongBinder(relativeLayerHandle); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 48 | output.writeStrongBinder(parentHandleForChild); | 
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 49 | output.writeFloat(color.r); | 
|  | 50 | output.writeFloat(color.g); | 
|  | 51 | output.writeFloat(color.b); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 52 | output.write(transparentRegion); | 
|  | 53 | return NO_ERROR; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
|  | 56 | status_t layer_state_t::read(const Parcel& input) | 
|  | 57 | { | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 58 | surface = input.readStrongBinder(); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 59 | what = input.readUint32(); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 60 | x = input.readFloat(); | 
|  | 61 | y = input.readFloat(); | 
| Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 62 | z = input.readInt32(); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 63 | w = input.readUint32(); | 
|  | 64 | h = input.readUint32(); | 
|  | 65 | layerStack = input.readUint32(); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 66 | alpha = input.readFloat(); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 67 | flags = static_cast<uint8_t>(input.readUint32()); | 
|  | 68 | mask = static_cast<uint8_t>(input.readUint32()); | 
| Michael Lentine | 8afa1c4 | 2014-10-31 11:10:13 -0700 | [diff] [blame] | 69 | const void* matrix_data = input.readInplace(sizeof(layer_state_t::matrix22_t)); | 
|  | 70 | if (matrix_data) { | 
|  | 71 | matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(matrix_data); | 
|  | 72 | } else { | 
|  | 73 | return BAD_VALUE; | 
|  | 74 | } | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 75 | input.read(crop); | 
| Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 76 | input.read(finalCrop); | 
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 77 | barrierHandle = input.readStrongBinder(); | 
| Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 78 | reparentHandle = input.readStrongBinder(); | 
| Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 79 | frameNumber = input.readUint64(); | 
| Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 80 | overrideScalingMode = input.readInt32(); | 
| Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 81 | barrierGbp = | 
|  | 82 | interface_cast<IGraphicBufferProducer>(input.readStrongBinder()); | 
| Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 83 | relativeLayerHandle = input.readStrongBinder(); | 
| chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame] | 84 | parentHandleForChild = input.readStrongBinder(); | 
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 85 | color.r = input.readFloat(); | 
|  | 86 | color.g = input.readFloat(); | 
|  | 87 | color.b = input.readFloat(); | 
| Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 88 | input.read(transparentRegion); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | return NO_ERROR; | 
|  | 90 | } | 
|  | 91 |  | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 92 | status_t ComposerState::write(Parcel& output) const { | 
| Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 93 | output.writeStrongBinder(IInterface::asBinder(client)); | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 94 | return state.write(output); | 
|  | 95 | } | 
|  | 96 |  | 
|  | 97 | status_t ComposerState::read(const Parcel& input) { | 
|  | 98 | client = interface_cast<ISurfaceComposerClient>(input.readStrongBinder()); | 
|  | 99 | return state.read(input); | 
|  | 100 | } | 
|  | 101 |  | 
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 102 |  | 
| Pablo Ceballos | 60d6922 | 2015-08-07 14:47:20 -0700 | [diff] [blame] | 103 | DisplayState::DisplayState() : | 
|  | 104 | what(0), | 
|  | 105 | layerStack(0), | 
|  | 106 | orientation(eOrientationDefault), | 
|  | 107 | viewport(Rect::EMPTY_RECT), | 
|  | 108 | frame(Rect::EMPTY_RECT), | 
|  | 109 | width(0), | 
|  | 110 | height(0) { | 
|  | 111 | } | 
|  | 112 |  | 
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 113 | status_t DisplayState::write(Parcel& output) const { | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 114 | output.writeStrongBinder(token); | 
| Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 115 | output.writeStrongBinder(IInterface::asBinder(surface)); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 116 | output.writeUint32(what); | 
|  | 117 | output.writeUint32(layerStack); | 
|  | 118 | output.writeUint32(orientation); | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 119 | output.write(viewport); | 
|  | 120 | output.write(frame); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 121 | output.writeUint32(width); | 
|  | 122 | output.writeUint32(height); | 
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 123 | return NO_ERROR; | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | status_t DisplayState::read(const Parcel& input) { | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 127 | token = input.readStrongBinder(); | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 128 | surface = interface_cast<IGraphicBufferProducer>(input.readStrongBinder()); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 129 | what = input.readUint32(); | 
|  | 130 | layerStack = input.readUint32(); | 
|  | 131 | orientation = input.readUint32(); | 
| Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 132 | input.read(viewport); | 
|  | 133 | input.read(frame); | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 134 | width = input.readUint32(); | 
|  | 135 | height = input.readUint32(); | 
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 136 | return NO_ERROR; | 
|  | 137 | } | 
|  | 138 |  | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 139 | void DisplayState::merge(const DisplayState& other) { | 
|  | 140 | if (other.what & eSurfaceChanged) { | 
|  | 141 | what |= eSurfaceChanged; | 
|  | 142 | surface = other.surface; | 
|  | 143 | } | 
|  | 144 | if (other.what & eLayerStackChanged) { | 
|  | 145 | what |= eLayerStackChanged; | 
|  | 146 | layerStack = other.layerStack; | 
|  | 147 | } | 
|  | 148 | if (other.what & eDisplayProjectionChanged) { | 
|  | 149 | what |= eDisplayProjectionChanged; | 
|  | 150 | orientation = other.orientation; | 
|  | 151 | viewport = other.viewport; | 
|  | 152 | frame = other.frame; | 
|  | 153 | } | 
|  | 154 | if (other.what & eDisplaySizeChanged) { | 
|  | 155 | what |= eDisplaySizeChanged; | 
|  | 156 | width = other.width; | 
|  | 157 | height = other.height; | 
|  | 158 | } | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | void layer_state_t::merge(const layer_state_t& other) { | 
|  | 162 | if (other.what & ePositionChanged) { | 
|  | 163 | what |= ePositionChanged; | 
|  | 164 | x = other.x; | 
|  | 165 | y = other.y; | 
|  | 166 | } | 
|  | 167 | if (other.what & eLayerChanged) { | 
|  | 168 | what |= eLayerChanged; | 
|  | 169 | z = other.z; | 
|  | 170 | } | 
|  | 171 | if (other.what & eSizeChanged) { | 
|  | 172 | what |= eSizeChanged; | 
|  | 173 | w = other.w; | 
|  | 174 | h = other.h; | 
|  | 175 | } | 
|  | 176 | if (other.what & eAlphaChanged) { | 
|  | 177 | what |= eAlphaChanged; | 
|  | 178 | alpha = other.alpha; | 
|  | 179 | } | 
|  | 180 | if (other.what & eMatrixChanged) { | 
|  | 181 | what |= eMatrixChanged; | 
|  | 182 | matrix = other.matrix; | 
|  | 183 | } | 
|  | 184 | if (other.what & eTransparentRegionChanged) { | 
|  | 185 | what |= eTransparentRegionChanged; | 
|  | 186 | transparentRegion = other.transparentRegion; | 
|  | 187 | } | 
|  | 188 | if (other.what & eFlagsChanged) { | 
|  | 189 | what |= eFlagsChanged; | 
|  | 190 | flags = other.flags; | 
|  | 191 | mask = other.mask; | 
|  | 192 | } | 
|  | 193 | if (other.what & eLayerStackChanged) { | 
|  | 194 | what |= eLayerStackChanged; | 
|  | 195 | layerStack = other.layerStack; | 
|  | 196 | } | 
|  | 197 | if (other.what & eCropChanged) { | 
|  | 198 | what |= eCropChanged; | 
|  | 199 | crop = other.crop; | 
|  | 200 | } | 
|  | 201 | if (other.what & eDeferTransaction) { | 
|  | 202 | what |= eDeferTransaction; | 
|  | 203 | barrierHandle = other.barrierHandle; | 
|  | 204 | barrierGbp = other.barrierGbp; | 
|  | 205 | frameNumber = other.frameNumber; | 
|  | 206 | } | 
|  | 207 | if (other.what & eFinalCropChanged) { | 
|  | 208 | what |= eFinalCropChanged; | 
|  | 209 | finalCrop = other.finalCrop; | 
|  | 210 | } | 
|  | 211 | if (other.what & eOverrideScalingModeChanged) { | 
|  | 212 | what |= eOverrideScalingModeChanged; | 
|  | 213 | overrideScalingMode = other.overrideScalingMode; | 
|  | 214 | } | 
|  | 215 | if (other.what & eGeometryAppliesWithResize) { | 
|  | 216 | what |= eGeometryAppliesWithResize; | 
|  | 217 | } | 
|  | 218 | if (other.what & eReparentChildren) { | 
|  | 219 | what |= eReparentChildren; | 
|  | 220 | reparentHandle = other.reparentHandle; | 
|  | 221 | } | 
|  | 222 | if (other.what & eDetachChildren) { | 
|  | 223 | what |= eDetachChildren; | 
|  | 224 | } | 
|  | 225 | if (other.what & eRelativeLayerChanged) { | 
|  | 226 | what |= eRelativeLayerChanged; | 
|  | 227 | z = other.z; | 
|  | 228 | relativeLayerHandle = other.relativeLayerHandle; | 
|  | 229 | } | 
|  | 230 | if (other.what & eReparent) { | 
|  | 231 | what |= eReparent; | 
|  | 232 | parentHandleForChild = other.parentHandleForChild; | 
|  | 233 | } | 
| chaviw | ca27f25 | 2018-02-06 16:46:39 -0800 | [diff] [blame] | 234 | if (other.what & eDestroySurface) { | 
|  | 235 | what |= eDestroySurface; | 
|  | 236 | } | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 237 | } | 
| Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 238 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | }; // namespace android |