summaryrefslogtreecommitdiff
path: root/sdm/include/core/core_interface.h
blob: 21651554398a8f85ad90e7fd473dc23176bf3442 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* Copyright (c) 2014 - 2016, 2018 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above
*       copyright notice, this list of conditions and the following
*       disclaimer in the documentation and/or other materials provided
*       with the distribution.
*     * Neither the name of The Linux Foundation nor the names of its
*       contributors may be used to endorse or promote products derived
*       from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*! @file core_interface.h
  @brief Interface file for core of the display subsystem.

  @details Display core is primarily used for loading and unloading different display device
  components viz primary, external and virtual. Display core is a statically linked library which
  runs in caller's process context.
*/
#ifndef __CORE_INTERFACE_H__
#define __CORE_INTERFACE_H__

#include <stdint.h>
#include <map>
#include <vector>

#include "display_interface.h"
#include "sdm_types.h"
#include "buffer_allocator.h"
#include "buffer_sync_handler.h"
#include "socket_handler.h"

/*! @brief Display manager interface version.

  @details Display manager interfaces are version tagged to maintain backward compatibility. This
  version is supplied as a default argument during display core initialization.

  Client may use an older version of interfaces and link to a higher version of display manager
  library, but vice versa is not allowed.

  A 32-bit client must use 32-bit display core library and a 64-bit client must use 64-bit display
  core library.

  Display manager interfaces follow default data structures alignment. Client must not override the
  default padding rules while using these interfaces.

  @warning It is assumed that client upgrades or downgrades display core interface all at once
  and recompile all binaries which use these interfaces. Mix and match of these interfaces can
  lead to unpredictable behaviour.

  @sa CoreInterface::CreateCore
*/
#define SDM_REVISION_MAJOR (1)
#define SDM_REVISION_MINOR (0)

#define SDM_VERSION_TAG ((uint32_t) ((SDM_REVISION_MAJOR << 24) | (SDM_REVISION_MINOR << 16) | \
                                    (sizeof(SDMCompatibility) << 8) | sizeof(int *)))

namespace sdm {

/*! @brief This enum represents max bandwidth limit mode.

  @sa DisplayInterface::SetMaxBandwidthMode
*/
enum HWBwModes {
  kBwDefault,      //!< Default state. No change in device bandwidth limit.
  kBwCamera,       //!< Camera is on. Bandwidth limit should be reduced accordingly.
  kBwVFlip,        //!< VFlip is required. Reduce bandwidth limit accordingly.
  kBwHFlip,        //!< HFlip is required.  Reduce bandwidth limit accordingly.
  kBwModeMax,      //!< Limiter for maximum available bandwidth modes.
};

/*! @brief Information on hardware for the first display

  @details This structure returns the display type of the first display on the device
  (internal display or HDMI etc) and whether it is currently connected.
*/
struct HWDisplayInterfaceInfo {
  DisplayType type = kDisplayTypeMax;
  bool is_connected = false;
};

/*! @brief Information about a single display/monitor/screen

  @details This structure returns the display configuration and status of a single display. A
  list of this structure type 'HWDisplaysInfo' is used to return information on all available
  displays. See \link HWDisplaysInfo \endlink
*/
struct HWDisplayInfo {
  int32_t display_id = -1;                     //!< ID of this display (Display ID).
  DisplayType display_type = kDisplayTypeMax;  //!< Type of display: BuiltIn/Pluggable/Virtual
  bool is_connected = false;                   //!< Connection status of the display.
  bool is_primary = false;                     //!< True only if this is the main display of the
                                               //!< device.
  bool is_wb_ubwc_supported = true;            //!< check hardware wb ubwc support
};

/*! @brief Information on all displays as a map with display_id as key.

  @details This map returns the display configuration and status of all displays.
*/
typedef std::map<int32_t, HWDisplayInfo> HWDisplaysInfo;

/*! @brief Display core interface.

  @details This class defines display core interfaces. It contains methods which client shall use
  to create/destroy different display devices. This interface is created during display core
  CreateCore() and remains valid until DestroyCore().

  @sa CoreInterface::CreateCore
  @sa CoreInterface::DestroyCore
*/
class CoreInterface {
 public:
  /*! @brief Method to create and get handle to display core interface.

    @details This method is the entry point into the display core. Client can create and operate on
    different display devices only through a valid interface handle obtained using this method. An
    object of display core is created and handle to this object is returned via output parameter.
    This interface shall be called only once.

    @param[in] buffer_allocator \link BufferAllocator \endlink
    @param[in] buffer_sync_handler \link BufferSyncHandler \endlink
    @param[in] socket_handler \link SocketHandler \endlink
    @param[out] interface \link CoreInterface \endlink
    @param[in] version \link SDM_VERSION_TAG \endlink. Client must not override this argument.

    @return \link DisplayError \endlink

    @sa DestroyCore
  */
  static DisplayError CreateCore(BufferAllocator *buffer_allocator,
                                 BufferSyncHandler *buffer_sync_handler,
                                 SocketHandler *socket_handler, CoreInterface **interface,
                                 uint32_t version = SDM_VERSION_TAG);

