1 /*
2 * Copyright (c) 2014 - 2015, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *     * Redistributions of source code must retain the above copyright
8 *       notice, this list of conditions and the following disclaimer.
9 *     * Redistributions in binary form must reproduce the above
10 *       copyright notice, this list of conditions and the following
11 *       disclaimer in the documentation and/or other materials provided
12 *       with the distribution.
13 *     * Neither the name of The Linux Foundation nor the names of its
14 *       contributors may be used to endorse or promote products derived
15 *       from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 
30 /*! @file core_interface.h
31   @brief Interface file for core of the display subsystem.
32 
33   @details Display core is primarily used for loading and unloading different display device
34   components viz primary, external and virtual. Display core is a statically linked library which
35   runs in caller's process context.
36 */
37 #ifndef __CORE_INTERFACE_H__
38 #define __CORE_INTERFACE_H__
39 
40 #include <stdint.h>
41 
42 #include "display_interface.h"
43 #include "sdm_types.h"
44 #include "buffer_allocator.h"
45 #include "buffer_sync_handler.h"
46 
47 /*! @brief Display manager interface version.
48 
49   @details Display manager interfaces are version tagged to maintain backward compatibility. This
50   version is supplied as a default argument during display core initialization.
51 
52   Client may use an older version of interfaces and link to a higher version of display manager
53   library, but vice versa is not allowed.
54 
55   A 32-bit client must use 32-bit display core library and a 64-bit client must use 64-bit display
56   core library.
57 
58   Display manager interfaces follow default data structures alignment. Client must not override the
59   default padding rules while using these interfaces.
60 
61   @warning It is assumed that client upgrades or downgrades display core interface all at once
62   and recompile all binaries which use these interfaces. Mix and match of these interfaces can
63   lead to unpredictable behaviour.
64 
65   @sa CoreInterface::CreateCore
66 */
67 #define SDM_REVISION_MAJOR (1)
68 #define SDM_REVISION_MINOR (0)
69 
70 #define SDM_VERSION_TAG ((uint32_t) ((SDM_REVISION_MAJOR << 24) | (SDM_REVISION_MINOR << 16) | \
71                                     (sizeof(SDMCompatibility) << 8) | sizeof(int *)))
72 
73 namespace sdm {
74 
75 /*! @brief Forward declaration for debug handler.
76 */
77 class DebugHandler;
78 
79 /*! @brief This enum represents max bandwidth limit mode.
80 
81   @sa DisplayInterface::SetMaxBandwidthMode
82 */
83 enum HWBwModes {
84   kBwDefault,      //!< Default state. No change in device bandwidth limit.
85   kBwCamera,       //!< Camera is on. Bandwidth limit should be reduced accordingly.
86   kBwVFlip,        //!< VFlip is required. Reduce bandwidth limit accordingly.
87   kBwHFlip,        //!< HFlip is required.  Reduce bandwidth limit accordingly.
88   kBwModeMax,      //!< Limiter for maximum available bandwidth modes.
89 };
90 
91 /*! @brief Display core interface.
92 
93   @details This class defines display core interfaces. It contains methods which client shall use
94   to create/destroy different display devices. This interface is created during display core
95   CreateCore() and remains valid until DestroyCore().
96 
97   @sa CoreInterface::CreateCore
98   @sa CoreInterface::DestroyCore
99 */
100 class CoreInterface {
101  public:
102   /*! @brief Method to create and get handle to display core interface.
103 
104     @details This method is the entry point into the display core. Client can create and operate on
105     different display devices only through a valid interface handle obtained using this method. An
106     object of display core is created and handle to this object is returned via output parameter.
107     This interface shall be called only once.
108 
109     @param[in] debug_handler \link DebugHandler \endlink
110     @param[in] buffer_allocator \link BufferAllocator \endlink
111     @param[in] buffer_sync_handler \link BufferSyncHandler \endlink
112     @param[out] interface \link CoreInterface \endlink
113     @param[in] version \link SDM_VERSION_TAG \endlink. Client must not override this argument.
114 
115     @return \link DisplayError \endlink
116 
117     @sa DestroyCore
118   */
119   static DisplayError CreateCore(DebugHandler *debug_handler, BufferAllocator *buffer_allocator,
120                                  BufferSyncHandler *buffer_sync_handler, CoreInterface **interface,
121                                  uint32_t version = SDM_VERSION_TAG);
122 
123   /*! @brief Method to release handle to display core interface.
124 
125     @details The object of corresponding display core is destroyed when this method is invoked.
126     Client must explicitly destroy all created display device objects associated with this handle
127     before invoking this method.
128 
129     @param[in] interface \link CoreInterface \endlink
130 
131     @return \link DisplayError \endlink
132 
133     @sa CreateCore
134   */
135   static DisplayError DestroyCore();
136 
137   /*! @brief Method to create a display device for a given type.
138 
139     @details Client shall use this method to create each of the connected display type. A handle to
140     interface associated with this object is returned via output parameter which can be used to
141     interact further with the display device.
142 
143     @param[in] type \link DisplayType \endlink
144     @param[in] event_handler \link DisplayEventHandler \endlink
145     @param[out] interface \link DisplayInterface \endlink
146 
147     @return \link DisplayError \endlink
148 
149     @sa DestroyDisplay
150   */
151   virtual DisplayError CreateDisplay(DisplayType type, DisplayEventHandler *event_handler,
152                                      DisplayInterface **interface) = 0;
153 
154   /*! @brief Method to destroy a display device.
155 
156     @details Client shall use this method to destroy each of the created display device objects.
157 
158     @param[in] interface \link DisplayInterface \endlink
159 
160     @return \link DisplayError \endlink
161 
162     @sa CreateDisplay
163   */
164   virtual DisplayError DestroyDisplay(DisplayInterface *interface) = 0;
165 
166   /*! @brief Method to update the bandwidth limit as per given mode.
167 
168     @param[in] mode indicate the mode or use case
169 
170     @return \link DisplayError \endlink
171 
172    */
173     virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0;
174 
175 
176  protected:
~CoreInterface()177   virtual ~CoreInterface() { }
178 };
179 
180 }  // namespace sdm
181 
182 #endif  // __CORE_INTERFACE_H__
183 
184