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 "display_log.h"
22 #include "hdf_log.h"
23 #include "hdf_trace.h"
24 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
25 #include "display_dump_service.h"
26 #endif
27
28 #undef LOG_TAG
29 #define LOG_TAG "COMPOSER_SRV"
30 #undef LOG_DOMAIN
31 #define LOG_DOMAIN 0xD002515
32
33 #undef DISPLAY_TRACE
34 #define DISPLAY_TRACE HdfTrace trace(__func__, "HDI:DISP:")
35
36 namespace OHOS {
37 namespace HDI {
38 namespace Display {
39 namespace Composer {
DisplayComposerImplGetInstance(void)40 extern "C" V1_1::IDisplayComposer* DisplayComposerImplGetInstance(void)
41 {
42 return new (std::nothrow) DisplayComposerService();
43 }
44
DisplayComposerService()45 DisplayComposerService::DisplayComposerService()
46 : libHandle_(nullptr),
47 cacheMgr_(nullptr),
48 currentBacklightLevel_(0),
49 hotPlugCb_(nullptr),
50 vBlankCb_(nullptr),
51 modeCb_(nullptr),
52 seamlessChangeCb_(nullptr),
53 vdiImpl_(nullptr),
54 destroyVdiFunc_(nullptr),
55 cmdResponser_(nullptr),
56 vdiImplV1_1_(nullptr),
57 destroyVdiFuncV1_1_(nullptr),
58 cmdResponserV1_1_(nullptr),
59 refreshCb_(nullptr)
60 {
61 int32_t ret = LoadVdiSo();
62 if (ret != HDF_SUCCESS) {
63 DISPLAY_LOGE("Load composer VDI failed, lib: %{public}s", DISPLAY_COMPOSER_VDI_LIBRARY);
64 return;
65 }
66
67 ret = LoadVdiV1_1();
68 if (ret != HDF_SUCCESS) {
69 ret = LoadVdiV1_0();
70 }
71
72 if (ret != HDF_SUCCESS) {
73 dlclose(libHandle_);
74 libHandle_ = nullptr;
75 DISPLAY_LOGE("Load composer VDI function failed");
76 }
77
78 HidumperInit();
79 }
80
~DisplayComposerService()81 DisplayComposerService::~DisplayComposerService()
82 {
83 cmdResponser_ = nullptr;
84 cmdResponserV1_1_ = nullptr;
85
86 if ((destroyVdiFunc_ != nullptr) && (vdiImpl_ != nullptr)) {
87 destroyVdiFunc_(vdiImpl_);
88 }
89
90 if ((destroyVdiFuncV1_1_ != nullptr) && (vdiImplV1_1_ != nullptr)) {
91 destroyVdiFuncV1_1_(vdiImplV1_1_);
92 }
93
94 if (libHandle_ != nullptr) {
95 dlclose(libHandle_);
96 }
97 }
98
HidumperInit()99 void DisplayComposerService::HidumperInit()
100 {
101 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
102 VdiDumper& dumper = VdiDumper::GetInstance();
103 dumper.SetDumpInfoFunc(reinterpret_cast<GetDumpInfoFunc>(dlsym(libHandle_, "GetDumpInfo")));
104 dumper.SetConfigFunc(reinterpret_cast<UpdateConfigFunc>(dlsym(libHandle_, "UpdateConfig")));
105 (void)DevHostRegisterDumpHost(ComposerDumpEvent);
106 #endif
107 }
108
LoadVdiSo()109 int32_t DisplayComposerService::LoadVdiSo()
110 {
111 const char* errStr = dlerror();
112 if (errStr != nullptr) {
113 DISPLAY_LOGI("composer load vdi, clear earlier dlerror: %{public}s", errStr);
114 }
115 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
116 libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY, RTLD_LAZY);
117 if (libHandle_ == nullptr) {
118 DISPLAY_LOGE("composer load vendor vdi default library failed: %{public}s",
119 DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
120 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
121 libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_LIBRARY, RTLD_LAZY);
122 DISPLAY_LOGI("composer load vendor vdi library: %{public}s", DISPLAY_COMPOSER_VDI_LIBRARY);
123 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
124 } else {
125 DISPLAY_LOGI("composer load vendor vdi default library: %{public}s", DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
126 }
127 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
128 CHECK_NULLPOINTER_RETURN_VALUE(libHandle_, HDF_FAILURE);
129
130 return HDF_SUCCESS;
131 }
132
LoadVdiV1_0()133 int32_t DisplayComposerService::LoadVdiV1_0()
134 {
135 CreateComposerVdiFunc createVdiFunc = nullptr;
136 const char* errStr = nullptr;
137
138 createVdiFunc = reinterpret_cast<CreateComposerVdiFunc>(dlsym(libHandle_, "CreateComposerVdi"));
139 if (createVdiFunc == nullptr) {
140 errStr = dlerror();
141 if (errStr != nullptr) {
142 DISPLAY_LOGE("CreateVdiFuncV1_0 dlsym error: %{public}s", errStr);
143 }
144 return HDF_FAILURE;
145 }
146
147 destroyVdiFunc_ = reinterpret_cast<DestroyComposerVdiFunc>(dlsym(libHandle_, "DestroyComposerVdi"));
148 if (destroyVdiFunc_ == nullptr) {
149 errStr = dlerror();
150 if (errStr != nullptr) {
151 DISPLAY_LOGE("DestroyVdiFuncV1_0 dlsym error: %{public}s", errStr);
152 }
153 return HDF_FAILURE;
154 }
155
156 vdiImpl_ = createVdiFunc();
157 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
158 cacheMgr_ = DeviceCacheManager::GetInstance();
159 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
160 cmdResponser_ = V1_0::HdiDisplayCmdResponser::Create(vdiImpl_, cacheMgr_);
161 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
162 return HDF_SUCCESS;
163 }
164
LoadVdiV1_1()165 int32_t DisplayComposerService::LoadVdiV1_1()
166 {
167 CreateComposerVdiFuncV1_1 createVdiFunc = nullptr;
168 const char* errStr = nullptr;
169
170 createVdiFunc = reinterpret_cast<CreateComposerVdiFuncV1_1>(dlsym(libHandle_, "CreateComposerVdiV1_1"));
171 if (createVdiFunc == nullptr) {
172 errStr = dlerror();
173 if (errStr != nullptr) {
174 DISPLAY_LOGE("CreateVdiFuncV1_1 dlsym error: %{public}s", errStr);
175 }
176 return HDF_FAILURE;
177 }
178
179 destroyVdiFuncV1_1_ = reinterpret_cast<DestroyComposerVdiFuncV1_1>(dlsym(libHandle_, "DestroyComposerVdiV1_1"));
180 if (destroyVdiFuncV1_1_ == nullptr) {
181 errStr = dlerror();
182 if (errStr != nullptr) {
183 DISPLAY_LOGE("DestroyVdiFuncV1_1 dlsym error: %{public}s", errStr);
184 }
185 return HDF_FAILURE;
186 }
187
188 vdiImplV1_1_ = createVdiFunc();
189 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_FAILURE);
190 vdiImpl_ = dynamic_cast<IDisplayComposerVdi*>(vdiImplV1_1_);
191 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
192 cacheMgr_ = DeviceCacheManager::GetInstance();
193 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
194 cmdResponserV1_1_ = V1_1::HdiDisplayCmdResponser::Create(vdiImplV1_1_, cacheMgr_);
195 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponserV1_1_, HDF_FAILURE);
196 return HDF_SUCCESS;
197 }
198
OnHotPlug(uint32_t outputId,bool connected,void * data)199 void DisplayComposerService::OnHotPlug(uint32_t outputId, bool connected, void* data)
200 {
201 if (data == nullptr) {
202 DISPLAY_LOGE("cb data is nullptr");
203 return;
204 }
205
206 auto cacheMgr = reinterpret_cast<DisplayComposerService*>(data)->cacheMgr_;
207 if (cacheMgr == nullptr) {
208 DISPLAY_LOGE("CacheMgr_ is nullptr");
209 return;
210 }
211 if (connected) {
212 std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
213 // Add new device cache
214 if (cacheMgr->AddDeviceCache(outputId) != HDF_SUCCESS) {
215 DISPLAY_LOGE("Add device cache failed");
216 }
217 } else {
218 std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
219 // Del new device cache
220 if (cacheMgr->RemoveDeviceCache(outputId) != HDF_SUCCESS) {
221 DISPLAY_LOGE("Del device cache failed");
222 }
223 }
224
225 sptr<IHotPlugCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->hotPlugCb_;
226 if (remoteCb == nullptr) {
227 DISPLAY_LOGE("hotPlugCb_ is nullptr");
228 return;
229 }
230 remoteCb->OnHotPlug(outputId, connected);
231 }
232
OnVBlank(unsigned int sequence,uint64_t ns,void * data)233 void DisplayComposerService::OnVBlank(unsigned int sequence, uint64_t ns, void* data)
234 {
235 if (data == nullptr) {
236 DISPLAY_LOGE("cb data is nullptr");
237 return;
238 }
239
240 IVBlankCallback* remoteCb = reinterpret_cast<IVBlankCallback*>(data);
241 if (remoteCb == nullptr) {
242 DISPLAY_LOGE("vblankCb_ is nullptr");
243 return;
244 }
245 remoteCb->OnVBlank(sequence, ns);
246 }
247
RegHotPlugCallback(const sptr<IHotPlugCallback> & cb)248 int32_t DisplayComposerService::RegHotPlugCallback(const sptr<IHotPlugCallback>& cb)
249 {
250 DISPLAY_TRACE;
251
252 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
253 hotPlugCb_ = cb;
254 int32_t ret = vdiImpl_->RegHotPlugCallback(OnHotPlug, this);
255 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
256 return ret;
257 }
258
SetClientBufferCacheCount(uint32_t devId,uint32_t count)259 int32_t DisplayComposerService::SetClientBufferCacheCount(uint32_t devId, uint32_t count)
260 {
261 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
262 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
263 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
264 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
265 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
266
267 DISPLAY_CHK_RETURN(devCache->SetClientBufferCacheCount(count) != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("fail"));
268 return HDF_SUCCESS;
269 }
270
GetDisplayCapability(uint32_t devId,DisplayCapability & info)271 int32_t DisplayComposerService::GetDisplayCapability(uint32_t devId, DisplayCapability& info)
272 {
273 DISPLAY_TRACE;
274
275 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
276 int32_t ret = vdiImpl_->GetDisplayCapability(devId, info);
277 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
278 return HDF_SUCCESS;
279 }
280
GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)281 int32_t DisplayComposerService::GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes)
282 {
283 DISPLAY_TRACE;
284
285 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
286 int32_t ret = vdiImpl_->GetDisplaySupportedModes(devId, modes);
287 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
288 return ret;
289 }
290
GetDisplayMode(uint32_t devId,uint32_t & modeId)291 int32_t DisplayComposerService::GetDisplayMode(uint32_t devId, uint32_t& modeId)
292 {
293 DISPLAY_TRACE;
294
295 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
296 int32_t ret = vdiImpl_->GetDisplayMode(devId, modeId);
297 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
298 return ret;
299 }
300
SetDisplayMode(uint32_t devId,uint32_t modeId)301 int32_t DisplayComposerService::SetDisplayMode(uint32_t devId, uint32_t modeId)
302 {
303 DISPLAY_TRACE;
304
305 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
306 int32_t ret = vdiImpl_->SetDisplayMode(devId, modeId);
307 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
308 return ret;
309 }
310
GetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus & status)311 int32_t DisplayComposerService::GetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus& status)
312 {
313 DISPLAY_TRACE;
314
315 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
316 int32_t ret = vdiImpl_->GetDisplayPowerStatus(devId, status);
317 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
318 return ret;
319 }
320
SetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus status)321 int32_t DisplayComposerService::SetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus status)
322 {
323 DISPLAY_TRACE;
324
325 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
326 int32_t ret = vdiImpl_->SetDisplayPowerStatus(devId, status);
327 DISPLAY_LOGI("devid: %{public}u, status: %{public}u, vdi return %{public}d", devId, status, ret);
328 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
329 return ret;
330 }
331
GetDisplayBacklight(uint32_t devId,uint32_t & level)332 int32_t DisplayComposerService::GetDisplayBacklight(uint32_t devId, uint32_t& level)
333 {
334 DISPLAY_TRACE;
335
336 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
337 int32_t ret = vdiImpl_->GetDisplayBacklight(devId, level);
338 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_SUCCESS, level = currentBacklightLevel_);
339 return ret;
340 }
341
SetDisplayBacklight(uint32_t devId,uint32_t level)342 int32_t DisplayComposerService::SetDisplayBacklight(uint32_t devId, uint32_t level)
343 {
344 DISPLAY_TRACE;
345
346 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
347 int32_t ret = vdiImpl_->SetDisplayBacklight(devId, level);
348 DISPLAY_LOGD("devid: %{public}u, level: %{public}u, vdi return %{public}d", devId, level, ret);
349 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
350 currentBacklightLevel_ = level;
351 return ret;
352 }
353
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)354 int32_t DisplayComposerService::GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value)
355 {
356 DISPLAY_TRACE;
357
358 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
359 int32_t ret = vdiImpl_->GetDisplayProperty(devId, id, value);
360 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
361 return ret;
362 }
363
SetDisplayClientCrop(uint32_t devId,const IRect & rect)364 int32_t DisplayComposerService::SetDisplayClientCrop(uint32_t devId, const IRect& rect)
365 {
366 DISPLAY_TRACE;
367
368 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
369 int32_t ret = vdiImpl_->SetDisplayClientCrop(devId, rect);
370 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
371 return ret;
372 }
373
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)374 int32_t DisplayComposerService::SetDisplayVsyncEnabled(uint32_t devId, bool enabled)
375 {
376 DISPLAY_TRACE;
377
378 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
379 int32_t ret = vdiImpl_->SetDisplayVsyncEnabled(devId, enabled);
380 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
381 return ret;
382 }
383
RegDisplayVBlankCallback(uint32_t devId,const sptr<IVBlankCallback> & cb)384 int32_t DisplayComposerService::RegDisplayVBlankCallback(uint32_t devId, const sptr<IVBlankCallback>& cb)
385 {
386 DISPLAY_TRACE;
387
388 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
389 int32_t ret = vdiImpl_->RegDisplayVBlankCallback(devId, OnVBlank, cb.GetRefPtr());
390 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
391 vBlankCb_ = cb;
392 return ret;
393 }
394
GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<sptr<HdifdParcelable>> & fences)395 int32_t DisplayComposerService::GetDisplayReleaseFence(
396 uint32_t devId, std::vector<uint32_t>& layers, std::vector<sptr<HdifdParcelable>>& fences)
397 {
398 DISPLAY_TRACE;
399
400 std::vector<int32_t> outFences;
401 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
402 int32_t ret = vdiImpl_->GetDisplayReleaseFence(devId, layers, outFences);
403 for (uint i = 0; i < outFences.size(); i++) {
404 int32_t dupFd = outFences[i];
405 sptr<HdifdParcelable> hdifd(new HdifdParcelable());
406 CHECK_NULLPOINTER_RETURN_VALUE(hdifd, HDF_FAILURE);
407 hdifd->Init(dupFd);
408 fences.push_back(hdifd);
409 }
410 return ret;
411 }
412
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)413 int32_t DisplayComposerService::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId)
414 {
415 DISPLAY_TRACE;
416
417 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
418 int32_t ret = vdiImpl_->CreateVirtualDisplay(width, height, format, devId);
419 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
420 return ret;
421 }
422
DestroyVirtualDisplay(uint32_t devId)423 int32_t DisplayComposerService::DestroyVirtualDisplay(uint32_t devId)
424 {
425 DISPLAY_TRACE;
426
427 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
428 int32_t ret = vdiImpl_->DestroyVirtualDisplay(devId);
429 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
430 return ret;
431 }
432
SetVirtualDisplayBuffer(uint32_t devId,const sptr<NativeBuffer> & buffer,const sptr<HdifdParcelable> & fence)433 int32_t DisplayComposerService::SetVirtualDisplayBuffer(
434 uint32_t devId, const sptr<NativeBuffer>& buffer, const sptr<HdifdParcelable>& fence)
435 {
436 DISPLAY_TRACE;
437
438 CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_FAILURE);
439 CHECK_NULLPOINTER_RETURN_VALUE(fence, HDF_FAILURE);
440 BufferHandle* handle = buffer->GetBufferHandle();
441 int32_t inFence = fence->GetFd();
442 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
443 CHECK_NULLPOINTER_RETURN_VALUE(handle, HDF_FAILURE);
444 int32_t ret = vdiImpl_->SetVirtualDisplayBuffer(devId, *handle, inFence);
445 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
446 return ret;
447 }
448
SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)449 int32_t DisplayComposerService::SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value)
450 {
451 DISPLAY_TRACE;
452
453 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
454 int32_t ret = vdiImpl_->SetDisplayProperty(devId, id, value);
455 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
456 return ret;
457 }
458
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)459 int32_t DisplayComposerService::CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount,
460 uint32_t& layerId)
461 {
462 DISPLAY_TRACE;
463
464 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
465 int32_t ret = vdiImpl_->CreateLayer(devId, layerInfo, layerId);
466 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
467
468 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
469 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
470 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
471 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
472
473 return devCache->AddLayerCache(layerId, cacheCount);
474 }
475
DestroyLayer(uint32_t devId,uint32_t layerId)476 int32_t DisplayComposerService::DestroyLayer(uint32_t devId, uint32_t layerId)
477 {
478 DISPLAY_TRACE;
479 CHECK_NULLPOINTER_RETURN_VALUE(vdiImpl_, HDF_FAILURE);
480 int32_t ret = vdiImpl_->DestroyLayer(devId, layerId);
481 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
482
483 CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
484 std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
485 DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
486 DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
487
488 return devCache->RemoveLayerCache(layerId);
489 }
490
RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback> & cb)491 int32_t DisplayComposerService::RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback>& cb)
492 {
493 DISPLAY_TRACE;
494 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
495 int32_t ret = vdiImplV1_1_->RegSeamlessChangeCallback(OnSeamlessChange, this);
496 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
497 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
498 if (ret == HDF_SUCCESS) {
499 seamlessChangeCb_ = cb;
500 }
501 return ret;
502 }
503
GetDisplaySupportedModesExt(uint32_t devId,std::vector<DisplayModeInfoExt> & modes)504 int32_t DisplayComposerService::GetDisplaySupportedModesExt(uint32_t devId, std::vector<DisplayModeInfoExt>& modes)
505 {
506 DISPLAY_TRACE;
507 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
508 int32_t ret = vdiImplV1_1_->GetDisplaySupportedModesExt(devId, modes);
509 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
510 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
511 return ret;
512 }
513
OnMode(uint32_t modeId,uint64_t vBlankPeriod,void * data)514 void DisplayComposerService::OnMode(uint32_t modeId, uint64_t vBlankPeriod, void* data)
515 {
516 if (data == nullptr) {
517 DISPLAY_LOGE("data is nullptr");
518 return;
519 }
520
521 sptr<IModeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->modeCb_;
522 if (remoteCb == nullptr) {
523 DISPLAY_LOGE("remoteCb is nullptr");
524 return;
525 }
526 remoteCb->OnMode(modeId, vBlankPeriod);
527 }
528
SetDisplayModeAsync(uint32_t devId,uint32_t modeId,const sptr<IModeCallback> & cb)529 int32_t DisplayComposerService::SetDisplayModeAsync(uint32_t devId, uint32_t modeId, const sptr<IModeCallback>& cb)
530 {
531 DISPLAY_TRACE;
532 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
533 int32_t ret = vdiImplV1_1_->SetDisplayModeAsync(devId, modeId, OnMode, this);
534 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
535 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
536 if (ret == HDF_SUCCESS) {
537 modeCb_ = cb;
538 }
539 return ret;
540 }
541
GetDisplayVBlankPeriod(uint32_t devId,uint64_t & period)542 int32_t DisplayComposerService::GetDisplayVBlankPeriod(uint32_t devId, uint64_t& period)
543 {
544 DISPLAY_TRACE;
545 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
546 int32_t ret = vdiImplV1_1_->GetDisplayVBlankPeriod(devId, period);
547 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
548 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
549 return ret;
550 }
551
OnSeamlessChange(uint32_t devId,void * data)552 void DisplayComposerService::OnSeamlessChange(uint32_t devId, void* data)
553 {
554 if (data == nullptr) {
555 DISPLAY_LOGE("data is nullptr");
556 return;
557 }
558
559 sptr<ISeamlessChangeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->seamlessChangeCb_;
560 if (remoteCb == nullptr) {
561 DISPLAY_LOGE("remoteCb is nullptr");
562 return;
563 }
564 remoteCb->OnSeamlessChange(devId);
565 }
566
InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>> & request)567 int32_t DisplayComposerService::InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request)
568 {
569 CHECK_NULLPOINTER_RETURN_VALUE(request, HDF_FAILURE);
570 int32_t ret = HDF_FAILURE;
571
572 if (cmdResponserV1_1_ != nullptr) {
573 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponserV1_1_, HDF_FAILURE);
574 ret = cmdResponserV1_1_->InitCmdRequest(request);
575 } else if (cmdResponser_ != nullptr) {
576 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
577 ret = cmdResponser_->InitCmdRequest(request);
578 }
579 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
580 return ret;
581 }
582
CmdRequest(uint32_t inEleCnt,const std::vector<HdifdInfo> & inFds,uint32_t & outEleCnt,std::vector<HdifdInfo> & outFds)583 int32_t DisplayComposerService::CmdRequest(
584 uint32_t inEleCnt, const std::vector<HdifdInfo>& inFds, uint32_t& outEleCnt, std::vector<HdifdInfo>& outFds)
585 {
586 int32_t ret = HDF_FAILURE;
587
588 if (cmdResponserV1_1_ != nullptr) {
589 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponserV1_1_, HDF_FAILURE);
590 ret = cmdResponserV1_1_->CmdRequest(inEleCnt, inFds, outEleCnt, outFds);
591 } else if (cmdResponser_ != nullptr) {
592 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
593 ret = cmdResponser_->CmdRequest(inEleCnt, inFds, outEleCnt, outFds);
594 }
595 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
596 return ret;
597 }
598
GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>> & reply)599 int32_t DisplayComposerService::GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply)
600 {
601 int32_t ret = HDF_FAILURE;
602
603 if (cmdResponserV1_1_ != nullptr) {
604 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponserV1_1_, HDF_FAILURE);
605 ret = cmdResponserV1_1_->GetCmdReply(reply);
606 } else if (cmdResponser_ != nullptr) {
607 CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
608 ret = cmdResponser_->GetCmdReply(reply);
609 }
610 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
611 return ret;
612 }
613
SetLayerPerFrameParameter(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)614 int32_t DisplayComposerService::SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
615 const std::vector<int8_t>& value)
616 {
617 DISPLAY_TRACE;
618 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
619 int32_t ret = vdiImplV1_1_->SetLayerPerFrameParameter(devId, layerId, key, value);
620 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
621 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
622 return ret;
623 }
624
GetSupportedLayerPerFrameParameterKey(std::vector<std::string> & keys)625 int32_t DisplayComposerService::GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys)
626 {
627 DISPLAY_TRACE;
628 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
629 int32_t ret = vdiImplV1_1_->GetSupportedLayerPerFrameParameterKey(keys);
630 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
631 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
632 return ret;
633 }
634
SetDisplayOverlayResolution(uint32_t devId,uint32_t width,uint32_t height)635 int32_t DisplayComposerService::SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height)
636 {
637 DISPLAY_TRACE;
638 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
639 int32_t ret = vdiImplV1_1_->SetDisplayOverlayResolution(devId, width, height);
640 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
641 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
642 return ret;
643 }
644
OnRefresh(uint32_t devId,void * data)645 void DisplayComposerService::OnRefresh(uint32_t devId, void *data)
646 {
647 if (data == nullptr) {
648 DISPLAY_LOGE("cb data is nullptr");
649 return;
650 }
651
652 sptr<IRefreshCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->refreshCb_;
653 if (remoteCb == nullptr) {
654 DISPLAY_LOGE("remoteCb is nullptr");
655 return;
656 }
657 remoteCb->OnRefresh(devId);
658 }
659
RegRefreshCallback(const sptr<IRefreshCallback> & cb)660 int32_t DisplayComposerService::RegRefreshCallback(const sptr<IRefreshCallback>& cb)
661 {
662 DISPLAY_TRACE;
663 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
664 int32_t ret = vdiImplV1_1_->RegRefreshCallback(OnRefresh, this);
665 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
666 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
667 if (ret == HDF_SUCCESS) {
668 refreshCb_ = cb;
669 }
670 return ret;
671 }
672
GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)673 int32_t DisplayComposerService::GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts)
674 {
675 DISPLAY_TRACE;
676 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
677 int32_t ret = vdiImplV1_1_->GetDisplaySupportedColorGamuts(devId, gamuts);
678 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
679 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
680 return ret;
681 }
682
GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)683 int32_t DisplayComposerService::GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info)
684 {
685 DISPLAY_TRACE;
686 CHECK_NULLPOINTER_RETURN_VALUE(vdiImplV1_1_, HDF_ERR_NOT_SUPPORT);
687 int32_t ret = vdiImplV1_1_->GetHDRCapabilityInfos(devId, info);
688 DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
689 DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
690 return ret;
691 }
692 } // namespace Composer
693 } // namespace Display
694 } // namespace HDI
695 } // namespace OHOS
696