  /*! @brief Method to release handle to display core interface.

    @details The object of corresponding display core is destroyed when this method is invoked.
    Client must explicitly destroy all created display device objects associated with this handle
    before invoking this method.

    @param[in] interface \link CoreInterface \endlink

    @return \link DisplayError \endlink

    @sa CreateCore
  */
  static DisplayError DestroyCore();

  /*! @brief Method to create a display device for a given type.

    @details Client shall use this method to create each of the connected display type. A handle to
    interface associated with this object is returned via output parameter which can be used to
    interact further with the display device.

    @param[in] type \link DisplayType \endlink
    @param[in] event_handler \link DisplayEventHandler \endlink
    @param[out] interface \link DisplayInterface \endlink

    @return \link DisplayError \endlink

    @sa DestroyDisplay
  */
  virtual DisplayError CreateDisplay(DisplayType type, DisplayEventHandler *event_handler,
                                     DisplayInterface **interface) = 0;

  /*! @brief Method to create a display device for a given display ID.

    @details Client shall use this method to create a DisplayInterface to a discovered display
    identified by its display ID. A handle to the DisplayInterface is returned via the 'interface'
    output parameter which can be used to interact further with the display device. Displays and
    their IDs must be discovered using GetDisplaysStatus().

    @param[in] display_id A display ID got from \link GetDisplaysStatus() \endlink
    @param[in] event_handler \link DisplayEventHandler \endlink
    @param[out] interface \link DisplayInterface \endlink

    @return \link DisplayError \endlink

    @sa DestroyDisplay
  */
  virtual DisplayError CreateDisplay(int32_t display_id, DisplayEventHandler *event_handler,
                                     DisplayInterface **interface) = 0;

  /*! @brief Method to destroy a display device.

    @details Client shall use this method to destroy each of the created display device objects.

    @param[in] interface \link DisplayInterface \endlink

    @return \link DisplayError \endlink

    @sa CreateDisplay
  */
  virtual DisplayError DestroyDisplay(DisplayInterface *interface) = 0;

  /*! @brief Method to update the bandwidth limit as per given mode.

    @param[in] mode indicate the mode or use case

    @return \link DisplayError \endlink
  */
  virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0;

  /*! @brief Method to get characteristics of the first display.

    @details Client shall use this method to determine if the first display is HDMI, and whether
    it is currently connected.

    @param[in] hw_disp_info structure that this method will fill up with info.

    @return \link DisplayError \endlink
  */
  virtual DisplayError GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) = 0;

  /*! @brief Method to get an up-to-date list of all available displays.

    @details Client shall use this method to get the updated list of all available displays and
    their properties, usually in response to a hot-plug event. Client must use one of the returned
    HWDisplayInfo::display_ids when using CreateDisplay(int32_t display_id, ...) to create the
    DisplayInterface to the display.

    @param[out] hw_displays_info \link HWDisplaysInfo \endlink which is a map of \link HWDisplayInfo
    \endlink structures with display_id as the key.

    @return \link DisplayError \endlink
  */
  virtual DisplayError GetDisplaysStatus(HWDisplaysInfo *hw_displays_info) = 0;

  /*! @brief Method to get the maximum supported number of concurrent displays of a particular type.

    @details Client shall use this method to get the maximum number of DisplayInterface instances
    that can be created for a particular \link DisplayType \endlink display. For the maximum
    number of concurrent DisplayInterfaces supported of all types, call with type kDisplayTypeMax.

    @param[in] type Type of display: BuiltIn/Pluggable/Virtual/kDisplayTypeMax
    key.

    @param[out] max_displays Maximum number of DisplayInterface instances possible.

    @return \link DisplayError \endlink
  */
  virtual DisplayError GetMaxDisplaysSupported(DisplayType type, int32_t *max_displays) = 0;

 protected:
  virtual ~CoreInterface() { }
};

}  // namespace sdm

#endif  // __CORE_INTERFACE_H__