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/macros.h"
13 #include "ui/gfx/overlay_transform.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/rect_f.h"
16 #include "ui/ozone/platform/dri/scoped_drm_types.h"
18 typedef struct _drmEventContext drmEventContext;
19 typedef struct _drmModeModeInfo drmModeModeInfo;
25 // Wraps DRM calls into a nice interface. Used to provide different
26 // implementations of the DRM calls. For the actual implementation the DRM API
27 // would be called. In unit tests this interface would be stubbed.
30 DriWrapper(const char* device_path);
31 virtual ~DriWrapper();
34 virtual void Initialize();
36 // Get the CRTC state. This is generally used to save state before using the
37 // CRTC. When the user finishes using the CRTC, the user should restore the
38 // CRTC to it's initial state. Use |SetCrtc| to restore the state.
39 virtual ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id);
41 // Used to configure CRTC with ID |crtc_id| to use the connector in
42 // |connectors|. The CRTC will be configured with mode |mode| and will display
43 // the framebuffer with ID |framebuffer|. Before being able to display the
44 // framebuffer, it should be registered with the CRTC using |AddFramebuffer|.
45 virtual bool SetCrtc(uint32_t crtc_id,
47 std::vector<uint32_t> connectors,
48 drmModeModeInfo* mode);
50 // Used to set a specific configuration to the CRTC. Normally this function
51 // would be called with a CRTC saved state (from |GetCrtc|) to restore it to
52 // its original configuration.
53 virtual bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors);
55 virtual bool DisableCrtc(uint32_t crtc_id);
57 // Returns the connector properties for |connector_id|.
58 virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id);
60 // Register a buffer with the CRTC. On successful registration, the CRTC will
61 // assign a framebuffer ID to |framebuffer|.
62 virtual bool AddFramebuffer(uint32_t width,
68 uint32_t* framebuffer);
70 // Deregister the given |framebuffer|.
71 virtual bool RemoveFramebuffer(uint32_t framebuffer);
73 // Get the DRM details associated with |framebuffer|.
74 virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
76 // Schedules a pageflip for CRTC |crtc_id|. This function will return
77 // immediately. Upon completion of the pageflip event, the CRTC will be
78 // displaying the buffer with ID |framebuffer| and will have a DRM event
79 // queued on |fd_|. |data| is a generic pointer to some information the user
80 // will receive when processing the pageflip event.
81 virtual bool PageFlip(uint32_t crtc_id, uint32_t framebuffer, void* data);
83 // Schedule an overlay to be show during the page flip for CRTC |crtc_id|.
84 // |source| location from |framebuffer| will be shown on overlay
85 // |overlay_plane|, in the bounds specified by |location| on the screen.
86 virtual bool PageFlipOverlay(uint32_t crtc_id,
88 const gfx::Rect& location,
89 const gfx::RectF& source,
92 // Returns the property with name |name| associated with |connector|. Returns
93 // NULL if property not found. If the returned value is valid, it must be
94 // released using FreeProperty().
95 virtual ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector,
98 // Sets the value of property with ID |property_id| to |value|. The property
99 // is applied to the connector with ID |connector_id|.
100 virtual bool SetProperty(uint32_t connector_id,
101 uint32_t property_id,
104 // Can be used to query device/driver |capability|. Sets the value of
105 // |capability to |value|. Returns true in case of a succesful query.
106 virtual bool GetCapability(uint64_t capability, uint64_t* value);
108 // Return a binary blob associated with |connector|. The binary blob is
109 // associated with the property with name |name|. Return NULL if the property
110 // could not be found or if the property does not have a binary blob. If valid
111 // the returned object must be freed using FreePropertyBlob().
112 virtual ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector,
115 // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
116 // cursor size pointed by |handle|.
117 virtual bool SetCursor(uint32_t crtc_id,
119 const gfx::Size& size);
122 // Move the cursor on CRTC |crtc_id| to (x, y);
123 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
125 virtual void HandleEvent(drmEventContext& event);
127 virtual bool CreateDumbBuffer(const SkImageInfo& info,
132 virtual void DestroyDumbBuffer(const SkImageInfo& info,
137 // Drm master related
138 virtual bool SetMaster();
139 virtual bool DropMaster();
141 int get_fd() const { return fd_; }
144 // The file descriptor associated with this wrapper. All DRM operations will
145 // be performed using this FD.
149 // Path to DRM device.
150 const char* device_path_;
152 DISALLOW_COPY_AND_ASSIGN(DriWrapper);
157 #endif // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_