OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ | 5 #ifndef UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ |
6 #define UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ | 6 #define UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <xf86drmMode.h> | 10 #include <xf86drmMode.h> |
| 11 #include <deque> |
11 #include <map> | 12 #include <map> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" |
15 #include "base/containers/scoped_ptr_hash_map.h" | 17 #include "base/containers/scoped_ptr_hash_map.h" |
16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
18 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
19 #include "ui/ozone/platform/dri/hardware_display_plane_manager.h" | 21 #include "ui/ozone/platform/dri/hardware_display_plane_manager.h" |
20 #include "ui/ozone/platform/dri/overlay_plane.h" | 22 #include "ui/ozone/platform/dri/overlay_plane.h" |
| 23 #include "ui/ozone/platform/dri/page_flip_observer.h" |
21 | 24 |
22 namespace gfx { | 25 namespace gfx { |
23 class Point; | 26 class Point; |
24 } | 27 } |
25 | 28 |
26 namespace ui { | 29 namespace ui { |
27 | 30 |
28 class CrtcController; | 31 class CrtcController; |
29 class ScanoutBuffer; | 32 class ScanoutBuffer; |
30 class DriWrapper; | 33 class DriWrapper; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // | | | 80 // | | |
78 // ---------------------- | 81 // ---------------------- |
79 // | CRTC1 | | 82 // | CRTC1 | |
80 // ---------------------- | 83 // ---------------------- |
81 // | 84 // |
82 // Note that it is possible to have more connectors than CRTCs which means that | 85 // Note that it is possible to have more connectors than CRTCs which means that |
83 // only a subset of connectors can be active independently, showing different | 86 // only a subset of connectors can be active independently, showing different |
84 // framebuffers. Though, in this case, it would be possible to have all | 87 // framebuffers. Though, in this case, it would be possible to have all |
85 // connectors active if some use the same CRTC to mirror the display. | 88 // connectors active if some use the same CRTC to mirror the display. |
86 class HardwareDisplayController | 89 class HardwareDisplayController |
87 : public base::SupportsWeakPtr<HardwareDisplayController> { | 90 : public base::SupportsWeakPtr<HardwareDisplayController>, |
| 91 public PageFlipObserver { |
88 public: | 92 public: |
89 explicit HardwareDisplayController(scoped_ptr<CrtcController> controller); | 93 explicit HardwareDisplayController(scoped_ptr<CrtcController> controller); |
90 ~HardwareDisplayController(); | 94 ~HardwareDisplayController() override; |
91 | 95 |
92 // Performs the initial CRTC configuration. If successful, it will display the | 96 // Performs the initial CRTC configuration. If successful, it will display the |
93 // framebuffer for |primary| with |mode|. | 97 // framebuffer for |primary| with |mode|. |
94 bool Modeset(const OverlayPlane& primary, | 98 bool Modeset(const OverlayPlane& primary, |
95 drmModeModeInfo mode); | 99 drmModeModeInfo mode); |
96 | 100 |
97 // Reconfigures the CRTC with the current surface and mode. | 101 // Reconfigures the CRTC with the current surface and mode. |
98 bool Enable(); | 102 bool Enable(); |
99 | 103 |
100 // Disables the CRTC. | 104 // Disables the CRTC. |
(...skipping 10 matching lines...) Expand all Loading... |
111 // | 115 // |
112 // Between this call and the callback, the framebuffers used in this call | 116 // Between this call and the callback, the framebuffers used in this call |
113 // should not be modified in any way as it would cause screen tearing if the | 117 // should not be modified in any way as it would cause screen tearing if the |
114 // hardware performed the flip. Note that the frontbuffer should also not | 118 // hardware performed the flip. Note that the frontbuffer should also not |
115 // be modified as it could still be displayed. | 119 // be modified as it could still be displayed. |
116 // | 120 // |
117 // Note that this function does not block. Also, this function should not be | 121 // Note that this function does not block. Also, this function should not be |
118 // called again before the page flip occurrs. | 122 // called again before the page flip occurrs. |
119 // | 123 // |
120 // Returns true if the page flip was successfully registered, false otherwise. | 124 // Returns true if the page flip was successfully registered, false otherwise. |
121 bool SchedulePageFlip(); | 125 bool SchedulePageFlip(const base::Closure& callback); |
122 | |
123 // TODO(dnicoara) This should be on the MessageLoop when Ozone can have | |
124 // BeginFrame can be triggered explicitly by Ozone. | |
125 void WaitForPageFlipEvent(); | |
126 | 126 |
127 // Set the hardware cursor to show the contents of |surface|. | 127 // Set the hardware cursor to show the contents of |surface|. |
128 bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer); | 128 bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer); |
129 | 129 |
130 bool UnsetCursor(); | 130 bool UnsetCursor(); |
131 | 131 |
132 // Moves the hardware cursor to |location|. | 132 // Moves the hardware cursor to |location|. |
133 bool MoveCursor(const gfx::Point& location); | 133 bool MoveCursor(const gfx::Point& location); |
134 | 134 |
135 void AddCrtc(scoped_ptr<CrtcController> controller); | 135 void AddCrtc(scoped_ptr<CrtcController> controller); |
136 scoped_ptr<CrtcController> RemoveCrtc(uint32_t crtc); | 136 scoped_ptr<CrtcController> RemoveCrtc(uint32_t crtc); |
137 bool HasCrtc(uint32_t crtc) const; | 137 bool HasCrtc(uint32_t crtc) const; |
138 bool IsMirrored() const; | 138 bool IsMirrored() const; |
139 bool IsDisabled() const; | 139 bool IsDisabled() const; |
140 gfx::Size GetModeSize() const; | 140 gfx::Size GetModeSize() const; |
141 | 141 |
142 gfx::Point origin() const { return origin_; } | 142 gfx::Point origin() const { return origin_; } |
143 void set_origin(const gfx::Point& origin) { origin_ = origin; } | 143 void set_origin(const gfx::Point& origin) { origin_ = origin; } |
144 | 144 |
145 const drmModeModeInfo& get_mode() const { return mode_; }; | 145 const drmModeModeInfo& get_mode() const { return mode_; }; |
146 | 146 |
147 uint64_t GetTimeOfLastFlip() const; | 147 uint64_t GetTimeOfLastFlip() const; |
148 | 148 |
149 const std::vector<CrtcController*>& crtc_controllers() const { | 149 const std::vector<CrtcController*>& crtc_controllers() const { |
150 return crtc_controllers_.get(); | 150 return crtc_controllers_.get(); |
151 } | 151 } |
152 | 152 |
153 private: | 153 private: |
| 154 // Returns true if any of the CRTCs is waiting for a page flip. |
| 155 bool HasPendingPageFlips() const; |
| 156 |
| 157 bool ActualSchedulePageFlip(); |
| 158 |
| 159 void ProcessPageFlipRequest(); |
| 160 |
| 161 void ClearPendingRequests(); |
| 162 |
| 163 // PageFlipObserver: |
| 164 void OnPageFlipEvent() override; |
| 165 |
| 166 struct PageFlipRequest { |
| 167 PageFlipRequest(const OverlayPlaneList& planes, |
| 168 const base::Closure& callback); |
| 169 ~PageFlipRequest(); |
| 170 |
| 171 OverlayPlaneList planes; |
| 172 base::Closure callback; |
| 173 }; |
| 174 |
154 // Buffers need to be declared first so that they are destroyed last. Needed | 175 // Buffers need to be declared first so that they are destroyed last. Needed |
155 // since the controllers may reference the buffers. | 176 // since the controllers may reference the buffers. |
156 OverlayPlaneList current_planes_; | 177 OverlayPlaneList current_planes_; |
157 OverlayPlaneList pending_planes_; | 178 OverlayPlaneList pending_planes_; |
| 179 std::deque<PageFlipRequest> requests_; |
158 scoped_refptr<ScanoutBuffer> cursor_buffer_; | 180 scoped_refptr<ScanoutBuffer> cursor_buffer_; |
159 | 181 |
160 base::ScopedPtrHashMap<DriWrapper*, HardwareDisplayPlaneList> | 182 base::ScopedPtrHashMap<DriWrapper*, HardwareDisplayPlaneList> |
161 owned_hardware_planes_; | 183 owned_hardware_planes_; |
162 | 184 |
163 // Stores the CRTC configuration. This is used to identify monitors and | 185 // Stores the CRTC configuration. This is used to identify monitors and |
164 // configure them. | 186 // configure them. |
165 ScopedVector<CrtcController> crtc_controllers_; | 187 ScopedVector<CrtcController> crtc_controllers_; |
166 | 188 |
167 // Location of the controller on the screen. | 189 // Location of the controller on the screen. |
168 gfx::Point origin_; | 190 gfx::Point origin_; |
169 | 191 |
170 // The mode used by the last modesetting operation. | 192 // The mode used by the last modesetting operation. |
171 drmModeModeInfo mode_; | 193 drmModeModeInfo mode_; |
172 | 194 |
173 bool is_disabled_; | 195 bool is_disabled_; |
174 | 196 |
175 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController); | 197 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController); |
176 }; | 198 }; |
177 | 199 |
178 } // namespace ui | 200 } // namespace ui |
179 | 201 |
180 #endif // UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ | 202 #endif // UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_ |
OLD | NEW |