1 // Copyright 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.
5 #ifndef UI_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_
6 #define UI_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_
10 #include <xf86drmMode.h>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/gfx/ozone/impl/drm_wrapper_ozone.h"
19 class SoftwareSurfaceOzone;
21 // The HDCOz will handle modesettings and scannout operations for hardware
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.
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.
36 // For example, the following configuration shows 2 different screens being
37 // initialized separately.
38 // ------------- -------------
39 // | Connector | | Connector |
41 // ------------- -------------
44 // ------------- -------------
45 // | Encoder1 | | Encoder2 |
46 // ------------- -------------
49 // ------------- -------------
50 // | CRTC1 | | CRTC2 |
51 // ------------- -------------
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
56 // ------------- -------------
57 // | Connector | | Connector |
59 // ------------- -------------
62 // ------------- -------------
63 // | Encoder1 | | Encoder2 |
64 // ------------- -------------
67 // ----------------------
69 // ----------------------
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.
76 // TODO(dnicoara) Need to have a way to detect events (such as monitor
77 // connected or disconnected).
78 class HardwareDisplayControllerOzone {
80 // Controller states. The state transitions will happen from top to bottom.
82 // When we allocate a HDCO as a stub. At this point there is no connector
83 // and CRTC associated with this device.
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.
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.
96 // The CRTC now knows about the surface attributes.
99 // Error state if any of the initialization steps fail.
103 HardwareDisplayControllerOzone();
105 ~HardwareDisplayControllerOzone();
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,
113 uint32_t dpms_property_id,
114 drmModeModeInfo mode);
116 // Associate the HDCO with a surface implementation and initialize it.
117 bool BindSurfaceToController(scoped_ptr<SoftwareSurfaceOzone> surface);
119 // Schedules the |surface_|'s framebuffer to be displayed on the next vsync
120 // event. The event will be posted on the graphics card file descriptor |fd_|
121 // and it can be read and processed by |drmHandleEvent|. That function can
122 // define the callback for the page flip event. A generic data argument will
123 // be presented to the callback. We use that argument to pass in the HDCO
124 // object the event belongs to.
126 // Between this call and the callback, the framebuffer used in this call
127 // should not be modified in any way as it would cause screen tearing if the
128 // hardware performed the flip. Note that the frontbuffer should also not
129 // be modified as it could still be displayed.
131 // Note that this function does not block. Also, this function should not be
132 // called again before the page flip occurrs.
134 // Returns true if the page flip was successfully registered, false otherwise.
135 bool SchedulePageFlip();
137 State get_state() const { return state_; };
139 int get_fd() const { return drm_->get_fd(); };
141 const drmModeModeInfo& get_mode() const { return mode_; };
143 SoftwareSurfaceOzone* get_surface() const { return surface_.get(); };
146 // Object containing the connection to the graphics device and wraps the API
147 // calls to control it.
148 DrmWrapperOzone* drm_;
150 // TODO(dnicoara) Need to allow a CRTC to have multiple connectors.
151 uint32_t connector_id_;
155 uint32_t dpms_property_id_;
157 // TODO(dnicoara) Need to store all the modes.
158 drmModeModeInfo mode_;
160 // Saved CRTC state from before we used it. Need it to restore state once we
161 // are finished using this device.
162 drmModeCrtc* saved_crtc_;
166 scoped_ptr<SoftwareSurfaceOzone> surface_;
168 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayControllerOzone);
173 #endif // UI_GFX_OZONE_IMPL_HARDWARE_DISPLAY_CONTROLLER_OZONE_H_