Upstream version 9.38.198.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   // 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);
37
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,
43                        uint32_t framebuffer,
44                        std::vector<uint32_t> connectors,
45                        drmModeModeInfo* mode);
46
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);
51
52   virtual bool DisableCrtc(uint32_t crtc_id);
53
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,
57                               uint32_t height,
58                               uint8_t depth,
59                               uint8_t bpp,
60                               uint32_t stride,
61                               uint32_t handle,
62                               uint32_t* framebuffer);
63
64   // Deregister the given |framebuffer|.
65   virtual bool RemoveFramebuffer(uint32_t framebuffer);
66
67   // Get the DRM details associated with |framebuffer|.
68   virtual ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer);
69
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);
76
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,
81                                uint32_t framebuffer,
82                                const gfx::Rect& location,
83                                const gfx::RectF& source,
84                                int overlay_plane);
85
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,
90                                            const char* name);
91
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,
95                            uint32_t property_id,
96                            uint64_t value);
97
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,
103                                                    const char* name);
104
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,
108                          uint32_t handle,
109                          const gfx::Size& size);
110
111
112   // Move the cursor on CRTC |crtc_id| to (x, y);
113   virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
114
115   virtual void HandleEvent(drmEventContext& event);
116
117   virtual bool CreateDumbBuffer(const SkImageInfo& info,
118                                 uint32_t* handle,
119                                 uint32_t* stride,
120                                 void** pixels);
121
122   virtual void DestroyDumbBuffer(const SkImageInfo& info,
123                                  uint32_t handle,
124                                  uint32_t stride,
125                                  void* pixels);
126
127   int get_fd() const { return fd_; }
128
129  protected:
130   // The file descriptor associated with this wrapper. All DRM operations will
131   // be performed using this FD.
132   int fd_;
133
134  private:
135   DISALLOW_COPY_AND_ASSIGN(DriWrapper);
136 };
137
138 }  // namespace ui
139
140 #endif  // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_