Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_device.h
blob7a1a98f50d2dbabbe6a30500d27cc6ef10ce31da
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_DRM_DEVICE_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_
8 #include <stdint.h>
10 #include <vector>
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 "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/rect_f.h"
19 #include "ui/gfx/overlay_transform.h"
20 #include "ui/ozone/ozone_export.h"
21 #include "ui/ozone/platform/drm/common/scoped_drm_types.h"
22 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.h"
24 typedef struct _drmEventContext drmEventContext;
25 typedef struct _drmModeModeInfo drmModeModeInfo;
27 struct SkImageInfo;
29 namespace base {
30 class SingleThreadTaskRunner;
31 } // namespace base
33 namespace ui {
35 class HardwareDisplayPlaneManager;
36 struct GammaRampRGBEntry;
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 DrmDevice : public base::RefCountedThreadSafe<DrmDevice> {
42 public:
43 typedef base::Callback<void(unsigned int /* frame */,
44 unsigned int /* seconds */,
45 unsigned int /* useconds */)> PageFlipCallback;
47 DrmDevice(const base::FilePath& device_path, base::File file);
49 // Open device.
50 virtual bool Initialize(bool use_atomic);
52 // |task_runner| will be used to asynchronously page flip.
53 virtual void InitializeTaskRunner(
54 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
56 // Get the CRTC state. This is generally used to save state before using the
57 // CRTC. When the user finishes using the CRTC, the user should restore the
58 // CRTC to it's initial state. Use |SetCrtc| to restore the state.
59 virtual ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id);
61 // Used to configure CRTC with ID |crtc_id| to use the connector in
62 // |connectors|. The CRTC will be configured with mode |mode| and will display
63 // the framebuffer with ID |framebuffer|. Before being able to display the
64 // framebuffer, it should be registered with the CRTC using |AddFramebuffer|.
65 virtual bool SetCrtc(uint32_t crtc_id,
66 uint32_t framebuffer,
67 std::vector<uint32_t> connectors,
68 drmModeModeInfo* mode);
70 // Used to set a specific configuration to the CRTC. Normally this function
71 // would be called with a CRTC saved state (from |GetCrtc|) to restore it to
72 // its original configuration.
73 virtual bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors);
75 virtual bool DisableCrtc(uint32_t crtc_id);
77 // Returns the connector properties for |connector_id|.
78 virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id);
80 // Register a buffer with the CRTC. On successful registration, the CRTC will
81 // assign a framebuffer ID to |framebuffer|.
82 virtual bool AddFramebuffer(uint32_t width,
83 uint32_t height,
84 uint8_t depth,
85 uint8_t bpp,
86 uint32_t stride,
87 uint32_t handle,
88 uint32_t* framebuffer);
90 // Deregister the given |framebuffer|.
91 virtual bool RemoveFramebuffer(uint32_t framebuffer);
93 // Get the DRM details associated with |framebuffer|.
94 virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
96 // Schedules a pageflip for CRTC |crtc_id|. This function will return
97 // immediately. Upon completion of the pageflip event, the CRTC will be
98 // displaying the buffer with ID |framebuffer| and will have a DRM event
99 // queued on |fd_|.
100 virtual bool PageFlip(uint32_t crtc_id,
101 uint32_t framebuffer,
102 const PageFlipCallback& callback);
104 // Schedule an overlay to be show during the page flip for CRTC |crtc_id|.
105 // |source| location from |framebuffer| will be shown on overlay
106 // |overlay_plane|, in the bounds specified by |location| on the screen.
107 virtual bool PageFlipOverlay(uint32_t crtc_id,
108 uint32_t framebuffer,
109 const gfx::Rect& location,
110 const gfx::Rect& source,
111 int overlay_plane);
113 // Returns the property with name |name| associated with |connector|. Returns
114 // NULL if property not found. If the returned value is valid, it must be
115 // released using FreeProperty().
116 virtual ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector,
117 const char* name);
119 // Sets the value of property with ID |property_id| to |value|. The property
120 // is applied to the connector with ID |connector_id|.
121 virtual bool SetProperty(uint32_t connector_id,
122 uint32_t property_id,
123 uint64_t value);
125 // Can be used to query device/driver |capability|. Sets the value of
126 // |capability to |value|. Returns true in case of a succesful query.
127 virtual bool GetCapability(uint64_t capability, uint64_t* value);
129 // Return a binary blob associated with |connector|. The binary blob is
130 // associated with the property with name |name|. Return NULL if the property
131 // could not be found or if the property does not have a binary blob. If valid
132 // the returned object must be freed using FreePropertyBlob().
133 virtual ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector,
134 const char* name);
136 // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
137 // cursor size pointed by |handle|.
138 virtual bool SetCursor(uint32_t crtc_id,
139 uint32_t handle,
140 const gfx::Size& size);
142 // Move the cursor on CRTC |crtc_id| to (x, y);
143 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
145 virtual bool CreateDumbBuffer(const SkImageInfo& info,
146 uint32_t* handle,
147 uint32_t* stride);
149 virtual bool DestroyDumbBuffer(uint32_t handle);
151 virtual bool MapDumbBuffer(uint32_t handle, size_t size, void** pixels);
153 virtual bool UnmapDumbBuffer(void* pixels, size_t size);
155 virtual bool CloseBufferHandle(uint32_t handle);
157 virtual bool CommitProperties(drmModeAtomicReq* properties,
158 uint32_t flags,
159 uint32_t crtc_count,
160 const PageFlipCallback& callback);
162 // Set the gamma ramp for |crtc_id| to reflect the ramps in |lut|.
163 virtual bool SetGammaRamp(uint32_t crtc_id,
164 const std::vector<GammaRampRGBEntry>& lut);
166 virtual bool SetCapability(uint64_t capability, uint64_t value);
168 // Drm master related
169 virtual bool SetMaster();
170 virtual bool DropMaster();
172 int get_fd() const { return file_.GetPlatformFile(); }
174 base::FilePath device_path() const { return device_path_; }
176 HardwareDisplayPlaneManager* plane_manager() { return plane_manager_.get(); }
178 protected:
179 friend class base::RefCountedThreadSafe<DrmDevice>;
181 virtual ~DrmDevice();
183 scoped_ptr<HardwareDisplayPlaneManager> plane_manager_;
185 private:
186 class IOWatcher;
187 class PageFlipManager;
189 // Path to DRM device.
190 const base::FilePath device_path_;
192 // DRM device.
193 base::File file_;
195 // Helper thread to perform IO listener operations.
196 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
198 // Watcher for |fd_| listening for page flip events.
199 scoped_refptr<IOWatcher> watcher_;
201 scoped_refptr<PageFlipManager> page_flip_manager_;
203 DISALLOW_COPY_AND_ASSIGN(DrmDevice);
206 } // namespace ui
208 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_