OSDN Git Service

053a995648e4db14221c5e4beaae5f0aa2d1a769
[android-x86/external-IA-Hardware-Composer.git] / common / core / logicaldisplay.cpp
1 /*
2 // Copyright (c) 2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include "logicaldisplay.h"
18
19 #include <sstream>
20 #include <string>
21
22 #include "logicaldisplaymanager.h"
23
24 namespace hwcomposer {
25
26 LogicalDisplay::LogicalDisplay(LogicalDisplayManager *display_manager,
27                                NativeDisplay *physical_display,
28                                uint32_t total_divisions, uint32_t index)
29     : logical_display_manager_(display_manager),
30       physical_display_(physical_display),
31       index_(index),
32       total_divisions_(total_divisions) {
33 }
34
35 LogicalDisplay::~LogicalDisplay() {
36 }
37
38 bool LogicalDisplay::Initialize(NativeBufferHandler * /*buffer_handler*/) {
39   return true;
40 }
41
42 bool LogicalDisplay::IsConnected() const {
43   return physical_display_->IsConnected();
44 }
45
46 uint32_t LogicalDisplay::PowerMode() const {
47   return power_mode_;
48 }
49
50 int LogicalDisplay::GetDisplayPipe() {
51   return physical_display_->GetDisplayPipe();
52 }
53
54 bool LogicalDisplay::SetActiveConfig(uint32_t config) {
55   bool success = physical_display_->SetActiveConfig(config);
56   width_ = (physical_display_->Width()) / total_divisions_;
57   return success;
58 }
59
60 bool LogicalDisplay::GetActiveConfig(uint32_t *config) {
61   return physical_display_->GetActiveConfig(config);
62 }
63
64 bool LogicalDisplay::SetPowerMode(uint32_t power_mode) {
65   power_mode_ = power_mode;
66   logical_display_manager_->UpdatePowerMode();
67   return true;
68 }
69
70 void LogicalDisplay::SetHDCPState(HWCContentProtection state,
71                                   HWCContentType content_type) {
72   logical_display_manager_->SetHDCPState(state, content_type);
73 }
74
75 void LogicalDisplay::SetHDCPSRM(const int8_t *SRM, uint32_t SRMLength) {
76   logical_display_manager_->SetHDCPSRM(SRM, SRMLength);
77 }
78
79 bool LogicalDisplay::ContainConnector(const uint32_t connector_id) {
80   return logical_display_manager_->ContainConnector(connector_id);
81 }
82
83 bool LogicalDisplay::Present(std::vector<HwcLayer *> &source_layers,
84                              int32_t *retire_fence,
85                              PixelUploaderCallback *call_back,
86                              bool handle_constraints) {
87   if (power_mode_ != kOn)
88     return true;
89
90   return logical_display_manager_->Present(source_layers, retire_fence,
91                                            call_back, handle_constraints);
92 }
93
94 bool LogicalDisplay::PresentClone(NativeDisplay * /*display*/) {
95   return false;
96 }
97
98 int LogicalDisplay::RegisterVsyncCallback(
99     std::shared_ptr<VsyncCallback> callback, uint32_t display_id) {
100   display_id_ = display_id;
101   vsync_callback_ = callback;
102   return 0;
103 }
104
105 void LogicalDisplay::RegisterRefreshCallback(
106     std::shared_ptr<RefreshCallback> callback, uint32_t display_id) {
107   display_id_ = display_id;
108   refresh_callback_ = callback;
109 }
110
111 void LogicalDisplay::RegisterHotPlugCallback(
112     std::shared_ptr<HotPlugCallback> callback, uint32_t display_id) {
113   display_id_ = display_id;
114   hotplug_callback_ = callback;
115   logical_display_manager_->RegisterHotPlugNotification();
116 }
117
118 void LogicalDisplay::VSyncControl(bool enabled) {
119   enable_vsync_ = enabled;
120   logical_display_manager_->UpdateVSyncControl();
121 }
122
123 void LogicalDisplay::VSyncUpdate(int64_t timestamp) {
124   if (vsync_callback_ && enable_vsync_) {
125     vsync_callback_->Callback(display_id_, timestamp);
126   }
127 }
128
129 void LogicalDisplay::RefreshUpdate() {
130   if (refresh_callback_ && power_mode_ == kOn) {
131     refresh_callback_->Callback(display_id_);
132   }
133 }
134
135 void LogicalDisplay::HotPlugUpdate(bool connected) {
136   if (hotplug_callback_) {
137     hotplug_callback_->Callback(display_id_, connected);
138   }
139 }
140
141 bool LogicalDisplay::CheckPlaneFormat(uint32_t format) {
142   return physical_display_->CheckPlaneFormat(format);
143 }
144
145 void LogicalDisplay::SetGamma(float red, float green, float blue) {
146   physical_display_->SetGamma(red, green, blue);
147 }
148
149 void LogicalDisplay::SetContrast(uint32_t red, uint32_t green, uint32_t blue) {
150   physical_display_->SetContrast(red, green, blue);
151 }
152
153 void LogicalDisplay::SetBrightness(uint32_t red, uint32_t green,
154                                    uint32_t blue) {
155   physical_display_->SetBrightness(red, green, blue);
156 }
157
158 void LogicalDisplay::SetDisableExplicitSync(bool disable_explicit_sync) {
159   physical_display_->SetDisableExplicitSync(disable_explicit_sync);
160 }
161
162 void LogicalDisplay::SetVideoScalingMode(uint32_t mode) {
163   physical_display_->SetVideoScalingMode(mode);
164 }
165
166 void LogicalDisplay::SetVideoColor(HWCColorControl color, float value) {
167   physical_display_->SetVideoColor(color, value);
168 }
169
170 void LogicalDisplay::GetVideoColor(HWCColorControl color, float *value,
171                                    float *start, float *end) {
172   physical_display_->GetVideoColor(color, value, start, end);
173 }
174
175 void LogicalDisplay::RestoreVideoDefaultColor(HWCColorControl color) {
176   physical_display_->RestoreVideoDefaultColor(color);
177 }
178
179 void LogicalDisplay::SetVideoDeinterlace(HWCDeinterlaceFlag flag,
180                                          HWCDeinterlaceControl mode) {
181   physical_display_->SetVideoDeinterlace(flag, mode);
182 }
183
184 void LogicalDisplay::RestoreVideoDefaultDeinterlace() {
185   physical_display_->RestoreVideoDefaultDeinterlace();
186 }
187
188 void LogicalDisplay::SetCanvasColor(uint16_t bpc, uint16_t red, uint16_t green,
189                                     uint16_t blue, uint16_t alpha) {
190   physical_display_->SetCanvasColor(bpc, red, green, blue, alpha);
191 }
192
193 void LogicalDisplay::UpdateScalingRatio(uint32_t /*primary_width*/,
194                                         uint32_t /*primary_height*/,
195                                         uint32_t /*display_width*/,
196                                         uint32_t /*display_height*/) {
197 }
198
199 void LogicalDisplay::CloneDisplay(NativeDisplay * /*source_display*/) {
200 }
201
202 bool LogicalDisplay::GetDisplayAttribute(uint32_t config /*config*/,
203                                          HWCDisplayAttribute attribute,
204                                          int32_t *value) {
205   switch (attribute) {
206     case HWCDisplayAttribute::kWidth:
207       physical_display_->GetDisplayAttribute(config, attribute, value);
208       *value = *value / total_divisions_;
209       return true;
210     default:
211       break;
212   }
213
214   return physical_display_->GetDisplayAttribute(config, attribute, value);
215 }
216
217 bool LogicalDisplay::GetDisplayConfigs(uint32_t *num_configs,
218                                        uint32_t *configs) {
219   return physical_display_->GetDisplayConfigs(num_configs, configs);
220 }
221
222 bool LogicalDisplay::GetDisplayName(uint32_t *size, char *name) {
223   std::ostringstream stream;
224   stream << "Logical";
225   std::string string = stream.str();
226   size_t length = string.length();
227   if (!name) {
228     *size = length;
229     return true;
230   }
231
232   *size = std::min<uint32_t>(static_cast<uint32_t>(length - 1), *size);
233   strncpy(name, string.c_str(), *size);
234   return true;
235 }
236
237 }  // namespace hwcomposer