OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef UI_OZONE_PLATFORM_DRM_GPU_HARDWARE_DISPLAY_CONTROLLER_H_ |
| 6 #define UI_OZONE_PLATFORM_DRM_GPU_HARDWARE_DISPLAY_CONTROLLER_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 #include <xf86drmMode.h> |
| 11 #include <deque> |
| 12 #include <map> |
| 13 #include <vector> |
| 14 |
| 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" |
| 17 #include "base/containers/scoped_ptr_hash_map.h" |
| 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/memory/scoped_vector.h" |
| 20 #include "ui/gfx/swap_result.h" |
| 21 #include "ui/ozone/ozone_export.h" |
| 22 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.h" |
| 23 #include "ui/ozone/platform/drm/gpu/overlay_plane.h" |
| 24 |
| 25 namespace gfx { |
| 26 class Point; |
| 27 } |
| 28 |
| 29 namespace ui { |
| 30 |
| 31 class CrtcController; |
| 32 class ScanoutBuffer; |
| 33 class DrmDevice; |
| 34 |
| 35 // The HDCOz will handle modesettings and scannout operations for hardware |
| 36 // devices. |
| 37 // |
| 38 // In the DRM world there are 3 components that need to be paired up to be able |
| 39 // to display an image to the monitor: CRTC (cathode ray tube controller), |
| 40 // encoder and connector. The CRTC determines which framebuffer to read, when |
| 41 // to scanout and where to scanout. Encoders converts the stream from the CRTC |
| 42 // to the appropriate format for the connector. The connector is the physical |
| 43 // connection that monitors connect to. |
| 44 // |
| 45 // There is no 1:1:1 pairing for these components. It is possible for an encoder |
| 46 // to be compatible to multiple CRTCs and each connector can be used with |
| 47 // multiple encoders. In addition, it is possible to use one CRTC with multiple |
| 48 // connectors such that we can display the same image on multiple monitors. |
| 49 // |
| 50 // For example, the following configuration shows 2 different screens being |
| 51 // initialized separately. |
| 52 // ------------- ------------- |
| 53 // | Connector | | Connector | |
| 54 // | HDMI | | VGA | |
| 55 // ------------- ------------- |
| 56 // ^ ^ |
| 57 // | | |
| 58 // ------------- ------------- |
| 59 // | Encoder1 | | Encoder2 | |
| 60 // ------------- ------------- |
| 61 // ^ ^ |
| 62 // | | |
| 63 // ------------- ------------- |
| 64 // | CRTC1 | | CRTC2 | |
| 65 // ------------- ------------- |
| 66 // |
| 67 // In the following configuration 2 different screens are associated with the |
| 68 // same CRTC, so on scanout the same framebuffer will be displayed on both |
| 69 // monitors. |
| 70 // ------------- ------------- |
| 71 // | Connector | | Connector | |
| 72 // | HDMI | | VGA | |
| 73 // ------------- ------------- |
| 74 // ^ ^ |
| 75 // | | |
| 76 // ------------- ------------- |
| 77 // | Encoder1 | | Encoder2 | |
| 78 // ------------- ------------- |
| 79 // ^ ^ |
| 80 // | | |
| 81 // ---------------------- |
| 82 // | CRTC1 | |
| 83 // ---------------------- |
| 84 // |
| 85 // Note that it is possible to have more connectors than CRTCs which means that |
| 86 // only a subset of connectors can be active independently, showing different |
| 87 // framebuffers. Though, in this case, it would be possible to have all |
| 88 // connectors active if some use the same CRTC to mirror the display. |
| 89 class OZONE_EXPORT HardwareDisplayController { |
| 90 typedef base::Callback<void(gfx::SwapResult)> PageFlipCallback; |
| 91 |
| 92 public: |
| 93 HardwareDisplayController(scoped_ptr<CrtcController> controller, |
| 94 const gfx::Point& origin); |
| 95 ~HardwareDisplayController(); |
| 96 |
| 97 // Performs the initial CRTC configuration. If successful, it will display the |
| 98 // framebuffer for |primary| with |mode|. |
| 99 bool Modeset(const OverlayPlane& primary, drmModeModeInfo mode); |
| 100 |
| 101 // Disables the CRTC. |
| 102 void Disable(); |
| 103 |
| 104 // Schedules the |overlays|' framebuffers to be displayed on the next vsync |
| 105 // event. The event will be posted on the graphics card file descriptor |fd_| |
| 106 // and it can be read and processed by |drmHandleEvent|. That function can |
| 107 // define the callback for the page flip event. A generic data argument will |
| 108 // be presented to the callback. We use that argument to pass in the HDCO |
| 109 // object the event belongs to. |
| 110 // |
| 111 // Between this call and the callback, the framebuffers used in this call |
| 112 // should not be modified in any way as it would cause screen tearing if the |
| 113 // hardware performed the flip. Note that the frontbuffer should also not |
| 114 // be modified as it could still be displayed. |
| 115 // |
| 116 // Note that this function does not block. Also, this function should not be |
| 117 // called again before the page flip occurrs. |
| 118 // |
| 119 // Returns true if the page flip was successfully registered, false otherwise. |
| 120 // |
| 121 // When called with |test_only| true, this performs the page flip without |
| 122 // changing any state, reporting if this page flip would be allowed to occur. |
| 123 // This is always a synchronous operation, so |is_sync| is ignored and the |
| 124 // callback is called immediately but should also be ignored; only the return |
| 125 // value matters. |
| 126 bool SchedulePageFlip(const OverlayPlaneList& plane_list, |
| 127 bool is_sync, |
| 128 bool test_only, |
| 129 const PageFlipCallback& callback); |
| 130 |
| 131 // Set the hardware cursor to show the contents of |surface|. |
| 132 bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer); |
| 133 |
| 134 bool UnsetCursor(); |
| 135 |
| 136 // Moves the hardware cursor to |location|. |
| 137 bool MoveCursor(const gfx::Point& location); |
| 138 |
| 139 void AddCrtc(scoped_ptr<CrtcController> controller); |
| 140 scoped_ptr<CrtcController> RemoveCrtc(const scoped_refptr<DrmDevice>& drm, |
| 141 uint32_t crtc); |
| 142 bool HasCrtc(const scoped_refptr<DrmDevice>& drm, uint32_t crtc) const; |
| 143 bool IsMirrored() const; |
| 144 bool IsDisabled() const; |
| 145 gfx::Size GetModeSize() const; |
| 146 |
| 147 gfx::Point origin() const { return origin_; } |
| 148 void set_origin(const gfx::Point& origin) { origin_ = origin; } |
| 149 |
| 150 const drmModeModeInfo& get_mode() const { return mode_; }; |
| 151 |
| 152 uint64_t GetTimeOfLastFlip() const; |
| 153 |
| 154 const std::vector<CrtcController*>& crtc_controllers() const { |
| 155 return crtc_controllers_.get(); |
| 156 } |
| 157 |
| 158 scoped_refptr<DrmDevice> GetAllocationDrmDevice() const; |
| 159 |
| 160 private: |
| 161 base::ScopedPtrHashMap<DrmDevice*, scoped_ptr<HardwareDisplayPlaneList>> |
| 162 owned_hardware_planes_; |
| 163 |
| 164 // Stores the CRTC configuration. This is used to identify monitors and |
| 165 // configure them. |
| 166 ScopedVector<CrtcController> crtc_controllers_; |
| 167 |
| 168 // Location of the controller on the screen. |
| 169 gfx::Point origin_; |
| 170 |
| 171 // The mode used by the last modesetting operation. |
| 172 drmModeModeInfo mode_; |
| 173 |
| 174 bool is_disabled_; |
| 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController); |
| 177 }; |
| 178 |
| 179 } // namespace ui |
| 180 |
| 181 #endif // UI_OZONE_PLATFORM_DRM_GPU_HARDWARE_DISPLAY_CONTROLLER_H_ |
OLD | NEW |