blob: 9d116c1440e2b61b857d30e9e5b4868e68954e7b [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"
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080017#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:
Stephen Kiazyk016e5e32017-02-21 17:09:22 -080025 bool IsInitialized() const override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080026 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.
Jin Qian7480c062017-03-21 00:04:15 +000039 int UpdateActiveDisplaySurfaces();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080040
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
Jin Qian7480c062017-03-21 00:04:15 +000063 void SetActive(bool activated) {
64 if (activated) {
65 hardware_composer_.Resume();
66 } else {
67 hardware_composer_.Suspend();
68 }
69 }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080070
Steven Thomas3cfac282017-02-06 12:29:30 -080071 void OnHardwareComposerRefresh();
72
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080073 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,
84 int format, int usage, DisplaySurfaceFlags flags);
85
86 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message);
87
Jin Qian7480c062017-03-21 00:04:15 +000088 int OnEnterVrMode(pdx::Message& message);
89 int OnExitVrMode(pdx::Message& message);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080090 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params);
91
92 // Called by DisplaySurface to signal that a surface property has changed and
93 // the display manager should be notified.
94 void NotifyDisplayConfigurationUpdate();
95
96 int HandleSurfaceMessage(pdx::Message& message);
97
98 DisplayService(const DisplayService&) = delete;
99 void operator=(const DisplayService&) = delete;
100
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800101 HardwareComposer hardware_composer_;
102 DisplayConfigurationUpdateNotifier update_notifier_;
103};
104
105} // namespace dvr
106} // namespace android
107
108#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_