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();
33 // Get the CRTC state. This is generally used to save state before using the
34 // CRTC. When the user finishes using the CRTC, the user should restore the
35 // CRTC to it's initial state. Use |SetCrtc| to restore the state.
36 virtual ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id);
38 // Used to configure CRTC with ID |crtc_id| to use the connector in
39 // |connectors|. The CRTC will be configured with mode |mode| and will display
40 // the framebuffer with ID |framebuffer|. Before being able to display the
41 // framebuffer, it should be registered with the CRTC using |AddFramebuffer|.
42 virtual bool SetCrtc(uint32_t crtc_id,
44 std::vector<uint32_t> connectors,
45 drmModeModeInfo* mode);
47 // Used to set a specific configuration to the CRTC. Normally this function
48 // would be called with a CRTC saved state (from |GetCrtc|) to restore it to
49 // its original configuration.
50 virtual bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors);
52 virtual bool DisableCrtc(uint32_t crtc_id);
54 // Register a buffer with the CRTC. On successful registration, the CRTC will
55 // assign a framebuffer ID to |framebuffer|.
56 virtual bool AddFramebuffer(uint32_t width,
62 uint32_t* framebuffer);
64 // Deregister the given |framebuffer|.
65 virtual bool RemoveFramebuffer(uint32_t framebuffer);
67 // Get the DRM details associated with |framebuffer|.
68 virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
70 // Schedules a pageflip for CRTC |crtc_id|. This function will return
71 // immediately. Upon completion of the pageflip event, the CRTC will be
72 // displaying the buffer with ID |framebuffer| and will have a DRM event
73 // queued on |fd_|. |data| is a generic pointer to some information the user
74 // will receive when processing the pageflip event.
75 virtual bool PageFlip(uint32_t crtc_id, uint32_t framebuffer, void* data);
77 // Schedule an overlay to be show during the page flip for CRTC |crtc_id|.
78 // |source| location from |framebuffer| will be shown on overlay
79 // |overlay_plane|, in the bounds specified by |location| on the screen.
80 virtual bool PageFlipOverlay(uint32_t crtc_id,
82 const gfx::Rect& location,
83 const gfx::RectF& source,
86 // Returns the property with name |name| associated with |connector|. Returns
87 // NULL if property not found. If the returned value is valid, it must be
88 // released using FreeProperty().
89 virtual ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector,
92 // Sets the value of property with ID |property_id| to |value|. The property
93 // is applied to the connector with ID |connector_id|.
94 virtual bool SetProperty(uint32_t connector_id,
98 // Return a binary blob associated with |connector|. The binary blob is
99 // associated with the property with name |name|. Return NULL if the property
100 // could not be found or if the property does not have a binary blob. If valid
101 // the returned object must be freed using FreePropertyBlob().
102 virtual ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector,
105 // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
106 // cursor size pointed by |handle|.
107 virtual bool SetCursor(uint32_t crtc_id,
109 const gfx::Size& size);
112 // Move the cursor on CRTC |crtc_id| to (x, y);
113 virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
115 virtual void HandleEvent(drmEventContext& event);
117 virtual bool CreateDumbBuffer(const SkImageInfo& info,
122 virtual void DestroyDumbBuffer(const SkImageInfo& info,
127 int get_fd() const { return fd_; }
130 // The file descriptor associated with this wrapper. All DRM operations will
131 // be performed using this FD.
135 DISALLOW_COPY_AND_ASSIGN(DriWrapper);
140 #endif // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_