• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "base/macros.h"
11 #include "ui/ozone/ozone_export.h"
12 
13 typedef struct _drmEventContext drmEventContext;
14 typedef struct _drmModeConnector drmModeConnector;
15 typedef struct _drmModeCrtc drmModeCrtc;
16 typedef struct _drmModeModeInfo drmModeModeInfo;
17 typedef struct _drmModeProperty drmModePropertyRes;
18 typedef struct _drmModePropertyBlob drmModePropertyBlobRes;
19 
20 namespace ui {
21 
22 // Wraps DRM calls into a nice interface. Used to provide different
23 // implementations of the DRM calls. For the actual implementation the DRM API
24 // would be called. In unit tests this interface would be stubbed.
25 class OZONE_EXPORT DriWrapper {
26  public:
27   DriWrapper(const char* device_path);
28   virtual ~DriWrapper();
29 
30   // Get the CRTC state. This is generally used to save state before using the
31   // CRTC. When the user finishes using the CRTC, the user should restore the
32   // CRTC to it's initial state. Use |SetCrtc| to restore the state.
33   virtual drmModeCrtc* GetCrtc(uint32_t crtc_id);
34 
35   // Frees the CRTC mode object.
36   virtual void FreeCrtc(drmModeCrtc* crtc);
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                        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, 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   // Schedules a pageflip for CRTC |crtc_id|. This function will return
68   // immediately. Upon completion of the pageflip event, the CRTC will be
69   // displaying the buffer with ID |framebuffer| and will have a DRM event
70   // queued on |fd_|. |data| is a generic pointer to some information the user
71   // will receive when processing the pageflip event.
72   virtual bool PageFlip(uint32_t crtc_id, uint32_t framebuffer, void* data);
73 
74   // Returns the property with name |name| associated with |connector|. Returns
75   // NULL if property not found. If the returned value is valid, it must be
76   // released using FreeProperty().
77   virtual drmModePropertyRes* GetProperty(drmModeConnector* connector,
78                                           const char* name);
79 
80   // Sets the value of property with ID |property_id| to |value|. The property
81   // is applied to the connector with ID |connector_id|.
82   virtual bool SetProperty(uint32_t connector_id,
83                            uint32_t property_id,
84                            uint64_t value);
85 
86   // Frees |prop| and any resources it allocated when it was created. |prop|
87   // must be a valid object.
88   virtual void FreeProperty(drmModePropertyRes* prop);
89 
90   // Return a binary blob associated with |connector|. The binary blob is
91   // associated with the property with name |name|. Return NULL if the property
92   // could not be found or if the property does not have a binary blob. If valid
93   // the returned object must be freed using FreePropertyBlob().
94   virtual drmModePropertyBlobRes* GetPropertyBlob(drmModeConnector* connector,
95                                                   const char* name);
96 
97   // Frees |blob| and any resources allocated when it was created. |blob| must
98   // be a valid object.
99   virtual void FreePropertyBlob(drmModePropertyBlobRes* blob);
100 
101   // Set the cursor to be displayed in CRTC |crtc_id|. (width, height) is the
102   // cursor size pointed by |handle|.
103   virtual bool SetCursor(uint32_t crtc_id,
104                          uint32_t handle,
105                          uint32_t width,
106                          uint32_t height);
107 
108 
109   // Move the cursor on CRTC |crtc_id| to (x, y);
110   virtual bool MoveCursor(uint32_t crtc_id, int x, int y);
111 
112   virtual void HandleEvent(drmEventContext& event);
113 
get_fd()114   int get_fd() const { return fd_; }
115 
116  protected:
117   // The file descriptor associated with this wrapper. All DRM operations will
118   // be performed using this FD.
119   int fd_;
120 
121  private:
122   DISALLOW_COPY_AND_ASSIGN(DriWrapper);
123 };
124 
125 }  // namespace ui
126 
127 #endif  // UI_OZONE_PLATFORM_DRI_DRI_WRAPPER_H_
128