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 #ifndef ANDROID_SF_LAYER_STATE_H 18 #define ANDROID_SF_LAYER_STATE_H 19 20 #include <stdint.h> 21 #include <sys/types.h> 22 23 #include <utils/Errors.h> 24 25 #include <ui/Region.h> 26 #include <ui/Rect.h> 27 #include <gui/IGraphicBufferProducer.h> 28 #include <math/vec3.h> 29 30 namespace android { 31 32 class Parcel; 33 class ISurfaceComposerClient; 34 35 /* 36 * Used to communicate layer information between SurfaceFlinger and its clients. 37 */ 38 struct layer_state_t { 39 40 41 enum { 42 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java 43 eLayerOpaque = 0x02, // SURFACE_OPAQUE 44 eLayerSecure = 0x80, // SECURE 45 }; 46 47 enum { 48 ePositionChanged = 0x00000001, 49 eLayerChanged = 0x00000002, 50 eSizeChanged = 0x00000004, 51 eAlphaChanged = 0x00000008, 52 eMatrixChanged = 0x00000010, 53 eTransparentRegionChanged = 0x00000020, 54 eFlagsChanged = 0x00000040, 55 eLayerStackChanged = 0x00000080, 56 eCropChanged = 0x00000100, 57 eDeferTransaction = 0x00000200, 58 eFinalCropChanged = 0x00000400, 59 eOverrideScalingModeChanged = 0x00000800, 60 eGeometryAppliesWithResize = 0x00001000, 61 eReparentChildren = 0x00002000, 62 eDetachChildren = 0x00004000, 63 eRelativeLayerChanged = 0x00008000, 64 eReparent = 0x00010000, 65 eColorChanged = 0x00020000, 66 eDestroySurface = 0x00040000 67 }; 68 69 layer_state_t() 70 : what(0), 71 x(0), y(0), z(0), w(0), h(0), layerStack(0), 72 alpha(0), flags(0), mask(0), 73 reserved(0), crop(Rect::INVALID_RECT), 74 finalCrop(Rect::INVALID_RECT), frameNumber(0), 75 overrideScalingMode(-1) 76 { 77 matrix.dsdx = matrix.dtdy = 1.0f; 78 matrix.dsdy = matrix.dtdx = 0.0f; 79 } 80 81 void merge(const layer_state_t& other); 82 status_t write(Parcel& output) const; 83 status_t read(const Parcel& input); 84 85 struct matrix22_t { 86 float dsdx{0}; 87 float dtdx{0}; 88 float dtdy{0}; 89 float dsdy{0}; 90 }; 91 sp<IBinder> surface; 92 uint32_t what; 93 float x; 94 float y; 95 int32_t z; 96 uint32_t w; 97 uint32_t h; 98 uint32_t layerStack; 99 float alpha; 100 uint8_t flags; 101 uint8_t mask; 102 uint8_t reserved; 103 matrix22_t matrix; 104 Rect crop; 105 Rect finalCrop; 106 sp<IBinder> barrierHandle; 107 sp<IBinder> reparentHandle; 108 uint64_t frameNumber; 109 int32_t overrideScalingMode; 110 111 sp<IGraphicBufferProducer> barrierGbp; 112 113 sp<IBinder> relativeLayerHandle; 114 115 sp<IBinder> parentHandleForChild; 116 117 half3 color; 118 119 // non POD must be last. see write/read 120 Region transparentRegion; 121 }; 122 123 struct ComposerState { 124 sp<ISurfaceComposerClient> client; 125 layer_state_t state; 126 status_t write(Parcel& output) const; 127 status_t read(const Parcel& input); 128 }; 129 130 struct DisplayState { 131 132 enum { 133 eOrientationDefault = 0, 134 eOrientation90 = 1, 135 eOrientation180 = 2, 136 eOrientation270 = 3, 137 eOrientationUnchanged = 4, 138 eOrientationSwapMask = 0x01 139 }; 140 141 enum { 142 eSurfaceChanged = 0x01, 143 eLayerStackChanged = 0x02, 144 eDisplayProjectionChanged = 0x04, 145 eDisplaySizeChanged = 0x08 146 }; 147 148 DisplayState(); 149 void merge(const DisplayState& other); 150 151 uint32_t what; 152 sp<IBinder> token; 153 sp<IGraphicBufferProducer> surface; 154 uint32_t layerStack; 155 uint32_t orientation; 156 Rect viewport; 157 Rect frame; 158 uint32_t width, height; 159 status_t write(Parcel& output) const; 160 status_t read(const Parcel& input); 161 }; 162 163 static inline 164 int compare_type(const ComposerState& lhs, const ComposerState& rhs) { 165 if (lhs.client < rhs.client) return -1; 166 if (lhs.client > rhs.client) return 1; 167 if (lhs.state.surface < rhs.state.surface) return -1; 168 if (lhs.state.surface > rhs.state.surface) return 1; 169 return 0; 170 } 171 172 static inline 173 int compare_type(const DisplayState& lhs, const DisplayState& rhs) { 174 return compare_type(lhs.token, rhs.token); 175 } 176 177 }; // namespace android 178 179 #endif // ANDROID_SF_LAYER_STATE_H 180 181