Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / host / drm_display_host_manager.h
blob5f14cf35b87cf784edd08d29e2f0092924a3c963
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_
8 #include <queue>
9 #include <set>
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"
20 namespace ui {
22 class DeviceManager;
23 class DrmDeviceHandle;
24 class DrmDisplayHost;
25 class DrmGpuPlatformSupportHost;
26 class DrmNativeDisplayDelegate;
28 struct DisplaySnapshot_Params;
30 class DrmDisplayHostManager : public DeviceEventObserver,
31 public GpuPlatformSupportHost {
32 public:
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(
52 int host_id,
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;
60 private:
61 struct DisplayEvent {
62 DisplayEvent(DeviceEvent::ActionType action_type,
63 const base::FilePath& path)
64 : action_type(action_type), path(path) {}
66 DeviceEvent::ActionType action_type;
67 base::FilePath path;
70 void OnUpdateNativeDisplays(
71 const std::vector<DisplaySnapshot_Params>& displays);
72 void OnDisplayConfigured(int64_t display_id, bool status);
74 void ProcessEvent();
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
133 // established.
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);
144 } // namespace ui
146 #endif // UI_OZONE_PLATFORM_DRM_HOST_DRM_DISPLAY_HOST_MANAGER_H_