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_DRM_GPU_DRM_DEVICE_H_ |
| 6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_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/drm/common/scoped_drm_types.h" |
| 23 #include "ui/ozone/platform/drm/gpu/hardware_display_plane_manager.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 struct GammaRampRGBEntry; |
| 38 |
| 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; |
| 47 |
| 48 DrmDevice(const base::FilePath& device_path, base::File file); |
| 49 |
| 50 // Open device. |
| 51 virtual bool Initialize(bool use_atomic); |
| 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 // Move the cursor on CRTC |crtc_id| to (x, y); |
| 145 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point); |
| 146 |
| 147 virtual bool CreateDumbBuffer(const SkImageInfo& info, |
| 148 uint32_t* handle, |
| 149 uint32_t* stride); |
| 150 |
| 151 virtual bool DestroyDumbBuffer(uint32_t handle); |
| 152 |
| 153 virtual bool MapDumbBuffer(uint32_t handle, size_t size, void** pixels); |
| 154 |
| 155 virtual bool UnmapDumbBuffer(void* pixels, size_t size); |
| 156 |
| 157 virtual bool CloseBufferHandle(uint32_t handle); |
| 158 |
| 159 virtual bool CommitProperties(drmModePropertySet* properties, |
| 160 uint32_t flags, |
| 161 bool is_sync, |
| 162 bool test_only, |
| 163 const PageFlipCallback& callback); |
| 164 |
| 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); |
| 168 |
| 169 virtual bool SetCapability(uint64_t capability, uint64_t value); |
| 170 |
| 171 // Drm master related |
| 172 virtual bool SetMaster(); |
| 173 virtual bool DropMaster(); |
| 174 |
| 175 int get_fd() const { return file_.GetPlatformFile(); } |
| 176 |
| 177 base::FilePath device_path() const { return device_path_; } |
| 178 |
| 179 HardwareDisplayPlaneManager* plane_manager() { return plane_manager_.get(); } |
| 180 |
| 181 protected: |
| 182 friend class base::RefCountedThreadSafe<DrmDevice>; |
| 183 |
| 184 virtual ~DrmDevice(); |
| 185 |
| 186 scoped_ptr<HardwareDisplayPlaneManager> plane_manager_; |
| 187 |
| 188 private: |
| 189 class IOWatcher; |
| 190 class PageFlipManager; |
| 191 |
| 192 // Path to DRM device. |
| 193 const base::FilePath device_path_; |
| 194 |
| 195 // DRM device. |
| 196 base::File file_; |
| 197 |
| 198 // Helper thread to perform IO listener operations. |
| 199 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 200 |
| 201 // Watcher for |fd_| listening for page flip events. |
| 202 scoped_refptr<IOWatcher> watcher_; |
| 203 |
| 204 scoped_refptr<PageFlipManager> page_flip_manager_; |
| 205 |
| 206 DISALLOW_COPY_AND_ASSIGN(DrmDevice); |
| 207 }; |
| 208 |
| 209 } // namespace ui |
| 210 |
| 211 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_DEVICE_H_ |
OLD | NEW |