Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / ozone / platform / dri / dri_wrapper.h
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_DRI_DRI_WRAPPER_H_
6 #define UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_
7
8 #include <stdint.h>
9
10 #include <vector>
11
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"
17
18 typedef struct _drmEventContext drmEventContext;
19 typedef struct _drmModeModeInfo drmModeModeInfo;
20
21 struct SkImageInfo;
22
23 namespace ui {
24
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.
28 class DriWrapper {
29  public:
30   DriWrapper(const char* device_path);
31   virtual ~DriWrapper();
32
33   // Open device.
34   virtual void Initialize();
35
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);
40
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,
46                        uint32_t framebuffer,
47                        std::vector<uint32_t> connectors,
48                        drmModeModeInfo* mode);
49
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);
54
55   virtual bool DisableCrtc(uint32_t crtc_id);
56
57   // Returns the connector properties for |connector_id|.
58   virtual ScopedDrmConnectorPtr GetConnector(uint32_t connector_id);
59
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,
63                               uint32_t height,
64                               uint8_t depth,
65                               uint8_t bpp,
66                               uint32_t stride,
67                               uint32_t handle,
68                               uint32_t* framebuffer);
69
70   // Deregister the given |framebuffer|.
71   virtual bool RemoveFramebuffer(uint32_t framebuffer);
72
73   // Get the DRM details associated with |framebuffer|.
74   virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
75
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);
82
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,
87                                uint32_t framebuffer,
88                                const gfx::Rect& location,
89                                const gfx::RectF& source,
90                                int overlay_plane);
91
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,
96                                            const char* name);
97
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,
102                            uint64_t value);
103
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);
107
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,
113                                                    const char* name);
114
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,
118                          uint32_t handle,
119                          const gfx::Size& size);
120
121
122   // Move the cursor on CRTC |crtc_id| to (x, y);
123   virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
124
125   virtual void HandleEvent(drmEventContext& event);
126
127   virtual bool CreateDumbBuffer(const SkImageInfo& info,
128                                 uint32_t* handle,
129                                 uint32_t* stride,
130                                 void** pixels);
131
132   virtual void DestroyDumbBuffer(const SkImageInfo& info,
133                                  uint32_t handle,
134                                  uint32_t stride,
135                                  void* pixels);
136
137   // Drm master related
138   virtual bool SetMaster();
139   virtual bool DropMaster();
140
141   int get_fd() const { return fd_; }
142
143  protected:
144   // The file descriptor associated with this wrapper. All DRM operations will
145   // be performed using this FD.
146   int fd_;
147
148  private:
149   // Path to DRM device.
150   const char* device_path_;
151
152   DISALLOW_COPY_AND_ASSIGN(DriWrapper);
153 };
154
155 }  // namespace ui
156
157 #endif  // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_