OLD | NEW |
| (Empty) |
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_DRI_WRAPPER_H_ | |
6 #define UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/files/file.h" | |
14 #include "base/files/file_path.h" | |
15 #include "base/macros.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "base/memory/scoped_vector.h" | |
18 #include "ui/gfx/geometry/rect.h" | |
19 #include "ui/gfx/geometry/rect_f.h" | |
20 #include "ui/gfx/overlay_transform.h" | |
21 #include "ui/ozone/ozone_export.h" | |
22 #include "ui/ozone/platform/dri/hardware_display_plane_manager.h" | |
23 #include "ui/ozone/platform/dri/scoped_drm_types.h" | |
24 | |
25 typedef struct _drmEventContext drmEventContext; | |
26 typedef struct _drmModeModeInfo drmModeModeInfo; | |
27 | |
28 struct SkImageInfo; | |
29 | |
30 namespace base { | |
31 class SingleThreadTaskRunner; | |
32 } // namespace base | |
33 | |
34 namespace ui { | |
35 | |
36 class HardwareDisplayPlaneManager; | |
37 | |
38 // Wraps DRM calls into a nice interface. Used to provide different | |
39 // implementations of the DRM calls. For the actual implementation the DRM API | |
40 // would be called. In unit tests this interface would be stubbed. | |
41 class OZONE_EXPORT DriWrapper : public base::RefCountedThreadSafe<DriWrapper> { | |
42 public: | |
43 typedef base::Callback<void(unsigned int /* frame */, | |
44 unsigned int /* seconds */, | |
45 unsigned int /* useconds */)> PageFlipCallback; | |
46 | |
47 DriWrapper(const base::FilePath& device_path); | |
48 DriWrapper(const base::FilePath& device_path, base::File file); | |
49 | |
50 // Open device. | |
51 virtual bool Initialize(); | |
52 | |
53 // |task_runner| will be used to asynchronously page flip. | |
54 virtual void InitializeTaskRunner( | |
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | |
56 | |
57 // Get the CRTC state. This is generally used to save state before using the | |
58 // CRTC. When the user finishes using the CRTC, the user should restore the | |
59 // CRTC to it's initial state. Use |SetCrtc| to restore the state. | |
60 virtual ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id); | |
61 | |
62 // Used to configure CRTC with ID |crtc_id| to use the connector in | |
63 // |connectors|. The CRTC will be configured with mode |mode| and will display | |
64 // the framebuffer with ID |framebuffer|. Before being able to display the | |
65 // framebuffer, it should be registered with the CRTC using |AddFramebuffer|. | |
66 virtual bool SetCrtc(uint32_t crtc_id, | |
67 uint32_t framebuffer, | |
68 std::vector<uint32_t> connectors, | |
69 drmModeModeInfo* mode); | |
70 | |
71 // Used to set a specific configuration to the CRTC. Normally this function | |
72 // would be called with a CRTC saved state (from |GetCrtc|) to restore it to | |
73 // its original configuration. | |
74 virtual bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors); | |
75 | |
76 virtual bool DisableCrtc(uint32_t crtc_id); | |
77 | |
78 // Returns the connector properties for |connector_id|. | |
79 virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id); | |
80 | |
81 // Register a buffer with the CRTC. On successful registration, the CRTC will | |
82 // assign a framebuffer ID to |framebuffer|. | |
83 virtual bool AddFramebuffer(uint32_t width, | |
84 uint32_t height, | |
85 uint8_t depth, | |
86 uint8_t bpp, | |
87 uint32_t stride, | |
88 uint32_t handle, | |
89 uint32_t* framebuffer); | |
90 | |
91 // Deregister the given |framebuffer|. | |
92 virtual bool RemoveFramebuffer(uint32_t framebuffer); | |
93 | |
94 // Get the DRM details associated with |framebuffer|. | |
95 virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer); | |
96 | |
97 // Schedules a pageflip for CRTC |crtc_id|. This function will return | |
98 // immediately. Upon completion of the pageflip event, the CRTC will be | |
99 // displaying the buffer with ID |framebuffer| and will have a DRM event | |
100 // queued on |fd_|. | |
101 virtual bool PageFlip(uint32_t crtc_id, | |
102 uint32_t framebuffer, | |
103 bool is_sync, | |
104 const PageFlipCallback& callback); | |
105 | |
106 // Schedule an overlay to be show during the page flip for CRTC |crtc_id|. | |
107 // |source| location from |framebuffer| will be shown on overlay | |
108 // |overlay_plane|, in the bounds specified by |location| on the screen. | |
109 virtual bool PageFlipOverlay(uint32_t crtc_id, | |
110 uint32_t framebuffer, | |
111 const gfx::Rect& location, | |
112 const gfx::Rect& source, | |
113 int overlay_plane); | |
114 | |
115 // Returns the property with name |name| associated with |connector|. Returns | |
116 // NULL if property not found. If the returned value is valid, it must be | |
117 // released using FreeProperty(). | |
118 virtual ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector, | |
119 const char* name); | |
120 | |
121 // Sets the value of property with ID |property_id| to |value|. The property | |
122 // is applied to the connector with ID |connector_id|. | |
123 virtual bool SetProperty(uint32_t connector_id, | |
124 uint32_t property_id, | |
125 uint64_t value); | |
126 | |
127 // Can be used to query device/driver |capability|. Sets the value of | |
128 // |capability to |value|. Returns true in case of a succesful query. | |
129 virtual bool GetCapability(uint64_t capability, uint64_t* value); | |
130 | |
131 // Return a binary blob associated with |connector|. The binary blob is | |
132 // associated with the property with name |name|. Return NULL if the property | |
133 // could not be found or if the property does not have a binary blob. If valid | |
134 // the returned object must be freed using FreePropertyBlob(). | |
135 virtual ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector, | |
136 const char* name); | |
137 | |
138 // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the | |
139 // cursor size pointed by |handle|. | |
140 virtual bool SetCursor(uint32_t crtc_id, | |
141 uint32_t handle, | |
142 const gfx::Size& size); | |
143 | |
144 | |
145 // Move the cursor on CRTC |crtc_id| to (x, y); | |
146 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point); | |
147 | |
148 virtual bool CreateDumbBuffer(const SkImageInfo& info, | |
149 uint32_t* handle, | |
150 uint32_t* stride, | |
151 void** pixels); | |
152 | |
153 virtual void DestroyDumbBuffer(const SkImageInfo& info, | |
154 uint32_t handle, | |
155 uint32_t stride, | |
156 void* pixels); | |
157 | |
158 // Drm master related | |
159 virtual bool SetMaster(); | |
160 virtual bool DropMaster(); | |
161 | |
162 int get_fd() const { return file_.GetPlatformFile(); } | |
163 | |
164 base::FilePath device_path() const { return device_path_; } | |
165 | |
166 HardwareDisplayPlaneManager* plane_manager() { return plane_manager_.get(); } | |
167 | |
168 protected: | |
169 friend class base::RefCountedThreadSafe<DriWrapper>; | |
170 | |
171 virtual ~DriWrapper(); | |
172 | |
173 scoped_ptr<HardwareDisplayPlaneManager> plane_manager_; | |
174 | |
175 private: | |
176 class IOWatcher; | |
177 | |
178 // Path to DRM device. | |
179 const base::FilePath device_path_; | |
180 | |
181 // DRM device. | |
182 base::File file_; | |
183 | |
184 // Helper thread to perform IO listener operations. | |
185 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
186 | |
187 // Watcher for |fd_| listening for page flip events. | |
188 scoped_refptr<IOWatcher> watcher_; | |
189 | |
190 DISALLOW_COPY_AND_ASSIGN(DriWrapper); | |
191 }; | |
192 | |
193 } // namespace ui | |
194 | |
195 #endif // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_ | |
OLD | NEW |