Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / hardware_display_controller.h
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_DRI_HARDWARE_DISPLAY_CONTROLLER_H_
6 #define UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_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 "base/memory/scoped_vector.h"
16 #include "base/memory/weak_ptr.h"
17 #include "ui/ozone/platform/dri/overlay_plane.h"
18
19 namespace gfx {
20 class Point;
21 }
22
23 namespace ui {
24
25 class CrtcController;
26 class ScanoutBuffer;
27
28 // The HDCOz will handle modesettings and scannout operations for hardware
29 // devices.
30 //
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.
37 //
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.
42 //
43 // For example, the following configuration shows 2 different screens being
44 // initialized separately.
45 // -------------      -------------
46 // | Connector |      | Connector |
47 // |   HDMI    |      |    VGA    |
48 // -------------      -------------
49 //       ^                  ^
50 //       |                  |
51 // -------------      -------------
52 // |  Encoder1  |     |  Encoder2 |
53 // -------------      -------------
54 //       ^                  ^
55 //       |                  |
56 // -------------      -------------
57 // |   CRTC1   |      |   CRTC2   |
58 // -------------      -------------
59 //
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
62 // monitors.
63 // -------------      -------------
64 // | Connector |      | Connector |
65 // |   HDMI    |      |    VGA    |
66 // -------------      -------------
67 //       ^                  ^
68 //       |                  |
69 // -------------      -------------
70 // |  Encoder1  |     |  Encoder2 |
71 // -------------      -------------
72 //       ^                  ^
73 //       |                  |
74 //      ----------------------
75 //      |        CRTC1       |
76 //      ----------------------
77 //
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> {
84  public:
85   explicit HardwareDisplayController(scoped_ptr<CrtcController> controller);
86   ~HardwareDisplayController();
87
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);
92
93   // Reconfigures the CRTC with the current surface and mode.
94   bool Enable();
95
96   // Disables the CRTC.
97   void Disable();
98
99   void QueueOverlayPlane(const OverlayPlane& plane);
100
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.
107   //
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.
112   //
113   // Note that this function does not block. Also, this function should not be
114   // called again before the page flip occurrs.
115   //
116   // Returns true if the page flip was successfully registered, false otherwise.
117   bool SchedulePageFlip();
118
119   // TODO(dnicoara) This should be on the MessageLoop when Ozone can have
120   // BeginFrame can be triggered explicitly by Ozone.
121   void WaitForPageFlipEvent();
122
123   // Set the hardware cursor to show the contents of |surface|.
124   bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer);
125
126   bool UnsetCursor();
127
128   // Moves the hardware cursor to |location|.
129   bool MoveCursor(const gfx::Point& location);
130
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;
137
138   gfx::Point origin() const { return origin_; }
139   void set_origin(const gfx::Point& origin) { origin_ = origin; }
140
141   const drmModeModeInfo& get_mode() const { return mode_; };
142
143   uint64_t GetTimeOfLastFlip() const;
144
145  private:
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_;
151
152   // Stores the CRTC configuration. This is used to identify monitors and
153   // configure them.
154   ScopedVector<CrtcController> crtc_controllers_;
155
156   // Location of the controller on the screen.
157   gfx::Point origin_;
158
159   // The mode used by the last modesetting operation.
160   drmModeModeInfo mode_;
161
162   bool is_disabled_;
163
164   DISALLOW_COPY_AND_ASSIGN(HardwareDisplayController);
165 };
166
167 }  // namespace ui
168
169 #endif  // UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_CONTROLLER_H_