display_service.h revision b7c8a4bd8131ce18fb4ab4ee986c3b6b1ed27ad5
1#ifndef ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_
2#define ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_
3
4#include <pdx/service.h>
5#include <private/dvr/buffer_hub_client.h>
6#include <private/dvr/display_rpc.h>
7#include <private/dvr/late_latch.h>
8
9#include <functional>
10#include <iterator>
11#include <memory>
12#include <string>
13#include <vector>
14
15#include "acquired_buffer.h"
16#include "display_surface.h"
17#include "hardware_composer.h"
18
19namespace android {
20namespace dvr {
21
22// DisplayService implements the displayd display service over ServiceFS.
23class DisplayService : public pdx::ServiceBase<DisplayService> {
24 public:
25  bool IsInitialized() const override;
26  std::string DumpState(size_t max_length) override;
27
28  void OnChannelClose(pdx::Message& message,
29                      const std::shared_ptr<pdx::Channel>& channel) override;
30  int HandleMessage(pdx::Message& message) override;
31
32  std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
33  std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
34  std::vector<std::shared_ptr<DisplaySurface>> GetVisibleDisplaySurfaces()
35      const;
36
37  // Updates the list of actively displayed surfaces. This must be called after
38  // any change to client/manager attributes that affect visibility or z order.
39  void UpdateActiveDisplaySurfaces();
40
41  pdx::BorrowedChannelHandle SetupPoseBuffer(size_t extended_region_size,
42                                             int usage);
43
44  template <class A>
45  void ForEachDisplaySurface(A action) const {
46    ForEachChannel([action](const ChannelIterator::value_type& pair) mutable {
47      auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second);
48      if (surface->type() == SurfaceTypeEnum::Normal)
49        action(std::static_pointer_cast<DisplaySurface>(surface));
50    });
51  }
52
53  using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
54  void SetDisplayConfigurationUpdateNotifier(
55      DisplayConfigurationUpdateNotifier notifier);
56
57  using VSyncCallback = HardwareComposer::VSyncCallback;
58  void SetVSyncCallback(VSyncCallback callback) {
59    hardware_composer_.SetVSyncCallback(callback);
60  }
61
62  HWCDisplayMetrics GetDisplayMetrics() {
63    return hardware_composer_.display_metrics();
64  }
65
66  void GrantDisplayOwnership() { hardware_composer_.Enable(); }
67  void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
68
69  void OnHardwareComposerRefresh();
70
71 private:
72  friend BASE;
73  friend DisplaySurface;
74
75  friend class VrDisplayStateService;
76
77  DisplayService();
78  DisplayService(android::Hwc2::Composer* hidl);
79
80  SystemDisplayMetrics OnGetMetrics(pdx::Message& message);
81  int OnCreateSurface(pdx::Message& message, int width, int height, int format,
82                      int usage, DisplaySurfaceFlags flags);
83
84  DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message);
85
86  void OnSetViewerParams(pdx::Message& message,
87                         const ViewerParams& view_params);
88  pdx::LocalChannelHandle OnGetPoseBuffer(pdx::Message& message);
89
90  // Temporary query for current VR status. Will be removed later.
91  int IsVrAppRunning(pdx::Message& message);
92
93  // Called by DisplaySurface to signal that a surface property has changed and
94  // the display manager should be notified.
95  void NotifyDisplayConfigurationUpdate();
96
97  int HandleSurfaceMessage(pdx::Message& message);
98
99  DisplayService(const DisplayService&) = delete;
100  void operator=(const DisplayService&) = delete;
101
102  HardwareComposer hardware_composer_;
103  DisplayConfigurationUpdateNotifier update_notifier_;
104
105  std::unique_ptr<BufferProducer> pose_buffer_;
106};
107
108}  // namespace dvr
109}  // namespace android
110
111#endif  // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_
112