1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_
6 #define UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_
11 #include "base/files/scoped_file.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "ui/display/types/native_display_delegate.h"
15 #include "ui/events/ozone/device/device_event.h"
16 #include "ui/events/ozone/device/device_event_observer.h"
17 #include "ui/events/ozone/evdev/event_factory_evdev.h"
18 #include "ui/ozone/public/gpu_platform_support_host.h"
23 class DrmDeviceHandle
;
25 class DrmGpuPlatformSupportHost
;
26 class DrmNativeDisplayDelegate
;
28 struct DisplaySnapshot_Params
;
30 class DrmDisplayHostManager
: public DeviceEventObserver
,
31 public GpuPlatformSupportHost
{
33 DrmDisplayHostManager(DrmGpuPlatformSupportHost
* proxy
,
34 DeviceManager
* device_manager
,
35 InputControllerEvdev
* input_controller
);
36 ~DrmDisplayHostManager() override
;
38 DrmDisplayHost
* GetDisplay(int64_t display_id
);
40 void AddDelegate(DrmNativeDisplayDelegate
* delegate
);
41 void RemoveDelegate(DrmNativeDisplayDelegate
* delegate
);
43 void TakeDisplayControl(const DisplayControlCallback
& callback
);
44 void RelinquishDisplayControl(const DisplayControlCallback
& callback
);
45 void UpdateDisplays(const GetDisplaysCallback
& callback
);
47 // DeviceEventObserver overrides:
48 void OnDeviceEvent(const DeviceEvent
& event
) override
;
50 // GpuPlatformSupportHost:
51 void OnChannelEstablished(
53 scoped_refptr
<base::SingleThreadTaskRunner
> send_runner
,
54 const base::Callback
<void(IPC::Message
*)>& send_callback
) override
;
55 void OnChannelDestroyed(int host_id
) override
;
57 // IPC::Listener overrides:
58 bool OnMessageReceived(const IPC::Message
& message
) override
;
62 DisplayEvent(DeviceEvent::ActionType action_type
,
63 const base::FilePath
& path
)
64 : action_type(action_type
), path(path
) {}
66 DeviceEvent::ActionType action_type
;
70 void OnUpdateNativeDisplays(
71 const std::vector
<DisplaySnapshot_Params
>& displays
);
72 void OnDisplayConfigured(int64_t display_id
, bool status
);
76 // Called as a result of finishing to process the display hotplug event. These
77 // are responsible for dequing the event and scheduling the next event.
78 void OnAddGraphicsDevice(const base::FilePath
& path
,
79 scoped_ptr
<DrmDeviceHandle
> handle
);
80 void OnUpdateGraphicsDevice();
81 void OnRemoveGraphicsDevice(const base::FilePath
& path
);
83 void OnHDCPStateReceived(int64_t display_id
, bool status
, HDCPState state
);
84 void OnHDCPStateUpdated(int64_t display_id
, bool status
);
86 void OnTakeDisplayControl(bool status
);
87 void OnRelinquishDisplayControl(bool status
);
89 void RunUpdateDisplaysCallback(const GetDisplaysCallback
& callback
) const;
91 void NotifyDisplayDelegate() const;
93 DrmGpuPlatformSupportHost
* proxy_
; // Not owned.
94 DeviceManager
* device_manager_
; // Not owned.
95 InputControllerEvdev
* input_controller_
; // Not owned.
97 DrmNativeDisplayDelegate
* delegate_
= nullptr; // Not owned.
99 // File path for the primary graphics card which is opened by default in the
100 // GPU process. We'll avoid opening this in hotplug events since it will race
101 // with the GPU process trying to open it and aquire DRM master.
102 base::FilePath primary_graphics_card_path_
;
104 // File path for virtual gem (VGEM) device.
105 base::FilePath vgem_card_path_
;
107 // Keeps track if there is a dummy display. This happens on initialization
108 // when there is no connection to the GPU to update the displays.
109 bool has_dummy_display_
= false;
111 ScopedVector
<DrmDisplayHost
> displays_
;
113 GetDisplaysCallback get_displays_callback_
;
115 bool display_externally_controlled_
= false;
116 bool display_control_change_pending_
= false;
117 DisplayControlCallback take_display_control_callback_
;
118 DisplayControlCallback relinquish_display_control_callback_
;
120 // Used to serialize display event processing. This is done since
121 // opening/closing DRM devices cannot be done on the UI thread and are handled
122 // on a worker thread. Thus, we need to queue events in order to process them
123 // in the correct order.
124 std::queue
<DisplayEvent
> event_queue_
;
126 // True if a display event is currently being processed on a worker thread.
127 bool task_pending_
= false;
129 // Keeps track of all the active DRM devices.
130 std::set
<base::FilePath
> drm_devices_
;
132 // This is used to cache the primary DRM device until the channel is
134 scoped_ptr
<DrmDeviceHandle
> primary_drm_device_handle_
;
136 // Manages the VGEM device by itself and doesn't send it to GPU process.
137 base::ScopedFD vgem_card_device_file_
;
139 base::WeakPtrFactory
<DrmDisplayHostManager
> weak_ptr_factory_
;
141 DISALLOW_COPY_AND_ASSIGN(DrmDisplayHostManager
);
146 #endif // UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_