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_DRI_WRAPPER_H_
6 #define UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/rect_f.h"
17 #include "ui/gfx/overlay_transform.h"
18 #include "ui/ozone/platform/dri/hardware_display_plane_manager.h"
19 #include "ui/ozone/platform/dri/scoped_drm_types.h"
21 typedef struct _drmEventContext drmEventContext
;
22 typedef struct _drmModeModeInfo drmModeModeInfo
;
27 class SingleThreadTaskRunner
;
32 class HardwareDisplayPlaneManager
;
34 // Wraps DRM calls into a nice interface. Used to provide different
35 // implementations of the DRM calls. For the actual implementation the DRM API
36 // would be called. In unit tests this interface would be stubbed.
39 typedef base::Callback
<void(unsigned int /* frame */,
40 unsigned int /* seconds */,
41 unsigned int /* useconds */)> PageFlipCallback
;
43 DriWrapper(const char* device_path
);
44 virtual ~DriWrapper();
47 virtual void Initialize();
49 // |task_runner| will be used to asynchronously page flip.
50 virtual void InitializeTaskRunner(
51 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
);
53 // Get the CRTC state. This is generally used to save state before using the
54 // CRTC. When the user finishes using the CRTC, the user should restore the
55 // CRTC to it's initial state. Use |SetCrtc| to restore the state.
56 virtual ScopedDrmCrtcPtr
GetCrtc(uint32_t crtc_id
);
58 // Used to configure CRTC with ID |crtc_id| to use the connector in
59 // |connectors|. The CRTC will be configured with mode |mode| and will display
60 // the framebuffer with ID |framebuffer|. Before being able to display the
61 // framebuffer, it should be registered with the CRTC using |AddFramebuffer|.
62 virtual bool SetCrtc(uint32_t crtc_id
,
64 std::vector
<uint32_t> connectors
,
65 drmModeModeInfo
* mode
);
67 // Used to set a specific configuration to the CRTC. Normally this function
68 // would be called with a CRTC saved state (from |GetCrtc|) to restore it to
69 // its original configuration.
70 virtual bool SetCrtc(drmModeCrtc
* crtc
, std::vector
<uint32_t> connectors
);
72 virtual bool DisableCrtc(uint32_t crtc_id
);
74 // Returns the connector properties for |connector_id|.
75 virtual ScopedDrmConnectorPtr
GetConnector(uint32_t connector_id
);
77 // Register a buffer with the CRTC. On successful registration, the CRTC will
78 // assign a framebuffer ID to |framebuffer|.
79 virtual bool AddFramebuffer(uint32_t width
,
85 uint32_t* framebuffer
);
87 // Deregister the given |framebuffer|.
88 virtual bool RemoveFramebuffer(uint32_t framebuffer
);
90 // Get the DRM details associated with |framebuffer|.
91 virtual ScopedDrmFramebufferPtr
GetFramebuffer(uint32_t framebuffer
);
93 // Schedules a pageflip for CRTC |crtc_id|. This function will return
94 // immediately. Upon completion of the pageflip event, the CRTC will be
95 // displaying the buffer with ID |framebuffer| and will have a DRM event
97 virtual bool PageFlip(uint32_t crtc_id
,
99 const PageFlipCallback
& callback
);
101 // Schedule an overlay to be show during the page flip for CRTC |crtc_id|.
102 // |source| location from |framebuffer| will be shown on overlay
103 // |overlay_plane|, in the bounds specified by |location| on the screen.
104 virtual bool PageFlipOverlay(uint32_t crtc_id
,
105 uint32_t framebuffer
,
106 const gfx::Rect
& location
,
107 const gfx::Rect
& source
,
110 // Returns the property with name |name| associated with |connector|. Returns
111 // NULL if property not found. If the returned value is valid, it must be
112 // released using FreeProperty().
113 virtual ScopedDrmPropertyPtr
GetProperty(drmModeConnector
* connector
,
116 // Sets the value of property with ID |property_id| to |value|. The property
117 // is applied to the connector with ID |connector_id|.
118 virtual bool SetProperty(uint32_t connector_id
,
119 uint32_t property_id
,
122 // Can be used to query device/driver |capability|. Sets the value of
123 // |capability to |value|. Returns true in case of a succesful query.
124 virtual bool GetCapability(uint64_t capability
, uint64_t* value
);
126 // Return a binary blob associated with |connector|. The binary blob is
127 // associated with the property with name |name|. Return NULL if the property
128 // could not be found or if the property does not have a binary blob. If valid
129 // the returned object must be freed using FreePropertyBlob().
130 virtual ScopedDrmPropertyBlobPtr
GetPropertyBlob(drmModeConnector
* connector
,
133 // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
134 // cursor size pointed by |handle|.
135 virtual bool SetCursor(uint32_t crtc_id
,
137 const gfx::Size
& size
);
140 // Move the cursor on CRTC |crtc_id| to (x, y);
141 virtual bool MoveCursor(uint32_t crtc_id
, const gfx::Point
& point
);
143 virtual bool CreateDumbBuffer(const SkImageInfo
& info
,
148 virtual void DestroyDumbBuffer(const SkImageInfo
& info
,
153 // Drm master related
154 virtual bool SetMaster();
155 virtual bool DropMaster();
157 int get_fd() const { return fd_
; }
159 HardwareDisplayPlaneManager
* plane_manager() { return plane_manager_
.get(); }
162 // The file descriptor associated with this wrapper. All DRM operations will
163 // be performed using this FD.
164 // TODO(dnicoara) Make this a base::File
167 scoped_ptr
<HardwareDisplayPlaneManager
> plane_manager_
;
172 // Path to DRM device.
173 const char* device_path_
;
175 // Helper thread to perform IO listener operations.
176 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
178 // Watcher for |fd_| listening for page flip events.
179 scoped_refptr
<IOWatcher
> watcher_
;
181 DISALLOW_COPY_AND_ASSIGN(DriWrapper
);
186 #endif // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_