Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / ozone / dri / dri_wrapper.h
1 // Copyright 2013 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_GFX_OZONE_DRI_DRI_WRAPPER_H_
6 #define UI_GFX_OZONE_DRI_DRI_WRAPPER_H_
7
8 #include <stdint.h>
9
10 #include "base/basictypes.h"
11 #include "ui/gfx/gfx_export.h"
12
13 typedef struct _drmModeCrtc drmModeCrtc;
14 typedef struct _drmModeModeInfo drmModeModeInfo;
15
16 namespace gfx {
17
18 // Wraps DRM calls into a nice interface. Used to provide different
19 // implementations of the DRM calls. For the actual implementation the DRM API
20 // would be called. In unit tests this interface would be stubbed.
21 class GFX_EXPORT DriWrapper {
22  public:
23   DriWrapper(const char* device_path);
24   virtual ~DriWrapper();
25
26   // Get the CRTC state. This is generally used to save state before using the
27   // CRTC. When the user finishes using the CRTC, the user should restore the
28   // CRTC to it's initial state. Use |SetCrtc| to restore the state.
29   virtual drmModeCrtc* GetCrtc(uint32_t crtc_id);
30
31   // Frees the CRTC mode object.
32   virtual void FreeCrtc(drmModeCrtc* crtc);
33
34   // Used to configure CRTC with ID |crtc_id| to use the connector in
35   // |connectors|. The CRTC will be configured with mode |mode| and will display
36   // the framebuffer with ID |framebuffer|. Before being able to display the
37   // framebuffer, it should be registered with the CRTC using |AddFramebuffer|.
38   virtual bool SetCrtc(uint32_t crtc_id,
39                        uint32_t framebuffer,
40                        uint32_t* connectors,
41                        drmModeModeInfo* mode);
42
43   // Used to set a specific configuration to the CRTC. Normally this function
44   // would be called with a CRTC saved state (from |GetCrtc|) to restore it to
45   // its original configuration.
46   virtual bool SetCrtc(drmModeCrtc* crtc, uint32_t* connectors);
47
48   // Register a buffer with the CRTC. On successful registration, the CRTC will
49   // assign a framebuffer ID to |framebuffer|.
50   virtual bool AddFramebuffer(const drmModeModeInfo& mode,
51                               uint8_t depth,
52                               uint8_t bpp,
53                               uint32_t stride,
54                               uint32_t handle,
55                               uint32_t* framebuffer);
56
57   // Deregister the given |framebuffer|.
58   virtual bool RemoveFramebuffer(uint32_t framebuffer);
59
60   // Schedules a pageflip for CRTC |crtc_id|. This function will return
61   // immediately. Upon completion of the pageflip event, the CRTC will be
62   // displaying the buffer with ID |framebuffer| and will have a DRM event
63   // queued on |fd_|. |data| is a generic pointer to some information the user
64   // will receive when processing the pageflip event.
65   virtual bool PageFlip(uint32_t crtc_id, uint32_t framebuffer, void* data);
66
67   // Sets the value of property with ID |property_id| to |value|. The property
68   // is applied to the connector with ID |connector_id|.
69   virtual bool ConnectorSetProperty(uint32_t connector_id,
70                                     uint32_t property_id,
71                                     uint64_t value);
72
73   // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
74   // cursor size pointed by |handle|.
75   virtual bool SetCursor(uint32_t crtc_id,
76                          uint32_t handle,
77                          uint32_t width,
78                          uint32_t height);
79
80
81   // Move the cursor on CRTC |crtc_id| to (x, y);
82   virtual bool MoveCursor(uint32_t crtc_id, int x, int y);
83
84   int get_fd() const { return fd_; }
85
86  protected:
87   // The file descriptor associated with this wrapper. All DRM operations will
88   // be performed using this FD.
89   int fd_;
90
91  private:
92   DISALLOW_COPY_AND_ASSIGN(DriWrapper);
93 };
94
95 }  // namespace gfx
96
97 #endif  // UI_GFX_OZONE_DRI_DRI_WRAPPER_H_