OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_ |
| 6 #define UI_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_ |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 #include <xf86drmMode.h> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/basictypes.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "ui/gfx/ozone/impl/drm_wrapper_ozone.h" |
| 16 |
| 17 namespace gfx { |
| 18 |
| 19 class SoftwareSurfaceOzone; |
| 20 |
| 21 // The HDCOz will handle modesettings and scannout operations for hardware |
| 22 // devices. |
| 23 // |
| 24 // In the DRM world there are 3 components that need to be paired up to be able |
| 25 // to display an image to the monitor: CRTC (cathode ray tube controller), |
| 26 // encoder and connector. The CRTC determines which framebuffer to read, when |
| 27 // to scanout and where to scanout. Encoders converts the stream from the CRTC |
| 28 // to the appropriate format for the connector. The connector is the physical |
| 29 // connection that monitors connect to. |
| 30 // |
| 31 // There is no 1:1:1 pairing for these components. It is possible for an encoder |
| 32 // to be compatible to multiple CRTCs and each connector can be used with |
| 33 // multiple encoders. In addition, it is possible to use one CRTC with multiple |
| 34 // connectors such that we can display the same image on multiple monitors. |
| 35 // |
| 36 // For example, the following configuration shows 2 different screens being |
| 37 // initialized separately. |
| 38 // ------------- ------------- |
| 39 // | Connector | | Connector | |
| 40 // | HDMI | | VGA | |
| 41 // ------------- ------------- |
| 42 // ^ ^ |
| 43 // | | |
| 44 // ------------- ------------- |
| 45 // | Encoder1 | | Encoder2 | |
| 46 // ------------- ------------- |
| 47 // ^ ^ |
| 48 // | | |
| 49 // ------------- ------------- |
| 50 // | CRTC1 | | CRTC2 | |
| 51 // ------------- ------------- |
| 52 // |
| 53 // In the following configuration 2 different screens are associated with the |
| 54 // same CRTC, so on scanout the same framebuffer will be displayed on both |
| 55 // monitors. |
| 56 // ------------- ------------- |
| 57 // | Connector | | Connector | |
| 58 // | HDMI | | VGA | |
| 59 // ------------- ------------- |
| 60 // ^ ^ |
| 61 // | | |
| 62 // ------------- ------------- |
| 63 // | Encoder1 | | Encoder2 | |
| 64 // ------------- ------------- |
| 65 // ^ ^ |
| 66 // | | |
| 67 // ---------------------- |
| 68 // | CRTC1 | |
| 69 // ---------------------- |
| 70 // |
| 71 // Note that it is possible to have more connectors than CRTCs which means that |
| 72 // only a subset of connectors can be active independently, showing different |
| 73 // framebuffers. Though, in this case, it would be possible to have all |
| 74 // connectors active if some use the same CRTC to mirror the display. |
| 75 // |
| 76 // TODO(dnicoara) Need to have a way to detect events (such as monitor |
| 77 // connected or disconnected). |
| 78 class HardwareDisplayControllerOzone { |
| 79 public: |
| 80 // Controller states. The state transitions will happen from top to bottom. |
| 81 enum State { |
| 82 // When we allocate a HDCO as a stub. At this point there is no connector |
| 83 // and CRTC associated with this device. |
| 84 UNASSOCIATED, |
| 85 |
| 86 // When |SetControllerInfo| is called and the HDCO has the information of |
| 87 // the hardware it will control. At this point it knows everything it needs |
| 88 // to control the hardware but doesn't have a surface. |
| 89 UNINITIALIZED, |
| 90 |
| 91 // A surface is associated with the HDCO. This means that the controller can |
| 92 // potentially display the backing surface to the display. Though the |
| 93 // surface framebuffer still needs to be registered with the CRTC. |
| 94 SURFACE_INITIALIZED, |
| 95 |
| 96 // The CRTC now knows about the surface attributes. |
| 97 INITIALIZED, |
| 98 |
| 99 // Error state if any of the initialization steps fail. |
| 100 FAILED, |
| 101 }; |
| 102 |
| 103 HardwareDisplayControllerOzone(); |
| 104 |
| 105 ~HardwareDisplayControllerOzone(); |
| 106 |
| 107 // Set the hardware configuration for this HDCO. Once this is set, the HDCO is |
| 108 // responsible for keeping track of the connector and CRTC and cleaning up |
| 109 // when it is destroyed. |
| 110 void SetControllerInfo(DrmWrapperOzone* drm, |
| 111 uint32_t connector_id, |
| 112 uint32_t crtc_id, |
| 113 drmModeModeInfo mode); |
| 114 |
| 115 // Associate the HDCO with a surface implementation and initialize it. |
| 116 bool BindSurfaceToController(SoftwareSurfaceOzone* surface); |
| 117 |
| 118 // Schedules the |surface_|'s framebuffer to be displayed on the next vsync |
| 119 // event. The event will be posted on the graphics card file descriptor |fd_| |
| 120 // and it can be read and processed by |drmHandleEvent|. That function can |
| 121 // define the callback for the page flip event. A generic data argument will |
| 122 // be presented to the callback. We use that argument to pass in the HDCO |
| 123 // object the event belongs to. |
| 124 // |
| 125 // Between this call and the callback, the framebuffer used in this call |
| 126 // should not be modified in any way as it would cause screen tearing if the |
| 127 // hardware performed the flip. Note that the frontbuffer should also not |
| 128 // be modified as it could still be displayed. |
| 129 // |
| 130 // Note that this function does not block. Also, this function should not be |
| 131 // called again before the page flip occurrs. |
| 132 // |
| 133 // Returns true if the page flip was successfully registered, false otherwise. |
| 134 bool SchedulePageFlip(); |
| 135 |
| 136 State get_state() const { return state_; }; |
| 137 |
| 138 int get_fd() const { return drm_->get_fd(); }; |
| 139 |
| 140 const drmModeModeInfo& get_mode() const { return mode_; }; |
| 141 |
| 142 SoftwareSurfaceOzone* get_surface() const { return surface_.get(); }; |
| 143 |
| 144 private: |
| 145 // Object containing the connection to the graphics device and wraps the API |
| 146 // calls to control it. |
| 147 DrmWrapperOzone* drm_; |
| 148 |
| 149 // TODO(dnicoara) Need to allow a CRTC to have multiple connectors. |
| 150 uint32_t connector_id_; |
| 151 |
| 152 uint32_t crtc_id_; |
| 153 |
| 154 // TODO(dnicoara) Need to store all the modes. |
| 155 drmModeModeInfo mode_; |
| 156 |
| 157 // Saved CRTC state from before we used it. Need it to restore state once we |
| 158 // are finished using this device. |
| 159 drmModeCrtc* saved_crtc_; |
| 160 |
| 161 State state_; |
| 162 |
| 163 scoped_ptr<SoftwareSurfaceOzone> surface_; |
| 164 |
| 165 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayControllerOzone); |
| 166 }; |
| 167 |
| 168 } // namespace gfx |
| 169 |
| 170 #endif // UI_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_ |
OLD | NEW |