1 /*
2 * Copyright (c) 2017-2021, 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 #include <algorithm>
31 #include "display_null.h"
32 
33 #define __CLASS__ "DisplayNull"
34 
35 namespace sdm {
36 
Init()37 DisplayError DisplayNull::Init() {
38   default_variable_config_.vsync_period_ns = 16600000;
39   default_variable_config_.x_pixels = 1080;
40   default_variable_config_.y_pixels = 1920;
41   default_variable_config_.x_dpi = 300;
42   default_variable_config_.y_dpi = 300;
43   default_variable_config_.fps = 60;
44   default_variable_config_.is_yuv = false;
45 
46   return kErrorNone;
47 }
48 
GetMixerResolution(uint32_t * width,uint32_t * height)49 DisplayError DisplayNull::GetMixerResolution(uint32_t *width, uint32_t *height) {
50   if (!width || !height) {
51     return kErrorParameters;
52   }
53 
54   *width = default_variable_config_.x_pixels;
55   *height = default_variable_config_.y_pixels;
56   return kErrorNone;
57 }
58 
GetFrameBufferConfig(DisplayConfigVariableInfo * variable_info)59 DisplayError DisplayNull::GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) {
60   if (!variable_info) {
61     return kErrorParameters;
62   }
63 
64   *variable_info = default_variable_config_;
65   return kErrorNone;
66 }
67 
GetConfig(uint32_t index,DisplayConfigVariableInfo * disp_attr)68 DisplayError DisplayNull::GetConfig(uint32_t index, DisplayConfigVariableInfo *disp_attr) {
69   if (!disp_attr) {
70     return kErrorParameters;
71   }
72 
73   *disp_attr = default_variable_config_;
74   return kErrorNone;
75 }
76 
GetConfig(DisplayConfigFixedInfo * fixed_info)77 DisplayError DisplayNull::GetConfig(DisplayConfigFixedInfo *fixed_info) {
78   if (!fixed_info) {
79     return kErrorParameters;
80   }
81 
82   *fixed_info = default_fixed_config_;
83   return kErrorNone;
84 }
85 
GetRefreshRateRange(uint32_t * min_refresh_rate,uint32_t * max_refresh_rate)86 DisplayError DisplayNull::GetRefreshRateRange(uint32_t *min_refresh_rate,
87                                               uint32_t *max_refresh_rate) {
88   if (!min_refresh_rate || !max_refresh_rate) {
89     return kErrorParameters;
90   }
91 
92   *min_refresh_rate = 60;
93   *max_refresh_rate = 60;
94   return kErrorNone;
95 }
96 
GetActiveConfig(uint32_t * config)97 DisplayError DisplayNull::GetActiveConfig(uint32_t *config) {
98   if (!config) {
99     return kErrorParameters;
100   }
101 
102   *config = 0;
103   return kErrorNone;
104 }
105 
GetNumVariableInfoConfigs(uint32_t * count)106 DisplayError DisplayNull::GetNumVariableInfoConfigs(uint32_t *count) {
107   if (!count) {
108     return kErrorParameters;
109   }
110 
111   *count = 1;
112   return kErrorNone;
113 }
114 
Prepare(LayerStack * layer_stack)115 DisplayError DisplayNull::Prepare(LayerStack *layer_stack) {
116   if (!layer_stack) {
117     return kErrorParameters;
118   }
119 
120   for (auto layer : layer_stack->layers) {
121     if (layer->composition != kCompositionGPUTarget) {
122       layer->composition = kCompositionGPU;
123     }
124   }
125   return kErrorNone;
126 }
127 
GetDisplayIdentificationData(uint8_t * out_port,uint32_t * out_data_size,uint8_t * out_data)128 DisplayError DisplayNull::GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
129                                                        uint8_t *out_data) {
130   *out_port = 1;  // DSI0 Encoder Index
131   if (out_data == nullptr) {
132     *out_data_size = (uint32_t)(edid_.size());
133   } else {
134     *out_data_size = std::min(*out_data_size, (uint32_t)(edid_.size()));
135     memcpy(out_data, edid_.data(), *out_data_size);
136   }
137 
138   return kErrorNone;
139 }
140 
Commit(LayerStack * layer_stack)141 DisplayError DisplayNullExternal::Commit(LayerStack *layer_stack) {
142   if (!layer_stack) {
143     return kErrorParameters;
144   }
145 
146   for (Layer *layer : layer_stack->layers) {
147     if (layer->composition != kCompositionGPUTarget) {
148       layer->composition = kCompositionSDE;
149       layer->input_buffer.release_fence = nullptr;
150     }
151   }
152 
153   return kErrorNone;
154 }
155 
GetDisplayState(DisplayState * state)156 DisplayError DisplayNullExternal::GetDisplayState(DisplayState *state) {
157   if (!state) {
158     return kErrorParameters;
159   }
160 
161   *state = state_;
162   return kErrorNone;
163 }
164 
SetDisplayState(DisplayState state,bool teardown,shared_ptr<Fence> * release_fence)165 DisplayError DisplayNullExternal::SetDisplayState(DisplayState state, bool teardown,
166                                                   shared_ptr<Fence> *release_fence) {
167   state_ = state;
168   return kErrorNone;
169 }
170 
SetFrameBufferConfig(const DisplayConfigVariableInfo & variable_info)171 DisplayError DisplayNullExternal::SetFrameBufferConfig(const DisplayConfigVariableInfo
172                                                        &variable_info) {
173   fb_config_ = variable_info;
174   return kErrorNone;
175 }
176 
GetFrameBufferConfig(DisplayConfigVariableInfo * variable_info)177 DisplayError DisplayNullExternal::GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) {
178   if (!variable_info) {
179     return kErrorParameters;
180   }
181 
182   *variable_info = fb_config_;
183   return kErrorNone;
184 }
185 
GetDisplayIdentificationData(uint8_t * out_port,uint32_t * out_data_size,uint8_t * out_data)186 DisplayError DisplayNullExternal::GetDisplayIdentificationData(uint8_t *out_port,
187                                                                uint32_t *out_data_size,
188                                                                uint8_t *out_data) {
189   DisplayNull::GetDisplayIdentificationData(out_port, out_data_size, out_data);
190   *out_port = 4;  // TMDS Encoder Index
191 
192   return kErrorNone;
193 }
194 
195 }  // namespace sdm
196