blob: ebd97de2fa7e76126ac7190e4773ba32823603d1 [file] [log] [blame]
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08001#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 "epoll_event_dispatcher.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 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 int UpdateActiveDisplaySurfaces();
40
41 template <class A>
42 void ForEachDisplaySurface(A action) const {
43 ForEachChannel([action](const ChannelIterator::value_type& pair) mutable {
44 auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second);
45 if (surface->type() == SurfaceTypeEnum::Normal)
46 action(std::static_pointer_cast<DisplaySurface>(surface));
47 });
48 }
49
50 using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
51 void SetDisplayConfigurationUpdateNotifier(
52 DisplayConfigurationUpdateNotifier notifier);
53
54 using VSyncCallback = HardwareComposer::VSyncCallback;
55 void SetVSyncCallback(VSyncCallback callback) {
56 hardware_composer_.SetVSyncCallback(callback);
57 }
58
59 HWCDisplayMetrics GetDisplayMetrics() {
60 return hardware_composer_.display_metrics();
61 }
62
63 void SetActive(bool activated) {
64 if (activated) {
65 hardware_composer_.Resume();
66 } else {
67 hardware_composer_.Suspend();
68 }
69 }
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,
82 int format, int usage, DisplaySurfaceFlags flags);
83
84 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message);
85
86 int OnEnterVrMode(pdx::Message& message);
87 int OnExitVrMode(pdx::Message& message);
88 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params);
89
90 // Called by DisplaySurface to signal that a surface property has changed and
91 // the display manager should be notified.
92 void NotifyDisplayConfigurationUpdate();
93
94 int HandleSurfaceMessage(pdx::Message& message);
95
96 DisplayService(const DisplayService&) = delete;
97 void operator=(const DisplayService&) = delete;
98
99 EpollEventDispatcher dispatcher_;
100 HardwareComposer hardware_composer_;
101 DisplayConfigurationUpdateNotifier update_notifier_;
102};
103
104} // namespace dvr
105} // namespace android
106
107#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_