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_SURFACE_FLINGER_H |
| 18 | #define ANDROID_SURFACE_FLINGER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * NOTE: Make sure this file doesn't include anything from <gl/ > or <gl2/ > |
| 27 | */ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 28 | |
Glenn Kasten | 99ed224 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 29 | #include <cutils/compiler.h> |
| 30 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <utils/Atomic.h> |
| 32 | #include <utils/Errors.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 33 | #include <utils/KeyedVector.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 34 | #include <utils/RefBase.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 35 | #include <utils/SortedVector.h> |
| 36 | #include <utils/threads.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 38 | #include <binder/IMemory.h> |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 39 | |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 40 | #include <ui/FenceTime.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include <ui/PixelFormat.h> |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 42 | #include <ui/mat4.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 43 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 44 | #include <gui/ISurfaceComposer.h> |
| 45 | #include <gui/ISurfaceComposerClient.h> |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 46 | #include <gui/OccupancyTracker.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 48 | #include <hardware/hwcomposer_defs.h> |
| 49 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 50 | #include <system/graphics.h> |
| 51 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 52 | #include <private/gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 54 | #include "Barrier.h" |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 55 | #include "DisplayDevice.h" |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 56 | #include "DispSync.h" |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 57 | #include "FrameTracker.h" |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 58 | #include "LayerVector.h" |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 59 | #include "MessageQueue.h" |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 60 | #include "SurfaceInterceptor.h" |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame^] | 61 | #include "StartBootAnimThread.h" |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 62 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 63 | #include "DisplayHardware/HWComposer.h" |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 64 | #include "Effects/Daltonizer.h" |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 65 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 66 | #include <map> |
| 67 | #include <string> |
| 68 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | namespace android { |
| 70 | |
| 71 | // --------------------------------------------------------------------------- |
| 72 | |
| 73 | class Client; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 74 | class DisplayEventConnection; |
| 75 | class EventThread; |
Mathias Agopian | f33e4b6 | 2012-09-20 16:54:14 -0700 | [diff] [blame] | 76 | class IGraphicBufferAlloc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | class Layer; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 78 | class LayerDim; |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 79 | class Surface; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 80 | class RenderEngine; |
Jamie Gennis | d170075 | 2013-10-14 12:22:52 -0700 | [diff] [blame] | 81 | class EventControlThread; |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 82 | class VSyncSource; |
| 83 | class InjectVSyncSource; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | // --------------------------------------------------------------------------- |
| 86 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | enum { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 88 | eTransactionNeeded = 0x01, |
| 89 | eTraversalNeeded = 0x02, |
| 90 | eDisplayTransactionNeeded = 0x04, |
| 91 | eTransactionMask = 0x07 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 94 | class SurfaceFlinger : public BnSurfaceComposer, |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 95 | private IBinder::DeathRecipient, |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 96 | private HWComposer::EventHandler |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | { |
| 98 | public: |
Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 99 | static char const* getServiceName() ANDROID_API { |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 100 | return "SurfaceFlinger"; |
| 101 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | |
Mathias Agopian | b6df7d0 | 2013-05-09 14:53:35 -0700 | [diff] [blame] | 103 | SurfaceFlinger() ANDROID_API; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 105 | // must be called before clients can connect |
| 106 | void init() ANDROID_API; |
| 107 | |
| 108 | // starts SurfaceFlinger main loop in the current thread |
| 109 | void run() ANDROID_API; |
| 110 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 111 | enum { |
| 112 | EVENT_VSYNC = HWC_EVENT_VSYNC |
| 113 | }; |
| 114 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 115 | // post an asynchronous message to the main thread |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 116 | status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 118 | // post a synchronous message to the main thread |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 119 | status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0, uint32_t flags = 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 121 | // force full composition on all displays |
| 122 | void repaintEverything(); |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 123 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 124 | // returns the default Display |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 125 | sp<const DisplayDevice> getDefaultDisplayDevice() const { |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 126 | return getDisplayDevice(mBuiltinDisplays[DisplayDevice::DISPLAY_PRIMARY]); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 127 | } |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 128 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 129 | // utility function to delete a texture on the main thread |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 130 | void deleteTextureAsync(uint32_t texture); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 131 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 132 | // enable/disable h/w composer event |
| 133 | // TODO: this should be made accessible only to EventThread |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 134 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 135 | void setVsyncEnabled(int disp, int enabled); |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 136 | #else |
| 137 | void eventControl(int disp, int event, int enabled); |
| 138 | #endif |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 139 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 140 | // called on the main thread by MessageQueue when an internal message |
| 141 | // is received |
| 142 | // TODO: this should be made accessible only to MessageQueue |
| 143 | void onMessageReceived(int32_t what); |
Mathias Agopian | 3094df3 | 2012-06-18 18:06:45 -0700 | [diff] [blame] | 144 | |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 145 | // for debugging only |
| 146 | // TODO: this should be made accessible only to HWComposer |
Jesse Hall | 48bc05b | 2013-03-21 14:06:52 -0700 | [diff] [blame] | 147 | const Vector< sp<Layer> >& getLayerSortedByZForHwcDisplay(int id); |
Mathias Agopian | cb55857 | 2012-10-04 15:58:54 -0700 | [diff] [blame] | 148 | |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 149 | RenderEngine& getRenderEngine() const { |
| 150 | return *mRenderEngine; |
Jesse Hall | 29c3f35 | 2013-05-21 15:36:55 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 153 | private: |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 154 | friend class Client; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 155 | friend class DisplayEventConnection; |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 156 | friend class EventThread; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | friend class Layer; |
Dan Stoza | b9b0883 | 2014-03-13 11:55:57 -0700 | [diff] [blame] | 158 | friend class MonitoredProducer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 160 | // This value is specified in number of frames. Log frame stats at most |
| 161 | // every half hour. |
| 162 | enum { LOG_FRAME_STATS_PERIOD = 30*60*60 }; |
| 163 | |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 164 | static const size_t MAX_LAYERS = 4096; |
| 165 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 166 | // We're reference counted, never destroy SurfaceFlinger directly |
| 167 | virtual ~SurfaceFlinger(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 169 | /* ------------------------------------------------------------------------ |
| 170 | * Internal data structures |
| 171 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 173 | class State { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | public: |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 175 | LayerVector layersSortedByZ; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 176 | DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays; |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 177 | |
| 178 | void traverseInZOrder(const std::function<void(Layer*)>& consume) const; |
| 179 | void traverseInReverseZOrder(const std::function<void(Layer*)>& consume) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 182 | /* ------------------------------------------------------------------------ |
| 183 | * IBinder interface |
| 184 | */ |
| 185 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 186 | Parcel* reply, uint32_t flags); |
| 187 | virtual status_t dump(int fd, const Vector<String16>& args); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 189 | /* ------------------------------------------------------------------------ |
| 190 | * ISurfaceComposer interface |
| 191 | */ |
| 192 | virtual sp<ISurfaceComposerClient> createConnection(); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 193 | virtual sp<ISurfaceComposerClient> createScopedConnection(const sp<IGraphicBufferProducer>& gbp); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 194 | virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc(); |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 195 | virtual sp<IBinder> createDisplay(const String8& displayName, bool secure); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 196 | virtual void destroyDisplay(const sp<IBinder>& display); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 197 | virtual sp<IBinder> getBuiltInDisplay(int32_t id); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 198 | virtual void setTransactionState(const Vector<ComposerState>& state, |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 199 | const Vector<DisplayState>& displays, uint32_t flags); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 200 | virtual void bootFinished(); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 201 | virtual bool authenticateSurfaceTexture( |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 202 | const sp<IGraphicBufferProducer>& bufferProducer) const; |
Brian Anderson | 069b365 | 2016-07-22 10:32:47 -0700 | [diff] [blame] | 203 | virtual status_t getSupportedFrameTimestamps( |
Brian Anderson | 3890c39 | 2016-07-25 12:48:08 -0700 | [diff] [blame] | 204 | std::vector<FrameEvent>* outSupported) const; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 205 | virtual sp<IDisplayEventConnection> createDisplayEventConnection(); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 206 | virtual status_t captureScreen(const sp<IBinder>& display, |
| 207 | const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 208 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 209 | int32_t minLayerZ, int32_t maxLayerZ, |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 210 | bool useIdentityTransform, ISurfaceComposer::Rotation rotation); |
Lajos Molnar | 67d8bd6 | 2014-09-11 14:58:45 -0700 | [diff] [blame] | 211 | virtual status_t getDisplayStats(const sp<IBinder>& display, |
| 212 | DisplayStatInfo* stats); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 213 | virtual status_t getDisplayConfigs(const sp<IBinder>& display, |
| 214 | Vector<DisplayInfo>* configs); |
| 215 | virtual int getActiveConfig(const sp<IBinder>& display); |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 216 | virtual status_t getDisplayColorModes(const sp<IBinder>& display, |
| 217 | Vector<android_color_mode_t>* configs); |
| 218 | virtual android_color_mode_t getActiveColorMode(const sp<IBinder>& display); |
| 219 | virtual status_t setActiveColorMode(const sp<IBinder>& display, android_color_mode_t colorMode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 220 | virtual void setPowerMode(const sp<IBinder>& display, int mode); |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 221 | virtual status_t setActiveConfig(const sp<IBinder>& display, int id); |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 222 | virtual status_t clearAnimationFrameStats(); |
| 223 | virtual status_t getAnimationFrameStats(FrameStats* outStats) const; |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 224 | virtual status_t getHdrCapabilities(const sp<IBinder>& display, |
| 225 | HdrCapabilities* outCapabilities) const; |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 226 | virtual status_t enableVSyncInjections(bool enable); |
| 227 | virtual status_t injectVSync(nsecs_t when); |
| 228 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 229 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 230 | /* ------------------------------------------------------------------------ |
| 231 | * DeathRecipient interface |
| 232 | */ |
| 233 | virtual void binderDied(const wp<IBinder>& who); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 234 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 235 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 4f4f094 | 2013-08-19 17:26:18 -0700 | [diff] [blame] | 236 | * RefBase interface |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 237 | */ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 238 | virtual void onFirstRef(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 240 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 241 | * HWComposer::EventHandler interface |
| 242 | */ |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 243 | virtual void onVSyncReceived(int type, nsecs_t timestamp); |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame] | 244 | virtual void onHotplugReceived(int disp, bool connected); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 245 | |
| 246 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 247 | * Message handling |
| 248 | */ |
| 249 | void waitForEvent(); |
| 250 | void signalTransaction(); |
| 251 | void signalLayerUpdate(); |
| 252 | void signalRefresh(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 254 | // called on the main thread in response to initializeDisplays() |
| 255 | void onInitializeDisplays(); |
Michael Lentine | 6c9e34a | 2014-07-14 13:48:55 -0700 | [diff] [blame] | 256 | // called on the main thread in response to setActiveConfig() |
| 257 | void setActiveConfigInternal(const sp<DisplayDevice>& hw, int mode); |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 258 | // called on the main thread in response to setPowerMode() |
| 259 | void setPowerModeInternal(const sp<DisplayDevice>& hw, int mode); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 261 | // Called on the main thread in response to setActiveColorMode() |
| 262 | void setActiveColorModeInternal(const sp<DisplayDevice>& hw, android_color_mode_t colorMode); |
| 263 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 264 | // Returns whether the transaction actually modified any state |
| 265 | bool handleMessageTransaction(); |
| 266 | |
| 267 | // Returns whether a new buffer has been latched (see handlePageFlip()) |
| 268 | bool handleMessageInvalidate(); |
| 269 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 270 | void handleMessageRefresh(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 271 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 272 | void handleTransaction(uint32_t transactionFlags); |
| 273 | void handleTransactionLocked(uint32_t transactionFlags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | |
Riley Andrews | 03414a1 | 2014-07-01 14:22:59 -0700 | [diff] [blame] | 275 | void updateCursorAsync(); |
| 276 | |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 277 | /* handlePageFlip - latch a new buffer if available and compute the dirty |
| 278 | * region. Returns whether a new buffer has been latched, i.e., whether it |
| 279 | * is necessary to perform a refresh during this vsync. |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 280 | */ |
Dan Stoza | 6b9454d | 2014-11-07 16:00:59 -0800 | [diff] [blame] | 281 | bool handlePageFlip(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 283 | /* ------------------------------------------------------------------------ |
| 284 | * Transactions |
| 285 | */ |
| 286 | uint32_t getTransactionFlags(uint32_t flags); |
Fabien Sanglard | c8251eb | 2016-12-07 13:59:48 -0800 | [diff] [blame] | 287 | uint32_t peekTransactionFlags(); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 288 | uint32_t setTransactionFlags(uint32_t flags); |
| 289 | void commitTransaction(); |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 290 | uint32_t setClientStateLocked(const sp<Client>& client, const layer_state_t& s); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 291 | uint32_t setDisplayStateLocked(const DisplayState& s); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 293 | /* ------------------------------------------------------------------------ |
| 294 | * Layer management |
| 295 | */ |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 296 | status_t createLayer(const String8& name, const sp<Client>& client, |
| 297 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, |
Albert Chaulk | 479c60c | 2017-01-27 14:21:34 -0500 | [diff] [blame] | 298 | uint32_t windowType, uint32_t ownerUid, sp<IBinder>* handle, |
| 299 | sp<IGraphicBufferProducer>* gbp, sp<Layer>* parent); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 301 | status_t createNormalLayer(const sp<Client>& client, const String8& name, |
| 302 | uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format, |
| 303 | sp<IBinder>* outHandle, sp<IGraphicBufferProducer>* outGbp, |
| 304 | sp<Layer>* outLayer); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 306 | status_t createDimLayer(const sp<Client>& client, const String8& name, |
| 307 | uint32_t w, uint32_t h, uint32_t flags, sp<IBinder>* outHandle, |
| 308 | sp<IGraphicBufferProducer>* outGbp, sp<Layer>* outLayer); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 309 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 310 | // called in response to the window-manager calling |
| 311 | // ISurfaceComposerClient::destroySurface() |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 312 | status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 313 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 314 | // called when all clients have released all their references to |
| 315 | // this layer meaning it is entirely safe to destroy all |
| 316 | // resources associated to this layer. |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 317 | status_t onLayerDestroyed(const wp<Layer>& layer); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 318 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 319 | // remove a layer from SurfaceFlinger immediately |
Dan Stoza | 22851c3 | 2016-08-09 13:21:03 -0700 | [diff] [blame] | 320 | status_t removeLayer(const wp<Layer>& layer); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 321 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 322 | // add a layer to SurfaceFlinger |
Dan Stoza | 7d89d06 | 2015-04-30 13:29:25 -0700 | [diff] [blame] | 323 | status_t addClientLayer(const sp<Client>& client, |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 324 | const sp<IBinder>& handle, |
| 325 | const sp<IGraphicBufferProducer>& gbc, |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 326 | const sp<Layer>& lbc, |
| 327 | const sp<Layer>& parent); |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 328 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 329 | /* ------------------------------------------------------------------------ |
| 330 | * Boot animation, on/off animations and screen capture |
| 331 | */ |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 332 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 333 | void startBootAnim(); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 334 | |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 335 | void renderScreenImplLocked( |
| 336 | const sp<const DisplayDevice>& hw, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 337 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 338 | int32_t minLayerZ, int32_t maxLayerZ, |
Riley Andrews | c3ebe66 | 2014-09-04 16:20:31 -0700 | [diff] [blame] | 339 | bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation); |
Mathias Agopian | 180f10d | 2013-04-10 22:55:41 -0700 | [diff] [blame] | 340 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 341 | status_t captureScreenImplLocked( |
| 342 | const sp<const DisplayDevice>& hw, |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 343 | const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 344 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 345 | int32_t minLayerZ, int32_t maxLayerZ, |
Pablo Ceballos | b5b3563 | 2016-02-23 11:18:51 -0800 | [diff] [blame] | 346 | bool useIdentityTransform, Transform::orientation_flags rotation, |
| 347 | bool isLocalScreenshot); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 348 | |
Wei Wang | b254fa3 | 2017-01-31 17:43:23 -0800 | [diff] [blame^] | 349 | sp<StartBootAnimThread> mStartBootAnimThread = nullptr; |
| 350 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 351 | /* ------------------------------------------------------------------------ |
| 352 | * EGL |
| 353 | */ |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 354 | size_t getMaxTextureSize() const; |
| 355 | size_t getMaxViewportDims() const; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 356 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 357 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 358 | * Display and layer stack management |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 359 | */ |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 360 | // called when starting, or restarting after system_server death |
| 361 | void initializeDisplays(); |
| 362 | |
Jesse Hall | 692c723 | 2012-11-08 15:41:56 -0800 | [diff] [blame] | 363 | // Create an IBinder for a builtin display and add it to current state |
| 364 | void createBuiltinDisplayLocked(DisplayDevice::DisplayType type); |
| 365 | |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 366 | // NOTE: can only be called from the main thread or with mStateLock held |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 367 | sp<const DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) const { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 368 | return mDisplays.valueFor(dpy); |
| 369 | } |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 370 | |
| 371 | // NOTE: can only be called from the main thread or with mStateLock held |
| 372 | sp<DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 373 | return mDisplays.valueFor(dpy); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 374 | } |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 375 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 376 | int32_t getDisplayType(const sp<IBinder>& display) { |
| 377 | if (!display.get()) return NAME_NOT_FOUND; |
| 378 | for (int i = 0; i < DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES; ++i) { |
| 379 | if (display == mBuiltinDisplays[i]) { |
| 380 | return i; |
| 381 | } |
| 382 | } |
| 383 | return NAME_NOT_FOUND; |
| 384 | } |
| 385 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 386 | // mark a region of a layer stack dirty. this updates the dirty |
| 387 | // region of all screens presenting this layer stack. |
| 388 | void invalidateLayerStack(uint32_t layerStack, const Region& dirty); |
| 389 | |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 390 | #ifndef USE_HWC2 |
| 391 | int32_t allocateHwcDisplayId(DisplayDevice::DisplayType type); |
| 392 | #endif |
| 393 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 394 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 395 | * H/W composer |
| 396 | */ |
| 397 | |
| 398 | HWComposer& getHwComposer() const { return *mHwc; } |
| 399 | |
Mathias Agopian | 888c822 | 2012-08-04 21:10:38 -0700 | [diff] [blame] | 400 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 401 | * Compositing |
| 402 | */ |
| 403 | void invalidateHwcGeometry(); |
Robert Carr | 2047fae | 2016-11-28 14:09:09 -0800 | [diff] [blame] | 404 | void computeVisibleRegions(uint32_t layerStack, |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 405 | Region& dirtyRegion, Region& opaqueRegion); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 406 | |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 407 | void preComposition(nsecs_t refreshStartTime); |
| 408 | void postComposition(); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 409 | void rebuildLayerStacks(); |
| 410 | void setUpHWComposer(); |
| 411 | void doComposition(); |
| 412 | void doDebugFlashRegions(); |
Fabien Sanglard | 830b847 | 2016-11-30 16:35:58 -0800 | [diff] [blame] | 413 | void doDisplayComposition(const sp<const DisplayDevice>& displayDevice, const Region& dirtyRegion); |
Michael Lentine | 3f121fc | 2014-10-01 11:17:28 -0700 | [diff] [blame] | 414 | |
| 415 | // compose surfaces for display hw. this fails if using GL and the surface |
| 416 | // has been destroyed and is no longer valid. |
Fabien Sanglard | 830b847 | 2016-11-30 16:35:58 -0800 | [diff] [blame] | 417 | bool doComposeSurfaces(const sp<const DisplayDevice>& displayDevice, const Region& dirty); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 418 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 419 | void postFramebuffer(); |
Fabien Sanglard | 830b847 | 2016-11-30 16:35:58 -0800 | [diff] [blame] | 420 | void drawWormhole(const sp<const DisplayDevice>& displayDevice, const Region& region) const; |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 421 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 422 | /* ------------------------------------------------------------------------ |
Jamie Gennis | 0bceb84 | 2012-08-23 20:19:38 -0700 | [diff] [blame] | 423 | * Display management |
| 424 | */ |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 425 | |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 426 | /* ------------------------------------------------------------------------ |
| 427 | * VSync |
| 428 | */ |
| 429 | void enableHardwareVsync(); |
Dan Stoza | 67264e9 | 2016-04-14 16:11:48 +0000 | [diff] [blame] | 430 | void resyncToHardwareVsync(bool makeAvailable); |
Tim Murray | 4a4e4a2 | 2016-04-19 16:29:23 +0000 | [diff] [blame] | 431 | void disableHardwareVsync(bool makeUnavailable); |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 432 | |
Tim Murray | 4a4e4a2 | 2016-04-19 16:29:23 +0000 | [diff] [blame] | 433 | public: |
| 434 | void resyncWithRateLimit(); |
| 435 | private: |
Jamie Gennis | 0bceb84 | 2012-08-23 20:19:38 -0700 | [diff] [blame] | 436 | |
| 437 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 438 | * Debugging & dumpsys |
| 439 | */ |
Mathias Agopian | 3f84483 | 2013-08-07 21:24:32 -0700 | [diff] [blame] | 440 | void listLayersLocked(const Vector<String16>& args, size_t& index, String8& result) const; |
| 441 | void dumpStatsLocked(const Vector<String16>& args, size_t& index, String8& result) const; |
| 442 | void clearStatsLocked(const Vector<String16>& args, size_t& index, String8& result); |
| 443 | void dumpAllLocked(const Vector<String16>& args, size_t& index, String8& result) const; |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 444 | bool startDdmConnection(); |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 445 | void appendSfConfigString(String8& result) const; |
Mathias Agopian | d555684 | 2013-09-19 17:08:37 -0700 | [diff] [blame] | 446 | void checkScreenshot(size_t w, size_t s, size_t h, void const* vaddr, |
Mathias Agopian | fee2b46 | 2013-07-03 12:34:01 -0700 | [diff] [blame] | 447 | const sp<const DisplayDevice>& hw, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 448 | int32_t minLayerZ, int32_t maxLayerZ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 449 | |
Jamie Gennis | 6547ff4 | 2013-07-16 20:12:42 -0700 | [diff] [blame] | 450 | void logFrameStats(); |
| 451 | |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 452 | void dumpStaticScreenStats(String8& result) const; |
Brian Anderson | d6927fb | 2016-07-23 23:37:30 -0700 | [diff] [blame] | 453 | // Not const because each Layer needs to query Fences and cache timestamps. |
| 454 | void dumpFrameEventsLocked(String8& result); |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 455 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 456 | void recordBufferingStats(const char* layerName, |
| 457 | std::vector<OccupancyTracker::Segment>&& history); |
| 458 | void dumpBufferingStats(String8& result) const; |
| 459 | |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 460 | bool isLayerTripleBufferingDisabled() const { |
| 461 | return this->mLayerTripleBufferingDisabled; |
| 462 | } |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 463 | /* ------------------------------------------------------------------------ |
| 464 | * Attributes |
| 465 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 466 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 467 | // access must be protected by mStateLock |
| 468 | mutable Mutex mStateLock; |
| 469 | State mCurrentState; |
| 470 | volatile int32_t mTransactionFlags; |
| 471 | Condition mTransactionCV; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 472 | bool mTransactionPending; |
| 473 | bool mAnimTransactionPending; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 474 | SortedVector< sp<Layer> > mLayersPendingRemoval; |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 475 | SortedVector< wp<IBinder> > mGraphicBufferProducerList; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 477 | // protected by mStateLock (but we could use another lock) |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 478 | bool mLayersRemoved; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 479 | bool mLayersAdded; |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 480 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 481 | // access must be protected by mInvalidateLock |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 482 | volatile int32_t mRepaintEverything; |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 483 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 484 | // constant members (no synchronization needed for access) |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 485 | HWComposer* mHwc; |
Mathias Agopian | 875d8e1 | 2013-06-07 15:35:48 -0700 | [diff] [blame] | 486 | RenderEngine* mRenderEngine; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 487 | nsecs_t mBootTime; |
Mathias Agopian | b4b1730 | 2013-03-20 18:36:41 -0700 | [diff] [blame] | 488 | bool mGpuToCpuSupported; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 489 | sp<EventThread> mEventThread; |
Jamie Gennis | 0a645cc | 2013-10-14 20:52:46 -0700 | [diff] [blame] | 490 | sp<EventThread> mSFEventThread; |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 491 | sp<EventThread> mInjectorEventThread; |
| 492 | sp<InjectVSyncSource> mVSyncInjector; |
Jamie Gennis | d170075 | 2013-10-14 12:22:52 -0700 | [diff] [blame] | 493 | sp<EventControlThread> mEventControlThread; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 494 | EGLContext mEGLContext; |
Jesse Hall | 34a09ba | 2012-07-29 22:35:34 -0700 | [diff] [blame] | 495 | EGLDisplay mEGLDisplay; |
Jesse Hall | 9e663de | 2013-08-16 14:28:37 -0700 | [diff] [blame] | 496 | sp<IBinder> mBuiltinDisplays[DisplayDevice::NUM_BUILTIN_DISPLAY_TYPES]; |
Mathias Agopian | 3094df3 | 2012-06-18 18:06:45 -0700 | [diff] [blame] | 497 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 498 | // Can only accessed from the main thread, these members |
| 499 | // don't need synchronization |
| 500 | State mDrawingState; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 501 | bool mVisibleRegionsDirty; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 502 | #ifndef USE_HWC2 |
| 503 | bool mHwWorkListDirty; |
| 504 | #else |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 505 | bool mGeometryInvalid; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 506 | #endif |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 507 | bool mAnimCompositionPending; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 508 | #ifdef USE_HWC2 |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 509 | std::vector<sp<Layer>> mLayersWithQueuedFrames; |
Dan Stoza | 05dacfb | 2016-07-01 13:33:38 -0700 | [diff] [blame] | 510 | sp<Fence> mPreviousPresentFence = Fence::NO_FENCE; |
| 511 | bool mHadClientComposition = false; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 512 | #endif |
Brian Anderson | 3d4039d | 2016-09-23 16:31:30 -0700 | [diff] [blame] | 513 | FenceTimeline mGlCompositionDoneTimeline; |
| 514 | FenceTimeline mDisplayTimeline; |
Mathias Agopian | db9b41f | 2012-10-15 16:51:41 -0700 | [diff] [blame] | 515 | |
| 516 | // this may only be written from the main thread with mStateLock held |
| 517 | // it may be read from other threads with mStateLock held |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 518 | DefaultKeyedVector< wp<IBinder>, sp<DisplayDevice> > mDisplays; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 519 | |
| 520 | // don't use a lock for these, we don't care |
| 521 | int mDebugRegion; |
| 522 | int mDebugDDMS; |
| 523 | int mDebugDisableHWC; |
| 524 | int mDebugDisableTransformHint; |
| 525 | volatile nsecs_t mDebugInSwapBuffers; |
| 526 | nsecs_t mLastSwapBufferTime; |
| 527 | volatile nsecs_t mDebugInTransaction; |
| 528 | nsecs_t mLastTransactionTime; |
| 529 | bool mBootFinished; |
Dan Stoza | ee44edd | 2015-03-23 15:50:23 -0700 | [diff] [blame] | 530 | bool mForceFullDamage; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 531 | #ifdef USE_HWC2 |
Dan Stoza | c5da271 | 2016-07-20 15:38:12 -0700 | [diff] [blame] | 532 | bool mPropagateBackpressure = true; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 533 | #endif |
Irvel | 468051e | 2016-06-13 16:44:44 -0700 | [diff] [blame] | 534 | SurfaceInterceptor mInterceptor; |
Dan Stoza | 8cf150a | 2016-08-02 10:27:31 -0700 | [diff] [blame] | 535 | bool mUseHwcVirtualDisplays = true; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 536 | |
Fabien Sanglard | 63a5fcd | 2016-12-29 15:13:07 -0800 | [diff] [blame] | 537 | // Restrict layers to use two buffers in their bufferqueues. |
| 538 | bool mLayerTripleBufferingDisabled = false; |
| 539 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 540 | // these are thread safe |
| 541 | mutable MessageQueue mEventQueue; |
Jamie Gennis | 4b0eba9 | 2013-02-05 13:30:24 -0800 | [diff] [blame] | 542 | FrameTracker mAnimFrameTracker; |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 543 | DispSync mPrimaryDispSync; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 544 | |
| 545 | // protected by mDestroyedLayerLock; |
| 546 | mutable Mutex mDestroyedLayerLock; |
Mathias Agopian | 13127d8 | 2013-03-05 17:47:11 -0800 | [diff] [blame] | 547 | Vector<Layer const *> mDestroyedLayers; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 548 | |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 549 | // protected by mHWVsyncLock |
| 550 | Mutex mHWVsyncLock; |
| 551 | bool mPrimaryHWVsyncEnabled; |
Jesse Hall | 948fe0c | 2013-10-14 12:56:09 -0700 | [diff] [blame] | 552 | bool mHWVsyncAvailable; |
Jamie Gennis | faf77cc | 2013-07-30 15:10:32 -0700 | [diff] [blame] | 553 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 554 | /* ------------------------------------------------------------------------ |
| 555 | * Feature prototyping |
| 556 | */ |
| 557 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 558 | bool mInjectVSyncs; |
| 559 | |
Mathias Agopian | ff2ed70 | 2013-09-01 21:36:12 -0700 | [diff] [blame] | 560 | Daltonizer mDaltonizer; |
Fabien Sanglard | 9d96de4 | 2016-10-11 00:15:18 +0000 | [diff] [blame] | 561 | #ifndef USE_HWC2 |
| 562 | bool mDaltonize; |
| 563 | #endif |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 564 | |
Dan Stoza | 9f26a9c | 2016-06-22 14:51:09 -0700 | [diff] [blame] | 565 | mat4 mPreviousColorMatrix; |
Alan Viverette | 9c5a333 | 2013-09-12 20:04:35 -0700 | [diff] [blame] | 566 | mat4 mColorMatrix; |
| 567 | bool mHasColorMatrix; |
Dan Stoza | b90cf07 | 2015-03-05 11:05:59 -0800 | [diff] [blame] | 568 | |
| 569 | // Static screen stats |
| 570 | bool mHasPoweredOff; |
| 571 | static const size_t NUM_BUCKETS = 8; // < 1-7, 7+ |
| 572 | nsecs_t mFrameBuckets[NUM_BUCKETS]; |
| 573 | nsecs_t mTotalTime; |
Tim Murray | 4a4e4a2 | 2016-04-19 16:29:23 +0000 | [diff] [blame] | 574 | std::atomic<nsecs_t> mLastSwapTime; |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 575 | |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 576 | size_t mNumLayers; |
| 577 | |
Dan Stoza | e77c766 | 2016-05-13 11:37:28 -0700 | [diff] [blame] | 578 | // Double- vs. triple-buffering stats |
| 579 | struct BufferingStats { |
| 580 | BufferingStats() |
| 581 | : numSegments(0), |
| 582 | totalTime(0), |
| 583 | twoBufferTime(0), |
| 584 | doubleBufferedTime(0), |
| 585 | tripleBufferedTime(0) {} |
| 586 | |
| 587 | size_t numSegments; |
| 588 | nsecs_t totalTime; |
| 589 | |
| 590 | // "Two buffer" means that a third buffer was never used, whereas |
| 591 | // "double-buffered" means that on average the segment only used two |
| 592 | // buffers (though it may have used a third for some part of the |
| 593 | // segment) |
| 594 | nsecs_t twoBufferTime; |
| 595 | nsecs_t doubleBufferedTime; |
| 596 | nsecs_t tripleBufferedTime; |
| 597 | }; |
| 598 | mutable Mutex mBufferingStatsMutex; |
| 599 | std::unordered_map<std::string, BufferingStats> mBufferingStats; |
Fabien Sanglard | 6e8e98a | 2016-10-27 20:04:11 -0700 | [diff] [blame] | 600 | |
| 601 | // Verify that transaction is being called by an approved process: |
| 602 | // either AID_GRAPHICS or AID_SYSTEM. |
| 603 | status_t CheckTransactCodeCredentials(uint32_t code); |
| 604 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | }; // namespace android |
| 607 | |
| 608 | #endif // ANDROID_SURFACE_FLINGER_H |