1 /*
2 * Copyright (c) 2017-2019, 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     layer->composition = kCompositionGPU;
122   }
123   return kErrorNone;
124 }
125 
GetDisplayIdentificationData(uint8_t * out_port,uint32_t * out_data_size,uint8_t * out_data)126 DisplayError DisplayNull::GetDisplayIdentificationData(uint8_t *out_port, uint32_t *out_data_size,
127                                                        uint8_t *out_data) {
128   *out_port = 1;  // DSI0 Encoder Index
129   if (out_data == nullptr) {
130     *out_data_size = (uint32_t)(edid_.size());
131   } else {
132     *out_data_size = std::min(*out_data_size, (uint32_t)(edid_.size()));
133     memcpy(out_data, edid_.data(), *out_data_size);
134   }
135 
136   return kErrorNone;
137 }
138 
Commit(LayerStack * layer_stack)139 DisplayError DisplayNullExternal::Commit(LayerStack *layer_stack) {
140   if (!layer_stack) {
141     return kErrorParameters;
142   }
143 
144   for (Layer *layer : layer_stack->layers) {
145     if (layer->composition != kCompositionGPUTarget) {
146       layer->composition = kCompositionSDE;
147       layer->input_buffer.release_fence_fd = -1;
148     }
149   }
150   layer_stack->retire_fence_fd = -1;
151   return kErrorNone;
152 }
153 
GetDisplayState(DisplayState * state)154 DisplayError DisplayNullExternal::GetDisplayState(DisplayState *state) {
155   if (!state) {
156     return kErrorParameters;
157   }
158 
159   *state = state_;
160   return kErrorNone;
161 }
162 
SetDisplayState(DisplayState state,bool teardown,int * release_fence)163 DisplayError DisplayNullExternal::SetDisplayState(DisplayState state, bool teardown,
164                                                   int *release_fence) {
165   state_ = state;
166   return kErrorNone;
167 }
168 
SetFrameBufferConfig(const DisplayConfigVariableInfo & variable_info)169 DisplayError DisplayNullExternal::SetFrameBufferConfig(const DisplayConfigVariableInfo
170                                                        &variable_info) {
171   fb_config_ = variable_info;
172   return kErrorNone;
173 }
174 
GetFrameBufferConfig(DisplayConfigVariableInfo * variable_info)175 DisplayError DisplayNullExternal::GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) {
176   if (!variable_info) {
177     return kErrorParameters;
178   }
179 
180   *variable_info = fb_config_;
181   return kErrorNone;
182 }
183 
GetDisplayIdentificationData(uint8_t * out_port,uint32_t * out_data_size,uint8_t * out_data)184 DisplayError DisplayNullExternal::GetDisplayIdentificationData(uint8_t *out_port,
185                                                                uint32_t *out_data_size,
186                                                                uint8_t *out_data) {
187   DisplayNull::GetDisplayIdentificationData(out_port, out_data_size, out_data);
188   *out_port = 4;  // TMDS Encoder Index
189 
190   return kErrorNone;
191 }
192 
193 }  // namespace sdm
194