ozone: fix HDPMLegacy - do the PF after overlays, also clear old overlays
[chromium-blink-merge.git] / ui / ozone / platform / dri / dri_wrapper.h
blob381459ee7e0b3476ec14f3e569ac9ab14dffc803
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_
8 #include <stdint.h>
10 #include <vector>
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;
24 struct SkImageInfo;
26 namespace base {
27 class SingleThreadTaskRunner;
28 } // namespace base
30 namespace ui {
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.
37 class DriWrapper {
38 public:
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();
46 // Open device.
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,
63 uint32_t framebuffer,
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,
80 uint32_t height,
81 uint8_t depth,
82 uint8_t bpp,
83 uint32_t stride,
84 uint32_t handle,
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
96 // queued on |fd_|.
97 virtual bool PageFlip(uint32_t crtc_id,
98 uint32_t framebuffer,
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,
108 int overlay_plane);
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,
114 const char* name);
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,
120 uint64_t value);
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,
131 const char* name);
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,
136 uint32_t handle,
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,
144 uint32_t* handle,
145 uint32_t* stride,
146 void** pixels);
148 virtual void DestroyDumbBuffer(const SkImageInfo& info,
149 uint32_t handle,
150 uint32_t stride,
151 void* pixels);
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(); }
161 protected:
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
165 int fd_;
167 scoped_ptr<HardwareDisplayPlaneManager> plane_manager_;
169 private:
170 class IOWatcher;
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);
184 } // namespace ui
186 #endif // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_