| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 1 | #ifndef ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_ | 
|  | 2 | #define ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_ | 
|  | 3 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 4 | #include <ui/GraphicBuffer.h> | 
|  | 5 | #include "DisplayHardware/ComposerHal.h" | 
|  | 6 | #include "hwc_types.h" | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 7 |  | 
| Okan Arikan | 822b710 | 2017-05-08 13:31:34 -0700 | [diff] [blame] | 8 | #include <dvr/dvr_shared_buffers.h> | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 9 | #include <hardware/gralloc.h> | 
|  | 10 | #include <log/log.h> | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 11 |  | 
|  | 12 | #include <array> | 
|  | 13 | #include <condition_variable> | 
|  | 14 | #include <memory> | 
|  | 15 | #include <mutex> | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 16 | #include <optional> | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 17 | #include <thread> | 
|  | 18 | #include <tuple> | 
|  | 19 | #include <vector> | 
|  | 20 |  | 
| Okan Arikan | 6f468c6 | 2017-05-31 14:48:30 -0700 | [diff] [blame] | 21 | #include <dvr/dvr_config.h> | 
| Okan Arikan | 822b710 | 2017-05-08 13:31:34 -0700 | [diff] [blame] | 22 | #include <dvr/dvr_vsync.h> | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 23 | #include <pdx/file_handle.h> | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 24 | #include <pdx/rpc/variant.h> | 
| Okan Arikan | 822b710 | 2017-05-08 13:31:34 -0700 | [diff] [blame] | 25 | #include <private/dvr/shared_buffer_helpers.h> | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 26 | #include <private/dvr/vsync_service.h> | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 27 |  | 
|  | 28 | #include "acquired_buffer.h" | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 29 | #include "display_surface.h" | 
|  | 30 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 31 | // Hardware composer HAL doesn't define HWC_TRANSFORM_NONE as of this writing. | 
|  | 32 | #ifndef HWC_TRANSFORM_NONE | 
|  | 33 | #define HWC_TRANSFORM_NONE static_cast<hwc_transform_t>(0) | 
|  | 34 | #endif | 
|  | 35 |  | 
|  | 36 | namespace android { | 
|  | 37 | namespace dvr { | 
|  | 38 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 39 | // Basic display metrics for physical displays. | 
|  | 40 | struct DisplayParams { | 
|  | 41 | hwc2_display_t id; | 
|  | 42 | bool is_primary; | 
|  | 43 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 44 | int width; | 
|  | 45 | int height; | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 46 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 47 | struct { | 
|  | 48 | int x; | 
|  | 49 | int y; | 
|  | 50 | } dpi; | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 51 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 52 | int vsync_period_ns; | 
|  | 53 | }; | 
|  | 54 |  | 
|  | 55 | // Layer represents the connection between a hardware composer layer and the | 
|  | 56 | // source supplying buffers for the layer's contents. | 
|  | 57 | class Layer { | 
|  | 58 | public: | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 59 | Layer() = default; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 60 |  | 
|  | 61 | // Sets up the layer to use a display surface as its content source. The Layer | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 62 | // automatically handles ACQUIRE/RELEASE phases for the surface's buffer train | 
|  | 63 | // every frame. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 64 | // | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 65 | // |composer| The composer instance. | 
|  | 66 | // |display_params| Info about the display to use. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 67 | // |blending| receives HWC_BLENDING_* values. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 68 | // |composition_type| receives either HWC_FRAMEBUFFER for most layers or | 
|  | 69 | // HWC_FRAMEBUFFER_TARGET (unless you know what you are doing). | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 70 | // |index| is the index of this surface in the DirectDisplaySurface array. | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 71 | Layer(Hwc2::Composer* composer, const DisplayParams& display_params, | 
|  | 72 | const std::shared_ptr<DirectDisplaySurface>& surface, | 
|  | 73 | HWC::BlendMode blending, HWC::Composition composition_type, | 
|  | 74 | size_t z_order); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 75 |  | 
|  | 76 | // Sets up the layer to use a direct buffer as its content source. No special | 
|  | 77 | // handling of the buffer is performed; responsibility for updating or | 
|  | 78 | // changing the buffer each frame is on the caller. | 
|  | 79 | // | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 80 | // |composer| The composer instance. | 
|  | 81 | // |display_params| Info about the display to use. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 82 | // |blending| receives HWC_BLENDING_* values. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 83 | // |composition_type| receives either HWC_FRAMEBUFFER for most layers or | 
|  | 84 | // HWC_FRAMEBUFFER_TARGET (unless you know what you are doing). | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 85 | Layer(Hwc2::Composer* composer, const DisplayParams& display_params, | 
|  | 86 | const std::shared_ptr<IonBuffer>& buffer, HWC::BlendMode blending, | 
|  | 87 | HWC::Composition composition_type, size_t z_order); | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 88 |  | 
| Chih-Hung Hsieh | 5bc849f | 2018-09-25 14:21:50 -0700 | [diff] [blame] | 89 | Layer(Layer&&) noexcept; | 
|  | 90 | Layer& operator=(Layer&&) noexcept; | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 91 |  | 
|  | 92 | ~Layer(); | 
|  | 93 |  | 
|  | 94 | // Releases any shared pointers and fence handles held by this instance. | 
|  | 95 | void Reset(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 96 |  | 
|  | 97 | // Layers that use a direct IonBuffer should call this each frame to update | 
|  | 98 | // which buffer will be used for the next PostLayers. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 99 | void UpdateBuffer(const std::shared_ptr<IonBuffer>& buffer); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 100 |  | 
|  | 101 | // Sets up the hardware composer layer for the next frame. When the layer is | 
|  | 102 | // associated with a display surface, this method automatically ACQUIRES a new | 
|  | 103 | // buffer if one is available. | 
|  | 104 | void Prepare(); | 
|  | 105 |  | 
|  | 106 | // After calling prepare, if this frame is to be dropped instead of passing | 
|  | 107 | // along to the HWC, call Drop to close the contained fence(s). | 
|  | 108 | void Drop(); | 
|  | 109 |  | 
|  | 110 | // Performs fence bookkeeping after the frame has been posted to hardware | 
|  | 111 | // composer. | 
|  | 112 | void Finish(int release_fence_fd); | 
|  | 113 |  | 
|  | 114 | // Sets the blending for the layer. |blending| receives HWC_BLENDING_* values. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 115 | void SetBlending(HWC::BlendMode blending); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 116 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 117 | // Sets the z-order of this layer | 
|  | 118 | void SetZOrder(size_t z_order); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 119 |  | 
|  | 120 | // Gets the current IonBuffer associated with this layer. Ownership of the | 
|  | 121 | // buffer DOES NOT pass to the caller and the pointer is not guaranteed to | 
|  | 122 | // remain valid across calls to Layer::Setup(), Layer::Prepare(), or | 
|  | 123 | // Layer::Reset(). YOU HAVE BEEN WARNED. | 
|  | 124 | IonBuffer* GetBuffer(); | 
|  | 125 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 126 | HWC::Composition GetCompositionType() const { return composition_type_; } | 
|  | 127 | HWC::Layer GetLayerHandle() const { return hardware_composer_layer_; } | 
|  | 128 | bool IsLayerSetup() const { return !source_.empty(); } | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 129 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 130 | int GetSurfaceId() const { | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 131 | int surface_id = -1; | 
|  | 132 | pdx::rpc::IfAnyOf<SourceSurface>::Call( | 
|  | 133 | &source_, [&surface_id](const SourceSurface& surface_source) { | 
| Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 134 | surface_id = surface_source.GetSurfaceId(); | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 135 | }); | 
|  | 136 | return surface_id; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 137 | } | 
|  | 138 |  | 
| Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 139 | int GetBufferId() const { | 
|  | 140 | int buffer_id = -1; | 
|  | 141 | pdx::rpc::IfAnyOf<SourceSurface>::Call( | 
|  | 142 | &source_, [&buffer_id](const SourceSurface& surface_source) { | 
|  | 143 | buffer_id = surface_source.GetBufferId(); | 
|  | 144 | }); | 
|  | 145 | return buffer_id; | 
|  | 146 | } | 
|  | 147 |  | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 148 | // Compares Layers by surface id. | 
|  | 149 | bool operator<(const Layer& other) const { | 
|  | 150 | return GetSurfaceId() < other.GetSurfaceId(); | 
|  | 151 | } | 
| Corey Tabaka | b3732f0 | 2017-09-16 00:58:54 -0700 | [diff] [blame] | 152 | bool operator<(int surface_id) const { return GetSurfaceId() < surface_id; } | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 153 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 154 | void IgnoreBadDisplayErrorsOnDestroy(bool ignore) { | 
|  | 155 | ignore_bad_display_errors_on_destroy_ = ignore; | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 158 | private: | 
|  | 159 | void CommonLayerSetup(); | 
|  | 160 |  | 
|  | 161 | // Applies all of the settings to this layer using the hwc functions | 
|  | 162 | void UpdateLayerSettings(); | 
|  | 163 |  | 
|  | 164 | // Applies visibility settings that may have changed. | 
|  | 165 | void UpdateVisibilitySettings(); | 
|  | 166 |  | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 167 | // Checks whether the buffer, given by id, is associated with the given slot | 
|  | 168 | // in the HWC buffer cache. If the slot is not associated with the given | 
|  | 169 | // buffer the cache is updated to establish the association and the buffer | 
|  | 170 | // should be sent to HWC using setLayerBuffer. Returns true if the association | 
|  | 171 | // was already established, false if not. A buffer_id of -1 is never | 
|  | 172 | // associated and always returns false. | 
|  | 173 | bool CheckAndUpdateCachedBuffer(std::size_t slot, int buffer_id); | 
|  | 174 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 175 | // Composer instance. | 
|  | 176 | Hwc2::Composer* composer_ = nullptr; | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 177 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 178 | // Parameters of the display to use for this layer. | 
|  | 179 | DisplayParams display_params_; | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 180 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 181 | // The hardware composer layer and metrics to use during the prepare cycle. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 182 | hwc2_layer_t hardware_composer_layer_ = 0; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 183 |  | 
|  | 184 | // Layer properties used to setup the hardware composer layer during the | 
|  | 185 | // Prepare phase. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 186 | size_t z_order_ = 0; | 
|  | 187 | HWC::BlendMode blending_ = HWC::BlendMode::None; | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 188 | HWC::Composition composition_type_ = HWC::Composition::Invalid; | 
|  | 189 | HWC::Composition target_composition_type_ = HWC::Composition::Device; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 190 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 191 | // State when the layer is connected to a surface. Provides the same interface | 
|  | 192 | // as SourceBuffer to simplify internal use by Layer. | 
|  | 193 | struct SourceSurface { | 
|  | 194 | std::shared_ptr<DirectDisplaySurface> surface; | 
|  | 195 | AcquiredBuffer acquired_buffer; | 
|  | 196 | pdx::LocalHandle release_fence; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 197 |  | 
| Chih-Hung Hsieh | 79e7f1b | 2018-12-20 15:53:43 -0800 | [diff] [blame] | 198 | explicit SourceSurface(const std::shared_ptr<DirectDisplaySurface>& surface) | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 199 | : surface(surface) {} | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 200 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 201 | // Attempts to acquire a new buffer from the surface and return a tuple with | 
|  | 202 | // width, height, buffer handle, and fence. If a new buffer is not available | 
|  | 203 | // the previous buffer is returned or an empty value if no buffer has ever | 
|  | 204 | // been posted. When a new buffer is acquired the previous buffer's release | 
|  | 205 | // fence is passed out automatically. | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 206 | std::tuple<int, int, int, sp<GraphicBuffer>, pdx::LocalHandle, std::size_t> | 
|  | 207 | Acquire() { | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 208 | if (surface->IsBufferAvailable()) { | 
|  | 209 | acquired_buffer.Release(std::move(release_fence)); | 
|  | 210 | acquired_buffer = surface->AcquireCurrentBuffer(); | 
|  | 211 | ATRACE_ASYNC_END("BufferPost", acquired_buffer.buffer()->id()); | 
|  | 212 | } | 
|  | 213 | if (!acquired_buffer.IsEmpty()) { | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 214 | return std::make_tuple( | 
|  | 215 | acquired_buffer.buffer()->width(), | 
|  | 216 | acquired_buffer.buffer()->height(), acquired_buffer.buffer()->id(), | 
|  | 217 | acquired_buffer.buffer()->buffer()->buffer(), | 
|  | 218 | acquired_buffer.ClaimAcquireFence(), acquired_buffer.slot()); | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 219 | } else { | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 220 | return std::make_tuple(0, 0, -1, nullptr, pdx::LocalHandle{}, 0); | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 221 | } | 
|  | 222 | } | 
|  | 223 |  | 
|  | 224 | void Finish(pdx::LocalHandle fence) { release_fence = std::move(fence); } | 
|  | 225 |  | 
|  | 226 | // Gets a pointer to the current acquired buffer or returns nullptr if there | 
|  | 227 | // isn't one. | 
|  | 228 | IonBuffer* GetBuffer() { | 
|  | 229 | if (acquired_buffer.IsAvailable()) | 
|  | 230 | return acquired_buffer.buffer()->buffer(); | 
|  | 231 | else | 
|  | 232 | return nullptr; | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | // Returns the surface id of the surface. | 
| Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 236 | int GetSurfaceId() const { return surface->surface_id(); } | 
|  | 237 |  | 
|  | 238 | // Returns the buffer id for the current buffer. | 
|  | 239 | int GetBufferId() const { | 
|  | 240 | if (acquired_buffer.IsAvailable()) | 
|  | 241 | return acquired_buffer.buffer()->id(); | 
|  | 242 | else | 
|  | 243 | return -1; | 
|  | 244 | } | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 245 | }; | 
|  | 246 |  | 
|  | 247 | // State when the layer is connected to a buffer. Provides the same interface | 
|  | 248 | // as SourceSurface to simplify internal use by Layer. | 
|  | 249 | struct SourceBuffer { | 
|  | 250 | std::shared_ptr<IonBuffer> buffer; | 
|  | 251 |  | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 252 | std::tuple<int, int, int, sp<GraphicBuffer>, pdx::LocalHandle, std::size_t> | 
|  | 253 | Acquire() { | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 254 | if (buffer) | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 255 | return std::make_tuple(buffer->width(), buffer->height(), -1, | 
|  | 256 | buffer->buffer(), pdx::LocalHandle{}, 0); | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 257 | else | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 258 | return std::make_tuple(0, 0, -1, nullptr, pdx::LocalHandle{}, 0); | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 259 | } | 
|  | 260 |  | 
|  | 261 | void Finish(pdx::LocalHandle /*fence*/) {} | 
|  | 262 |  | 
|  | 263 | IonBuffer* GetBuffer() { return buffer.get(); } | 
|  | 264 |  | 
|  | 265 | int GetSurfaceId() const { return -1; } | 
| Corey Tabaka | 0b485c9 | 2017-05-19 12:02:58 -0700 | [diff] [blame] | 266 | int GetBufferId() const { return -1; } | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 267 | }; | 
|  | 268 |  | 
|  | 269 | // The underlying hardware composer layer is supplied buffers either from a | 
|  | 270 | // surface buffer train or from a buffer directly. | 
|  | 271 | pdx::rpc::Variant<SourceSurface, SourceBuffer> source_; | 
|  | 272 |  | 
|  | 273 | pdx::LocalHandle acquire_fence_; | 
|  | 274 | bool surface_rect_functions_applied_ = false; | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 275 | bool pending_visibility_settings_ = true; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 276 |  | 
| Corey Tabaka | 0d07cdd | 2017-09-28 11:15:50 -0700 | [diff] [blame] | 277 | // Map of buffer slot assignments that have already been established with HWC: | 
|  | 278 | // slot -> buffer_id. When this map contains a matching slot and buffer_id the | 
|  | 279 | // buffer argument to setLayerBuffer may be nullptr to avoid the cost of | 
|  | 280 | // importing a buffer HWC already knows about. | 
|  | 281 | std::map<std::size_t, int> cached_buffer_map_; | 
|  | 282 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 283 | // When calling destroyLayer() on an external display that's been removed we | 
|  | 284 | // typically get HWC2_ERROR_BAD_DISPLAY errors. If | 
|  | 285 | // ignore_bad_display_errors_on_destroy_ is true, don't log the bad display | 
|  | 286 | // errors, since they're expected. | 
|  | 287 | bool ignore_bad_display_errors_on_destroy_ = false; | 
|  | 288 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 289 | Layer(const Layer&) = delete; | 
|  | 290 | void operator=(const Layer&) = delete; | 
|  | 291 | }; | 
|  | 292 |  | 
|  | 293 | // HardwareComposer encapsulates the hardware composer HAL, exposing a | 
|  | 294 | // simplified API to post buffers to the display. | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 295 | // | 
|  | 296 | // HardwareComposer is accessed by both the vr flinger dispatcher thread and the | 
|  | 297 | // surface flinger main thread, in addition to internally running a separate | 
|  | 298 | // thread for compositing/EDS and posting layers to the HAL. When changing how | 
|  | 299 | // variables are used or adding new state think carefully about which threads | 
|  | 300 | // will access the state and whether it needs to be synchronized. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 301 | class HardwareComposer { | 
|  | 302 | public: | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 303 | using RequestDisplayCallback = std::function<void(bool)>; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 304 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 305 | HardwareComposer(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 306 | ~HardwareComposer(); | 
|  | 307 |  | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 308 | bool Initialize(Hwc2::Composer* composer, | 
| Steven Thomas | 6e8f706 | 2017-11-22 14:15:29 -0800 | [diff] [blame] | 309 | hwc2_display_t primary_display_id, | 
| Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 310 | RequestDisplayCallback request_display_callback); | 
| Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 311 |  | 
|  | 312 | bool IsInitialized() const { return initialized_; } | 
|  | 313 |  | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 314 | // Start the post thread if there's work to do (i.e. visible layers). This | 
|  | 315 | // should only be called from surface flinger's main thread. | 
|  | 316 | void Enable(); | 
|  | 317 | // Pause the post thread, blocking until the post thread has signaled that | 
|  | 318 | // it's paused. This should only be called from surface flinger's main thread. | 
|  | 319 | void Disable(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 320 |  | 
| Steven Thomas | af33627 | 2018-01-04 17:36:47 -0800 | [diff] [blame] | 321 | // Called on a binder thread. | 
|  | 322 | void OnBootFinished(); | 
|  | 323 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 324 | std::string Dump(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 325 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 326 | const DisplayParams& GetPrimaryDisplayParams() const { | 
|  | 327 | return primary_display_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 328 | } | 
|  | 329 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 330 | // Sets the display surfaces to compose the hardware layer stack. | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 331 | void SetDisplaySurfaces( | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 332 | std::vector<std::shared_ptr<DirectDisplaySurface>> surfaces); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 333 |  | 
| John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 334 | int OnNewGlobalBuffer(DvrGlobalBufferKey key, IonBuffer& ion_buffer); | 
|  | 335 | void OnDeletedGlobalBuffer(DvrGlobalBufferKey key); | 
|  | 336 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 337 | private: | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 338 | DisplayParams GetDisplayParams(Hwc2::Composer* composer, | 
|  | 339 | hwc2_display_t display, bool is_primary); | 
| Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 340 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 341 | // Turn display vsync on/off. Returns true on success, false on failure. | 
|  | 342 | bool EnableVsync(const DisplayParams& display, bool enabled); | 
|  | 343 | // Turn display power on/off. Returns true on success, false on failure. | 
|  | 344 | bool SetPowerMode(const DisplayParams& display, bool active); | 
|  | 345 | // Convenience function to turn a display on/off. Turns both power and vsync | 
|  | 346 | // on/off. Returns true on success, false on failure. | 
|  | 347 | bool EnableDisplay(const DisplayParams& display, bool enabled); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 348 |  | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 349 | class VsyncService : public BnVsyncService { | 
|  | 350 | public: | 
|  | 351 | status_t registerCallback(const sp<IVsyncCallback> callback) override; | 
|  | 352 | status_t unregisterCallback(const sp<IVsyncCallback> callback) override; | 
|  | 353 | void OnVsync(int64_t vsync_timestamp); | 
|  | 354 | private: | 
|  | 355 | std::vector<sp<IVsyncCallback>>::const_iterator FindCallback( | 
|  | 356 | const sp<IVsyncCallback>& callback) const; | 
|  | 357 | std::mutex mutex_; | 
|  | 358 | std::vector<sp<IVsyncCallback>> callbacks_; | 
|  | 359 | }; | 
|  | 360 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 361 | class ComposerCallback : public Hwc2::IComposerCallback { | 
|  | 362 | public: | 
| Corey Tabaka | b3732f0 | 2017-09-16 00:58:54 -0700 | [diff] [blame] | 363 | ComposerCallback() = default; | 
| Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 364 | hardware::Return<void> onHotplug(Hwc2::Display display, | 
|  | 365 | Connection conn) override; | 
|  | 366 | hardware::Return<void> onRefresh(Hwc2::Display display) override; | 
|  | 367 | hardware::Return<void> onVsync(Hwc2::Display display, | 
|  | 368 | int64_t timestamp) override; | 
| Corey Tabaka | b3732f0 | 2017-09-16 00:58:54 -0700 | [diff] [blame] | 369 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 370 | bool GotFirstHotplug() { return got_first_hotplug_; } | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 371 | void SetVsyncService(const sp<VsyncService>& vsync_service); | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 372 |  | 
|  | 373 | struct Displays { | 
|  | 374 | hwc2_display_t primary_display = 0; | 
|  | 375 | std::optional<hwc2_display_t> external_display; | 
|  | 376 | bool external_display_was_hotplugged = false; | 
|  | 377 | }; | 
|  | 378 |  | 
|  | 379 | Displays GetDisplays(); | 
|  | 380 | pdx::Status<int64_t> GetVsyncTime(hwc2_display_t display); | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 381 |  | 
| Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 382 | private: | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 383 | struct DisplayInfo { | 
|  | 384 | hwc2_display_t id = 0; | 
|  | 385 | pdx::LocalHandle driver_vsync_event_fd; | 
|  | 386 | int64_t callback_vsync_timestamp{0}; | 
|  | 387 | }; | 
|  | 388 |  | 
|  | 389 | DisplayInfo* GetDisplayInfo(hwc2_display_t display); | 
|  | 390 |  | 
|  | 391 | std::mutex mutex_; | 
|  | 392 |  | 
|  | 393 | bool got_first_hotplug_ = false; | 
|  | 394 | DisplayInfo primary_display_; | 
|  | 395 | std::optional<DisplayInfo> external_display_; | 
|  | 396 | bool external_display_was_hotplugged_ = false; | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 397 | sp<VsyncService> vsync_service_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 398 | }; | 
|  | 399 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 400 | HWC::Error Validate(hwc2_display_t display); | 
|  | 401 | HWC::Error Present(hwc2_display_t display); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 402 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 403 | void PostLayers(hwc2_display_t display); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 404 | void PostThread(); | 
|  | 405 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 406 | // The post thread has two controlling states: | 
|  | 407 | // 1. Idle: no work to do (no visible surfaces). | 
|  | 408 | // 2. Suspended: explicitly halted (system is not in VR mode). | 
|  | 409 | // When either #1 or #2 is true then the post thread is quiescent, otherwise | 
|  | 410 | // it is active. | 
|  | 411 | using PostThreadStateType = uint32_t; | 
|  | 412 | struct PostThreadState { | 
|  | 413 | enum : PostThreadStateType { | 
|  | 414 | Active = 0, | 
|  | 415 | Idle = (1 << 0), | 
|  | 416 | Suspended = (1 << 1), | 
|  | 417 | Quit = (1 << 2), | 
|  | 418 | }; | 
|  | 419 | }; | 
|  | 420 |  | 
|  | 421 | void UpdatePostThreadState(uint32_t state, bool suspend); | 
|  | 422 |  | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 423 | // Blocks until either event_fd becomes readable, or we're interrupted by a | 
| Steven Thomas | d7f49c5 | 2017-07-26 18:48:28 -0700 | [diff] [blame] | 424 | // control thread, or timeout_ms is reached before any events occur. Any | 
|  | 425 | // errors are returned as negative errno values, with -ETIMEDOUT returned in | 
|  | 426 | // the case of a timeout. If we're interrupted, kPostThreadInterrupted will be | 
|  | 427 | // returned. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 428 | int PostThreadPollInterruptible(const pdx::LocalHandle& event_fd, | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 429 | int requested_events, int timeout_ms); | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 430 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 431 | // WaitForPredictedVSync and SleepUntil are blocking calls made on the post | 
|  | 432 | // thread that can be interrupted by a control thread. If interrupted, these | 
|  | 433 | // calls return kPostThreadInterrupted. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 434 | int ReadWaitPPState(); | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 435 | pdx::Status<int64_t> WaitForPredictedVSync(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 436 | int SleepUntil(int64_t wakeup_timestamp); | 
|  | 437 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 438 | // Initialize any newly connected displays, and set target_display_ to the | 
|  | 439 | // display we should render to. Returns true if target_display_ | 
|  | 440 | // changed. Called only from the post thread. | 
|  | 441 | bool UpdateTargetDisplay(); | 
|  | 442 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 443 | // Reconfigures the layer stack if the display surfaces changed since the last | 
|  | 444 | // frame. Called only from the post thread. | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 445 | void UpdateLayerConfig(); | 
|  | 446 |  | 
|  | 447 | // Called on the post thread to create the Composer instance. | 
|  | 448 | void CreateComposer(); | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 449 |  | 
|  | 450 | // Called on the post thread when the post thread is resumed. | 
|  | 451 | void OnPostThreadResumed(); | 
|  | 452 | // Called on the post thread when the post thread is paused or quits. | 
|  | 453 | void OnPostThreadPaused(); | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 454 |  | 
| Steven Thomas | af33627 | 2018-01-04 17:36:47 -0800 | [diff] [blame] | 455 | // Use post_thread_wait_ to wait for a specific condition, specified by pred. | 
|  | 456 | // timeout_sec < 0 means wait indefinitely, otherwise it specifies the timeout | 
|  | 457 | // in seconds. | 
|  | 458 | // The lock must be held when this function is called. | 
|  | 459 | // Returns true if the wait was interrupted because the post thread was asked | 
|  | 460 | // to quit. | 
|  | 461 | bool PostThreadCondWait(std::unique_lock<std::mutex>& lock, | 
|  | 462 | int timeout_sec, | 
|  | 463 | const std::function<bool()>& pred); | 
|  | 464 |  | 
| John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 465 | // Map the given shared memory buffer to our broadcast ring to track updates | 
|  | 466 | // to the config parameters. | 
|  | 467 | int MapConfigBuffer(IonBuffer& ion_buffer); | 
|  | 468 | void ConfigBufferDeleted(); | 
|  | 469 | // Poll for config udpates. | 
|  | 470 | void UpdateConfigBuffer(); | 
|  | 471 |  | 
| Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 472 | bool initialized_; | 
| Corey Tabaka | 7024b8f | 2017-08-22 11:59:15 -0700 | [diff] [blame] | 473 | bool is_standalone_device_; | 
| Stephen Kiazyk | 016e5e3 | 2017-02-21 17:09:22 -0800 | [diff] [blame] | 474 |  | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 475 | std::unique_ptr<Hwc2::Composer> composer_; | 
|  | 476 | sp<ComposerCallback> composer_callback_; | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 477 | RequestDisplayCallback request_display_callback_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 478 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 479 | DisplayParams primary_display_; | 
|  | 480 | std::optional<DisplayParams> external_display_; | 
|  | 481 | DisplayParams* target_display_ = &primary_display_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 482 |  | 
| Steven Thomas | bfe46a0 | 2018-02-16 14:27:35 -0800 | [diff] [blame] | 483 | // The list of surfaces we should draw. Set by the display service when | 
|  | 484 | // DirectSurfaces are added, removed, or change visibility. Written by the | 
|  | 485 | // message dispatch thread and read by the post thread. | 
|  | 486 | std::vector<std::shared_ptr<DirectDisplaySurface>> surfaces_; | 
|  | 487 | // Set to true by the dispatch thread whenever surfaces_ changes. Set to false | 
|  | 488 | // by the post thread when the new list of surfaces is processed. | 
|  | 489 | bool surfaces_changed_ = false; | 
|  | 490 |  | 
|  | 491 | std::vector<std::shared_ptr<DirectDisplaySurface>> current_surfaces_; | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 492 |  | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 493 | // Layer set for handling buffer flow into hardware composer layers. This | 
|  | 494 | // vector must be sorted by surface_id in ascending order. | 
|  | 495 | std::vector<Layer> layers_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 496 |  | 
| Steven Thomas | 282a5ed | 2017-02-07 18:07:01 -0800 | [diff] [blame] | 497 | // The layer posting thread. This thread wakes up a short time before vsync to | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 498 | // hand buffers to hardware composer. | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 499 | std::thread post_thread_; | 
|  | 500 |  | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 501 | // Post thread state machine and synchronization primitives. | 
| Corey Tabaka | 2c4aea3 | 2017-08-31 20:01:15 -0700 | [diff] [blame] | 502 | PostThreadStateType post_thread_state_{PostThreadState::Idle | | 
|  | 503 | PostThreadState::Suspended}; | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 504 | std::atomic<bool> post_thread_quiescent_{true}; | 
|  | 505 | bool post_thread_resumed_{false}; | 
|  | 506 | pdx::LocalHandle post_thread_event_fd_; | 
|  | 507 | std::mutex post_thread_mutex_; | 
|  | 508 | std::condition_variable post_thread_wait_; | 
|  | 509 | std::condition_variable post_thread_ready_; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 510 |  | 
| Steven Thomas | af33627 | 2018-01-04 17:36:47 -0800 | [diff] [blame] | 511 | // When boot is finished this will be set to true and the post thread will be | 
|  | 512 | // notified via post_thread_wait_. | 
|  | 513 | bool boot_finished_ = false; | 
|  | 514 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 515 | // VSync sleep timerfd. | 
|  | 516 | pdx::LocalHandle vsync_sleep_timer_fd_; | 
|  | 517 |  | 
|  | 518 | // The timestamp of the last vsync. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 519 | int64_t last_vsync_timestamp_ = 0; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 520 |  | 
| Corey Tabaka | b3732f0 | 2017-09-16 00:58:54 -0700 | [diff] [blame] | 521 | // The number of vsync intervals to predict since the last vsync. | 
|  | 522 | int vsync_prediction_interval_ = 1; | 
|  | 523 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 524 | // Vsync count since display on. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 525 | uint32_t vsync_count_ = 0; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 526 |  | 
|  | 527 | // Counter tracking the number of skipped frames. | 
| Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 528 | int frame_skip_count_ = 0; | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 529 |  | 
|  | 530 | // Fd array for tracking retire fences that are returned by hwc. This allows | 
|  | 531 | // us to detect when the display driver begins queuing frames. | 
|  | 532 | std::vector<pdx::LocalHandle> retire_fence_fds_; | 
|  | 533 |  | 
| Okan Arikan | 822b710 | 2017-05-08 13:31:34 -0700 | [diff] [blame] | 534 | // If we are publishing vsync data, we will put it here. | 
|  | 535 | std::unique_ptr<CPUMappedBroadcastRing<DvrVsyncRing>> vsync_ring_; | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 536 |  | 
| John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 537 | // Broadcast ring for receiving config data from the DisplayManager. | 
| Okan Arikan | 6f468c6 | 2017-05-31 14:48:30 -0700 | [diff] [blame] | 538 | DvrConfigRing shared_config_ring_; | 
| John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 539 | uint32_t shared_config_ring_sequence_{0}; | 
|  | 540 | // Config buffer for reading from the post thread. | 
| Okan Arikan | 6f468c6 | 2017-05-31 14:48:30 -0700 | [diff] [blame] | 541 | DvrConfig post_thread_config_; | 
| John Bates | 954796e | 2017-05-11 11:00:31 -0700 | [diff] [blame] | 542 | std::mutex shared_config_mutex_; | 
|  | 543 |  | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 544 | bool vsync_trace_parity_ = false; | 
|  | 545 | sp<VsyncService> vsync_service_; | 
|  | 546 |  | 
| Steven Thomas | 050b2c8 | 2017-03-06 11:45:16 -0800 | [diff] [blame] | 547 | static constexpr int kPostThreadInterrupted = 1; | 
|  | 548 |  | 
| Alex Vakulenko | a8a9278 | 2017-01-27 14:41:57 -0800 | [diff] [blame] | 549 | HardwareComposer(const HardwareComposer&) = delete; | 
|  | 550 | void operator=(const HardwareComposer&) = delete; | 
|  | 551 | }; | 
|  | 552 |  | 
|  | 553 | }  // namespace dvr | 
|  | 554 | }  // namespace android | 
|  | 555 |  | 
|  | 556 | #endif  // ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_ |