1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "display_composer_service.h"
17
18 #include <mutex>
19 #include <dlfcn.h>
20 #include <hdf_base.h>
21 #include <parameters.h>
22 #include <param_wrapper.h>
23 #include "display_log.h"
24 #include "hdf_log.h"
25 #include "hdf_trace.h"
26 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
27 #include "display_dump_service.h"
28 #endif
29
30 #undef LOG_TAG
31 #define LOG_TAG "COMPOSER_SRV"
32 #undef LOG_DOMAIN
33 #define LOG_DOMAIN 0xD002515
34
35 #undef DISPLAY_TRACE
36 #define DISPLAY_TRACE HdfTrace trace(__func__, "HDI:DISP:")
37
38 namespace OHOS {
39 namespace HDI {
40 namespace Display {
41 namespace Composer {
42
43 const std::string BOOTEVENT_COMPOSER_HOST_READY = "bootevent.composer_host.ready";
44
DisplayComposerImplGetInstance(void)45 extern "C" V1_3::IDisplayComposer* DisplayComposerImplGetInstance(void)
46 {
47 return new (std::nothrow) DisplayComposerService();
48 }
49
DisplayComposerService()50 DisplayComposerService::DisplayComposerService()
51 : libHandle_(nullptr),
52 vdiAdapter_(new(std::nothrow) DisplayComposerVdiAdapter),
53 cacheMgr_(nullptr),
54 hotPlugCb_(nullptr),
55 vBlankCb_(nullptr),
56 modeCb_(nullptr),
57 seamlessChangeCb_(nullptr),
58 refreshCb_(nullptr),
59 VBlankIdleCb_(nullptr),
60 hwcEventCb_(nullptr)
61 {
62 int32_t ret = LoadVdiSo();
63 if (ret != HDF_SUCCESS) {
64 DISPLAY_LOGE("LoadVdiSo failed");
65 return;
66 }
67
68 if (LoadVdiAdapter() != HDF_SUCCESS) {
69 ExitService();
70 DISPLAY_LOGE("Create DisplayComposerService failed");
71 return;
72 }
73
74 if (CreateResponser() != HDF_SUCCESS) {
75 ExitService();
76 DISPLAY_LOGE("CreateResponser failed");
77 return;
78 }
79
80 HidumperInit();
81
82 OHOS::system::SetParameter(BOOTEVENT_COMPOSER_HOST_READY.c_str(), "true");
83 vsyncEnableStatus_.clear();
84 currentBacklightLevel_.clear();
85 }
86
~DisplayComposerService()87 DisplayComposerService::~DisplayComposerService()
88 {
89 std::lock_guard<std::mutex> lck(mutex_);
90 ExitService();
91 }
92
ExitService()93 void DisplayComposerService::ExitService()
94 {
95 if (vdiAdapter_ != nullptr) {
96 delete vdiAdapter_;
97 vdiAdapter_ = nullptr;
98 }
99
100 if (libHandle_ != nullptr) {
101 dlclose(libHandle_);
102 libHandle_ = nullptr;
103 }
104 }
105
LoadVdiAdapter()106 int32_t DisplayComposerService::LoadVdiAdapter()
107 {
108 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
109
110 LoadVdiFuncPart1();
111 LoadVdiFuncPart2();
112 LoadVdiFuncPart3();
113 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegHotPlugCallback, HDF_FAILURE);
114 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayCapability, HDF_FAILURE);
115 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedModes, HDF_FAILURE);
116 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayMode, HDF_FAILURE);
117 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayMode, HDF_FAILURE);
118 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayPowerStatus, HDF_FAILURE);
119 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayPowerStatus, HDF_FAILURE);
120 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayBacklight, HDF_FAILURE);
121 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayBacklight, HDF_FAILURE);
122 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayProperty, HDF_FAILURE);
123 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayCompChange, HDF_FAILURE);
124 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientCrop, HDF_FAILURE);
125 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientBuffer, HDF_FAILURE);
126 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientDamage, HDF_FAILURE);
127 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayVsyncEnabled, HDF_FAILURE);
128 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegDisplayVBlankCallback, HDF_FAILURE);
129 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayReleaseFence, HDF_FAILURE);
130 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->CreateVirtualDisplay, HDF_FAILURE);
131 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->DestroyVirtualDisplay, HDF_FAILURE);
132 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetVirtualDisplayBuffer, HDF_FAILURE);
133 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayProperty, HDF_FAILURE);
134 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->Commit, HDF_FAILURE);
135 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->CreateLayer, HDF_FAILURE);
136 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->DestroyLayer, HDF_FAILURE);
137 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->PrepareDisplayLayers, HDF_FAILURE);
138 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerAlpha, HDF_FAILURE);
139 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerRegion, HDF_FAILURE);
140 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerCrop, HDF_FAILURE);
141 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerZorder, HDF_FAILURE);
142 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerPreMulti, HDF_FAILURE);
143 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerTransformMode, HDF_FAILURE);
144 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerDirtyRegion, HDF_FAILURE);
145 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerVisibleRegion, HDF_FAILURE);
146 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerBuffer, HDF_FAILURE);
147 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerCompositionType, HDF_FAILURE);
148 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerBlendType, HDF_FAILURE);
149 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerMaskInfo, HDF_FAILURE);
150 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerColor, HDF_FAILURE);
151 return HDF_SUCCESS;
152 }
153
LoadVdiFuncPart1()154 void DisplayComposerService::LoadVdiFuncPart1()
155 {
156 vdiAdapter_->RegHotPlugCallback =
157 reinterpret_cast<RegHotPlugCallbackFunc>(dlsym(libHandle_, "RegHotPlugCallback"));
158 vdiAdapter_->GetDisplayCapability =
159 reinterpret_cast<GetDisplayCapabilityFunc>(dlsym(libHandle_, "GetDisplayCapability"));
160 vdiAdapter_->GetDisplaySupportedModes =
161 reinterpret_cast<GetDisplaySupportedModesFunc>(dlsym(libHandle_, "GetDisplaySupportedModes"));
162 vdiAdapter_->GetDisplayMode = reinterpret_cast<GetDisplayModeFunc>(dlsym(libHandle_, "GetDisplayMode"));
163 vdiAdapter_->SetDisplayMode = reinterpret_cast<SetDisplayModeFunc>(dlsym(libHandle_, "SetDisplayMode"));
164 vdiAdapter_->GetDisplayPowerStatus =
165 reinterpret_cast<GetDisplayPowerStatusFunc>(dlsym(libHandle_, "GetDisplayPowerStatus"));
166 vdiAdapter_->SetDisplayPowerStatus =
167 reinterpret_cast<SetDisplayPowerStatusFunc>(dlsym(libHandle_, "SetDisplayPowerStatus"));
168 vdiAdapter_->GetDisplayBacklight =
169 reinterpret_cast<GetDisplayBacklightFunc>(dlsym(libHandle_, "GetDisplayBacklight"));
170 vdiAdapter_->SetDisplayBacklight =
171 reinterpret_cast<SetDisplayBacklightFunc>(dlsym(libHandle_, "SetDisplayBacklight"));
172 vdiAdapter_->GetDisplayProperty =
173 reinterpret_cast<GetDisplayPropertyFunc>(dlsym(libHandle_, "GetDisplayProperty"));
174 vdiAdapter_->GetDisplayCompChange =
175 reinterpret_cast<GetDisplayCompChangeFunc>(dlsym(libHandle_, "GetDisplayCompChange"));
176 vdiAdapter_->SetDisplayClientCrop =
177 reinterpret_cast<SetDisplayClientCropFunc>(dlsym(libHandle_, "SetDisplayClientCrop"));
178 vdiAdapter_->SetDisplayClientBuffer =
179 reinterpret_cast<SetDisplayClientBufferFunc>(dlsym(libHandle_, "SetDisplayClientBuffer"));
180 vdiAdapter_->SetDisplayClientDamage =
181 reinterpret_cast<SetDisplayClientDamageFunc>(dlsym(libHandle_, "SetDisplayClientDamage"));
182 vdiAdapter_->SetDisplayVsyncEnabled =
183 reinterpret_cast<SetDisplayVsyncEnabledFunc>(dlsym(libHandle_, "SetDisplayVsyncEnabled"));
184 vdiAdapter_->RegDisplayVBlankCallback =
185 reinterpret_cast<RegDisplayVBlankCallbackFunc>(dlsym(libHandle_, "RegDisplayVBlankCallback"));
186 vdiAdapter_->GetDisplayReleaseFence =
187 reinterpret_cast<GetDisplayReleaseFenceFunc>(dlsym(libHandle_, "GetDisplayReleaseFence"));
188 vdiAdapter_->CreateVirtualDisplay =
189 reinterpret_cast<CreateVirtualDisplayFunc>(dlsym(libHandle_, "CreateVirtualDisplay"));
190 vdiAdapter_->DestroyVirtualDisplay =
191 reinterpret_cast<DestroyVirtualDisplayFunc>(dlsym(libHandle_, "DestroyVirtualDisplay"));
192 vdiAdapter_->SetVirtualDisplayBuffer =
193 reinterpret_cast<SetVirtualDisplayBufferFunc>(dlsym(libHandle_, "SetVirtualDisplayBuffer"));
194 vdiAdapter_->SetDisplayProperty =
195 reinterpret_cast<SetDisplayPropertyFunc>(dlsym(libHandle_, "SetDisplayProperty"));
196 vdiAdapter_->Commit = reinterpret_cast<CommitFunc>(dlsym(libHandle_, "Commit"));
197 vdiAdapter_->CreateLayer = reinterpret_cast<CreateLayerFunc>(dlsym(libHandle_, "CreateLayer"));
198 vdiAdapter_->DestroyLayer = reinterpret_cast<DestroyLayerFunc>(dlsym(libHandle_, "DestroyLayer"));
199 vdiAdapter_->PrepareDisplayLayers =
200 reinterpret_cast<PrepareDisplayLayersFunc>(dlsym(libHandle_, "PrepareDisplayLayers"));
201 vdiAdapter_->SetLayerAlpha = reinterpret_cast<SetLayerAlphaFunc>(dlsym(libHandle_, "SetLayerAlpha"));
202 vdiAdapter_->SetLayerRegion = reinterpret_cast<SetLayerRegionFunc>(dlsym(libHandle_, "SetLayerRegion"));
203 }
204
LoadVdiFuncPart2()205 void DisplayComposerService::LoadVdiFuncPart2()
206 {
207 vdiAdapter_->SetLayerCrop = reinterpret_cast<SetLayerCropFunc>(dlsym(libHandle_, "SetLayerCrop"));
208 vdiAdapter_->SetLayerZorder = reinterpret_cast<SetLayerZorderFunc>(dlsym(libHandle_, "SetLayerZorder"));
209 vdiAdapter_->SetLayerPreMulti = reinterpret_cast<SetLayerPreMultiFunc>(dlsym(libHandle_, "SetLayerPreMulti"));
210 vdiAdapter_->SetLayerTransformMode =
211 reinterpret_cast<SetLayerTransformModeFunc>(dlsym(libHandle_, "SetLayerTransformMode"));
212 vdiAdapter_->SetLayerDirtyRegion =
213 reinterpret_cast<SetLayerDirtyRegionFunc>(dlsym(libHandle_, "SetLayerDirtyRegion"));
214 vdiAdapter_->SetLayerVisibleRegion =
215 reinterpret_cast<SetLayerVisibleRegionFunc>(dlsym(libHandle_, "SetLayerVisibleRegion"));
216 vdiAdapter_->SetLayerBuffer = reinterpret_cast<SetLayerBufferFunc>(dlsym(libHandle_, "SetLayerBuffer"));
217 vdiAdapter_->SetLayerCompositionType =
218 reinterpret_cast<SetLayerCompositionTypeFunc>(dlsym(libHandle_, "SetLayerCompositionType"));
219 vdiAdapter_->SetLayerBlendType =
220 reinterpret_cast<SetLayerBlendTypeFunc>(dlsym(libHandle_, "SetLayerBlendType"));
221 vdiAdapter_->SetLayerMaskInfo = reinterpret_cast<SetLayerMaskInfoFunc>(dlsym(libHandle_, "SetLayerMaskInfo"));
222 vdiAdapter_->SetLayerColor = reinterpret_cast<SetLayerColorFunc>(dlsym(libHandle_, "SetLayerColor"));
223 vdiAdapter_->RegSeamlessChangeCallback =
224 reinterpret_cast<RegSeamlessChangeCallbackFunc>(dlsym(libHandle_, "RegSeamlessChangeCallback"));
225 vdiAdapter_->GetDisplaySupportedModesExt =
226 reinterpret_cast<GetDisplaySupportedModesExtFunc>(dlsym(libHandle_, "GetDisplaySupportedModesExt"));
227 vdiAdapter_->SetDisplayModeAsync =
228 reinterpret_cast<SetDisplayModeAsyncFunc>(dlsym(libHandle_, "SetDisplayModeAsync"));
229 vdiAdapter_->GetDisplayVBlankPeriod =
230 reinterpret_cast<GetDisplayVBlankPeriodFunc>(dlsym(libHandle_, "GetDisplayVBlankPeriod"));
231 vdiAdapter_->SetLayerPerFrameParameter =
232 reinterpret_cast<SetLayerPerFrameParameterFunc>(dlsym(libHandle_, "SetLayerPerFrameParameter"));
233 vdiAdapter_->GetSupportedLayerPerFrameParameterKey = reinterpret_cast<GetSupportedLayerPerFrameParameterKeyFunc>(
234 dlsym(libHandle_, "GetSupportedLayerPerFrameParameterKey"));
235 vdiAdapter_->SetDisplayOverlayResolution =
236 reinterpret_cast<SetDisplayOverlayResolutionFunc>(dlsym(libHandle_, "SetDisplayOverlayResolution"));
237 vdiAdapter_->RegRefreshCallback =
238 reinterpret_cast<RegRefreshCallbackFunc>(dlsym(libHandle_, "RegRefreshCallback"));
239 vdiAdapter_->GetDisplaySupportedColorGamuts =
240 reinterpret_cast<GetDisplaySupportedColorGamutsFunc>(dlsym(libHandle_, "GetDisplaySupportedColorGamuts"));
241 vdiAdapter_->GetHDRCapabilityInfos =
242 reinterpret_cast<GetHDRCapabilityInfosFunc>(dlsym(libHandle_, "GetHDRCapabilityInfos"));
243 vdiAdapter_->RegDisplayVBlankIdleCallback =
244 reinterpret_cast<RegDisplayVBlankIdleCallbackFunc>(dlsym(libHandle_, "RegDisplayVBlankIdleCallback"));
245 vdiAdapter_->SetDisplayConstraint =
246 reinterpret_cast<SetDisplayConstraintFunc>(dlsym(libHandle_, "SetDisplayConstraint"));
247 vdiAdapter_->UpdateHardwareCursor =
248 reinterpret_cast<UpdateHardwareCursorFunc>(dlsym(libHandle_, "UpdateHardwareCursor"));
249 vdiAdapter_->EnableHardwareCursorStats =
250 reinterpret_cast<EnableHardwareCursorStatsFunc>(dlsym(libHandle_, "EnableHardwareCursorStats"));
251 vdiAdapter_->GetHardwareCursorStats =
252 reinterpret_cast<GetHardwareCursorStatsFunc>(dlsym(libHandle_, "GetHardwareCursorStats"));
253 vdiAdapter_->FastPresent = reinterpret_cast<FastPresentFunc>(dlsym(libHandle_, "FastPresent"));
254 }
255
LoadVdiFuncPart3()256 void DisplayComposerService::LoadVdiFuncPart3()
257 {
258 vdiAdapter_->SetDisplayActiveRegion =
259 reinterpret_cast<SetDisplayActiveRegionFunc>(dlsym(libHandle_, "SetDisplayActiveRegion"));
260 vdiAdapter_->ClearDisplayClientBuffer =
261 reinterpret_cast<ClearDisplayClientBufferFunc>(dlsym(libHandle_, "ClearDisplayClientBuffer"));
262 vdiAdapter_->ClearLayerBuffer =
263 reinterpret_cast<ClearLayerBufferFunc>(dlsym(libHandle_, "ClearLayerBuffer"));
264 vdiAdapter_->SetDisplayPerFrameParameter =
265 reinterpret_cast<SetDisplayPerFrameParameterFunc>(dlsym(libHandle_, "SetDisplayPerFrameParameter"));
266 vdiAdapter_->GetDisplayIdentificationData =
267 reinterpret_cast<GetDisplayIdentificationDataFunc>(dlsym(libHandle_, "GetDisplayIdentificationData"));
268 vdiAdapter_->RegHwcEventCallback =
269 reinterpret_cast<RegHwcEventCallbackFunc>(dlsym(libHandle_, "RegHwcEventCallback"));
270 }
271
HidumperInit()272 void DisplayComposerService::HidumperInit()
273 {
274 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
275 VdiDumper& dumper = VdiDumper::GetInstance();
276 dumper.SetDumpInfoFunc(reinterpret_cast<GetDumpInfoFunc>(dlsym(libHandle_, "GetDumpInfo")));
277 dumper.SetConfigFunc(reinterpret_cast<UpdateConfigFunc>(dlsym(libHandle_, "UpdateConfig")));
278 (void)DevHostRegisterDumpHost(ComposerDumpEvent);
279 #endif
280 }
281
LoadVdiSo()282 int32_t DisplayComposerService::LoadVdiSo()
283 {
284 const char* errStr = dlerror();
285 if (errStr != nullptr) {
286 DISPLAY_LOGD("composer load vdi, clear earlier dlerror: %{public}s", errStr);
287 }
288 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
289 libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY, RTLD_LAZY);
290 if (libHandle_ == nullptr) {
291 DISPLAY_LOGE("composer load vendor vdi default library failed: %{public}s",
292 DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
293 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
294 libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_LIBRARY, RTLD_LAZY);
295 DISPLAY_LOGD("composer load vendor vdi library: %{public}s", DISPLAY_COMPOSER_VDI_LIBRARY);
296 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
297 } else {
298 DISPLAY_LOGD("composer load vendor vdi default library: %{public}s", DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
299 }
300 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
301 CHECK_NULLPOINTER_RETURN_VALUE(libHandle_, HDF_FAILURE);
302
303 return HDF_SUCCESS;
304 }
305
CreateResponser()306 int32_t DisplayComposerService::DisplayComposerService::CreateResponser()
307 {
308 cacheMgr_ = DeviceCacheManager::GetInstance();
309 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
310 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
311 if (vdiAdapter_->RegDisplayVBlankIdleCallback != nullptr) {
312 DISPLAY_LOGI("%{public}s Enable Map", __func__);
313 cacheMgr_->SetNeedMap(true);
314 }
315 cmdResponser_ = V1_3::HdiDisplayCmdResponser::Create(vdiAdapter_, cacheMgr_);
316 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
317 DISPLAY_LOGI("%{public}s out", __func__);
318 return HDF_SUCCESS;
319 }
320
OnHotPlug(uint32_t outputId,bool connected,void * data)321 void DisplayComposerService::OnHotPlug(uint32_t outputId, bool connected, void* data)
322 {
323 if (data == nullptr) {
324 DISPLAY_LOGE("cb data is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
325 return;
326 }
327
328 auto cacheMgr = reinterpret_cast<DisplayComposerService*>(data)->cacheMgr_;
329 if (cacheMgr == nullptr) {
330 DISPLAY_LOGE("CacheMgr_ is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
331 return;
332 }
333 if (connected) {
334 std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
335 // Add new device cache
336 if (cacheMgr->AddDeviceCache(outputId) != HDF_SUCCESS) {
337 DISPLAY_LOGE("Add device cache failed outputId:%{public}u, connected:%{public}d", outputId, connected);
338 }
339 }
340
341 auto vsyncEnableStatus = reinterpret_cast<DisplayComposerService*>(data)->vsyncEnableStatus_;
342 auto currentBacklightLevel = reinterpret_cast<DisplayComposerService*>(data)->currentBacklightLevel_;
343 vsyncEnableStatus[outputId] = false;
344 currentBacklightLevel[outputId] = 0;
345
346 sptr<IHotPlugCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->hotPlugCb_;
347 if (remoteCb == nullptr) {
348 DISPLAY_LOGE("hotPlugCb_ is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
349 return;
350 }
351 remoteCb->OnHotPlug(outputId, connected);
352 }
353
OnVBlank(unsigned int sequence,uint64_t ns,void * data)354 void DisplayComposerService::OnVBlank(unsigned int sequence, uint64_t ns, void* data)
355 {
356 if (data == nullptr) {
357 DISPLAY_LOGE("cb data is nullptr sequence:%{public}u", sequence);
358 return;
359 }
360
361 IVBlankCallback* remoteCb = reinterpret_cast<IVBlankCallback*>(data);
362 if (remoteCb == nullptr) {
363 DISPLAY_LOGE("vblankCb_ is nullptr sequence:%{public}u", sequence);
364 return;
365 }
366 remoteCb->OnVBlank(sequence, ns);
367 }
368
RegHotPlugCallback(const sptr<IHotPlugCallback> & cb)369 int32_t DisplayComposerService::RegHotPlugCallback(const sptr<IHotPlugCallback>& cb)
370 {
371 DISPLAY_TRACE;
372
373 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
374 hotPlugCb_ = cb;
375 int32_t ret = vdiAdapter_->RegHotPlugCallback(OnHotPlug, this);
376 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
377 return ret;
378 }
379
SetClientBufferCacheCount(uint32_t devId,uint32_t count)380 int32_t DisplayComposerService::SetClientBufferCacheCount(uint32_t devId, uint32_t count)
381 {
382 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
383 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
384 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
385 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
386 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
387 DISPLAY_LOGE("%{public}s fail, devId:%{public}u, count:%{public}u", __func__, devId, count));
388
389 DISPLAY_CHK_RETURN(devCache->SetClientBufferCacheCount(count) != HDF_SUCCESS, HDF_FAILURE,
390 DISPLAY_LOGE("%{public}s fail, devId:%{public}u, count:%{public}u", __func__, devId, count));
391 return HDF_SUCCESS;
392 }
393
GetDisplayCapability(uint32_t devId,DisplayCapability & info)394 int32_t DisplayComposerService::GetDisplayCapability(uint32_t devId, DisplayCapability& info)
395 {
396 DISPLAY_TRACE;
397
398 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
399 int32_t ret = vdiAdapter_->GetDisplayCapability(devId, info);
400 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
401 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
402 DISPLAY_LOGI("%{public}s fail devId:%{public}u, width:%{public}u, height:%{public}u, count:%{public}u",
403 __func__, devId, info.phyWidth, info.phyHeight, info.propertyCount);
404 return HDF_SUCCESS;
405 }
406
GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)407 int32_t DisplayComposerService::GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes)
408 {
409 DISPLAY_TRACE;
410
411 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
412 int32_t ret = vdiAdapter_->GetDisplaySupportedModes(devId, modes);
413 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
414 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
415 return ret;
416 }
417
GetDisplayMode(uint32_t devId,uint32_t & modeId)418 int32_t DisplayComposerService::GetDisplayMode(uint32_t devId, uint32_t& modeId)
419 {
420 DISPLAY_TRACE;
421
422 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
423 int32_t ret = vdiAdapter_->GetDisplayMode(devId, modeId);
424 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
425 DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
426 return ret;
427 }
428
SetDisplayMode(uint32_t devId,uint32_t modeId)429 int32_t DisplayComposerService::SetDisplayMode(uint32_t devId, uint32_t modeId)
430 {
431 DISPLAY_TRACE;
432
433 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
434 int32_t ret = vdiAdapter_->SetDisplayMode(devId, modeId);
435 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
436 DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
437 return ret;
438 }
439
GetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus & status)440 int32_t DisplayComposerService::GetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus& status)
441 {
442 DISPLAY_TRACE;
443
444 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
445 int32_t ret = vdiAdapter_->GetDisplayPowerStatus(devId, status);
446 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
447 DISPLAY_LOGE("%{public}s fail devId:%{public}u, status:%{public}u", __func__, devId, status));
448 return ret;
449 }
450
SetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus status)451 int32_t DisplayComposerService::SetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus status)
452 {
453 DISPLAY_TRACE;
454
455 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
456 int32_t ret = vdiAdapter_->SetDisplayPowerStatus(devId, status);
457 DISPLAY_LOGI("devid: %{public}u, status: %{public}u, vdi return %{public}d", devId, status, ret);
458 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
459 if (vsyncEnableStatus_[devId]) {
460 (void)SetDisplayVsyncEnabled(devId, false);
461 vsyncEnableStatus_[devId] = false;
462 }
463
464 if (status == V1_0::DispPowerStatus::POWER_STATUS_OFF) {
465 currentBacklightLevel_[devId] = 0;
466 }
467
468 return ret;
469 }
470
GetDisplayBacklight(uint32_t devId,uint32_t & level)471 int32_t DisplayComposerService::GetDisplayBacklight(uint32_t devId, uint32_t& level)
472 {
473 DISPLAY_TRACE;
474
475 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
476 int32_t ret = vdiAdapter_->GetDisplayBacklight(devId, level);
477 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_SUCCESS, level = currentBacklightLevel_[devId]);
478 return ret;
479 }
480
SetDisplayBacklight(uint32_t devId,uint32_t level)481 int32_t DisplayComposerService::SetDisplayBacklight(uint32_t devId, uint32_t level)
482 {
483 DISPLAY_TRACE;
484
485 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
486 int32_t ret = vdiAdapter_->SetDisplayBacklight(devId, level);
487 DISPLAY_LOGD("devid: %{public}u, level: %{public}u, vdi return %{public}d", devId, level, ret);
488 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
489 DISPLAY_LOGE("%{public}s fail devId:%{public}u, level:%{public}u", __func__, devId, level));
490 currentBacklightLevel_[devId] = level;
491 return ret;
492 }
493
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)494 int32_t DisplayComposerService::GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value)
495 {
496 DISPLAY_TRACE;
497
498 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
499 int32_t ret = vdiAdapter_->GetDisplayProperty(devId, id, value);
500 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
501 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
502 DISPLAY_LOGE("%{public}s fail devId:%{public}u, id:%{public}u", __func__, devId, id));
503 return ret;
504 }
505
UpdateHardwareCursor(uint32_t devId,int32_t x,int32_t y,const sptr<NativeBuffer> & buffer)506 int32_t DisplayComposerService::UpdateHardwareCursor(uint32_t devId, int32_t x, int32_t y,
507 const sptr<NativeBuffer>& buffer)
508 {
509 DISPLAY_TRACE;
510 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
511 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->UpdateHardwareCursor, HDF_ERR_NOT_SUPPORT);
512 CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_ERR_NOT_SUPPORT);
513 BufferHandle* handle = buffer->GetBufferHandle();
514 int32_t ret = vdiAdapter_->UpdateHardwareCursor(devId, x, y, handle);
515 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
516 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
517 return ret;
518 }
519
EnableHardwareCursorStats(uint32_t devId,bool enable)520 int32_t DisplayComposerService::EnableHardwareCursorStats(uint32_t devId, bool enable)
521 {
522 DISPLAY_TRACE;
523 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
524 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->EnableHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
525 int32_t ret = vdiAdapter_->EnableHardwareCursorStats(devId, enable);
526 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
527 DISPLAY_LOGE("%{public}s fail devId:%{public}u, enable:%{public}d", __func__, devId, enable));
528 return ret;
529 }
530
GetHardwareCursorStats(uint32_t devId,uint32_t & frameCount,uint32_t & vsyncCount)531 int32_t DisplayComposerService::GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount)
532 {
533 DISPLAY_TRACE;
534 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
535 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
536 int32_t ret = vdiAdapter_->GetHardwareCursorStats(devId, frameCount, vsyncCount);
537 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(
538 "%{public}s fail Id:%{public}u, frame:%{public}u, vsync:%{public}u", __func__, devId, frameCount, vsyncCount));
539 return ret;
540 }
541
SetDisplayClientCrop(uint32_t devId,const IRect & rect)542 int32_t DisplayComposerService::SetDisplayClientCrop(uint32_t devId, const IRect& rect)
543 {
544 DISPLAY_TRACE;
545
546 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
547 int32_t ret = vdiAdapter_->SetDisplayClientCrop(devId, rect);
548 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
549 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
550 return ret;
551 }
552
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)553 int32_t DisplayComposerService::SetDisplayVsyncEnabled(uint32_t devId, bool enabled)
554 {
555 DISPLAY_TRACE;
556
557 /*Already enabled, return success */
558 if (enabled && vsyncEnableStatus_[devId]) {
559 DISPLAY_LOGW("%{public}s:vsyncStatus[%{public}u] = %{public}d, skip",
560 __func__, devId, vsyncEnableStatus_[devId]);
561 return HDF_SUCCESS;
562 }
563
564 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
565 int32_t ret = vdiAdapter_->SetDisplayVsyncEnabled(devId, enabled);
566 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
567 DISPLAY_LOGE("%{public}s: vsyncStatus[%{public}u] = %{public}d, fail", __func__, devId, enabled));
568 vsyncEnableStatus_[devId] = enabled;
569 return ret;
570 }
571
RegDisplayVBlankCallback(uint32_t devId,const sptr<IVBlankCallback> & cb)572 int32_t DisplayComposerService::RegDisplayVBlankCallback(uint32_t devId, const sptr<IVBlankCallback>& cb)
573 {
574 DISPLAY_TRACE;
575
576 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
577 int32_t ret = vdiAdapter_->RegDisplayVBlankCallback(devId, OnVBlank, cb.GetRefPtr());
578 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
579 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
580 vBlankCb_ = cb;
581 return ret;
582 }
583
GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<sptr<HdifdParcelable>> & fences)584 int32_t DisplayComposerService::GetDisplayReleaseFence(
585 uint32_t devId, std::vector<uint32_t>& layers, std::vector<sptr<HdifdParcelable>>& fences)
586 {
587 DISPLAY_TRACE;
588
589 std::vector<int32_t> outFences;
590 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
591 int32_t ret = vdiAdapter_->GetDisplayReleaseFence(devId, layers, outFences);
592 for (uint i = 0; i < outFences.size(); i++) {
593 int32_t dupFd = outFences[i];
594 sptr<HdifdParcelable> hdifd(new HdifdParcelable());
595 CHECK_NULLPOINTER_RETURN_VALUE(hdifd, HDF_FAILURE);
596 hdifd->Init(dupFd);
597 fences.push_back(hdifd);
598 }
599 return ret;
600 }
601
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)602 int32_t DisplayComposerService::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId)
603 {
604 DISPLAY_TRACE;
605
606 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
607 int32_t ret = vdiAdapter_->CreateVirtualDisplay(width, height, format, devId);
608 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(
609 "%{public}s fail width:%{public}u, height:%{public}u, format:%{public}d, devId:%{public}u",
610 __func__, width, height, format, devId));
611 return ret;
612 }
613
DestroyVirtualDisplay(uint32_t devId)614 int32_t DisplayComposerService::DestroyVirtualDisplay(uint32_t devId)
615 {
616 DISPLAY_TRACE;
617
618 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
619 int32_t ret = vdiAdapter_->DestroyVirtualDisplay(devId);
620 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
621 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
622 return ret;
623 }
624
SetVirtualDisplayBuffer(uint32_t devId,const sptr<NativeBuffer> & buffer,const sptr<HdifdParcelable> & fence)625 int32_t DisplayComposerService::SetVirtualDisplayBuffer(
626 uint32_t devId, const sptr<NativeBuffer>& buffer, const sptr<HdifdParcelable>& fence)
627 {
628 DISPLAY_TRACE;
629
630 CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_FAILURE);
631 CHECK_NULLPOINTER_RETURN_VALUE(fence, HDF_FAILURE);
632 BufferHandle* handle = buffer->GetBufferHandle();
633 int32_t inFence = fence->GetFd();
634 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
635 CHECK_NULLPOINTER_RETURN_VALUE(handle, HDF_FAILURE);
636 int32_t ret = vdiAdapter_->SetVirtualDisplayBuffer(devId, *handle, inFence);
637 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
638 DISPLAY_LOGE("%{public}s fail devId:%{public}u, inFence:%{public}d", __func__, devId, inFence));
639 return ret;
640 }
641
SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)642 int32_t DisplayComposerService::SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value)
643 {
644 DISPLAY_TRACE;
645
646 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
647 int32_t ret = vdiAdapter_->SetDisplayProperty(devId, id, value);
648 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
649 DISPLAY_LOGE("%{public}s fail devId:%{public}u, id:%{public}u", __func__, devId, id));
650 return ret;
651 }
652
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)653 int32_t DisplayComposerService::CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount,
654 uint32_t& layerId)
655 {
656 DISPLAY_TRACE;
657
658 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
659 int32_t ret = vdiAdapter_->CreateLayer(devId, layerInfo, layerId);
660 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
661 DISPLAY_LOGE("%{public}s fail devId:%{public}u, cacheCount:%{public}u, layerId:%{public}u",
662 __func__, devId, cacheCount, layerId));
663
664 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
665 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
666 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
667 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
668 DISPLAY_LOGE("%{public}s fail devId:%{public}u, cacheCount:%{public}u, layerId:%{public}u",
669 __func__, devId, cacheCount, layerId));
670
671 return devCache->AddLayerCache(layerId, cacheCount);
672 }
673
DestroyLayer(uint32_t devId,uint32_t layerId)674 int32_t DisplayComposerService::DestroyLayer(uint32_t devId, uint32_t layerId)
675 {
676 DISPLAY_TRACE;
677 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
678 int32_t ret = vdiAdapter_->DestroyLayer(devId, layerId);
679 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
680 DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
681
682 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
683 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
684 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
685 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
686 DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
687
688 return devCache->RemoveLayerCache(layerId);
689 }
690
RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback> & cb)691 int32_t DisplayComposerService::RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback>& cb)
692 {
693 DISPLAY_TRACE;
694 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
695 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegSeamlessChangeCallback, HDF_ERR_NOT_SUPPORT);
696 int32_t ret = vdiAdapter_->RegSeamlessChangeCallback(OnSeamlessChange, this);
697 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
698 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
699 DISPLAY_LOGE("%{public}s fail", __func__));
700 if (ret == HDF_SUCCESS) {
701 seamlessChangeCb_ = cb;
702 }
703 return ret;
704 }
705
GetDisplaySupportedModesExt(uint32_t devId,std::vector<DisplayModeInfoExt> & modes)706 int32_t DisplayComposerService::GetDisplaySupportedModesExt(uint32_t devId, std::vector<DisplayModeInfoExt>& modes)
707 {
708 DISPLAY_TRACE;
709 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
710 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedModesExt, HDF_ERR_NOT_SUPPORT);
711 int32_t ret = vdiAdapter_->GetDisplaySupportedModesExt(devId, modes);
712 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
713 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
714 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
715 return ret;
716 }
717
OnMode(uint32_t modeId,uint64_t vBlankPeriod,void * data)718 void DisplayComposerService::OnMode(uint32_t modeId, uint64_t vBlankPeriod, void* data)
719 {
720 if (data == nullptr) {
721 DISPLAY_LOGE("data is nullptr");
722 return;
723 }
724
725 sptr<IModeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->modeCb_;
726 if (remoteCb == nullptr) {
727 DISPLAY_LOGE("remoteCb is nullptr");
728 return;
729 }
730 remoteCb->OnMode(modeId, vBlankPeriod);
731 }
732
SetDisplayModeAsync(uint32_t devId,uint32_t modeId,const sptr<IModeCallback> & cb)733 int32_t DisplayComposerService::SetDisplayModeAsync(uint32_t devId, uint32_t modeId, const sptr<IModeCallback>& cb)
734 {
735 DISPLAY_TRACE;
736 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
737 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayModeAsync, HDF_ERR_NOT_SUPPORT);
738 int32_t ret = vdiAdapter_->SetDisplayModeAsync(devId, modeId, OnMode, this);
739 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
740 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
741 DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
742 if (ret == HDF_SUCCESS) {
743 modeCb_ = cb;
744 }
745 return ret;
746 }
747
GetDisplayVBlankPeriod(uint32_t devId,uint64_t & period)748 int32_t DisplayComposerService::GetDisplayVBlankPeriod(uint32_t devId, uint64_t& period)
749 {
750 DISPLAY_TRACE;
751 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
752 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayVBlankPeriod, HDF_ERR_NOT_SUPPORT);
753 int32_t ret = vdiAdapter_->GetDisplayVBlankPeriod(devId, period);
754 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
755 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
756 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
757 return ret;
758 }
759
OnSeamlessChange(uint32_t devId,void * data)760 void DisplayComposerService::OnSeamlessChange(uint32_t devId, void* data)
761 {
762 if (data == nullptr) {
763 DISPLAY_LOGE("data is nullptr");
764 return;
765 }
766
767 sptr<ISeamlessChangeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->seamlessChangeCb_;
768 if (remoteCb == nullptr) {
769 DISPLAY_LOGE("remoteCb is nullptr");
770 return;
771 }
772 remoteCb->OnSeamlessChange(devId);
773 }
774
InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>> & request)775 int32_t DisplayComposerService::InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request)
776 {
777 CHECK_NULLPOINTER_RETURN_VALUE(request, HDF_FAILURE);
778 int32_t ret = HDF_FAILURE;
779
780 if (cmdResponser_ != nullptr) {
781 ret = cmdResponser_->InitCmdRequest(request);
782 }
783 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
784 DISPLAY_LOGI("%{public}s out", __func__);
785 return ret;
786 }
787
CmdRequest(uint32_t inEleCnt,const std::vector<HdifdInfo> & inFds,uint32_t & outEleCnt,std::vector<HdifdInfo> & outFds)788 int32_t DisplayComposerService::CmdRequest(
789 uint32_t inEleCnt, const std::vector<HdifdInfo>& inFds, uint32_t& outEleCnt, std::vector<HdifdInfo>& outFds)
790 {
791 int32_t ret = HDF_FAILURE;
792
793 if (cmdResponser_ != nullptr) {
794 ret = cmdResponser_->CmdRequest(inEleCnt, inFds, outEleCnt, outFds);
795 }
796 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(
797 "%{public}s fail inEleCnt:%{public}u, outEleCnt:%{public}u", __func__, inEleCnt, outEleCnt));
798 return ret;
799 }
800
GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>> & reply)801 int32_t DisplayComposerService::GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply)
802 {
803 int32_t ret = HDF_FAILURE;
804
805 if (cmdResponser_ != nullptr) {
806 ret = cmdResponser_->GetCmdReply(reply);
807 }
808 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
809 return ret;
810 }
811
SetLayerPerFrameParameter(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)812 int32_t DisplayComposerService::SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
813 const std::vector<int8_t>& value)
814 {
815 DISPLAY_TRACE;
816 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
817 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerPerFrameParameter, HDF_ERR_NOT_SUPPORT);
818 int32_t ret = vdiAdapter_->SetLayerPerFrameParameter(devId, layerId, key, value);
819 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
820 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
821 DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
822 return ret;
823 }
824
GetSupportedLayerPerFrameParameterKey(std::vector<std::string> & keys)825 int32_t DisplayComposerService::GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys)
826 {
827 DISPLAY_TRACE;
828 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
829 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetSupportedLayerPerFrameParameterKey, HDF_ERR_NOT_SUPPORT);
830 int32_t ret = vdiAdapter_->GetSupportedLayerPerFrameParameterKey(keys);
831 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
832 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
833 DISPLAY_LOGE("%{public}s fail", __func__));
834 return ret;
835 }
836
SetDisplayOverlayResolution(uint32_t devId,uint32_t width,uint32_t height)837 int32_t DisplayComposerService::SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height)
838 {
839 DISPLAY_TRACE;
840 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
841 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayOverlayResolution, HDF_ERR_NOT_SUPPORT);
842 int32_t ret = vdiAdapter_->SetDisplayOverlayResolution(devId, width, height);
843 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
844 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(
845 "%{public}s fail devId:%{public}u, width:%{public}u, height:%{public}u", __func__, devId, width, height));
846 return ret;
847 }
848
OnRefresh(uint32_t devId,void * data)849 void DisplayComposerService::OnRefresh(uint32_t devId, void *data)
850 {
851 if (data == nullptr) {
852 DISPLAY_LOGE("cb data is nullptr devId:%{public}u", devId);
853 return;
854 }
855
856 sptr<IRefreshCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->refreshCb_;
857 if (remoteCb == nullptr) {
858 DISPLAY_LOGE("remoteCb is nullptr devId:%{public}u", devId);
859 return;
860 }
861 remoteCb->OnRefresh(devId);
862 }
863
RegRefreshCallback(const sptr<IRefreshCallback> & cb)864 int32_t DisplayComposerService::RegRefreshCallback(const sptr<IRefreshCallback>& cb)
865 {
866 DISPLAY_TRACE;
867 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
868 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegRefreshCallback, HDF_ERR_NOT_SUPPORT);
869 int32_t ret = vdiAdapter_->RegRefreshCallback(OnRefresh, this);
870 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
871 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
872 DISPLAY_LOGE("%{public}s fail", __func__));
873 if (ret == HDF_SUCCESS) {
874 refreshCb_ = cb;
875 }
876 return ret;
877 }
878
GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)879 int32_t DisplayComposerService::GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts)
880 {
881 DISPLAY_TRACE;
882 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
883 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedColorGamuts, HDF_ERR_NOT_SUPPORT);
884 int32_t ret = vdiAdapter_->GetDisplaySupportedColorGamuts(devId, gamuts);
885 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
886 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
887 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
888 return ret;
889 }
890
GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)891 int32_t DisplayComposerService::GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info)
892 {
893 DISPLAY_TRACE;
894 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
895 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHDRCapabilityInfos, HDF_ERR_NOT_SUPPORT);
896 int32_t ret = vdiAdapter_->GetHDRCapabilityInfos(devId, info);
897 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
898 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
899 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
900 return ret;
901 }
902
OnVBlankIdleCallback(uint32_t devId,uint64_t ns,void * data)903 void DisplayComposerService::OnVBlankIdleCallback(uint32_t devId, uint64_t ns, void* data)
904 {
905 if (data == nullptr) {
906 DISPLAY_LOGE("cb data is nullptr devId:%{public}u", devId);
907 return;
908 }
909
910 sptr<IVBlankIdleCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->VBlankIdleCb_;
911
912 if (remoteCb == nullptr) {
913 DISPLAY_LOGE("VBlankIdleCb_ is nullptr devId:%{public}u", devId);
914 return;
915 }
916 remoteCb->OnVBlankIdleCallback(devId, ns);
917 }
918
RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback> & cb)919 int32_t DisplayComposerService::RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback>& cb)
920 {
921 DISPLAY_TRACE;
922 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
923 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegDisplayVBlankIdleCallback, HDF_ERR_NOT_SUPPORT);
924 VBlankIdleCb_ = cb;
925 int32_t ret = vdiAdapter_->RegDisplayVBlankIdleCallback(OnVBlankIdleCallback, this);
926 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
927 return ret;
928 }
929
ClearClientBuffer(uint32_t devId)930 int32_t DisplayComposerService::ClearClientBuffer(uint32_t devId)
931 {
932 DISPLAY_LOGI("enter, devId %{public}u", devId);
933 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
934 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
935 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
936 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
937 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
938
939 if (vdiAdapter_ != nullptr && vdiAdapter_->ClearDisplayClientBuffer != nullptr) {
940 vdiAdapter_->ClearDisplayClientBuffer(devId);
941 }
942 return devCache->ClearClientCache();
943 }
944
ClearLayerBuffer(uint32_t devId,uint32_t layerId)945 int32_t DisplayComposerService::ClearLayerBuffer(uint32_t devId, uint32_t layerId)
946 {
947 DISPLAY_LOGI("enter, devId %{public}u, layerId %{public}u", devId, layerId);
948 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
949 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
950 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
951 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE(
952 "%{public}s fail devId:%{public}u layerId %{public}u", __func__, devId, layerId));
953
954 if (vdiAdapter_ != nullptr && vdiAdapter_->ClearLayerBuffer != nullptr) {
955 vdiAdapter_->ClearLayerBuffer(devId, layerId);
956 }
957 return devCache->ClearLayerBuffer(layerId);
958 }
959
SetDisplayActiveRegion(uint32_t devId,const IRect & rect)960 int32_t DisplayComposerService::SetDisplayActiveRegion(uint32_t devId, const IRect& rect)
961 {
962 HDF_LOGI("%{public}s: devId %{public}u, rect {%{public}u, %{public}u, %{public}u, %{public}u}",
963 __func__, devId, rect.x, rect.y, rect.w, rect.h);
964
965 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
966 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayActiveRegion, HDF_ERR_NOT_SUPPORT);
967
968 StartTrace(HITRACE_TAG_HDF, "vdiAdapter_->SetDisplayActiveRegion");
969 int32_t ret = vdiAdapter_->SetDisplayActiveRegion(devId, rect);
970 FinishTrace(HITRACE_TAG_HDF);
971
972 if (ret != HDF_SUCCESS) {
973 HDF_LOGI("%{public}s: fail, ret %{public}d", __func__, ret);
974 }
975
976 return ret;
977 }
978
GetDisplayIdentificationData(uint32_t devId,uint8_t & portId,std::vector<uint8_t> & edidData)979 int32_t DisplayComposerService::GetDisplayIdentificationData(uint32_t devId, uint8_t& portId,
980 std::vector<uint8_t>& edidData)
981 {
982 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
983 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayIdentificationData, HDF_ERR_NOT_SUPPORT);
984
985 StartTrace(HITRACE_TAG_HDF, "vdiAdapter_->GetDisplayIdentificationData");
986 int32_t ret = vdiAdapter_->GetDisplayIdentificationData(devId, portId, edidData);
987 FinishTrace(HITRACE_TAG_HDF);
988
989 DISPLAY_LOGI("%{public}s: ret %{public}d, devId {%{public}u, the param idx [{%{public}u],"
990 "the length of edidData [%{public}zu]", __func__, ret, devId, portId, edidData.size());
991
992 return ret;
993 }
994
FastPresent(uint32_t devId,const PresentParam & param,const std::vector<sptr<NativeBuffer>> & inHandles)995 int32_t DisplayComposerService::FastPresent(uint32_t devId, const PresentParam& param,
996 const std::vector<sptr<NativeBuffer>>& inHandles)
997 {
998 DISPLAY_TRACE;
999 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
1000 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->FastPresent, HDF_ERR_NOT_SUPPORT);
1001
1002 if (param.sliceNum != inHandles.size()) {
1003 DISPLAY_LOGE("%{public}s fail devId:%{public}u inHandles size not equals sliceNum inHandles size = %{public}zu "
1004 "sliceNum = %{public}u", __func__, devId, inHandles.size(), param.sliceNum);
1005 return HDF_FAILURE;
1006 }
1007 std::vector<BufferHandle *> handles;
1008 for (uint32_t i = 0; i < param.sliceNum; i++) {
1009 if (!inHandles[i]) {
1010 DISPLAY_LOGE("%{public}s fail devId:%{public}u inHandle is nullptr i = %{public}u", __func__, devId, i);
1011 return HDF_FAILURE;
1012 }
1013 handles.emplace_back(inHandles[i]->GetBufferHandle());
1014 }
1015
1016 int32_t ret = vdiAdapter_->FastPresent(devId, param, handles);
1017 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
1018 DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
1019 return ret;
1020 }
1021
OnHwcEvent(uint32_t devId,uint32_t eventId,const std::vector<int32_t> & eventData,void * data)1022 void DisplayComposerService::OnHwcEvent(uint32_t devId, uint32_t eventId,
1023 const std::vector<int32_t>& eventData, void *data)
1024 {
1025 if (data == nullptr) {
1026 DISPLAY_LOGE("cb data is nullptr");
1027 return;
1028 }
1029
1030 sptr<IHwcEventCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->hwcEventCb_;
1031 if (remoteCb == nullptr) {
1032 DISPLAY_LOGE("remoteCb is nullptr");
1033 return;
1034 }
1035 remoteCb->OnHwcEvent(devId, eventId, eventData);
1036 }
1037
RegHwcEventCallback(const sptr<IHwcEventCallback> & cb)1038 int32_t DisplayComposerService::RegHwcEventCallback(const sptr<IHwcEventCallback>& cb)
1039 {
1040 DISPLAY_TRACE;
1041 DISPLAY_CHK_RETURN(vdiAdapter_ == nullptr, HDF_ERR_NOT_SUPPORT);
1042 CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegHwcEventCallback, HDF_ERR_NOT_SUPPORT);
1043 hwcEventCb_ = cb;
1044 int32_t ret = vdiAdapter_->RegHwcEventCallback(OnHwcEvent, this);
1045 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
1046 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
1047 return ret;
1048 }
1049 } // namespace Composer
1050 } // namespace Display
1051 } // namespace HDI
1052 } // namespace OHOS
1053