blob: c93488aee0808d37dbcaa0fd250a38ddb3a6d7b8 [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.
Steven Thomasf43d13e2017-03-06 11:45:16 -080039 void 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
Steven Thomasf43d13e2017-03-06 11:45:16 -080063 void GrantDisplayOwnership() { hardware_composer_.Enable(); }
64 void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080065
Steven Thomas3cfac282017-02-06 12:29:30 -080066 void OnHardwareComposerRefresh();
67
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080068 private:
69 friend BASE;
70 friend DisplaySurface;
71
72 friend class VrDisplayStateService;
73
74 DisplayService();
75 DisplayService(android::Hwc2::Composer* hidl);
76
77 SystemDisplayMetrics OnGetMetrics(pdx::Message& message);
78 int OnCreateSurface(pdx::Message& message, int width, int height,
79 int format, int usage, DisplaySurfaceFlags flags);
80
81 DisplayRPC::ByteBuffer OnGetEdsCapture(pdx::Message& message);
82
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080083 void OnSetViewerParams(pdx::Message& message, const ViewerParams& view_params);
84
85 // Called by DisplaySurface to signal that a surface property has changed and
86 // the display manager should be notified.
87 void NotifyDisplayConfigurationUpdate();
88
89 int HandleSurfaceMessage(pdx::Message& message);
90
91 DisplayService(const DisplayService&) = delete;
92 void operator=(const DisplayService&) = delete;
93
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080094 HardwareComposer hardware_composer_;
95 DisplayConfigurationUpdateNotifier update_notifier_;
96};
97
98} // namespace dvr
99} // namespace android
100
101#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_