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