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 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 #include <utils/constants.h>
26 #include <utils/debug.h>
27
28 #include "display_virtual.h"
29 #include "hw_interface.h"
30 #include "hw_info_interface.h"
31 #include "fb/hw_virtual.h"
32
33 #define __CLASS__ "DisplayVirtual"
34
35 namespace sdm {
36
DisplayVirtual(DisplayEventHandler * event_handler,HWInfoInterface * hw_info_intf,BufferSyncHandler * buffer_sync_handler,CompManager * comp_manager,RotatorInterface * rotator_intf)37 DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
38 BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
39 RotatorInterface *rotator_intf)
40 : DisplayBase(kVirtual, event_handler, kDeviceVirtual, buffer_sync_handler, comp_manager,
41 rotator_intf, hw_info_intf) {
42 }
43
Init()44 DisplayError DisplayVirtual::Init() {
45 SCOPE_LOCK(locker_);
46
47 DisplayError error = HWVirtual::Create(&hw_intf_, hw_info_intf_,
48 DisplayBase::buffer_sync_handler_);
49 if (error != kErrorNone) {
50 return error;
51 }
52
53 hw_intf_->GetDisplayAttributes(0 /* active_index */, &display_attributes_);
54
55 error = DisplayBase::Init();
56 if (error != kErrorNone) {
57 HWVirtual::Destroy(hw_intf_);
58 }
59
60 return error;
61 }
62
Deinit()63 DisplayError DisplayVirtual::Deinit() {
64 SCOPE_LOCK(locker_);
65
66 DisplayError error = DisplayBase::Deinit();
67 HWVirtual::Destroy(hw_intf_);
68
69 return error;
70 }
71
Prepare(LayerStack * layer_stack)72 DisplayError DisplayVirtual::Prepare(LayerStack *layer_stack) {
73 SCOPE_LOCK(locker_);
74 return DisplayBase::Prepare(layer_stack);
75 }
76
Commit(LayerStack * layer_stack)77 DisplayError DisplayVirtual::Commit(LayerStack *layer_stack) {
78 SCOPE_LOCK(locker_);
79 return DisplayBase::Commit(layer_stack);
80 }
81
Flush()82 DisplayError DisplayVirtual::Flush() {
83 SCOPE_LOCK(locker_);
84 return DisplayBase::Flush();
85 }
86
GetDisplayState(DisplayState * state)87 DisplayError DisplayVirtual::GetDisplayState(DisplayState *state) {
88 SCOPE_LOCK(locker_);
89 return DisplayBase::GetDisplayState(state);
90 }
91
GetNumVariableInfoConfigs(uint32_t * count)92 DisplayError DisplayVirtual::GetNumVariableInfoConfigs(uint32_t *count) {
93 SCOPE_LOCK(locker_);
94 *count = 1;
95 return kErrorNone;
96 }
97
GetConfig(uint32_t index,DisplayConfigVariableInfo * variable_info)98 DisplayError DisplayVirtual::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
99 SCOPE_LOCK(locker_);
100 *variable_info = display_attributes_;
101 return kErrorNone;
102 }
103
GetActiveConfig(uint32_t * index)104 DisplayError DisplayVirtual::GetActiveConfig(uint32_t *index) {
105 SCOPE_LOCK(locker_);
106 *index = 0;
107 return kErrorNone;
108 }
109
GetVSyncState(bool * enabled)110 DisplayError DisplayVirtual::GetVSyncState(bool *enabled) {
111 SCOPE_LOCK(locker_);
112 return DisplayBase::GetVSyncState(enabled);
113 }
114
IsUnderscanSupported()115 bool DisplayVirtual::IsUnderscanSupported() {
116 SCOPE_LOCK(locker_);
117 return DisplayBase::IsUnderscanSupported();
118 }
119
SetDisplayState(DisplayState state)120 DisplayError DisplayVirtual::SetDisplayState(DisplayState state) {
121 SCOPE_LOCK(locker_);
122 return DisplayBase::SetDisplayState(state);
123 }
124
SetActiveConfig(DisplayConfigVariableInfo * variable_info)125 DisplayError DisplayVirtual::SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
126 SCOPE_LOCK(locker_);
127 DisplayError error = kErrorNone;
128
129 if (!variable_info) {
130 return kErrorParameters;
131 }
132
133 display_attributes_.x_pixels = variable_info->x_pixels;
134 display_attributes_.y_pixels = variable_info->y_pixels;
135 display_attributes_.fps = variable_info->fps;
136
137 // if display is already connected, unregister display from composition manager and register
138 // the display with new configuration.
139 if (display_comp_ctx_) {
140 comp_manager_->UnregisterDisplay(display_comp_ctx_);
141 }
142
143 error = comp_manager_->RegisterDisplay(display_type_, display_attributes_, hw_panel_info_,
144 &display_comp_ctx_);
145 if (error != kErrorNone) {
146 return error;
147 }
148
149 return error;
150 }
151
SetActiveConfig(uint32_t index)152 DisplayError DisplayVirtual::SetActiveConfig(uint32_t index) {
153 SCOPE_LOCK(locker_);
154 return kErrorNotSupported;
155 }
156
SetVSyncState(bool enable)157 DisplayError DisplayVirtual::SetVSyncState(bool enable) {
158 SCOPE_LOCK(locker_);
159 return kErrorNotSupported;
160 }
161
SetIdleTimeoutMs(uint32_t timeout_ms)162 void DisplayVirtual::SetIdleTimeoutMs(uint32_t timeout_ms) { }
163
SetMaxMixerStages(uint32_t max_mixer_stages)164 DisplayError DisplayVirtual::SetMaxMixerStages(uint32_t max_mixer_stages) {
165 SCOPE_LOCK(locker_);
166 return DisplayBase::SetMaxMixerStages(max_mixer_stages);
167 }
168
SetDisplayMode(uint32_t mode)169 DisplayError DisplayVirtual::SetDisplayMode(uint32_t mode) {
170 SCOPE_LOCK(locker_);
171 return DisplayBase::SetDisplayMode(mode);
172 }
173
IsScalingValid(const LayerRect & crop,const LayerRect & dst,bool rotate90)174 DisplayError DisplayVirtual::IsScalingValid(const LayerRect &crop, const LayerRect &dst,
175 bool rotate90) {
176 SCOPE_LOCK(locker_);
177 return DisplayBase::IsScalingValid(crop, dst, rotate90);
178 }
179
GetRefreshRateRange(uint32_t * min_refresh_rate,uint32_t * max_refresh_rate)180 DisplayError DisplayVirtual::GetRefreshRateRange(uint32_t *min_refresh_rate,
181 uint32_t *max_refresh_rate) {
182 SCOPE_LOCK(locker_);
183 return DisplayBase::GetRefreshRateRange(min_refresh_rate, max_refresh_rate);
184 }
185
SetRefreshRate(uint32_t refresh_rate)186 DisplayError DisplayVirtual::SetRefreshRate(uint32_t refresh_rate) {
187 SCOPE_LOCK(locker_);
188 return kErrorNotSupported;
189 }
190
SetPanelBrightness(int level)191 DisplayError DisplayVirtual::SetPanelBrightness(int level) {
192 SCOPE_LOCK(locker_);
193 return DisplayBase::SetPanelBrightness(level);
194 }
195
AppendDump(char * buffer,uint32_t length)196 void DisplayVirtual::AppendDump(char *buffer, uint32_t length) {
197 SCOPE_LOCK(locker_);
198 DisplayBase::AppendDump(buffer, length);
199 }
200
SetCursorPosition(int x,int y)201 DisplayError DisplayVirtual::SetCursorPosition(int x, int y) {
202 SCOPE_LOCK(locker_);
203 return DisplayBase::SetCursorPosition(x, y);
204 }
205
206 } // namespace sdm
207
208