blob: ac7857504456226c673afa045d769606661c9d00 [file] [log] [blame]
Ray Zhangb59a9ec2019-04-25 19:19:38 +08001/*
2* Copyright (c) 2019, The Linux Foundation. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without modification, are permitted
5* provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright notice, this list of
7* conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright notice, this list of
9* conditions and the following disclaimer in the documentation and/or other materials provided
10* with the distribution.
11* * Neither the name of The Linux Foundation nor the names of its contributors may be used to
12* endorse or promote products derived from this software without specific prior written
13* permission.
14*
15* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23*/
24
25/*! @file smomo.h
26 @brief Interface file for SmoMo which defines the public interface exposed to SmoMo clients.
27
28 @details SmoMo clients use these interfaces to feed SmoMo required info like frame rate, refresh
29 rate, these info are used to update SmoMo internal state.
30*/
31
32#ifndef __SMOMO_INTERFACE_H__
33#define __SMOMO_INTERFACE_H__
34
35#include <sys/types.h>
36
37#include <vector>
38#include <string>
39
40namespace smomo {
41
42typedef int64_t nsecs_t;
43
44/*! @brief This structure defines the layer stats required by SmoMo.
45
46 @sa SmomoIntf::updateSmomoState
47*/
48struct SmomoLayerStats {
49 std::string name; // layer full name
50 int32_t id; // layer ID
51};
52
53/*! @brief This structure defines the buffer stats required by SmoMo.
54
55 @sa SmomoIntf::CollectLayerStats
56 @sa SmomoIntf::ShouldPresentNow
57*/
58struct SmomoBufferStats {
59 int32_t id; // layer ID
60 int32_t queued_frames; // queued frame count of this layer
61 bool auto_timestamp; // whether timestamp was generated automatically
62 nsecs_t timestamp; // layer buffer's timestamp
63};
64
65/*! @brief SmoMo interface implemented by SmoMo library.
66
67 @details This class declares prototype for SmoMo public interfaces which must be
68 implemented by SmoMo library. SmoMo clients will use these methods to feed required
69 info to SmoMo implementation.
70*/
71class SmomoIntf {
72 public:
73 virtual ~SmomoIntf() = default;
74
75 /*! @brief Update SmoMo internal state.
76
77 @details This function is called once per each composition so that required layer info are feed
78 to SmoMo, the SmoMo uses these info to update its internal state.
79
80 @param[in] layers \link SmomoLayerStats \endlink
81 @param[in] refresh_rate current display refresh rate
82
83 @return \link void \endlink
84 */
85 virtual void UpdateSmomoState(const std::vector<SmomoLayerStats> &layers,
86 float refresh_rate) = 0;
87
88 /*! @brief Collect layer buffer stats.
89
90 @details This function is called once new buffer is ready for this layer. It's used to collect
91 layer's buffer stats for SmoMo.
92
93 @param[in] \link SmomoBufferStats \endlink
94
95 @return \link void \endlink
96 */
97 virtual void CollectLayerStats(const SmomoBufferStats &buffer_stats) = 0;
98
99 /*! @brief Is this layer buffer ready to present.
100
101 @details This function is called by SmoMo clients used to check whether this layer buffer is
102 due to present.
103
104 @param[in] \link SmomoBufferStats \endlink
105 @param[in] next_vsync_time When next VSYNC arrives
106
107 @return \link bool \endlink
108 */
109 virtual bool ShouldPresentNow(const SmomoBufferStats &buffer_stats,
110 const nsecs_t next_vsync_time) = 0;
111
112 /*! @brief Change refresh rate callback type definition.
113 */
114 using ChangeRefreshRateCallback = std::function<void(int32_t)>;
115
116 /*! @brief Set the callback used by SmoMo to change display refresh rate.
117
118 @details This function is called by SmoMo clients used to set the refresh rate callback.
119
120 @param[in] callback \link ChangeRefreshRateCallback \endlink
121
122 @return \link void \endlink
123 */
124 virtual void SetChangeRefreshRateCallback(
125 const ChangeRefreshRateCallback& callback) = 0;
126
127 /*! @brief Set the refersh rates supported by display.
128
129 @details This function is called to tell SmoMo what refresh rates this display can suport.
130
131 @param[in] refresh_rates The refresh rates list supported by the display
132
133 @return \link void \endlink
134 */
135 virtual void SetDisplayRefreshRates(const std::vector<float> &refresh_rates) = 0;
136};
137
138} // namespace smomo
139
140#endif // __SMOMO_INTERFACE_H__