blob: e0f2eddfea08237d601c325a69128b719493598f [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>
Hendrik Wagenaareaa55222017-04-06 10:56:23 -07007#include <private/dvr/bufferhub_rpc.h>
Corey Tabaka3f82d312017-04-20 14:42:08 -07008#include <private/dvr/display_protocol.h>
Alex Vakulenkoa8a92782017-01-27 14:41:57 -08009
10#include <functional>
11#include <iterator>
12#include <memory>
13#include <string>
14#include <vector>
15
16#include "acquired_buffer.h"
17#include "display_surface.h"
Corey Tabaka2251d822017-04-20 16:04:07 -070018#include "epoll_event_dispatcher.h"
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080019#include "hardware_composer.h"
20
21namespace android {
22namespace dvr {
23
Corey Tabaka2251d822017-04-20 16:04:07 -070024// DisplayService implements the display service component of VrFlinger.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080025class DisplayService : public pdx::ServiceBase<DisplayService> {
26 public:
Stephen Kiazyk016e5e32017-02-21 17:09:22 -080027 bool IsInitialized() const override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080028 std::string DumpState(size_t max_length) override;
29
30 void OnChannelClose(pdx::Message& message,
31 const std::shared_ptr<pdx::Channel>& channel) override;
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -070032 pdx::Status<void> HandleMessage(pdx::Message& message) override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080033
34 std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
35 std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
Corey Tabaka2251d822017-04-20 16:04:07 -070036 std::vector<std::shared_ptr<DirectDisplaySurface>> GetVisibleDisplaySurfaces()
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080037 const;
38
39 // Updates the list of actively displayed surfaces. This must be called after
40 // any change to client/manager attributes that affect visibility or z order.
Steven Thomas050b2c82017-03-06 11:45:16 -080041 void UpdateActiveDisplaySurfaces();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080042
Okan Arikan36d23802017-05-15 15:20:39 -070043 pdx::Status<BorrowedNativeBufferHandle> SetupGlobalBuffer(
44 DvrGlobalBufferKey key, size_t size, uint64_t usage);
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -070045
John Bates954796e2017-05-11 11:00:31 -070046 pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key);
47
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080048 template <class A>
Corey Tabaka2251d822017-04-20 16:04:07 -070049 void ForEachDisplaySurface(SurfaceType surface_type, A action) const {
50 ForEachChannel([surface_type,
51 action](const ChannelIterator::value_type& pair) mutable {
52 auto surface = std::static_pointer_cast<DisplaySurface>(pair.second);
53 if (surface->surface_type() == surface_type)
54 action(surface);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080055 });
56 }
57
58 using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
59 void SetDisplayConfigurationUpdateNotifier(
60 DisplayConfigurationUpdateNotifier notifier);
61
Steven Thomas050b2c82017-03-06 11:45:16 -080062 void GrantDisplayOwnership() { hardware_composer_.Enable(); }
63 void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
Steven Thomasaf336272018-01-04 17:36:47 -080064 void OnBootFinished() { hardware_composer_.OnBootFinished(); }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080065
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080066 private:
67 friend BASE;
68 friend DisplaySurface;
69
70 friend class VrDisplayStateService;
71
Corey Tabaka2251d822017-04-20 16:04:07 -070072 using RequestDisplayCallback = std::function<void(bool)>;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080073
Corey Tabaka2251d822017-04-20 16:04:07 -070074 DisplayService(android::Hwc2::Composer* hidl,
Steven Thomas6e8f7062017-11-22 14:15:29 -080075 hwc2_display_t primary_display_id,
Corey Tabaka2251d822017-04-20 16:04:07 -070076 RequestDisplayCallback request_display_callback);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080077
Okan Arikan36d23802017-05-15 15:20:39 -070078 pdx::Status<BorrowedNativeBufferHandle> OnGetGlobalBuffer(
79 pdx::Message& message, DvrGlobalBufferKey key);
Corey Tabaka2251d822017-04-20 16:04:07 -070080 pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message);
Hendrik Wagenaarbcb03d02017-05-23 14:59:08 -070081 pdx::Status<std::string> OnGetConfigurationData(
82 pdx::Message& message, display::ConfigFileType config_type);
Corey Tabaka2251d822017-04-20 16:04:07 -070083 pdx::Status<display::SurfaceInfo> OnCreateSurface(
84 pdx::Message& message, const display::SurfaceAttributes& attributes);
Corey Tabaka99c2d732017-06-07 17:54:33 -070085 pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer(
86 pdx::Message& message, DvrGlobalBufferKey key, size_t size,
87 uint64_t usage);
88 pdx::Status<void> OnDeleteGlobalBuffer(pdx::Message& message,
89 DvrGlobalBufferKey key);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080090
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -040091 // Temporary query for current VR status. Will be removed later.
Corey Tabaka2251d822017-04-20 16:04:07 -070092 pdx::Status<bool> IsVrAppRunning(pdx::Message& message);
93
94 pdx::Status<void> AddEventHandler(int fd, int events,
95 EpollEventDispatcher::Handler handler) {
96 return dispatcher_.AddEventHandler(fd, events, handler);
97 }
98 pdx::Status<void> RemoveEventHandler(int fd) {
99 return dispatcher_.RemoveEventHandler(fd);
100 }
101
102 void SurfaceUpdated(SurfaceType surface_type,
103 display::SurfaceUpdateFlags update_flags);
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -0400104
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800105 // Called by DisplaySurface to signal that a surface property has changed and
106 // the display manager should be notified.
107 void NotifyDisplayConfigurationUpdate();
108
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -0700109 pdx::Status<void> HandleSurfaceMessage(pdx::Message& message);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800110
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800111 HardwareComposer hardware_composer_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700112 EpollEventDispatcher dispatcher_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800113 DisplayConfigurationUpdateNotifier update_notifier_;
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -0700114
Okan Arikan36d23802017-05-15 15:20:39 -0700115 std::unordered_map<DvrGlobalBufferKey, std::unique_ptr<IonBuffer>>
116 global_buffers_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700117
118 DisplayService(const DisplayService&) = delete;
119 void operator=(const DisplayService&) = delete;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800120};
121
122} // namespace dvr
123} // namespace android
124
125#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_