blob: 3090bd1e7a950a72378134702f2cca043ad58150 [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
Okan Arikan36d23802017-05-15 15:20:39 -07004#include <dvr/dvr_api.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08005#include <pdx/service.h>
Corey Tabaka2251d822017-04-20 16:04:07 -07006#include <pdx/status.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08007#include <private/dvr/buffer_hub_client.h>
Hendrik Wagenaareaa55222017-04-06 10:56:23 -07008#include <private/dvr/bufferhub_rpc.h>
Corey Tabaka3f82d312017-04-20 14:42:08 -07009#include <private/dvr/display_protocol.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080010
11#include <functional>
12#include <iterator>
13#include <memory>
14#include <string>
15#include <vector>
16
17#include "acquired_buffer.h"
18#include "display_surface.h"
Corey Tabaka2251d822017-04-20 16:04:07 -070019#include "epoll_event_dispatcher.h"
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080020#include "hardware_composer.h"
21
22namespace android {
23namespace dvr {
24
Corey Tabaka2251d822017-04-20 16:04:07 -070025// DisplayService implements the display service component of VrFlinger.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080026class DisplayService : public pdx::ServiceBase<DisplayService> {
27 public:
Stephen Kiazyk016e5e32017-02-21 17:09:22 -080028 bool IsInitialized() const override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080029 std::string DumpState(size_t max_length) override;
30
31 void OnChannelClose(pdx::Message& message,
32 const std::shared_ptr<pdx::Channel>& channel) override;
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -070033 pdx::Status<void> HandleMessage(pdx::Message& message) override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080034
35 std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
36 std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
Corey Tabaka2251d822017-04-20 16:04:07 -070037 std::vector<std::shared_ptr<DirectDisplaySurface>> GetVisibleDisplaySurfaces()
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080038 const;
39
40 // Updates the list of actively displayed surfaces. This must be called after
41 // any change to client/manager attributes that affect visibility or z order.
Steven Thomas050b2c82017-03-06 11:45:16 -080042 void UpdateActiveDisplaySurfaces();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080043
Okan Arikan36d23802017-05-15 15:20:39 -070044 pdx::Status<BorrowedNativeBufferHandle> SetupGlobalBuffer(
45 DvrGlobalBufferKey key, size_t size, uint64_t usage);
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -070046
John Bates954796e2017-05-11 11:00:31 -070047 pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key);
48
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080049 template <class A>
Corey Tabaka2251d822017-04-20 16:04:07 -070050 void ForEachDisplaySurface(SurfaceType surface_type, A action) const {
51 ForEachChannel([surface_type,
52 action](const ChannelIterator::value_type& pair) mutable {
53 auto surface = std::static_pointer_cast<DisplaySurface>(pair.second);
54 if (surface->surface_type() == surface_type)
55 action(surface);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080056 });
57 }
58
59 using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
60 void SetDisplayConfigurationUpdateNotifier(
61 DisplayConfigurationUpdateNotifier notifier);
62
63 using VSyncCallback = HardwareComposer::VSyncCallback;
64 void SetVSyncCallback(VSyncCallback callback) {
65 hardware_composer_.SetVSyncCallback(callback);
66 }
67
Steven Thomas050b2c82017-03-06 11:45:16 -080068 void GrantDisplayOwnership() { hardware_composer_.Enable(); }
69 void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
Steven Thomasaf336272018-01-04 17:36:47 -080070 void OnBootFinished() { hardware_composer_.OnBootFinished(); }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080071
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080072 private:
73 friend BASE;
74 friend DisplaySurface;
75
76 friend class VrDisplayStateService;
77
Corey Tabaka2251d822017-04-20 16:04:07 -070078 using RequestDisplayCallback = std::function<void(bool)>;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080079
Corey Tabaka2251d822017-04-20 16:04:07 -070080 DisplayService(android::Hwc2::Composer* hidl,
Steven Thomas6e8f7062017-11-22 14:15:29 -080081 hwc2_display_t primary_display_id,
Corey Tabaka2251d822017-04-20 16:04:07 -070082 RequestDisplayCallback request_display_callback);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080083
Okan Arikan36d23802017-05-15 15:20:39 -070084 pdx::Status<BorrowedNativeBufferHandle> OnGetGlobalBuffer(
85 pdx::Message& message, DvrGlobalBufferKey key);
Corey Tabaka2251d822017-04-20 16:04:07 -070086 pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message);
Hendrik Wagenaarbcb03d02017-05-23 14:59:08 -070087 pdx::Status<std::string> OnGetConfigurationData(
88 pdx::Message& message, display::ConfigFileType config_type);
Corey Tabaka2251d822017-04-20 16:04:07 -070089 pdx::Status<display::SurfaceInfo> OnCreateSurface(
90 pdx::Message& message, const display::SurfaceAttributes& attributes);
Corey Tabaka99c2d732017-06-07 17:54:33 -070091 pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer(
92 pdx::Message& message, DvrGlobalBufferKey key, size_t size,
93 uint64_t usage);
94 pdx::Status<void> OnDeleteGlobalBuffer(pdx::Message& message,
95 DvrGlobalBufferKey key);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080096
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -040097 // Temporary query for current VR status. Will be removed later.
Corey Tabaka2251d822017-04-20 16:04:07 -070098 pdx::Status<bool> IsVrAppRunning(pdx::Message& message);
99
100 pdx::Status<void> AddEventHandler(int fd, int events,
101 EpollEventDispatcher::Handler handler) {
102 return dispatcher_.AddEventHandler(fd, events, handler);
103 }
104 pdx::Status<void> RemoveEventHandler(int fd) {
105 return dispatcher_.RemoveEventHandler(fd);
106 }
107
108 void SurfaceUpdated(SurfaceType surface_type,
109 display::SurfaceUpdateFlags update_flags);
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -0400110
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800111 // Called by DisplaySurface to signal that a surface property has changed and
112 // the display manager should be notified.
113 void NotifyDisplayConfigurationUpdate();
114
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -0700115 pdx::Status<void> HandleSurfaceMessage(pdx::Message& message);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800116
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800117 HardwareComposer hardware_composer_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700118 EpollEventDispatcher dispatcher_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800119 DisplayConfigurationUpdateNotifier update_notifier_;
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -0700120
Okan Arikan36d23802017-05-15 15:20:39 -0700121 std::unordered_map<DvrGlobalBufferKey, std::unique_ptr<IonBuffer>>
122 global_buffers_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700123
124 DisplayService(const DisplayService&) = delete;
125 void operator=(const DisplayService&) = delete;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800126};
127
128} // namespace dvr
129} // namespace android
130
131#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_