blob: b207e4dd4483d364d7a5520b36ec0b64b2e4f50f [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:
Stephen Kiazyk016e5e32017-02-21 17:09:22 -080026 bool IsInitialized() const override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080027 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 int 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 int UpdateActiveDisplaySurfaces();
41
42 template <class A>
43 void ForEachDisplaySurface(A action) const {
44 ForEachChannel([action](const ChannelIterator::value_type& pair) mutable {
45 auto surface = std::static_pointer_cast<SurfaceChannel>(pair.second);
46 if (surface->type() == SurfaceTypeEnum::Normal)
47 action(std::static_pointer_cast<DisplaySurface>(surface));
48 });
49 }
50
51 using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
52 void SetDisplayConfigurationUpdateNotifier(
53 DisplayConfigurationUpdateNotifier notifier);
54
55 using VSyncCallback = HardwareComposer::VSyncCallback;
56 void SetVSyncCallback(VSyncCallback callback) {
57 hardware_composer_.SetVSyncCallback(callback);
58 }
59
60 HWCDisplayMetrics GetDisplayMetrics() {
61 return hardware_composer_.display_metrics();
62 }
63
64 void SetActive(bool activated) {
65 if (activated) {
66 hardware_composer_.Resume();
67 } else {
68 hardware_composer_.Suspend();
69 }
70 }
71
Steven Thomas3cfac282017-02-06 12:29:30 -080072 void OnHardwareComposerRefresh();
73
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080074 private:
75 friend BASE;
76 friend DisplaySurface;
77
78 friend class VrDisplayStateService;
79
80 DisplayService();
81 DisplayService(android::Hwc2::Composer* hidl);
82
83 SystemDisplayMetrics OnGetMetrics(pdx::Message& message);
84 int OnCreateSurface(pdx::Message& message, int width, int height,
85 int format, int usage, DisplaySurfaceFlags flags);
86
87 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message);
88
89 int OnEnterVrMode(pdx::Message& message);
90 int OnExitVrMode(pdx::Message& message);
91 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params);
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 EpollEventDispatcher dispatcher_;
103 HardwareComposer hardware_composer_;
104 DisplayConfigurationUpdateNotifier update_notifier_;
105};
106
107} // namespace dvr
108} // namespace android
109
110#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_