blob: 98e8905fff3314fefa4d6817a5b38218a28b4b28 [file] [log] [blame]
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08001#ifndef ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_
2#define ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_
3
Corey Tabaka2251d822017-04-20 16:04:07 -07004#include <ui/GraphicBuffer.h>
5#include "DisplayHardware/ComposerHal.h"
6#include "hwc_types.h"
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08007
Okan Arikan822b7102017-05-08 13:31:34 -07008#include <dvr/dvr_shared_buffers.h>
Corey Tabaka2251d822017-04-20 16:04:07 -07009#include <hardware/gralloc.h>
10#include <log/log.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080011
12#include <array>
13#include <condition_variable>
14#include <memory>
15#include <mutex>
16#include <thread>
17#include <tuple>
18#include <vector>
19
Okan Arikan6f468c62017-05-31 14:48:30 -070020#include <dvr/dvr_config.h>
Okan Arikan822b7102017-05-08 13:31:34 -070021#include <dvr/dvr_vsync.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080022#include <pdx/file_handle.h>
Corey Tabaka2251d822017-04-20 16:04:07 -070023#include <pdx/rpc/variant.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080024#include <private/dvr/buffer_hub_client.h>
Okan Arikan822b7102017-05-08 13:31:34 -070025#include <private/dvr/shared_buffer_helpers.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080026
27#include "acquired_buffer.h"
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080028#include "display_surface.h"
29
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080030// Hardware composer HAL doesn't define HWC_TRANSFORM_NONE as of this writing.
31#ifndef HWC_TRANSFORM_NONE
32#define HWC_TRANSFORM_NONE static_cast<hwc_transform_t>(0)
33#endif
34
35namespace android {
36namespace dvr {
37
38// Basic display metrics for physical displays. Dimensions and densities are
39// relative to the physical display orientation, which may be different from the
40// logical display orientation exposed to applications.
41struct HWCDisplayMetrics {
42 int width;
43 int height;
44 struct {
45 int x;
46 int y;
47 } dpi;
48 int vsync_period_ns;
49};
50
51// Layer represents the connection between a hardware composer layer and the
52// source supplying buffers for the layer's contents.
53class Layer {
54 public:
Corey Tabaka2251d822017-04-20 16:04:07 -070055 Layer() {}
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080056
Corey Tabaka2251d822017-04-20 16:04:07 -070057 // Sets up the global state used by all Layer instances. This must be called
58 // before using any Layer methods.
59 static void InitializeGlobals(Hwc2::Composer* hwc2_hidl,
60 const HWCDisplayMetrics* metrics);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080061
62 // Releases any shared pointers and fence handles held by this instance.
63 void Reset();
64
65 // Sets up the layer to use a display surface as its content source. The Layer
Corey Tabaka2251d822017-04-20 16:04:07 -070066 // automatically handles ACQUIRE/RELEASE phases for the surface's buffer train
67 // every frame.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080068 //
69 // |blending| receives HWC_BLENDING_* values.
70 // |transform| receives HWC_TRANSFORM_* values.
71 // |composition_type| receives either HWC_FRAMEBUFFER for most layers or
72 // HWC_FRAMEBUFFER_TARGET (unless you know what you are doing).
Corey Tabaka2251d822017-04-20 16:04:07 -070073 // |index| is the index of this surface in the DirectDisplaySurface array.
74 void Setup(const std::shared_ptr<DirectDisplaySurface>& surface,
75 HWC::BlendMode blending, HWC::Transform transform,
76 HWC::Composition composition_type, size_t z_roder);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080077
78 // Sets up the layer to use a direct buffer as its content source. No special
79 // handling of the buffer is performed; responsibility for updating or
80 // changing the buffer each frame is on the caller.
81 //
82 // |blending| receives HWC_BLENDING_* values.
83 // |transform| receives HWC_TRANSFORM_* values.
84 // |composition_type| receives either HWC_FRAMEBUFFER for most layers or
85 // HWC_FRAMEBUFFER_TARGET (unless you know what you are doing).
Corey Tabaka2251d822017-04-20 16:04:07 -070086 void Setup(const std::shared_ptr<IonBuffer>& buffer, HWC::BlendMode blending,
87 HWC::Transform transform, HWC::Composition composition_type,
88 size_t z_order);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080089
90 // Layers that use a direct IonBuffer should call this each frame to update
91 // which buffer will be used for the next PostLayers.
Corey Tabaka2251d822017-04-20 16:04:07 -070092 void UpdateBuffer(const std::shared_ptr<IonBuffer>& buffer);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080093
94 // Sets up the hardware composer layer for the next frame. When the layer is
95 // associated with a display surface, this method automatically ACQUIRES a new
96 // buffer if one is available.
97 void Prepare();
98
99 // After calling prepare, if this frame is to be dropped instead of passing
100 // along to the HWC, call Drop to close the contained fence(s).
101 void Drop();
102
103 // Performs fence bookkeeping after the frame has been posted to hardware
104 // composer.
105 void Finish(int release_fence_fd);
106
107 // Sets the blending for the layer. |blending| receives HWC_BLENDING_* values.
Corey Tabaka2251d822017-04-20 16:04:07 -0700108 void SetBlending(HWC::BlendMode blending);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800109
Corey Tabaka2251d822017-04-20 16:04:07 -0700110 // Sets the z-order of this layer
111 void SetZOrder(size_t z_order);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800112
113 // Gets the current IonBuffer associated with this layer. Ownership of the
114 // buffer DOES NOT pass to the caller and the pointer is not guaranteed to
115 // remain valid across calls to Layer::Setup(), Layer::Prepare(), or
116 // Layer::Reset(). YOU HAVE BEEN WARNED.
117 IonBuffer* GetBuffer();
118
Corey Tabaka2251d822017-04-20 16:04:07 -0700119 HWC::Composition GetCompositionType() const { return composition_type_; }
120 HWC::Layer GetLayerHandle() const { return hardware_composer_layer_; }
121 bool IsLayerSetup() const { return !source_.empty(); }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800122
123 // Applies all of the settings to this layer using the hwc functions
124 void UpdateLayerSettings();
125
126 int GetSurfaceId() const {
Corey Tabaka2251d822017-04-20 16:04:07 -0700127 int surface_id = -1;
128 pdx::rpc::IfAnyOf<SourceSurface>::Call(
129 &source_, [&surface_id](const SourceSurface& surface_source) {
130 surface_id = surface_source.surface->surface_id();
131 });
132 return surface_id;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800133 }
134
135 private:
136 void CommonLayerSetup();
137
Corey Tabaka2251d822017-04-20 16:04:07 -0700138 static Hwc2::Composer* hwc2_hidl_;
139 static const HWCDisplayMetrics* display_metrics_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800140
141 // The hardware composer layer and metrics to use during the prepare cycle.
Corey Tabaka2251d822017-04-20 16:04:07 -0700142 hwc2_layer_t hardware_composer_layer_ = 0;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800143
144 // Layer properties used to setup the hardware composer layer during the
145 // Prepare phase.
Corey Tabaka2251d822017-04-20 16:04:07 -0700146 size_t z_order_ = 0;
147 HWC::BlendMode blending_ = HWC::BlendMode::None;
148 HWC::Transform transform_ = HWC::Transform::None;
149 HWC::Composition composition_type_ = HWC::Composition::Invalid;
150 HWC::Composition target_composition_type_ = HWC::Composition::Device;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800151
Corey Tabaka2251d822017-04-20 16:04:07 -0700152 // State when the layer is connected to a surface. Provides the same interface
153 // as SourceBuffer to simplify internal use by Layer.
154 struct SourceSurface {
155 std::shared_ptr<DirectDisplaySurface> surface;
156 AcquiredBuffer acquired_buffer;
157 pdx::LocalHandle release_fence;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800158
Corey Tabaka2251d822017-04-20 16:04:07 -0700159 SourceSurface(const std::shared_ptr<DirectDisplaySurface>& surface)
160 : surface(surface) {}
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800161
Corey Tabaka2251d822017-04-20 16:04:07 -0700162 // Attempts to acquire a new buffer from the surface and return a tuple with
163 // width, height, buffer handle, and fence. If a new buffer is not available
164 // the previous buffer is returned or an empty value if no buffer has ever
165 // been posted. When a new buffer is acquired the previous buffer's release
166 // fence is passed out automatically.
167 std::tuple<int, int, sp<GraphicBuffer>, pdx::LocalHandle> Acquire() {
168 if (surface->IsBufferAvailable()) {
169 acquired_buffer.Release(std::move(release_fence));
170 acquired_buffer = surface->AcquireCurrentBuffer();
171 ATRACE_ASYNC_END("BufferPost", acquired_buffer.buffer()->id());
172 }
173 if (!acquired_buffer.IsEmpty()) {
174 return std::make_tuple(acquired_buffer.buffer()->width(),
175 acquired_buffer.buffer()->height(),
176 acquired_buffer.buffer()->buffer()->buffer(),
177 acquired_buffer.ClaimAcquireFence());
178 } else {
179 return std::make_tuple(0, 0, nullptr, pdx::LocalHandle{});
180 }
181 }
182
183 void Finish(pdx::LocalHandle fence) { release_fence = std::move(fence); }
184
185 // Gets a pointer to the current acquired buffer or returns nullptr if there
186 // isn't one.
187 IonBuffer* GetBuffer() {
188 if (acquired_buffer.IsAvailable())
189 return acquired_buffer.buffer()->buffer();
190 else
191 return nullptr;
192 }
193
194 // Returns the surface id of the surface.
195 int GetSurfaceId() { return surface->surface_id(); }
196 };
197
198 // State when the layer is connected to a buffer. Provides the same interface
199 // as SourceSurface to simplify internal use by Layer.
200 struct SourceBuffer {
201 std::shared_ptr<IonBuffer> buffer;
202
203 std::tuple<int, int, sp<GraphicBuffer>, pdx::LocalHandle> Acquire() {
204 if (buffer)
205 return std::make_tuple(buffer->width(), buffer->height(),
206 buffer->buffer(), pdx::LocalHandle{});
207 else
208 return std::make_tuple(0, 0, nullptr, pdx::LocalHandle{});
209 }
210
211 void Finish(pdx::LocalHandle /*fence*/) {}
212
213 IonBuffer* GetBuffer() { return buffer.get(); }
214
215 int GetSurfaceId() const { return -1; }
216 };
217
218 // The underlying hardware composer layer is supplied buffers either from a
219 // surface buffer train or from a buffer directly.
220 pdx::rpc::Variant<SourceSurface, SourceBuffer> source_;
221
222 pdx::LocalHandle acquire_fence_;
223 bool surface_rect_functions_applied_ = false;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800224
225 Layer(const Layer&) = delete;
226 void operator=(const Layer&) = delete;
227};
228
229// HardwareComposer encapsulates the hardware composer HAL, exposing a
230// simplified API to post buffers to the display.
Steven Thomas050b2c82017-03-06 11:45:16 -0800231//
232// HardwareComposer is accessed by both the vr flinger dispatcher thread and the
233// surface flinger main thread, in addition to internally running a separate
234// thread for compositing/EDS and posting layers to the HAL. When changing how
235// variables are used or adding new state think carefully about which threads
236// will access the state and whether it needs to be synchronized.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800237class HardwareComposer {
238 public:
239 // Type for vsync callback.
240 using VSyncCallback = std::function<void(int, int64_t, int64_t, uint32_t)>;
Corey Tabaka2251d822017-04-20 16:04:07 -0700241 using RequestDisplayCallback = std::function<void(bool)>;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800242
243 // Since there is no universal way to query the number of hardware layers,
244 // just set it to 4 for now.
Corey Tabaka2251d822017-04-20 16:04:07 -0700245 static constexpr size_t kMaxHardwareLayers = 4;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800246
247 HardwareComposer();
Corey Tabaka2251d822017-04-20 16:04:07 -0700248 HardwareComposer(Hwc2::Composer* hidl,
249 RequestDisplayCallback request_display_callback);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800250 ~HardwareComposer();
251
Stephen Kiazyk016e5e32017-02-21 17:09:22 -0800252 bool Initialize();
253
254 bool IsInitialized() const { return initialized_; }
255
Steven Thomas050b2c82017-03-06 11:45:16 -0800256 // Start the post thread if there's work to do (i.e. visible layers). This
257 // should only be called from surface flinger's main thread.
258 void Enable();
259 // Pause the post thread, blocking until the post thread has signaled that
260 // it's paused. This should only be called from surface flinger's main thread.
261 void Disable();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800262
263 // Get the HMD display metrics for the current display.
Corey Tabaka2251d822017-04-20 16:04:07 -0700264 display::Metrics GetHmdDisplayMetrics() const;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800265
Corey Tabaka2251d822017-04-20 16:04:07 -0700266 HWC::Error GetDisplayAttribute(hwc2_display_t display, hwc2_config_t config,
267 hwc2_attribute_t attributes,
268 int32_t* out_value) const;
269 HWC::Error GetDisplayMetrics(hwc2_display_t display, hwc2_config_t config,
270 HWCDisplayMetrics* out_metrics) const;
271 std::string Dump();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800272
273 void SetVSyncCallback(VSyncCallback callback);
274
275 // Metrics of the logical display, which is always landscape.
276 int DisplayWidth() const { return display_metrics_.width; }
277 int DisplayHeight() const { return display_metrics_.height; }
278 HWCDisplayMetrics display_metrics() const { return display_metrics_; }
279
280 // Metrics of the native display, which depends on the specific hardware
281 // implementation of the display.
282 HWCDisplayMetrics native_display_metrics() const {
283 return native_display_metrics_;
284 }
285
Corey Tabaka2251d822017-04-20 16:04:07 -0700286 // Sets the display surfaces to compose the hardware layer stack.
Steven Thomas050b2c82017-03-06 11:45:16 -0800287 void SetDisplaySurfaces(
Corey Tabaka2251d822017-04-20 16:04:07 -0700288 std::vector<std::shared_ptr<DirectDisplaySurface>> surfaces);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800289
John Bates954796e2017-05-11 11:00:31 -0700290 int OnNewGlobalBuffer(DvrGlobalBufferKey key, IonBuffer& ion_buffer);
291 void OnDeletedGlobalBuffer(DvrGlobalBufferKey key);
292
Steven Thomas3cfac282017-02-06 12:29:30 -0800293 void OnHardwareComposerRefresh();
294
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800295 private:
296 int32_t EnableVsync(bool enabled);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800297
298 class ComposerCallback : public Hwc2::IComposerCallback {
299 public:
300 ComposerCallback() {}
301
302 hardware::Return<void> onHotplug(Hwc2::Display /*display*/,
303 Connection /*connected*/) override {
304 // TODO(skiazyk): depending on how the server is implemented, we might
305 // have to set it up to synchronize with receiving this event, as it can
306 // potentially be a critical event for setting up state within the
307 // hwc2 module. That is, we (technically) should not call any other hwc
308 // methods until this method has been called after registering the
309 // callbacks.
310 return hardware::Void();
311 }
312
313 hardware::Return<void> onRefresh(Hwc2::Display /*display*/) override {
314 return hardware::Void();
315 }
316
317 hardware::Return<void> onVsync(Hwc2::Display /*display*/,
318 int64_t /*timestamp*/) override {
319 return hardware::Void();
320 }
321 };
322
Corey Tabaka2251d822017-04-20 16:04:07 -0700323 HWC::Error Validate(hwc2_display_t display);
324 HWC::Error Present(hwc2_display_t display);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800325
326 void SetBacklightBrightness(int brightness);
327
Corey Tabaka2251d822017-04-20 16:04:07 -0700328 void PostLayers();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800329 void PostThread();
330
Corey Tabaka2251d822017-04-20 16:04:07 -0700331 // The post thread has two controlling states:
332 // 1. Idle: no work to do (no visible surfaces).
333 // 2. Suspended: explicitly halted (system is not in VR mode).
334 // When either #1 or #2 is true then the post thread is quiescent, otherwise
335 // it is active.
336 using PostThreadStateType = uint32_t;
337 struct PostThreadState {
338 enum : PostThreadStateType {
339 Active = 0,
340 Idle = (1 << 0),
341 Suspended = (1 << 1),
342 Quit = (1 << 2),
343 };
344 };
345
346 void UpdatePostThreadState(uint32_t state, bool suspend);
347
Steven Thomas050b2c82017-03-06 11:45:16 -0800348 // Blocks until either event_fd becomes readable, or we're interrupted by a
349 // control thread. Any errors are returned as negative errno values. If we're
350 // interrupted, kPostThreadInterrupted will be returned.
Corey Tabaka2251d822017-04-20 16:04:07 -0700351 int PostThreadPollInterruptible(const pdx::LocalHandle& event_fd,
352 int requested_events);
Steven Thomas050b2c82017-03-06 11:45:16 -0800353
354 // BlockUntilVSync, WaitForVSync, and SleepUntil are all blocking calls made
355 // on the post thread that can be interrupted by a control thread. If
356 // interrupted, these calls return kPostThreadInterrupted.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800357 int ReadWaitPPState();
Steven Thomas050b2c82017-03-06 11:45:16 -0800358 int BlockUntilVSync();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800359 int ReadVSyncTimestamp(int64_t* timestamp);
360 int WaitForVSync(int64_t* timestamp);
361 int SleepUntil(int64_t wakeup_timestamp);
362
363 bool IsFramePendingInDriver() { return ReadWaitPPState() == 1; }
364
Corey Tabaka2251d822017-04-20 16:04:07 -0700365 // Reconfigures the layer stack if the display surfaces changed since the last
366 // frame. Called only from the post thread.
Steven Thomas050b2c82017-03-06 11:45:16 -0800367 bool UpdateLayerConfig();
Steven Thomas050b2c82017-03-06 11:45:16 -0800368
369 // Called on the post thread when the post thread is resumed.
370 void OnPostThreadResumed();
371 // Called on the post thread when the post thread is paused or quits.
372 void OnPostThreadPaused();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800373
John Bates954796e2017-05-11 11:00:31 -0700374 // Map the given shared memory buffer to our broadcast ring to track updates
375 // to the config parameters.
376 int MapConfigBuffer(IonBuffer& ion_buffer);
377 void ConfigBufferDeleted();
378 // Poll for config udpates.
379 void UpdateConfigBuffer();
380
Stephen Kiazyk016e5e32017-02-21 17:09:22 -0800381 bool initialized_;
382
Corey Tabaka2251d822017-04-20 16:04:07 -0700383 // Hardware composer HAL device from SurfaceFlinger. VrFlinger does not own
384 // this pointer.
385 Hwc2::Composer* hwc2_hidl_;
386 RequestDisplayCallback request_display_callback_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800387 sp<ComposerCallback> callbacks_;
388
389 // Display metrics of the physical display.
390 HWCDisplayMetrics native_display_metrics_;
391 // Display metrics of the logical display, adjusted so that orientation is
392 // landscape.
393 HWCDisplayMetrics display_metrics_;
394 // Transform required to get from native to logical display orientation.
Corey Tabaka2251d822017-04-20 16:04:07 -0700395 HWC::Transform display_transform_ = HWC::Transform::None;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800396
Corey Tabaka2251d822017-04-20 16:04:07 -0700397 // Pending surface list. Set by the display service when DirectSurfaces are
398 // added, removed, or change visibility. Written by the message dispatch
399 // thread and read by the post thread.
400 std::vector<std::shared_ptr<DirectDisplaySurface>> pending_surfaces_;
Steven Thomas050b2c82017-03-06 11:45:16 -0800401
402 // The surfaces displayed by the post thread. Used exclusively by the post
403 // thread.
Corey Tabaka2251d822017-04-20 16:04:07 -0700404 std::vector<std::shared_ptr<DirectDisplaySurface>> display_surfaces_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800405
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800406 // Layer array for handling buffer flow into hardware composer layers.
Corey Tabaka2251d822017-04-20 16:04:07 -0700407 std::array<Layer, kMaxHardwareLayers> layers_;
408 size_t active_layer_count_ = 0;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800409
410 // Handler to hook vsync events outside of this class.
411 VSyncCallback vsync_callback_;
412
Steven Thomas282a5ed2017-02-07 18:07:01 -0800413 // The layer posting thread. This thread wakes up a short time before vsync to
Corey Tabaka2251d822017-04-20 16:04:07 -0700414 // hand buffers to hardware composer.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800415 std::thread post_thread_;
416
Corey Tabaka2251d822017-04-20 16:04:07 -0700417 // Post thread state machine and synchronization primitives.
418 PostThreadStateType post_thread_state_{PostThreadState::Idle};
419 std::atomic<bool> post_thread_quiescent_{true};
420 bool post_thread_resumed_{false};
421 pdx::LocalHandle post_thread_event_fd_;
422 std::mutex post_thread_mutex_;
423 std::condition_variable post_thread_wait_;
424 std::condition_variable post_thread_ready_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800425
426 // Backlight LED brightness sysfs node.
427 pdx::LocalHandle backlight_brightness_fd_;
428
429 // Primary display vsync event sysfs node.
430 pdx::LocalHandle primary_display_vsync_event_fd_;
431
432 // Primary display wait_pingpong state sysfs node.
433 pdx::LocalHandle primary_display_wait_pp_fd_;
434
435 // VSync sleep timerfd.
436 pdx::LocalHandle vsync_sleep_timer_fd_;
437
438 // The timestamp of the last vsync.
Corey Tabaka2251d822017-04-20 16:04:07 -0700439 int64_t last_vsync_timestamp_ = 0;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800440
441 // Vsync count since display on.
Corey Tabaka2251d822017-04-20 16:04:07 -0700442 uint32_t vsync_count_ = 0;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800443
444 // Counter tracking the number of skipped frames.
Corey Tabaka2251d822017-04-20 16:04:07 -0700445 int frame_skip_count_ = 0;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800446
447 // Fd array for tracking retire fences that are returned by hwc. This allows
448 // us to detect when the display driver begins queuing frames.
449 std::vector<pdx::LocalHandle> retire_fence_fds_;
450
Okan Arikan822b7102017-05-08 13:31:34 -0700451 // If we are publishing vsync data, we will put it here.
452 std::unique_ptr<CPUMappedBroadcastRing<DvrVsyncRing>> vsync_ring_;
Steven Thomas050b2c82017-03-06 11:45:16 -0800453
John Bates954796e2017-05-11 11:00:31 -0700454 // Broadcast ring for receiving config data from the DisplayManager.
Okan Arikan6f468c62017-05-31 14:48:30 -0700455 DvrConfigRing shared_config_ring_;
John Bates954796e2017-05-11 11:00:31 -0700456 uint32_t shared_config_ring_sequence_{0};
457 // Config buffer for reading from the post thread.
Okan Arikan6f468c62017-05-31 14:48:30 -0700458 DvrConfig post_thread_config_;
John Bates954796e2017-05-11 11:00:31 -0700459 std::mutex shared_config_mutex_;
460
Steven Thomas050b2c82017-03-06 11:45:16 -0800461 static constexpr int kPostThreadInterrupted = 1;
462
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800463 static void HwcRefresh(hwc2_callback_data_t data, hwc2_display_t display);
464 static void HwcVSync(hwc2_callback_data_t data, hwc2_display_t display,
465 int64_t timestamp);
466 static void HwcHotplug(hwc2_callback_data_t callbackData,
467 hwc2_display_t display, hwc2_connection_t connected);
468
469 HardwareComposer(const HardwareComposer&) = delete;
470 void operator=(const HardwareComposer&) = delete;
471};
472
473} // namespace dvr
474} // namespace android
475
476#endif // ANDROID_DVR_SERVICES_DISPLAYD_HARDWARE_COMPOSER_H_