Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / gpu / drm_device.h
blob012dde70373e9a56a20d9663f77a5aa5a411b05f
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 "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/drm/common/scoped_drm_types.h"
23 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.h"
25 typedef struct _drmEventContext drmEventContext;
26 typedef struct _drmModeModeInfo drmModeModeInfo;
28 struct SkImageInfo;
30 namespace base {
31 class SingleThreadTaskRunner;
32 } // namespace base
34 namespace ui {
36 class HardwareDisplayPlaneManager;
37 struct GammaRampRGBEntry;
39 // Wraps DRM calls into a nice interface. Used to provide different
40 // implementations of the DRM calls. For the actual implementation the DRM API
41 // would be called. In unit tests this interface would be stubbed.
42 class OZONE_EXPORT DrmDevice : public base::RefCountedThreadSafe<DrmDevice> {
43 public:
44 typedef base::Callback<void(unsigned int /* frame */,
45 unsigned int /* seconds */,
46 unsigned int /* useconds */)> PageFlipCallback;
48 DrmDevice(const base::FilePath& device_path, base::File file);
50 // Open device.
51 virtual bool Initialize(bool use_atomic);
53 // |task_runner| will be used to asynchronously page flip.
54 virtual void InitializeTaskRunner(
55 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner);
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);
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);
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);
76 virtual bool DisableCrtc(uint32_t crtc_id);
78 // Returns the connector properties for |connector_id|.
79 virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id);
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);
91 // Deregister the given |framebuffer|.
92 virtual bool RemoveFramebuffer(uint32_t framebuffer);
94 // Get the DRM details associated with |framebuffer|.
95 virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
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);
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);
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);
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);
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);
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);
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);
144 // Move the cursor on CRTC |crtc_id| to (x, y);
145 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
147 virtual bool CreateDumbBuffer(const SkImageInfo& info,
148 uint32_t* handle,
149 uint32_t* stride);
151 virtual bool DestroyDumbBuffer(uint32_t handle);
153 virtual bool MapDumbBuffer(uint32_t handle, size_t size, void** pixels);
155 virtual bool UnmapDumbBuffer(void* pixels, size_t size);
157 virtual bool CloseBufferHandle(uint32_t handle);
159 virtual bool CommitProperties(drmModePropertySet* properties,
160 uint32_t flags,
161 bool is_sync,
162 bool test_only,
163 const PageFlipCallback& callback);
165 // Set the gamma ramp for |crtc_id| to reflect the ramps in |lut|.
166 virtual bool SetGammaRamp(uint32_t crtc_id,
167 const std::vector<GammaRampRGBEntry>& lut);
169 virtual bool SetCapability(uint64_t capability, uint64_t value);
171 // Drm master related
172 virtual bool SetMaster();
173 virtual bool DropMaster();
175 int get_fd() const { return file_.GetPlatformFile(); }
177 base::FilePath device_path() const { return device_path_; }
179 HardwareDisplayPlaneManager* plane_manager() { return plane_manager_.get(); }
181 protected:
182 friend class base::RefCountedThreadSafe<DrmDevice>;
184 virtual ~DrmDevice();
186 scoped_ptr<HardwareDisplayPlaneManager> plane_manager_;
188 private:
189 class IOWatcher;
190 class PageFlipManager;
192 // Path to DRM device.
193 const base::FilePath device_path_;
195 // DRM device.
196 base::File file_;
198 // Helper thread to perform IO listener operations.
199 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
201 // Watcher for |fd_| listening for page flip events.
202 scoped_refptr<IOWatcher> watcher_;
204 scoped_refptr<PageFlipManager> page_flip_manager_;
206 DISALLOW_COPY_AND_ASSIGN(DrmDevice);
209 } // namespace ui
211 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_