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_GPU_HARDWARE_DISPLAY_CONTROLLER_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_HARDWARE_DISPLAY_CONTROLLER_H_
10 #include <xf86drmMode.h>
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"
35 // The HDCOz will handle modesettings and scannout operations for hardware
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.
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.
50 // For example, the following configuration shows 2 different screens being
51 // initialized separately.
52 // ------------- -------------
53 // | Connector | | Connector |
55 // ------------- -------------
58 // ------------- -------------
59 // | Encoder1 | | Encoder2 |
60 // ------------- -------------
63 // ------------- -------------
64 // | CRTC1 | | CRTC2 |
65 // ------------- -------------
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
70 // ------------- -------------
71 // | Connector | | Connector |
73 // ------------- -------------
76 // ------------- -------------
77 // | Encoder1 | | Encoder2 |
78 // ------------- -------------
81 // ----------------------
83 // ----------------------
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
;
93 HardwareDisplayController(scoped_ptr
<CrtcController
> controller
,
94 const gfx::Point
& origin
);
95 ~HardwareDisplayController();
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
);
101 // Disables the CRTC.
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.
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.
116 // Note that this function does not block. Also, this function should not be
117 // called again before the page flip occurrs.
119 // Returns true if the page flip was successfully registered, false otherwise.
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
126 bool SchedulePageFlip(const OverlayPlaneList
& plane_list
,
129 const PageFlipCallback
& callback
);
131 // Set the hardware cursor to show the contents of |surface|.
132 bool SetCursor(const scoped_refptr
<ScanoutBuffer
>& buffer
);
136 // Moves the hardware cursor to |location|.
137 bool MoveCursor(const gfx::Point
& location
);
139 void AddCrtc(scoped_ptr
<CrtcController
> controller
);
140 scoped_ptr
<CrtcController
> RemoveCrtc(const scoped_refptr
<DrmDevice
>& drm
,
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;
147 gfx::Point
origin() const { return origin_
; }
148 void set_origin(const gfx::Point
& origin
) { origin_
= origin
; }
150 const drmModeModeInfo
& get_mode() const { return mode_
; };
152 uint64_t GetTimeOfLastFlip() const;
154 const std::vector
<CrtcController
*>& crtc_controllers() const {
155 return crtc_controllers_
.get();
158 scoped_refptr
<DrmDevice
> GetAllocationDrmDevice() const;
161 base::ScopedPtrHashMap
<DrmDevice
*, scoped_ptr
<HardwareDisplayPlaneList
>>
162 owned_hardware_planes_
;
164 // Stores the CRTC configuration. This is used to identify monitors and
166 ScopedVector
<CrtcController
> crtc_controllers_
;
168 // Location of the controller on the screen.
171 // The mode used by the last modesetting operation.
172 drmModeModeInfo mode_
;
176 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController
);
181 #endif // UI_OZONE_PLATFORM_DRM_GPU_HARDWARE_DISPLAY_CONTROLLER_H_