The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 | #ifndef ANDROID_LAYER_H |
| 18 | #define ANDROID_LAYER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
| 24 | #include <EGL/eglext.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 25 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 26 | #include <utils/RefBase.h> |
| 27 | #include <utils/String8.h> |
| 28 | #include <utils/Timers.h> |
| 29 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 30 | #include <ui/FrameStats.h> |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 31 | #include <ui/GraphicBuffer.h> |
| 32 | #include <ui/PixelFormat.h> |
| 33 | #include <ui/Region.h> |
| 34 | |
| 35 | #include <gui/ISurfaceComposerClient.h> |
Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame^] | 36 | #include <gui/LayerState.h> |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 37 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 38 | #include <list> |
| 39 | |
Jamie Gennis | 82dbc74 | 2012-11-08 19:23:28 -0800 | [diff] [blame] | 40 | #include "FrameTracker.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 41 | #include "Client.h" |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 42 | #include "LayerVector.h" |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 43 | #include "MonitoredProducer.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 44 | #include "SurfaceFlinger.h" |
| 45 | #include "SurfaceFlingerConsumer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | #include "Transform.h" |
| 47 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 48 | #include "DisplayHardware/HWComposer.h" |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 49 | #include "DisplayHardware/HWComposerBufferCache.h" |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 50 | #include "RenderEngine/Mesh.h" |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 51 | #include "RenderEngine/Texture.h" |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 52 | |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 53 | #include <math/vec4.h> |
| 54 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | namespace android { |
| 56 | |
| 57 | // --------------------------------------------------------------------------- |
| 58 | |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 59 | class Client; |
Mathias Agopian | 3e25fd8 | 2013-04-22 17:52:16 +0200 | [diff] [blame] | 60 | class Colorizer; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 61 | class DisplayDevice; |
| 62 | class GraphicBuffer; |
| 63 | class SurfaceFlinger; |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 64 | class LayerDebugInfo; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | |
| 66 | // --------------------------------------------------------------------------- |
| 67 | |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 68 | /* |
Andy McFadden | 882e3a3 | 2013-01-08 16:06:15 -0800 | [diff] [blame] | 69 | * A new BufferQueue and a new SurfaceFlingerConsumer are created when the |
| 70 | * Layer is first referenced. |
| 71 | * |
| 72 | * This also implements onFrameAvailable(), which notifies SurfaceFlinger |
| 73 | * that new data has arrived. |
| 74 | */ |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 75 | class Layer : public SurfaceFlingerConsumer::ContentsChangedListener { |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 76 | static int32_t sSequence; |
| 77 | |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 78 | public: |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 79 | mutable bool contentDirty; |
| 80 | // regions below are in window-manager space |
| 81 | Region visibleRegion; |
| 82 | Region coveredRegion; |
| 83 | Region visibleNonTransparentRegion; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 84 | Region surfaceDamageRegion; |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 85 | |
| 86 | // Layer serial number. This gives layers an explicit ordering, so we |
| 87 | // have a stable sort order when their layer stack and Z-order are |
| 88 | // the same. |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 89 | int32_t sequence; |
| 90 | |
| 91 | enum { // flags for doTransaction() |
| 92 | eDontUpdateGeometryState = 0x00000001, |
| 93 | eVisibleRegion = 0x00000002, |
| 94 | }; |
| 95 | |
| 96 | struct Geometry { |
| 97 | uint32_t w; |
| 98 | uint32_t h; |
Robert Carr | 3dcabfa | 2016-03-01 18:36:58 -0800 | [diff] [blame] | 99 | Transform transform; |
| 100 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 101 | inline bool operator ==(const Geometry& rhs) const { |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 102 | return (w == rhs.w && h == rhs.h) && |
| 103 | (transform.tx() == rhs.transform.tx()) && |
| 104 | (transform.ty() == rhs.transform.ty()); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 105 | } |
| 106 | inline bool operator !=(const Geometry& rhs) const { |
| 107 | return !operator ==(rhs); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | struct State { |
| 112 | Geometry active; |
| 113 | Geometry requested; |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 114 | int32_t z; |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 115 | |
| 116 | // The identifier of the layer stack this layer belongs to. A layer can |
| 117 | // only be associated to a single layer stack. A layer stack is a |
| 118 | // z-ordered group of layers which can be associated to one or more |
| 119 | // displays. Using the same layer stack on different displays is a way |
| 120 | // to achieve mirroring. |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 121 | uint32_t layerStack; |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 122 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 123 | uint8_t flags; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 124 | uint8_t mask; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 125 | uint8_t reserved[2]; |
| 126 | int32_t sequence; // changes when visible regions can change |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 127 | bool modified; |
| 128 | |
Fabien Sanglard | 4ed383c | 2016-12-13 14:02:41 -0800 | [diff] [blame] | 129 | // Crop is expressed in layer space coordinate. |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 130 | Rect crop; |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 131 | Rect requestedCrop; |
| 132 | |
Fabien Sanglard | 4ed383c | 2016-12-13 14:02:41 -0800 | [diff] [blame] | 133 | // finalCrop is expressed in display space coordinate. |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 134 | Rect finalCrop; |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 135 | Rect requestedFinalCrop; |
Robert Carr | b5d3d26 | 2016-03-25 15:08:13 -0700 | [diff] [blame] | 136 | |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 137 | // If set, defers this state update until the identified Layer |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 138 | // receives a frame with the given frameNumber |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 139 | wp<Layer> barrierLayer; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 140 | uint64_t frameNumber; |
| 141 | |
Mathias Agopian | 2ca7939 | 2013-04-02 18:30:32 -0700 | [diff] [blame] | 142 | // the transparentRegion hint is a bit special, it's latched only |
| 143 | // when we receive a buffer -- this is because it's "content" |
| 144 | // dependent. |
| 145 | Region activeTransparentRegion; |
| 146 | Region requestedTransparentRegion; |
Courtney Goeltzenleuchter | bb09b43 | 2016-11-30 13:51:28 -0700 | [diff] [blame] | 147 | android_dataspace dataSpace; |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 148 | |
| 149 | uint32_t appId; |
| 150 | uint32_t type; |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 151 | |
| 152 | // If non-null, a Surface this Surface's Z-order is interpreted relative to. |
| 153 | wp<Layer> zOrderRelativeOf; |
| 154 | |
| 155 | // A list of surfaces whose Z-order is interpreted relative to ours. |
| 156 | SortedVector<wp<Layer>> zOrderRelatives; |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 157 | |
| 158 | half4 color; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 161 | // ----------------------------------------------------------------------- |
| 162 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 163 | Layer(SurfaceFlinger* flinger, const sp<Client>& client, |
| 164 | const String8& name, uint32_t w, uint32_t h, uint32_t flags); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 165 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 166 | virtual ~Layer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 168 | void setPrimaryDisplayOnly() { mPrimaryDisplayOnly = true; } |
| 169 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 170 | // the this layer's size and format |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 171 | status_t setBuffers(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 173 | // ------------------------------------------------------------------------ |
| 174 | // Geometry setting functions. |
| 175 | // |
| 176 | // The following group of functions are used to specify the layers |
| 177 | // bounds, and the mapping of the texture on to those bounds. According |
| 178 | // to various settings changes to them may apply immediately, or be delayed until |
| 179 | // a pending resize is completed by the producer submitting a buffer. For example |
| 180 | // if we were to change the buffer size, and update the matrix ahead of the |
| 181 | // new buffer arriving, then we would be stretching the buffer to a different |
| 182 | // aspect before and after the buffer arriving, which probably isn't what we wanted. |
| 183 | // |
| 184 | // The first set of geometry functions are controlled by the scaling mode, described |
| 185 | // in window.h. The scaling mode may be set by the client, as it submits buffers. |
| 186 | // This value may be overriden through SurfaceControl, with setOverrideScalingMode. |
| 187 | // |
| 188 | // Put simply, if our scaling mode is SCALING_MODE_FREEZE, then |
| 189 | // matrix updates will not be applied while a resize is pending |
| 190 | // and the size and transform will remain in their previous state |
| 191 | // until a new buffer is submitted. If the scaling mode is another value |
| 192 | // then the old-buffer will immediately be scaled to the pending size |
| 193 | // and the new matrix will be immediately applied following this scaling |
| 194 | // transformation. |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 195 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 196 | // Set the default buffer size for the assosciated Producer, in pixels. This is |
| 197 | // also the rendered size of the layer prior to any transformations. Parent |
| 198 | // or local matrix transformations will not affect the size of the buffer, |
| 199 | // but may affect it's on-screen size or clipping. |
| 200 | bool setSize(uint32_t w, uint32_t h); |
| 201 | // Set a 2x2 transformation matrix on the layer. This transform |
| 202 | // will be applied after parent transforms, but before any final |
| 203 | // producer specified transform. |
| 204 | bool setMatrix(const layer_state_t::matrix22_t& matrix); |
| 205 | |
| 206 | // This second set of geometry attributes are controlled by |
| 207 | // setGeometryAppliesWithResize, and their default mode is to be |
| 208 | // immediate. If setGeometryAppliesWithResize is specified |
| 209 | // while a resize is pending, then update of these attributes will |
| 210 | // be delayed until the resize completes. |
| 211 | |
| 212 | // setPosition operates in parent buffer space (pre parent-transform) or display |
| 213 | // space for top-level layers. |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 214 | bool setPosition(float x, float y, bool immediate); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 215 | // Buffer space |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 216 | bool setCrop(const Rect& crop, bool immediate); |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 217 | // Parent buffer space/display space |
Robert Carr | 8d5227b | 2017-03-16 15:41:03 -0700 | [diff] [blame] | 218 | bool setFinalCrop(const Rect& crop, bool immediate); |
| 219 | |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 220 | // TODO(b/38182121): Could we eliminate the various latching modes by |
| 221 | // using the layer hierarchy? |
| 222 | // ----------------------------------------------------------------------- |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 223 | bool setLayer(int32_t z); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 224 | bool setRelativeLayer(const sp<IBinder>& relativeToHandle, int32_t relativeZ); |
| 225 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 226 | bool setAlpha(float alpha); |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 227 | bool setColor(const half3& color); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 228 | bool setTransparentRegionHint(const Region& transparent); |
| 229 | bool setFlags(uint8_t flags, uint8_t mask); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 230 | bool setLayerStack(uint32_t layerStack); |
Courtney Goeltzenleuchter | bb09b43 | 2016-11-30 13:51:28 -0700 | [diff] [blame] | 231 | bool setDataSpace(android_dataspace dataSpace); |
Courtney Goeltzenleuchter | 532b263 | 2017-05-05 16:34:38 -0600 | [diff] [blame] | 232 | android_dataspace getDataSpace() const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 233 | uint32_t getLayerStack() const; |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 234 | void deferTransactionUntil(const sp<IBinder>& barrierHandle, uint64_t frameNumber); |
| 235 | void deferTransactionUntil(const sp<Layer>& barrierLayer, uint64_t frameNumber); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 236 | bool setOverrideScalingMode(int32_t overrideScalingMode); |
Daniel Nicoara | 2f5f8a5 | 2016-12-20 16:11:58 -0500 | [diff] [blame] | 237 | void setInfo(uint32_t type, uint32_t appId); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 238 | bool reparentChildren(const sp<IBinder>& layer); |
chaviw | f1961f7 | 2017-09-18 16:41:07 -0700 | [diff] [blame] | 239 | bool reparent(const sp<IBinder>& newParentHandle); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 240 | bool detachChildren(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 241 | |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 242 | // If we have received a new buffer this frame, we will pass its surface |
| 243 | // damage down to hardware composer. Otherwise, we must send a region with |
| 244 | // one empty rect. |
| 245 | void useSurfaceDamage(); |
| 246 | void useEmptyDamage(); |
| 247 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 248 | uint32_t getTransactionFlags(uint32_t flags); |
| 249 | uint32_t setTransactionFlags(uint32_t flags); |
| 250 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 251 | bool belongsToDisplay(uint32_t layerStack, bool isPrimaryDisplay) const { |
| 252 | return getLayerStack() == layerStack && (!mPrimaryDisplayOnly || isPrimaryDisplay); |
| 253 | } |
| 254 | |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 255 | void computeGeometry(const sp<const DisplayDevice>& hw, Mesh& mesh, |
| 256 | bool useIdentityTransform) const; |
Michael Lentine | 6c925ed | 2014-09-26 17:55:01 -0700 | [diff] [blame] | 257 | Rect computeBounds(const Region& activeTransparentRegion) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 258 | Rect computeBounds() const; |
| 259 | |
Pablo Ceballos | 40845df | 2016-01-25 17:41:15 -0800 | [diff] [blame] | 260 | int32_t getSequence() const { return sequence; } |
| 261 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 262 | // ----------------------------------------------------------------------- |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 263 | // Virtuals |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 264 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 265 | virtual const char* getTypeId() const { return "Layer"; } |
| 266 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 267 | /* |
| 268 | * isOpaque - true if this surface is opaque |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 269 | * |
| 270 | * This takes into account the buffer format (i.e. whether or not the |
| 271 | * pixel format includes an alpha channel) and the "opaque" flag set |
| 272 | * on the layer. It does not examine the current plane alpha value. |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 273 | */ |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 274 | virtual bool isOpaque(const Layer::State& s) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * isSecure - true if this surface is secure, that is if it prevents |
| 278 | * screenshots or VNC servers. |
| 279 | */ |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 280 | virtual bool isSecure() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * isProtected - true if the layer may contain protected content in the |
| 284 | * GRALLOC_USAGE_PROTECTED sense. |
| 285 | */ |
Jamie Gennis | 7a4d0df | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 286 | virtual bool isProtected() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * isVisible - true if this layer is visible, false otherwise |
| 290 | */ |
Mathias Agopian | da27af9 | 2012-09-13 18:17:13 -0700 | [diff] [blame] | 291 | virtual bool isVisible() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 293 | /* |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 294 | * isHiddenByPolicy - true if this layer has been forced invisible. |
| 295 | * just because this is false, doesn't mean isVisible() is true. |
| 296 | * For example if this layer has no active buffer, it may not be hidden by |
| 297 | * policy, but it still can not be visible. |
| 298 | */ |
| 299 | virtual bool isHiddenByPolicy() const; |
| 300 | |
| 301 | /* |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 302 | * isFixedSize - true if content has a fixed size |
| 303 | */ |
| 304 | virtual bool isFixedSize() const; |
Jamie Gennis | 582270d | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 305 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 306 | protected: |
| 307 | /* |
| 308 | * onDraw - draws the surface. |
| 309 | */ |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 310 | virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip, |
| 311 | bool useIdentityTransform) const; |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 312 | |
| 313 | public: |
| 314 | // ----------------------------------------------------------------------- |
| 315 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 316 | #ifdef USE_HWC2 |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 317 | void setGeometry(const sp<const DisplayDevice>& displayDevice, uint32_t z); |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 318 | void forceClientComposition(int32_t hwcId); |
| 319 | void setPerFrameData(const sp<const DisplayDevice>& displayDevice); |
| 320 | |
| 321 | // callIntoHwc exists so we can update our local state and call |
| 322 | // acceptDisplayChanges without unnecessarily updating the device's state |
| 323 | void setCompositionType(int32_t hwcId, HWC2::Composition type, |
| 324 | bool callIntoHwc = true); |
| 325 | HWC2::Composition getCompositionType(int32_t hwcId) const; |
| 326 | |
| 327 | void setClearClientTarget(int32_t hwcId, bool clear); |
| 328 | bool getClearClientTarget(int32_t hwcId) const; |
| 329 | |
| 330 | void updateCursorPosition(const sp<const DisplayDevice>& hw); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 331 | #else |
| 332 | void setGeometry(const sp<const DisplayDevice>& hw, |
| 333 | HWComposer::HWCLayerInterface& layer); |
| 334 | void setPerFrameData(const sp<const DisplayDevice>& hw, |
| 335 | HWComposer::HWCLayerInterface& layer); |
| 336 | void setAcquireFence(const sp<const DisplayDevice>& hw, |
| 337 | HWComposer::HWCLayerInterface& layer); |
| 338 | |
| 339 | Rect getPosition(const sp<const DisplayDevice>& hw); |
| 340 | #endif |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 341 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 342 | /* |
| 343 | * called after page-flip |
| 344 | */ |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 345 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 346 | void onLayerDisplayed(const sp<Fence>& releaseFence); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 347 | #else |
| 348 | void onLayerDisplayed(const sp<const DisplayDevice>& hw, |
| 349 | HWComposer::HWCLayerInterface* layer); |
| 350 | #endif |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 351 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 352 | bool shouldPresentNow(const DispSync& dispSync) const; |
| 353 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 354 | /* |
| 355 | * called before composition. |
| 356 | * returns true if the layer has pending updates. |
| 357 | */ |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 358 | bool onPreComposition(nsecs_t refreshStartTime); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 359 | |
| 360 | /* |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 361 | * called after composition. |
| 362 | * returns true if the layer latched a new buffer this frame. |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 363 | */ |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 364 | bool onPostComposition(const std::shared_ptr<FenceTime>& glDoneFence, |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 365 | const std::shared_ptr<FenceTime>& presentFence, |
Brian Anderson | 0a61b0c | 2016-12-07 14:55:56 -0800 | [diff] [blame] | 366 | const CompositorTiming& compositorTiming); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 367 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 368 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 369 | // If a buffer was replaced this frame, release the former buffer |
Brian Anderson | f638686 | 2016-10-31 16:34:13 -0700 | [diff] [blame] | 370 | void releasePendingBuffer(nsecs_t dequeueReadyTime); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 371 | #endif |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 372 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 373 | /* |
| 374 | * draw - performs some global clipping optimizations |
| 375 | * and calls onDraw(). |
| 376 | */ |
| 377 | void draw(const sp<const DisplayDevice>& hw, const Region& clip) const; |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 378 | void draw(const sp<const DisplayDevice>& hw, bool useIdentityTransform) const; |
| 379 | void draw(const sp<const DisplayDevice>& hw) const; |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 380 | |
| 381 | /* |
| 382 | * doTransaction - process the transaction. This is a good place to figure |
| 383 | * out which attributes of the surface have changed. |
| 384 | */ |
| 385 | uint32_t doTransaction(uint32_t transactionFlags); |
| 386 | |
| 387 | /* |
| 388 | * setVisibleRegion - called to set the new visible region. This gives |
| 389 | * a chance to update the new visible region or record the fact it changed. |
| 390 | */ |
| 391 | void setVisibleRegion(const Region& visibleRegion); |
| 392 | |
| 393 | /* |
| 394 | * setCoveredRegion - called when the covered region changes. The covered |
| 395 | * region corresponds to any area of the surface that is covered |
| 396 | * (transparently or not) by another surface. |
| 397 | */ |
| 398 | void setCoveredRegion(const Region& coveredRegion); |
| 399 | |
| 400 | /* |
| 401 | * setVisibleNonTransparentRegion - called when the visible and |
| 402 | * non-transparent region changes. |
| 403 | */ |
| 404 | void setVisibleNonTransparentRegion(const Region& |
| 405 | visibleNonTransparentRegion); |
| 406 | |
| 407 | /* |
| 408 | * latchBuffer - called each time the screen is redrawn and returns whether |
| 409 | * the visible regions need to be recomputed (this is a fairly heavy |
| 410 | * operation, so this should be set only if needed). Typically this is used |
| 411 | * to figure out if the content or size of a surface has changed. |
| 412 | */ |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 413 | Region latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime); |
Chia-I Wu | a36bf92 | 2017-06-30 12:51:05 -0700 | [diff] [blame] | 414 | bool isBufferLatched() const { return mRefreshPending; } |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 415 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 416 | bool isPotentialCursor() const { return mPotentialCursor;} |
| 417 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 418 | /* |
Chia-I Wu | c665702 | 2017-08-15 11:18:17 -0700 | [diff] [blame] | 419 | * called with the state lock from a binder thread when the layer is |
| 420 | * removed from the current list to the pending removal list |
| 421 | */ |
| 422 | void onRemovedFromCurrentState(); |
| 423 | |
| 424 | /* |
| 425 | * called with the state lock from the main thread when the layer is |
| 426 | * removed from the pending removal list |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 427 | */ |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 428 | void onRemoved(); |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 429 | |
| 430 | |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 431 | // Updates the transform hint in our SurfaceFlingerConsumer to match |
Mathias Agopian | 8430095 | 2012-11-21 16:02:13 -0800 | [diff] [blame] | 432 | // the current orientation of the display device. |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 433 | void updateTransformHint(const sp<const DisplayDevice>& hw) const; |
Andy McFadden | 6905205 | 2012-09-14 16:10:11 -0700 | [diff] [blame] | 434 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 435 | /* |
| 436 | * returns the rectangle that crops the content of the layer and scales it |
| 437 | * to the layer's size. |
| 438 | */ |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 439 | Rect getContentCrop() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 440 | |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 441 | /* |
| 442 | * Returns if a frame is queued. |
| 443 | */ |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 444 | bool hasQueuedFrame() const { return mQueuedFrames > 0 || |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 445 | mSidebandStreamChanged || mAutoRefresh; } |
Eric Penner | 51c59cd | 2014-07-28 19:51:58 -0700 | [diff] [blame] | 446 | |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 447 | int32_t getQueuedFrameCount() const { return mQueuedFrames; } |
| 448 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 449 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 450 | // ----------------------------------------------------------------------- |
| 451 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 452 | bool createHwcLayer(HWComposer* hwc, int32_t hwcId); |
| 453 | void destroyHwcLayer(int32_t hwcId); |
| 454 | void destroyAllHwcLayers(); |
| 455 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 456 | bool hasHwcLayer(int32_t hwcId) { |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 457 | return mHwcLayers.count(hwcId) > 0; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 458 | } |
| 459 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 460 | HWC2::Layer* getHwcLayer(int32_t hwcId) { |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 461 | if (mHwcLayers.count(hwcId) == 0) { |
| 462 | return nullptr; |
| 463 | } |
| 464 | return mHwcLayers[hwcId].layer; |
| 465 | } |
| 466 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 467 | #endif |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 468 | // ----------------------------------------------------------------------- |
| 469 | |
Fabien Sanglard | 1748719 | 2016-12-07 13:03:32 -0800 | [diff] [blame] | 470 | void clearWithOpenGL(const sp<const DisplayDevice>& hw) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 471 | void setFiltering(bool filtering); |
| 472 | bool getFiltering() const; |
| 473 | |
| 474 | // only for debugging |
| 475 | inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; } |
| 476 | |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 477 | inline const State& getDrawingState() const { return mDrawingState; } |
| 478 | inline const State& getCurrentState() const { return mCurrentState; } |
| 479 | inline State& getCurrentState() { return mCurrentState; } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 480 | |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 481 | LayerDebugInfo getLayerDebugInfo() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 482 | |
| 483 | /* always call base class first */ |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 484 | #ifdef USE_HWC2 |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 485 | static void miniDumpHeader(String8& result); |
| 486 | void miniDump(String8& result, int32_t hwcId) const; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 487 | #endif |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 488 | void dumpFrameStats(String8& result) const; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 489 | void dumpFrameEvents(String8& result); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 490 | void clearFrameStats(); |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 491 | void logFrameStats(); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 492 | void getFrameStats(FrameStats* outStats) const; |
Mathias Agopian | 1b5e102 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 493 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 494 | std::vector<OccupancyTracker::Segment> getOccupancyHistory(bool forceFlush); |
| 495 | |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 496 | void onDisconnect(); |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 497 | void addAndGetFrameTimestamps(const NewFrameEventsEntry* newEntry, |
| 498 | FrameEventHistoryDelta* outDelta); |
Pablo Ceballos | ce796e7 | 2016-02-04 19:10:51 -0800 | [diff] [blame] | 499 | |
Robert Carr | 367c568 | 2016-06-20 11:55:28 -0700 | [diff] [blame] | 500 | bool getTransformToDisplayInverse() const; |
| 501 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 502 | Transform getTransform() const; |
| 503 | |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 504 | // Returns the Alpha of the Surface, accounting for the Alpha |
| 505 | // of parent Surfaces in the hierarchy (alpha's will be multiplied |
| 506 | // down the hierarchy). |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 507 | half getAlpha() const; |
| 508 | half4 getColor() const; |
Robert Carr | 6452f12 | 2017-03-21 10:41:29 -0700 | [diff] [blame] | 509 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 510 | void traverseInReverseZOrder(LayerVector::StateSet stateSet, |
| 511 | const LayerVector::Visitor& visitor); |
| 512 | void traverseInZOrder(LayerVector::StateSet stateSet, const LayerVector::Visitor& visitor); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 513 | |
Chia-I Wu | 98f1c10 | 2017-05-30 14:54:08 -0700 | [diff] [blame] | 514 | size_t getChildrenCount() const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 515 | void addChild(const sp<Layer>& layer); |
| 516 | // Returns index if removed, or negative value otherwise |
| 517 | // for symmetry with Vector::remove |
| 518 | ssize_t removeChild(const sp<Layer>& layer); |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 519 | sp<Layer> getParent() const { return mCurrentParent.promote(); } |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 520 | bool hasParent() const { return getParent() != nullptr; } |
| 521 | |
| 522 | Rect computeScreenBounds(bool reduceTransparentRegion = true) const; |
| 523 | bool setChildLayer(const sp<Layer>& childLayer, int32_t z); |
| 524 | |
| 525 | // Copy the current list of children to the drawing state. Called by |
| 526 | // SurfaceFlinger to complete a transaction. |
| 527 | void commitChildList(); |
| 528 | |
| 529 | int32_t getZ() const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 530 | protected: |
| 531 | // constant |
| 532 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 533 | /* |
| 534 | * Trivial class, used to ensure that mFlinger->onLayerDestroyed(mLayer) |
| 535 | * is called. |
| 536 | */ |
| 537 | class LayerCleaner { |
| 538 | sp<SurfaceFlinger> mFlinger; |
| 539 | wp<Layer> mLayer; |
| 540 | protected: |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 541 | ~LayerCleaner() { |
| 542 | // destroy client resources |
| 543 | mFlinger->onLayerDestroyed(mLayer); |
| 544 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 545 | public: |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 546 | LayerCleaner(const sp<SurfaceFlinger>& flinger, |
| 547 | const sp<Layer>& layer) |
| 548 | : mFlinger(flinger), mLayer(layer) { |
| 549 | } |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 550 | }; |
| 551 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 552 | |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 553 | virtual void onFirstRef(); |
| 554 | |
| 555 | |
| 556 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | private: |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 558 | friend class SurfaceInterceptor; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 559 | // Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener |
Dan Stoza | dc13c5b | 2015-05-11 15:33:01 -0700 | [diff] [blame] | 560 | virtual void onFrameAvailable(const BufferItem& item) override; |
| 561 | virtual void onFrameReplaced(const BufferItem& item) override; |
| 562 | virtual void onSidebandStreamChanged() override; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 563 | |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 564 | void commitTransaction(const State& stateToCommit); |
Mathias Agopian | 1eae0ee | 2013-06-05 16:59:15 -0700 | [diff] [blame] | 565 | |
| 566 | // needsLinearFiltering - true if this surface's state requires filtering |
| 567 | bool needsFiltering(const sp<const DisplayDevice>& hw) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 568 | |
Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 569 | uint32_t getEffectiveUsage(uint32_t usage) const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 570 | |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 571 | FloatRect computeCrop(const sp<const DisplayDevice>& hw) const; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 572 | // Compute the initial crop as specified by parent layers and the SurfaceControl |
| 573 | // for this layer. Does not include buffer crop from the IGraphicBufferProducer |
| 574 | // client, as that should not affect child clipping. Returns in screen space. |
| 575 | Rect computeInitialCrop(const sp<const DisplayDevice>& hw) const; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 576 | bool isCropped() const; |
| 577 | static bool getOpacityForFormat(uint32_t format); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 578 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 579 | // drawing |
Fabien Sanglard | 1748719 | 2016-12-07 13:03:32 -0800 | [diff] [blame] | 580 | void clearWithOpenGL(const sp<const DisplayDevice>& hw, |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 581 | float r, float g, float b, float alpha) const; |
Fabien Sanglard | 8578980 | 2016-12-07 13:08:24 -0800 | [diff] [blame] | 582 | void drawWithOpenGL(const sp<const DisplayDevice>& hw, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 583 | bool useIdentityTransform) const; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 584 | |
Ruben Brunk | 1681d95 | 2014-06-27 15:51:55 -0700 | [diff] [blame] | 585 | // Temporary - Used only for LEGACY camera mode. |
| 586 | uint32_t getProducerStickyTransform() const; |
| 587 | |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 588 | // Loads the corresponding system property once per process |
| 589 | static bool latchUnsignaledBuffers(); |
| 590 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 591 | void setParent(const sp<Layer>& layer); |
| 592 | |
Dan Stoza | 412903f | 2017-04-27 13:42:17 -0700 | [diff] [blame] | 593 | LayerVector makeTraversalList(LayerVector::StateSet stateSet); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 594 | void addZOrderRelative(const wp<Layer>& relative); |
| 595 | void removeZOrderRelative(const wp<Layer>& relative); |
| 596 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 597 | // ----------------------------------------------------------------------- |
| 598 | |
| 599 | class SyncPoint |
| 600 | { |
| 601 | public: |
Chih-Hung Hsieh | 342b760 | 2016-09-01 11:34:16 -0700 | [diff] [blame] | 602 | explicit SyncPoint(uint64_t frameNumber) : mFrameNumber(frameNumber), |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 603 | mFrameIsAvailable(false), mTransactionIsApplied(false) {} |
| 604 | |
| 605 | uint64_t getFrameNumber() const { |
| 606 | return mFrameNumber; |
| 607 | } |
| 608 | |
| 609 | bool frameIsAvailable() const { |
| 610 | return mFrameIsAvailable; |
| 611 | } |
| 612 | |
| 613 | void setFrameAvailable() { |
| 614 | mFrameIsAvailable = true; |
| 615 | } |
| 616 | |
| 617 | bool transactionIsApplied() const { |
| 618 | return mTransactionIsApplied; |
| 619 | } |
| 620 | |
| 621 | void setTransactionApplied() { |
| 622 | mTransactionIsApplied = true; |
| 623 | } |
| 624 | |
| 625 | private: |
| 626 | const uint64_t mFrameNumber; |
| 627 | std::atomic<bool> mFrameIsAvailable; |
| 628 | std::atomic<bool> mTransactionIsApplied; |
| 629 | }; |
| 630 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 631 | // SyncPoints which will be signaled when the correct frame is at the head |
| 632 | // of the queue and dropped after the frame has been latched. Protected by |
| 633 | // mLocalSyncPointMutex. |
| 634 | Mutex mLocalSyncPointMutex; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 635 | std::list<std::shared_ptr<SyncPoint>> mLocalSyncPoints; |
| 636 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 637 | // SyncPoints which will be signaled and then dropped when the transaction |
| 638 | // is applied |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 639 | std::list<std::shared_ptr<SyncPoint>> mRemoteSyncPoints; |
| 640 | |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 641 | uint64_t getHeadFrameNumber() const; |
Dan Stoza | 1ce6581 | 2016-06-15 16:26:27 -0700 | [diff] [blame] | 642 | bool headFenceHasSignaled() const; |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 643 | |
| 644 | // Returns false if the relevant frame has already been latched |
| 645 | bool addSyncPoint(const std::shared_ptr<SyncPoint>& point); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 646 | |
| 647 | void pushPendingState(); |
Pablo Ceballos | 05289c2 | 2016-04-14 15:49:55 -0700 | [diff] [blame] | 648 | void popPendingState(State* stateToCommit); |
| 649 | bool applyPendingStates(State* stateToCommit); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 650 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 651 | void clearSyncPoints(); |
| 652 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 653 | // Returns mCurrentScaling mode (originating from the |
| 654 | // Client) or mOverrideScalingMode mode (originating from |
| 655 | // the Surface Controller) if set. |
| 656 | uint32_t getEffectiveScalingMode() const; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 657 | public: |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 658 | /* |
| 659 | * The layer handle is just a BBinder object passed to the client |
| 660 | * (remote process) -- we don't keep any reference on our side such that |
| 661 | * the dtor is called when the remote side let go of its reference. |
| 662 | * |
| 663 | * LayerCleaner ensures that mFlinger->onLayerDestroyed() is called for |
| 664 | * this layer when the handle is destroyed. |
| 665 | */ |
| 666 | class Handle : public BBinder, public LayerCleaner { |
| 667 | public: |
| 668 | Handle(const sp<SurfaceFlinger>& flinger, const sp<Layer>& layer) |
| 669 | : LayerCleaner(flinger, layer), owner(layer) {} |
| 670 | |
| 671 | wp<Layer> owner; |
| 672 | }; |
| 673 | |
| 674 | sp<IBinder> getHandle(); |
| 675 | sp<IGraphicBufferProducer> getProducer() const; |
| 676 | const String8& getName() const; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 677 | void notifyAvailableFrames(); |
Kalle Raita | a099a24 | 2017-01-11 11:17:29 -0800 | [diff] [blame] | 678 | PixelFormat getPixelFormat() const { return mFormat; } |
chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 679 | bool getPremultipledAlpha() const; |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 680 | private: |
Igor Murashkin | a4a3149 | 2012-10-29 13:36:11 -0700 | [diff] [blame] | 681 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 682 | // ----------------------------------------------------------------------- |
| 683 | |
Fabien Sanglard | cd6fd54 | 2016-10-13 12:47:39 -0700 | [diff] [blame] | 684 | // Check all of the local sync points to ensure that all transactions |
| 685 | // which need to have been applied prior to the frame which is about to |
| 686 | // be latched have signaled |
| 687 | bool allTransactionsSignaled(); |
| 688 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 689 | // constants |
Andy McFadden | bf974ab | 2012-12-04 16:51:15 -0800 | [diff] [blame] | 690 | sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 691 | sp<IGraphicBufferProducer> mProducer; |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 692 | uint32_t mTextureName; // from GLES |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 693 | bool mPremultipliedAlpha; |
| 694 | String8 mName; |
Dan Stoza | f7ba41a | 2017-05-10 15:11:11 -0700 | [diff] [blame] | 695 | String8 mTransactionName; // A cached version of "TX - " + mName for systraces |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 696 | PixelFormat mFormat; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 697 | |
Chia-I Wu | ab0c319 | 2017-08-01 11:29:00 -0700 | [diff] [blame] | 698 | bool mPrimaryDisplayOnly = false; |
| 699 | |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 700 | // these are protected by an external lock |
| 701 | State mCurrentState; |
| 702 | State mDrawingState; |
| 703 | volatile int32_t mTransactionFlags; |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 704 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 705 | // Accessed from main thread and binder threads |
| 706 | Mutex mPendingStateMutex; |
| 707 | Vector<State> mPendingStates; |
| 708 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 709 | // thread-safe |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 710 | volatile int32_t mQueuedFrames; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 711 | volatile int32_t mSidebandStreamChanged; // used like an atomic boolean |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 712 | |
| 713 | // Timestamp history for UIAutomation. Thread safe. |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 714 | FrameTracker mFrameTracker; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 715 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 716 | // Timestamp history for the consumer to query. |
| 717 | // Accessed by both consumer and producer on main and binder threads. |
| 718 | Mutex mFrameEventHistoryMutex; |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 719 | ConsumerFrameEventHistory mFrameEventHistory; |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 720 | FenceTimeline mAcquireTimeline; |
| 721 | FenceTimeline mReleaseTimeline; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 722 | |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 723 | // main thread |
Mathias Agopian | a934764 | 2017-02-13 16:42:28 -0800 | [diff] [blame] | 724 | int mActiveBufferSlot; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 725 | sp<GraphicBuffer> mActiveBuffer; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 726 | sp<NativeHandle> mSidebandStream; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 727 | Rect mCurrentCrop; |
| 728 | uint32_t mCurrentTransform; |
Mathias Agopian | 933389f | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 729 | uint32_t mCurrentScalingMode; |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 730 | // We encode unset as -1. |
| 731 | int32_t mOverrideScalingMode; |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 732 | bool mCurrentOpacity; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 733 | bool mBufferLatched = false; // TODO: Use mActiveBuffer? |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 734 | std::atomic<uint64_t> mCurrentFrameNumber; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 735 | uint64_t mPreviousFrameNumber; // Only accessed on the main thread. |
Mathias Agopian | 4d143ee | 2012-02-23 20:05:39 -0800 | [diff] [blame] | 736 | bool mRefreshPending; |
Jamie Gennis | e8696a4 | 2012-01-15 18:54:57 -0800 | [diff] [blame] | 737 | bool mFrameLatencyNeeded; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 738 | // Whether filtering is forced on or not |
| 739 | bool mFiltering; |
| 740 | // Whether filtering is needed b/c of the drawingstate |
| 741 | bool mNeedsFiltering; |
Mathias Agopian | 5cdc899 | 2013-08-13 20:51:23 -0700 | [diff] [blame] | 742 | // The mesh used to draw the layer in GLES composition mode |
| 743 | mutable Mesh mMesh; |
Andy McFadden | 4df87bd | 2014-04-21 18:08:54 -0700 | [diff] [blame] | 744 | // The texture used to draw the layer in GLES composition mode |
Mathias Agopian | 49457ac | 2013-08-14 18:20:17 -0700 | [diff] [blame] | 745 | mutable Texture mTexture; |
Mathias Agopian | d606de6 | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 746 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 747 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 748 | // HWC items, accessed from the main thread |
| 749 | struct HWCInfo { |
| 750 | HWCInfo() |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 751 | : hwc(nullptr), |
| 752 | layer(nullptr), |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 753 | forceClientComposition(false), |
| 754 | compositionType(HWC2::Composition::Invalid), |
| 755 | clearClientTarget(false) {} |
| 756 | |
Steven Thomas | b02664d | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 757 | HWComposer* hwc; |
| 758 | HWC2::Layer* layer; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 759 | bool forceClientComposition; |
| 760 | HWC2::Composition compositionType; |
| 761 | bool clearClientTarget; |
Dan Stoza | e22aec7 | 2016-08-01 13:20:59 -0700 | [diff] [blame] | 762 | Rect displayFrame; |
Dan Stoza | 5a423ea | 2017-02-16 14:10:39 -0800 | [diff] [blame] | 763 | FloatRect sourceCrop; |
Chia-I Wu | aaff73f | 2017-02-13 12:28:24 -0800 | [diff] [blame] | 764 | HWComposerBufferCache bufferCache; |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 765 | }; |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 766 | |
| 767 | // A layer can be attached to multiple displays when operating in mirror mode |
| 768 | // (a.k.a: when several displays are attached with equal layerStack). In this |
Fabien Sanglard | 4afbf41 | 2017-03-08 14:50:11 -0800 | [diff] [blame] | 769 | // case we need to keep track. In non-mirror mode, a layer will have only one |
Fabien Sanglard | f0c53d6 | 2017-03-03 18:58:50 -0800 | [diff] [blame] | 770 | // HWCInfo. This map key is a display layerStack. |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 771 | std::unordered_map<int32_t, HWCInfo> mHwcLayers; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 772 | #else |
| 773 | bool mIsGlesComposition; |
| 774 | #endif |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 775 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 776 | // page-flip thread (currently main thread) |
Glenn Kasten | 16f0453 | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 777 | bool mProtectedByApp; // application requires protected path to external sink |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 778 | |
| 779 | // protected by mLock |
| 780 | mutable Mutex mLock; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 781 | // Set to true once we've returned this surface's handle |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 782 | mutable bool mHasSurface; |
| 783 | const wp<Client> mClientRef; |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 784 | |
| 785 | // This layer can be a cursor on some displays. |
| 786 | bool mPotentialCursor; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 787 | |
| 788 | // Local copy of the queued contents of the incoming BufferQueue |
| 789 | mutable Mutex mQueueItemLock; |
Dan Stoza | a4650a5 | 2015-05-12 12:56:16 -0700 | [diff] [blame] | 790 | Condition mQueueItemCondition; |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 791 | Vector<BufferItem> mQueueItems; |
Dan Stoza | cac3538 | 2016-01-27 12:21:06 -0800 | [diff] [blame] | 792 | std::atomic<uint64_t> mLastFrameNumberReceived; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 793 | bool mUpdateTexImageFailed; // This is only accessed on the main thread. |
Pablo Ceballos | 0631218 | 2015-10-07 16:32:12 -0700 | [diff] [blame] | 794 | |
Pablo Ceballos | ff95aab | 2016-01-13 17:09:58 -0800 | [diff] [blame] | 795 | bool mAutoRefresh; |
Robert Carr | 7bf247e | 2017-05-18 14:02:49 -0700 | [diff] [blame] | 796 | bool mFreezeGeometryUpdates; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 797 | |
| 798 | // Child list about to be committed/used for editing. |
| 799 | LayerVector mCurrentChildren; |
| 800 | // Child list used for rendering. |
| 801 | LayerVector mDrawingChildren; |
| 802 | |
Chia-I Wu | e41dbe6 | 2017-06-13 14:10:56 -0700 | [diff] [blame] | 803 | wp<Layer> mCurrentParent; |
| 804 | wp<Layer> mDrawingParent; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 805 | }; |
| 806 | |
| 807 | // --------------------------------------------------------------------------- |
| 808 | |
| 809 | }; // namespace android |
| 810 | |
| 811 | #endif // ANDROID_LAYER_H |