blob: d45a61fad7d7964fd1e05eb06c2f33cf1a89fd44 [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
mamika08194b2019-07-25 13:07:21 -070021#include "DisplayHardware/DisplayIdentification.h"
22
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080023namespace android {
24namespace dvr {
25
Corey Tabaka2251d822017-04-20 16:04:07 -070026// DisplayService implements the display service component of VrFlinger.
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080027class DisplayService : public pdx::ServiceBase<DisplayService> {
28 public:
Stephen Kiazyk016e5e32017-02-21 17:09:22 -080029 bool IsInitialized() const override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080030 std::string DumpState(size_t max_length) override;
31
32 void OnChannelClose(pdx::Message& message,
33 const std::shared_ptr<pdx::Channel>& channel) override;
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -070034 pdx::Status<void> HandleMessage(pdx::Message& message) override;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080035
36 std::shared_ptr<DisplaySurface> GetDisplaySurface(int surface_id) const;
37 std::vector<std::shared_ptr<DisplaySurface>> GetDisplaySurfaces() const;
Corey Tabaka2251d822017-04-20 16:04:07 -070038 std::vector<std::shared_ptr<DirectDisplaySurface>> GetVisibleDisplaySurfaces()
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080039 const;
40
41 // Updates the list of actively displayed surfaces. This must be called after
42 // any change to client/manager attributes that affect visibility or z order.
Steven Thomas050b2c82017-03-06 11:45:16 -080043 void UpdateActiveDisplaySurfaces();
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080044
Okan Arikan36d23802017-05-15 15:20:39 -070045 pdx::Status<BorrowedNativeBufferHandle> SetupGlobalBuffer(
46 DvrGlobalBufferKey key, size_t size, uint64_t usage);
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -070047
John Bates954796e2017-05-11 11:00:31 -070048 pdx::Status<void> DeleteGlobalBuffer(DvrGlobalBufferKey key);
49
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080050 template <class A>
Corey Tabaka2251d822017-04-20 16:04:07 -070051 void ForEachDisplaySurface(SurfaceType surface_type, A action) const {
52 ForEachChannel([surface_type,
53 action](const ChannelIterator::value_type& pair) mutable {
54 auto surface = std::static_pointer_cast<DisplaySurface>(pair.second);
55 if (surface->surface_type() == surface_type)
56 action(surface);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080057 });
58 }
59
60 using DisplayConfigurationUpdateNotifier = std::function<void(void)>;
61 void SetDisplayConfigurationUpdateNotifier(
62 DisplayConfigurationUpdateNotifier notifier);
63
Steven Thomas050b2c82017-03-06 11:45:16 -080064 void GrantDisplayOwnership() { hardware_composer_.Enable(); }
65 void SeizeDisplayOwnership() { hardware_composer_.Disable(); }
Steven Thomasaf336272018-01-04 17:36:47 -080066 void OnBootFinished() { hardware_composer_.OnBootFinished(); }
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080067
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080068 private:
69 friend BASE;
70 friend DisplaySurface;
71
72 friend class VrDisplayStateService;
73
Corey Tabaka2251d822017-04-20 16:04:07 -070074 using RequestDisplayCallback = std::function<void(bool)>;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080075
Corey Tabaka2251d822017-04-20 16:04:07 -070076 DisplayService(android::Hwc2::Composer* hidl,
Steven Thomas6e8f7062017-11-22 14:15:29 -080077 hwc2_display_t primary_display_id,
Corey Tabaka2251d822017-04-20 16:04:07 -070078 RequestDisplayCallback request_display_callback);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080079
Okan Arikan36d23802017-05-15 15:20:39 -070080 pdx::Status<BorrowedNativeBufferHandle> OnGetGlobalBuffer(
81 pdx::Message& message, DvrGlobalBufferKey key);
Corey Tabaka2251d822017-04-20 16:04:07 -070082 pdx::Status<display::Metrics> OnGetMetrics(pdx::Message& message);
Hendrik Wagenaarbcb03d02017-05-23 14:59:08 -070083 pdx::Status<std::string> OnGetConfigurationData(
84 pdx::Message& message, display::ConfigFileType config_type);
Corey Tabaka2251d822017-04-20 16:04:07 -070085 pdx::Status<display::SurfaceInfo> OnCreateSurface(
86 pdx::Message& message, const display::SurfaceAttributes& attributes);
Corey Tabaka99c2d732017-06-07 17:54:33 -070087 pdx::Status<BorrowedNativeBufferHandle> OnSetupGlobalBuffer(
88 pdx::Message& message, DvrGlobalBufferKey key, size_t size,
89 uint64_t usage);
90 pdx::Status<void> OnDeleteGlobalBuffer(pdx::Message& message,
91 DvrGlobalBufferKey key);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -080092
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -040093 // Temporary query for current VR status. Will be removed later.
Corey Tabaka2251d822017-04-20 16:04:07 -070094 pdx::Status<bool> IsVrAppRunning(pdx::Message& message);
95
96 pdx::Status<void> AddEventHandler(int fd, int events,
97 EpollEventDispatcher::Handler handler) {
98 return dispatcher_.AddEventHandler(fd, events, handler);
99 }
100 pdx::Status<void> RemoveEventHandler(int fd) {
101 return dispatcher_.RemoveEventHandler(fd);
102 }
103
104 void SurfaceUpdated(SurfaceType surface_type,
105 display::SurfaceUpdateFlags update_flags);
Albert Chaulkb7c8a4b2017-03-20 13:03:39 -0400106
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800107 // Called by DisplaySurface to signal that a surface property has changed and
108 // the display manager should be notified.
109 void NotifyDisplayConfigurationUpdate();
110
Alex Vakulenkof0a7bd02017-03-31 18:06:19 -0700111 pdx::Status<void> HandleSurfaceMessage(pdx::Message& message);
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800112
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800113 HardwareComposer hardware_composer_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700114 EpollEventDispatcher dispatcher_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800115 DisplayConfigurationUpdateNotifier update_notifier_;
Hendrik Wagenaar10e68eb2017-03-15 13:29:02 -0700116
Okan Arikan36d23802017-05-15 15:20:39 -0700117 std::unordered_map<DvrGlobalBufferKey, std::unique_ptr<IonBuffer>>
118 global_buffers_;
Corey Tabaka2251d822017-04-20 16:04:07 -0700119
120 DisplayService(const DisplayService&) = delete;
121 void operator=(const DisplayService&) = delete;
mamika08194b2019-07-25 13:07:21 -0700122
123 DisplayIdentificationData display_identification_data_;
Alex Vakulenkoa8a92782017-01-27 14:41:57 -0800124};
125
126} // namespace dvr
127} // namespace android
128
129#endif // ANDROID_DVR_SERVICES_DISPLAYD_DISPLAY_SERVICE_H_