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_DRI_HARDWARE_DISPLAY_CONTROLLER_H_
6 #define UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_
10 #include <xf86drmMode.h>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h"
17 #include "ui/ozone/platform/dri/overlay_plane.h"
28 // The HDCOz will handle modesettings and scannout operations for hardware
31 // In the DRM world there are 3 components that need to be paired up to be able
32 // to display an image to the monitor: CRTC (cathode ray tube controller),
33 // encoder and connector. The CRTC determines which framebuffer to read, when
34 // to scanout and where to scanout. Encoders converts the stream from the CRTC
35 // to the appropriate format for the connector. The connector is the physical
36 // connection that monitors connect to.
38 // There is no 1:1:1 pairing for these components. It is possible for an encoder
39 // to be compatible to multiple CRTCs and each connector can be used with
40 // multiple encoders. In addition, it is possible to use one CRTC with multiple
41 // connectors such that we can display the same image on multiple monitors.
43 // For example, the following configuration shows 2 different screens being
44 // initialized separately.
45 // ------------- -------------
46 // | Connector | | Connector |
48 // ------------- -------------
51 // ------------- -------------
52 // | Encoder1 | | Encoder2 |
53 // ------------- -------------
56 // ------------- -------------
57 // | CRTC1 | | CRTC2 |
58 // ------------- -------------
60 // In the following configuration 2 different screens are associated with the
61 // same CRTC, so on scanout the same framebuffer will be displayed on both
63 // ------------- -------------
64 // | Connector | | Connector |
66 // ------------- -------------
69 // ------------- -------------
70 // | Encoder1 | | Encoder2 |
71 // ------------- -------------
74 // ----------------------
76 // ----------------------
78 // Note that it is possible to have more connectors than CRTCs which means that
79 // only a subset of connectors can be active independently, showing different
80 // framebuffers. Though, in this case, it would be possible to have all
81 // connectors active if some use the same CRTC to mirror the display.
82 class HardwareDisplayController
83 : public base::SupportsWeakPtr<HardwareDisplayController> {
85 explicit HardwareDisplayController(scoped_ptr<CrtcController> controller);
86 ~HardwareDisplayController();
88 // Performs the initial CRTC configuration. If successful, it will display the
89 // framebuffer for |primary| with |mode|.
90 bool Modeset(const OverlayPlane& primary,
91 drmModeModeInfo mode);
93 // Reconfigures the CRTC with the current surface and mode.
99 void QueueOverlayPlane(const OverlayPlane& plane);
101 // Schedules the |overlays|' framebuffers to be displayed on the next vsync
102 // event. The event will be posted on the graphics card file descriptor |fd_|
103 // and it can be read and processed by |drmHandleEvent|. That function can
104 // define the callback for the page flip event. A generic data argument will
105 // be presented to the callback. We use that argument to pass in the HDCO
106 // object the event belongs to.
108 // Between this call and the callback, the framebuffers used in this call
109 // should not be modified in any way as it would cause screen tearing if the
110 // hardware performed the flip. Note that the frontbuffer should also not
111 // be modified as it could still be displayed.
113 // Note that this function does not block. Also, this function should not be
114 // called again before the page flip occurrs.
116 // Returns true if the page flip was successfully registered, false otherwise.
117 bool SchedulePageFlip();
119 // TODO(dnicoara) This should be on the MessageLoop when Ozone can have
120 // BeginFrame can be triggered explicitly by Ozone.
121 void WaitForPageFlipEvent();
123 // Set the hardware cursor to show the contents of |surface|.
124 bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer);
128 // Moves the hardware cursor to |location|.
129 bool MoveCursor(const gfx::Point& location);
131 void AddCrtc(scoped_ptr<CrtcController> controller);
132 scoped_ptr<CrtcController> RemoveCrtc(uint32_t crtc);
133 bool HasCrtc(uint32_t crtc) const;
134 bool IsMirrored() const;
135 bool IsDisabled() const;
136 gfx::Size GetModeSize() const;
138 gfx::Point origin() const { return origin_; }
139 void set_origin(const gfx::Point& origin) { origin_ = origin; }
141 const drmModeModeInfo& get_mode() const { return mode_; };
143 uint64_t GetTimeOfLastFlip() const;
146 // Buffers need to be declared first so that they are destroyed last. Needed
147 // since the controllers may reference the buffers.
148 OverlayPlaneList current_planes_;
149 OverlayPlaneList pending_planes_;
150 scoped_refptr<ScanoutBuffer> cursor_buffer_;
152 // Stores the CRTC configuration. This is used to identify monitors and
154 ScopedVector<CrtcController> crtc_controllers_;
156 // Location of the controller on the screen.
159 // The mode used by the last modesetting operation.
160 drmModeModeInfo mode_;
164 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController);
169 #endif // UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_