• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_2::IDisplayComposer* DisplayComposerImplGetInstance(void)
41 {
42     return new (std::nothrow) DisplayComposerService();
43 }
44 
DisplayComposerService()45 DisplayComposerService::DisplayComposerService()
46     : libHandle_(nullptr),
47     vdiAdapter_(new(std::nothrow) DisplayComposerVdiAdapter),
48     cacheMgr_(nullptr),
49     currentBacklightLevel_(0),
50     hotPlugCb_(nullptr),
51     vBlankCb_(nullptr),
52     modeCb_(nullptr),
53     seamlessChangeCb_(nullptr),
54     refreshCb_(nullptr),
55     VBlankIdleCb_(nullptr)
56 {
57     int32_t ret = LoadVdiSo();
58     if (ret != HDF_SUCCESS) {
59         DISPLAY_LOGE("LoadVdiSo failed");
60         return;
61     }
62 
63     if (LoadVdiAdapter() != HDF_SUCCESS) {
64         ExitService();
65         DISPLAY_LOGE("Create DisplayComposerService failed");
66         return;
67     }
68 
69     if (CreateResponser() != HDF_SUCCESS) {
70         ExitService();
71         DISPLAY_LOGE("CreateResponser failed");
72         return;
73     }
74 
75     HidumperInit();
76 }
77 
~DisplayComposerService()78 DisplayComposerService::~DisplayComposerService()
79 {
80     std::lock_guard<std::mutex> lck(mutex_);
81     ExitService();
82 }
83 
ExitService()84 void DisplayComposerService::ExitService()
85 {
86     if (vdiAdapter_ != nullptr) {
87         delete vdiAdapter_;
88         vdiAdapter_ = nullptr;
89     }
90 
91     if (libHandle_ != nullptr) {
92         dlclose(libHandle_);
93         libHandle_ = nullptr;
94     }
95 }
96 
LoadVdiAdapter()97 int32_t DisplayComposerService::LoadVdiAdapter()
98 {
99     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
100 
101     LoadVdiFuncPart1();
102     LoadVdiFuncPart2();
103     LoadVdiFuncPart3();
104     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegHotPlugCallback, HDF_FAILURE);
105     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayCapability, HDF_FAILURE);
106     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedModes, HDF_FAILURE);
107     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayMode, HDF_FAILURE);
108     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayMode, HDF_FAILURE);
109     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayPowerStatus, HDF_FAILURE);
110     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayPowerStatus, HDF_FAILURE);
111     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayBacklight, HDF_FAILURE);
112     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayBacklight, HDF_FAILURE);
113     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayProperty, HDF_FAILURE);
114     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayCompChange, HDF_FAILURE);
115     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientCrop, HDF_FAILURE);
116     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientBuffer, HDF_FAILURE);
117     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayClientDamage, HDF_FAILURE);
118     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayVsyncEnabled, HDF_FAILURE);
119     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegDisplayVBlankCallback, HDF_FAILURE);
120     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayReleaseFence, HDF_FAILURE);
121     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->CreateVirtualDisplay, HDF_FAILURE);
122     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->DestroyVirtualDisplay, HDF_FAILURE);
123     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetVirtualDisplayBuffer, HDF_FAILURE);
124     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayProperty, HDF_FAILURE);
125     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->Commit, HDF_FAILURE);
126     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->CreateLayer, HDF_FAILURE);
127     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->DestroyLayer, HDF_FAILURE);
128     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->PrepareDisplayLayers, HDF_FAILURE);
129     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerAlpha, HDF_FAILURE);
130     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerRegion, HDF_FAILURE);
131     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerCrop, HDF_FAILURE);
132     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerZorder, HDF_FAILURE);
133     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerPreMulti, HDF_FAILURE);
134     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerTransformMode, HDF_FAILURE);
135     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerDirtyRegion, HDF_FAILURE);
136     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerVisibleRegion, HDF_FAILURE);
137     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerBuffer, HDF_FAILURE);
138     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerCompositionType, HDF_FAILURE);
139     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerBlendType, HDF_FAILURE);
140     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerMaskInfo, HDF_FAILURE);
141     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerColor, HDF_FAILURE);
142     return HDF_SUCCESS;
143 }
144 
LoadVdiFuncPart1()145 void DisplayComposerService::LoadVdiFuncPart1()
146 {
147     vdiAdapter_->RegHotPlugCallback =
148         reinterpret_cast<RegHotPlugCallbackFunc>(dlsym(libHandle_, "RegHotPlugCallback"));
149     vdiAdapter_->GetDisplayCapability =
150         reinterpret_cast<GetDisplayCapabilityFunc>(dlsym(libHandle_, "GetDisplayCapability"));
151     vdiAdapter_->GetDisplaySupportedModes =
152         reinterpret_cast<GetDisplaySupportedModesFunc>(dlsym(libHandle_, "GetDisplaySupportedModes"));
153     vdiAdapter_->GetDisplayMode = reinterpret_cast<GetDisplayModeFunc>(dlsym(libHandle_, "GetDisplayMode"));
154     vdiAdapter_->SetDisplayMode = reinterpret_cast<SetDisplayModeFunc>(dlsym(libHandle_, "SetDisplayMode"));
155     vdiAdapter_->GetDisplayPowerStatus =
156         reinterpret_cast<GetDisplayPowerStatusFunc>(dlsym(libHandle_, "GetDisplayPowerStatus"));
157     vdiAdapter_->SetDisplayPowerStatus =
158         reinterpret_cast<SetDisplayPowerStatusFunc>(dlsym(libHandle_, "SetDisplayPowerStatus"));
159     vdiAdapter_->GetDisplayBacklight =
160         reinterpret_cast<GetDisplayBacklightFunc>(dlsym(libHandle_, "GetDisplayBacklight"));
161     vdiAdapter_->SetDisplayBacklight =
162         reinterpret_cast<SetDisplayBacklightFunc>(dlsym(libHandle_, "SetDisplayBacklight"));
163     vdiAdapter_->GetDisplayProperty =
164         reinterpret_cast<GetDisplayPropertyFunc>(dlsym(libHandle_, "GetDisplayProperty"));
165     vdiAdapter_->GetDisplayCompChange =
166         reinterpret_cast<GetDisplayCompChangeFunc>(dlsym(libHandle_, "GetDisplayCompChange"));
167     vdiAdapter_->SetDisplayClientCrop =
168         reinterpret_cast<SetDisplayClientCropFunc>(dlsym(libHandle_, "SetDisplayClientCrop"));
169     vdiAdapter_->SetDisplayClientBuffer =
170         reinterpret_cast<SetDisplayClientBufferFunc>(dlsym(libHandle_, "SetDisplayClientBuffer"));
171     vdiAdapter_->SetDisplayClientDamage =
172         reinterpret_cast<SetDisplayClientDamageFunc>(dlsym(libHandle_, "SetDisplayClientDamage"));
173     vdiAdapter_->SetDisplayVsyncEnabled =
174         reinterpret_cast<SetDisplayVsyncEnabledFunc>(dlsym(libHandle_, "SetDisplayVsyncEnabled"));
175     vdiAdapter_->RegDisplayVBlankCallback =
176         reinterpret_cast<RegDisplayVBlankCallbackFunc>(dlsym(libHandle_, "RegDisplayVBlankCallback"));
177     vdiAdapter_->GetDisplayReleaseFence =
178         reinterpret_cast<GetDisplayReleaseFenceFunc>(dlsym(libHandle_, "GetDisplayReleaseFence"));
179     vdiAdapter_->CreateVirtualDisplay =
180         reinterpret_cast<CreateVirtualDisplayFunc>(dlsym(libHandle_, "CreateVirtualDisplay"));
181     vdiAdapter_->DestroyVirtualDisplay =
182         reinterpret_cast<DestroyVirtualDisplayFunc>(dlsym(libHandle_, "DestroyVirtualDisplay"));
183     vdiAdapter_->SetVirtualDisplayBuffer =
184         reinterpret_cast<SetVirtualDisplayBufferFunc>(dlsym(libHandle_, "SetVirtualDisplayBuffer"));
185     vdiAdapter_->SetDisplayProperty =
186         reinterpret_cast<SetDisplayPropertyFunc>(dlsym(libHandle_, "SetDisplayProperty"));
187     vdiAdapter_->Commit = reinterpret_cast<CommitFunc>(dlsym(libHandle_, "Commit"));
188     vdiAdapter_->CreateLayer = reinterpret_cast<CreateLayerFunc>(dlsym(libHandle_, "CreateLayer"));
189     vdiAdapter_->DestroyLayer = reinterpret_cast<DestroyLayerFunc>(dlsym(libHandle_, "DestroyLayer"));
190     vdiAdapter_->PrepareDisplayLayers =
191         reinterpret_cast<PrepareDisplayLayersFunc>(dlsym(libHandle_, "PrepareDisplayLayers"));
192     vdiAdapter_->SetLayerAlpha = reinterpret_cast<SetLayerAlphaFunc>(dlsym(libHandle_, "SetLayerAlpha"));
193     vdiAdapter_->SetLayerRegion = reinterpret_cast<SetLayerRegionFunc>(dlsym(libHandle_, "SetLayerRegion"));
194 }
195 
LoadVdiFuncPart2()196 void DisplayComposerService::LoadVdiFuncPart2()
197 {
198     vdiAdapter_->SetLayerCrop = reinterpret_cast<SetLayerCropFunc>(dlsym(libHandle_, "SetLayerCrop"));
199     vdiAdapter_->SetLayerZorder = reinterpret_cast<SetLayerZorderFunc>(dlsym(libHandle_, "SetLayerZorder"));
200     vdiAdapter_->SetLayerPreMulti = reinterpret_cast<SetLayerPreMultiFunc>(dlsym(libHandle_, "SetLayerPreMulti"));
201     vdiAdapter_->SetLayerTransformMode =
202         reinterpret_cast<SetLayerTransformModeFunc>(dlsym(libHandle_, "SetLayerTransformMode"));
203     vdiAdapter_->SetLayerDirtyRegion =
204         reinterpret_cast<SetLayerDirtyRegionFunc>(dlsym(libHandle_, "SetLayerDirtyRegion"));
205     vdiAdapter_->SetLayerVisibleRegion =
206         reinterpret_cast<SetLayerVisibleRegionFunc>(dlsym(libHandle_, "SetLayerVisibleRegion"));
207     vdiAdapter_->SetLayerBuffer = reinterpret_cast<SetLayerBufferFunc>(dlsym(libHandle_, "SetLayerBuffer"));
208     vdiAdapter_->SetLayerCompositionType =
209         reinterpret_cast<SetLayerCompositionTypeFunc>(dlsym(libHandle_, "SetLayerCompositionType"));
210     vdiAdapter_->SetLayerBlendType =
211         reinterpret_cast<SetLayerBlendTypeFunc>(dlsym(libHandle_, "SetLayerBlendType"));
212     vdiAdapter_->SetLayerMaskInfo = reinterpret_cast<SetLayerMaskInfoFunc>(dlsym(libHandle_, "SetLayerMaskInfo"));
213     vdiAdapter_->SetLayerColor = reinterpret_cast<SetLayerColorFunc>(dlsym(libHandle_, "SetLayerColor"));
214     vdiAdapter_->RegSeamlessChangeCallback =
215         reinterpret_cast<RegSeamlessChangeCallbackFunc>(dlsym(libHandle_, "RegSeamlessChangeCallback"));
216     vdiAdapter_->GetDisplaySupportedModesExt =
217         reinterpret_cast<GetDisplaySupportedModesExtFunc>(dlsym(libHandle_, "GetDisplaySupportedModesExt"));
218     vdiAdapter_->SetDisplayModeAsync =
219         reinterpret_cast<SetDisplayModeAsyncFunc>(dlsym(libHandle_, "SetDisplayModeAsync"));
220     vdiAdapter_->GetDisplayVBlankPeriod =
221         reinterpret_cast<GetDisplayVBlankPeriodFunc>(dlsym(libHandle_, "GetDisplayVBlankPeriod"));
222     vdiAdapter_->SetLayerPerFrameParameter =
223         reinterpret_cast<SetLayerPerFrameParameterFunc>(dlsym(libHandle_, "SetLayerPerFrameParameter"));
224     vdiAdapter_->GetSupportedLayerPerFrameParameterKey = reinterpret_cast<GetSupportedLayerPerFrameParameterKeyFunc>(
225         dlsym(libHandle_, "GetSupportedLayerPerFrameParameterKey"));
226     vdiAdapter_->SetDisplayOverlayResolution =
227         reinterpret_cast<SetDisplayOverlayResolutionFunc>(dlsym(libHandle_, "SetDisplayOverlayResolution"));
228     vdiAdapter_->RegRefreshCallback =
229         reinterpret_cast<RegRefreshCallbackFunc>(dlsym(libHandle_, "RegRefreshCallback"));
230     vdiAdapter_->GetDisplaySupportedColorGamuts =
231         reinterpret_cast<GetDisplaySupportedColorGamutsFunc>(dlsym(libHandle_, "GetDisplaySupportedColorGamuts"));
232     vdiAdapter_->GetHDRCapabilityInfos =
233         reinterpret_cast<GetHDRCapabilityInfosFunc>(dlsym(libHandle_, "GetHDRCapabilityInfos"));
234     vdiAdapter_->RegDisplayVBlankIdleCallback =
235         reinterpret_cast<RegDisplayVBlankIdleCallbackFunc>(dlsym(libHandle_, "RegDisplayVBlankIdleCallback"));
236     vdiAdapter_->SetDisplayConstraint =
237         reinterpret_cast<SetDisplayConstraintFunc>(dlsym(libHandle_, "SetDisplayConstraint"));
238     vdiAdapter_->SetHardwareCursorPosition =
239         reinterpret_cast<SetHardwareCursorPositionFunc>(dlsym(libHandle_, "SetHardwareCursorPosition"));
240     vdiAdapter_->EnableHardwareCursorStats =
241         reinterpret_cast<EnableHardwareCursorStatsFunc>(dlsym(libHandle_, "EnableHardwareCursorStats"));
242     vdiAdapter_->GetHardwareCursorStats =
243         reinterpret_cast<GetHardwareCursorStatsFunc>(dlsym(libHandle_, "GetHardwareCursorStats"));
244 }
245 
LoadVdiFuncPart3()246 void DisplayComposerService::LoadVdiFuncPart3()
247 {
248     vdiAdapter_->SetDisplayActiveRegion =
249         reinterpret_cast<SetDisplayActiveRegionFunc>(dlsym(libHandle_, "SetDisplayActiveRegion"));
250 }
251 
HidumperInit()252 void DisplayComposerService::HidumperInit()
253 {
254 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
255     VdiDumper& dumper = VdiDumper::GetInstance();
256     dumper.SetDumpInfoFunc(reinterpret_cast<GetDumpInfoFunc>(dlsym(libHandle_, "GetDumpInfo")));
257     dumper.SetConfigFunc(reinterpret_cast<UpdateConfigFunc>(dlsym(libHandle_, "UpdateConfig")));
258     (void)DevHostRegisterDumpHost(ComposerDumpEvent);
259 #endif
260 }
261 
LoadVdiSo()262 int32_t DisplayComposerService::LoadVdiSo()
263 {
264     const char* errStr = dlerror();
265     if (errStr != nullptr) {
266         DISPLAY_LOGD("composer load vdi, clear earlier dlerror: %{public}s", errStr);
267     }
268 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
269     libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY, RTLD_LAZY);
270     if (libHandle_ == nullptr) {
271         DISPLAY_LOGE("composer load vendor vdi default library failed: %{public}s",
272             DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
273 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
274         libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_LIBRARY, RTLD_LAZY);
275         DISPLAY_LOGD("composer load vendor vdi library: %{public}s", DISPLAY_COMPOSER_VDI_LIBRARY);
276 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
277     } else {
278         DISPLAY_LOGD("composer load vendor vdi default library: %{public}s", DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
279     }
280 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
281     CHECK_NULLPOINTER_RETURN_VALUE(libHandle_, HDF_FAILURE);
282 
283     return HDF_SUCCESS;
284 }
285 
CreateResponser()286 int32_t DisplayComposerService::DisplayComposerService::CreateResponser()
287 {
288     cacheMgr_ = DeviceCacheManager::GetInstance();
289     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
290     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
291     cmdResponser_ = V1_2::HdiDisplayCmdResponser::Create(vdiAdapter_, cacheMgr_);
292     CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
293     DISPLAY_LOGI("%{public}s out", __func__);
294     return HDF_SUCCESS;
295 }
296 
OnHotPlug(uint32_t outputId,bool connected,void * data)297 void DisplayComposerService::OnHotPlug(uint32_t outputId, bool connected, void* data)
298 {
299     if (data == nullptr) {
300         DISPLAY_LOGE("cb data is nullptr");
301         return;
302     }
303 
304     auto cacheMgr = reinterpret_cast<DisplayComposerService*>(data)->cacheMgr_;
305     if (cacheMgr == nullptr) {
306         DISPLAY_LOGE("CacheMgr_ is nullptr");
307         return;
308     }
309     if (connected) {
310         std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
311         // Add new device cache
312         if (cacheMgr->AddDeviceCache(outputId) != HDF_SUCCESS) {
313             DISPLAY_LOGE("Add device cache failed");
314         }
315     } else {
316         std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
317         // Del new device cache
318         if (cacheMgr->RemoveDeviceCache(outputId) != HDF_SUCCESS) {
319             DISPLAY_LOGE("Del device cache failed");
320         }
321     }
322 
323     sptr<IHotPlugCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->hotPlugCb_;
324     if (remoteCb == nullptr) {
325         DISPLAY_LOGE("hotPlugCb_ is nullptr");
326         return;
327     }
328     remoteCb->OnHotPlug(outputId, connected);
329 }
330 
OnVBlank(unsigned int sequence,uint64_t ns,void * data)331 void DisplayComposerService::OnVBlank(unsigned int sequence, uint64_t ns, void* data)
332 {
333     if (data == nullptr) {
334         DISPLAY_LOGE("cb data is nullptr");
335         return;
336     }
337 
338     IVBlankCallback* remoteCb = reinterpret_cast<IVBlankCallback*>(data);
339     if (remoteCb == nullptr) {
340         DISPLAY_LOGE("vblankCb_ is nullptr");
341         return;
342     }
343     remoteCb->OnVBlank(sequence, ns);
344 }
345 
RegHotPlugCallback(const sptr<IHotPlugCallback> & cb)346 int32_t DisplayComposerService::RegHotPlugCallback(const sptr<IHotPlugCallback>& cb)
347 {
348     DISPLAY_TRACE;
349 
350     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
351     hotPlugCb_ = cb;
352     int32_t ret = vdiAdapter_->RegHotPlugCallback(OnHotPlug, this);
353     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
354     return ret;
355 }
356 
SetClientBufferCacheCount(uint32_t devId,uint32_t count)357 int32_t DisplayComposerService::SetClientBufferCacheCount(uint32_t devId, uint32_t count)
358 {
359     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
360     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
361     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
362     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
363     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
364 
365     DISPLAY_CHK_RETURN(devCache->SetClientBufferCacheCount(count) != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("fail"));
366     return HDF_SUCCESS;
367 }
368 
GetDisplayCapability(uint32_t devId,DisplayCapability & info)369 int32_t DisplayComposerService::GetDisplayCapability(uint32_t devId, DisplayCapability& info)
370 {
371     DISPLAY_TRACE;
372 
373     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
374     int32_t ret =  vdiAdapter_->GetDisplayCapability(devId, info);
375     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
376     return HDF_SUCCESS;
377 }
378 
GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)379 int32_t DisplayComposerService::GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes)
380 {
381     DISPLAY_TRACE;
382 
383     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
384     int32_t ret =  vdiAdapter_->GetDisplaySupportedModes(devId, modes);
385     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
386     return ret;
387 }
388 
GetDisplayMode(uint32_t devId,uint32_t & modeId)389 int32_t DisplayComposerService::GetDisplayMode(uint32_t devId, uint32_t& modeId)
390 {
391     DISPLAY_TRACE;
392 
393     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
394     int32_t ret =  vdiAdapter_->GetDisplayMode(devId, modeId);
395     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
396     return ret;
397 }
398 
SetDisplayMode(uint32_t devId,uint32_t modeId)399 int32_t DisplayComposerService::SetDisplayMode(uint32_t devId, uint32_t modeId)
400 {
401     DISPLAY_TRACE;
402 
403     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
404     int32_t ret =  vdiAdapter_->SetDisplayMode(devId, modeId);
405     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
406     return ret;
407 }
408 
GetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus & status)409 int32_t DisplayComposerService::GetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus& status)
410 {
411     DISPLAY_TRACE;
412 
413     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
414     int32_t ret = vdiAdapter_->GetDisplayPowerStatus(devId, status);
415     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
416     return ret;
417 }
418 
SetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus status)419 int32_t DisplayComposerService::SetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus status)
420 {
421     DISPLAY_TRACE;
422 
423     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
424     int32_t ret = vdiAdapter_->SetDisplayPowerStatus(devId, status);
425     DISPLAY_LOGI("devid: %{public}u, status: %{public}u, vdi return %{public}d", devId, status, ret);
426     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
427     return ret;
428 }
429 
GetDisplayBacklight(uint32_t devId,uint32_t & level)430 int32_t DisplayComposerService::GetDisplayBacklight(uint32_t devId, uint32_t& level)
431 {
432     DISPLAY_TRACE;
433 
434     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
435     int32_t ret = vdiAdapter_->GetDisplayBacklight(devId, level);
436     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_SUCCESS, level = currentBacklightLevel_);
437     return ret;
438 }
439 
SetDisplayBacklight(uint32_t devId,uint32_t level)440 int32_t DisplayComposerService::SetDisplayBacklight(uint32_t devId, uint32_t level)
441 {
442     DISPLAY_TRACE;
443 
444     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
445     int32_t ret = vdiAdapter_->SetDisplayBacklight(devId, level);
446     DISPLAY_LOGD("devid: %{public}u, level: %{public}u, vdi return %{public}d", devId, level, ret);
447     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
448     currentBacklightLevel_ = level;
449     return ret;
450 }
451 
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)452 int32_t DisplayComposerService::GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value)
453 {
454     DISPLAY_TRACE;
455 
456     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
457     int32_t ret = vdiAdapter_->GetDisplayProperty(devId, id, value);
458     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
459     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
460     return ret;
461 }
462 
SetHardwareCursorPosition(uint32_t devId,int32_t x,int32_t y)463 int32_t DisplayComposerService::SetHardwareCursorPosition(uint32_t devId, int32_t x, int32_t y)
464 {
465     DISPLAY_TRACE;
466     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
467     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetHardwareCursorPosition, HDF_ERR_NOT_SUPPORT);
468     int32_t ret = vdiAdapter_->SetHardwareCursorPosition(devId, x, y);
469     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
470     return ret;
471 }
472 
EnableHardwareCursorStats(uint32_t devId,bool enable)473 int32_t DisplayComposerService::EnableHardwareCursorStats(uint32_t devId, bool enable)
474 {
475     DISPLAY_TRACE;
476     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
477     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->EnableHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
478     int32_t ret = vdiAdapter_->EnableHardwareCursorStats(devId, enable);
479     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
480     return ret;
481 }
482 
GetHardwareCursorStats(uint32_t devId,uint32_t & frameCount,uint32_t & vsyncCount)483 int32_t DisplayComposerService::GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount)
484 {
485     DISPLAY_TRACE;
486     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
487     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
488     int32_t ret = vdiAdapter_->GetHardwareCursorStats(devId, frameCount, vsyncCount);
489     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
490     return ret;
491 }
492 
SetDisplayClientCrop(uint32_t devId,const IRect & rect)493 int32_t DisplayComposerService::SetDisplayClientCrop(uint32_t devId, const IRect& rect)
494 {
495     DISPLAY_TRACE;
496 
497     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
498     int32_t ret = vdiAdapter_->SetDisplayClientCrop(devId, rect);
499     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
500     return ret;
501 }
502 
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)503 int32_t DisplayComposerService::SetDisplayVsyncEnabled(uint32_t devId, bool enabled)
504 {
505     DISPLAY_TRACE;
506 
507     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
508     int32_t ret = vdiAdapter_->SetDisplayVsyncEnabled(devId, enabled);
509     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
510     return ret;
511 }
512 
RegDisplayVBlankCallback(uint32_t devId,const sptr<IVBlankCallback> & cb)513 int32_t DisplayComposerService::RegDisplayVBlankCallback(uint32_t devId, const sptr<IVBlankCallback>& cb)
514 {
515     DISPLAY_TRACE;
516 
517     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
518     int32_t ret = vdiAdapter_->RegDisplayVBlankCallback(devId, OnVBlank, cb.GetRefPtr());
519     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
520     vBlankCb_ = cb;
521     return ret;
522 }
523 
GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<sptr<HdifdParcelable>> & fences)524 int32_t DisplayComposerService::GetDisplayReleaseFence(
525     uint32_t devId, std::vector<uint32_t>& layers, std::vector<sptr<HdifdParcelable>>& fences)
526 {
527     DISPLAY_TRACE;
528 
529     std::vector<int32_t> outFences;
530     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
531     int32_t ret = vdiAdapter_->GetDisplayReleaseFence(devId, layers, outFences);
532     for (uint i = 0; i < outFences.size(); i++) {
533         int32_t dupFd = outFences[i];
534         sptr<HdifdParcelable> hdifd(new HdifdParcelable());
535         CHECK_NULLPOINTER_RETURN_VALUE(hdifd, HDF_FAILURE);
536         hdifd->Init(dupFd);
537         fences.push_back(hdifd);
538     }
539     return ret;
540 }
541 
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)542 int32_t DisplayComposerService::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId)
543 {
544     DISPLAY_TRACE;
545 
546     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
547     int32_t ret = vdiAdapter_->CreateVirtualDisplay(width, height, format, devId);
548     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
549     return ret;
550 }
551 
DestroyVirtualDisplay(uint32_t devId)552 int32_t DisplayComposerService::DestroyVirtualDisplay(uint32_t devId)
553 {
554     DISPLAY_TRACE;
555 
556     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
557     int32_t ret = vdiAdapter_->DestroyVirtualDisplay(devId);
558     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
559     return ret;
560 }
561 
SetVirtualDisplayBuffer(uint32_t devId,const sptr<NativeBuffer> & buffer,const sptr<HdifdParcelable> & fence)562 int32_t DisplayComposerService::SetVirtualDisplayBuffer(
563     uint32_t devId, const sptr<NativeBuffer>& buffer, const sptr<HdifdParcelable>& fence)
564 {
565     DISPLAY_TRACE;
566 
567     CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_FAILURE);
568     CHECK_NULLPOINTER_RETURN_VALUE(fence, HDF_FAILURE);
569     BufferHandle* handle = buffer->GetBufferHandle();
570     int32_t inFence = fence->GetFd();
571     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
572     CHECK_NULLPOINTER_RETURN_VALUE(handle, HDF_FAILURE);
573     int32_t ret = vdiAdapter_->SetVirtualDisplayBuffer(devId, *handle, inFence);
574     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
575     return ret;
576 }
577 
SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)578 int32_t DisplayComposerService::SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value)
579 {
580     DISPLAY_TRACE;
581 
582     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
583     int32_t ret = vdiAdapter_->SetDisplayProperty(devId, id, value);
584     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
585     return ret;
586 }
587 
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)588 int32_t DisplayComposerService::CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount,
589     uint32_t& layerId)
590 {
591     DISPLAY_TRACE;
592 
593     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
594     int32_t ret = vdiAdapter_->CreateLayer(devId, layerInfo, layerId);
595     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
596 
597     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
598     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
599     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
600     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
601 
602     return devCache->AddLayerCache(layerId, cacheCount);
603 }
604 
DestroyLayer(uint32_t devId,uint32_t layerId)605 int32_t DisplayComposerService::DestroyLayer(uint32_t devId, uint32_t layerId)
606 {
607     DISPLAY_TRACE;
608     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
609     int32_t ret = vdiAdapter_->DestroyLayer(devId, layerId);
610     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
611 
612     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
613     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
614     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
615     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
616 
617     return devCache->RemoveLayerCache(layerId);
618 }
619 
RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback> & cb)620 int32_t DisplayComposerService::RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback>& cb)
621 {
622     DISPLAY_TRACE;
623     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
624     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegSeamlessChangeCallback, HDF_ERR_NOT_SUPPORT);
625     int32_t ret = vdiAdapter_->RegSeamlessChangeCallback(OnSeamlessChange, this);
626     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
627     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
628     if (ret == HDF_SUCCESS) {
629         seamlessChangeCb_ = cb;
630     }
631     return ret;
632 }
633 
GetDisplaySupportedModesExt(uint32_t devId,std::vector<DisplayModeInfoExt> & modes)634 int32_t DisplayComposerService::GetDisplaySupportedModesExt(uint32_t devId, std::vector<DisplayModeInfoExt>& modes)
635 {
636     DISPLAY_TRACE;
637     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
638     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedModesExt, HDF_ERR_NOT_SUPPORT);
639     int32_t ret = vdiAdapter_->GetDisplaySupportedModesExt(devId, modes);
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 
OnMode(uint32_t modeId,uint64_t vBlankPeriod,void * data)645 void DisplayComposerService::OnMode(uint32_t modeId, uint64_t vBlankPeriod, void* data)
646 {
647     if (data == nullptr) {
648         DISPLAY_LOGE("data is nullptr");
649         return;
650     }
651 
652     sptr<IModeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->modeCb_;
653     if (remoteCb == nullptr) {
654         DISPLAY_LOGE("remoteCb is nullptr");
655         return;
656     }
657     remoteCb->OnMode(modeId, vBlankPeriod);
658 }
659 
SetDisplayModeAsync(uint32_t devId,uint32_t modeId,const sptr<IModeCallback> & cb)660 int32_t DisplayComposerService::SetDisplayModeAsync(uint32_t devId, uint32_t modeId, const sptr<IModeCallback>& cb)
661 {
662     DISPLAY_TRACE;
663     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
664     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayModeAsync, HDF_ERR_NOT_SUPPORT);
665     int32_t ret = vdiAdapter_->SetDisplayModeAsync(devId, modeId, OnMode, this);
666     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
667     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
668     if (ret == HDF_SUCCESS) {
669         modeCb_ = cb;
670     }
671     return ret;
672 }
673 
GetDisplayVBlankPeriod(uint32_t devId,uint64_t & period)674 int32_t DisplayComposerService::GetDisplayVBlankPeriod(uint32_t devId, uint64_t& period)
675 {
676     DISPLAY_TRACE;
677     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
678     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayVBlankPeriod, HDF_ERR_NOT_SUPPORT);
679     int32_t ret = vdiAdapter_->GetDisplayVBlankPeriod(devId, period);
680     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
681     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
682     return ret;
683 }
684 
OnSeamlessChange(uint32_t devId,void * data)685 void DisplayComposerService::OnSeamlessChange(uint32_t devId, void* data)
686 {
687     if (data == nullptr) {
688         DISPLAY_LOGE("data is nullptr");
689         return;
690     }
691 
692     sptr<ISeamlessChangeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->seamlessChangeCb_;
693     if (remoteCb == nullptr) {
694         DISPLAY_LOGE("remoteCb is nullptr");
695         return;
696     }
697     remoteCb->OnSeamlessChange(devId);
698 }
699 
InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>> & request)700 int32_t DisplayComposerService::InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request)
701 {
702     CHECK_NULLPOINTER_RETURN_VALUE(request, HDF_FAILURE);
703     int32_t ret = HDF_FAILURE;
704 
705     if (cmdResponser_ != nullptr) {
706         ret = cmdResponser_->InitCmdRequest(request);
707     }
708     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
709     DISPLAY_LOGI("%{public}s out", __func__);
710     return ret;
711 }
712 
CmdRequest(uint32_t inEleCnt,const std::vector<HdifdInfo> & inFds,uint32_t & outEleCnt,std::vector<HdifdInfo> & outFds)713 int32_t DisplayComposerService::CmdRequest(
714     uint32_t inEleCnt, const std::vector<HdifdInfo>& inFds, uint32_t& outEleCnt, std::vector<HdifdInfo>& outFds)
715 {
716     int32_t ret = HDF_FAILURE;
717 
718     if (cmdResponser_ != nullptr) {
719         ret = cmdResponser_->CmdRequest(inEleCnt, inFds, outEleCnt, outFds);
720     }
721     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
722     return ret;
723 }
724 
GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>> & reply)725 int32_t DisplayComposerService::GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply)
726 {
727     int32_t ret = HDF_FAILURE;
728 
729     if (cmdResponser_ != nullptr) {
730         ret = cmdResponser_->GetCmdReply(reply);
731     }
732     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
733     return ret;
734 }
735 
SetLayerPerFrameParameter(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)736 int32_t DisplayComposerService::SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
737     const std::vector<int8_t>& value)
738 {
739     DISPLAY_TRACE;
740     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
741     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerPerFrameParameter, HDF_ERR_NOT_SUPPORT);
742     int32_t ret = vdiAdapter_->SetLayerPerFrameParameter(devId, layerId, key, value);
743     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
744     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
745     return ret;
746 }
747 
GetSupportedLayerPerFrameParameterKey(std::vector<std::string> & keys)748 int32_t DisplayComposerService::GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys)
749 {
750     DISPLAY_TRACE;
751     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
752     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetSupportedLayerPerFrameParameterKey, HDF_ERR_NOT_SUPPORT);
753     int32_t ret = vdiAdapter_->GetSupportedLayerPerFrameParameterKey(keys);
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, DISPLAY_LOGE(" fail"));
756     return ret;
757 }
758 
SetDisplayOverlayResolution(uint32_t devId,uint32_t width,uint32_t height)759 int32_t DisplayComposerService::SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height)
760 {
761     DISPLAY_TRACE;
762     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
763     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayOverlayResolution, HDF_ERR_NOT_SUPPORT);
764     int32_t ret = vdiAdapter_->SetDisplayOverlayResolution(devId, width, height);
765     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
766     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
767     return ret;
768 }
769 
OnRefresh(uint32_t devId,void * data)770 void DisplayComposerService::OnRefresh(uint32_t devId, void *data)
771 {
772     if (data == nullptr) {
773         DISPLAY_LOGE("cb data is nullptr");
774         return;
775     }
776 
777     sptr<IRefreshCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->refreshCb_;
778     if (remoteCb == nullptr) {
779         DISPLAY_LOGE("remoteCb is nullptr");
780         return;
781     }
782     remoteCb->OnRefresh(devId);
783 }
784 
RegRefreshCallback(const sptr<IRefreshCallback> & cb)785 int32_t DisplayComposerService::RegRefreshCallback(const sptr<IRefreshCallback>& cb)
786 {
787     DISPLAY_TRACE;
788     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
789     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegRefreshCallback, HDF_ERR_NOT_SUPPORT);
790     int32_t ret = vdiAdapter_->RegRefreshCallback(OnRefresh, this);
791     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
792     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
793     if (ret == HDF_SUCCESS) {
794         refreshCb_ = cb;
795     }
796     return ret;
797 }
798 
GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)799 int32_t DisplayComposerService::GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts)
800 {
801     DISPLAY_TRACE;
802     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
803     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedColorGamuts, HDF_ERR_NOT_SUPPORT);
804     int32_t ret = vdiAdapter_->GetDisplaySupportedColorGamuts(devId, gamuts);
805     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
806     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
807     return ret;
808 }
809 
GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)810 int32_t DisplayComposerService::GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info)
811 {
812     DISPLAY_TRACE;
813     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
814     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHDRCapabilityInfos, HDF_ERR_NOT_SUPPORT);
815     int32_t ret = vdiAdapter_->GetHDRCapabilityInfos(devId, info);
816     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
817     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
818     return ret;
819 }
820 
OnVBlankIdleCallback(uint32_t devId,uint64_t ns,void * data)821 void DisplayComposerService::OnVBlankIdleCallback(uint32_t devId, uint64_t ns, void* data)
822 {
823     if (data == nullptr) {
824         DISPLAY_LOGE("cb data is nullptr");
825         return;
826     }
827 
828     sptr<IVBlankIdleCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->VBlankIdleCb_;
829 
830     if (remoteCb == nullptr) {
831         DISPLAY_LOGE("VBlankIdleCb_ is nullptr");
832         return;
833     }
834     remoteCb->OnVBlankIdleCallback(devId, ns);
835 }
836 
RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback> & cb)837 int32_t DisplayComposerService::RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback>& cb)
838 {
839     DISPLAY_TRACE;
840     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
841     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegDisplayVBlankIdleCallback, HDF_ERR_NOT_SUPPORT);
842     VBlankIdleCb_ = cb;
843     int32_t ret = vdiAdapter_->RegDisplayVBlankIdleCallback(OnVBlankIdleCallback, this);
844     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
845     return ret;
846 }
847 
ClearClientBuffer(uint32_t devId)848 int32_t DisplayComposerService::ClearClientBuffer(uint32_t devId)
849 {
850     DISPLAY_LOGI("enter, devId %{public}u", devId);
851     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
852     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
853     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
854     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
855 
856     return devCache->ClearClientCache();
857 }
858 
ClearLayerBuffer(uint32_t devId,uint32_t layerId)859 int32_t DisplayComposerService::ClearLayerBuffer(uint32_t devId, uint32_t layerId)
860 {
861     DISPLAY_LOGI("enter, devId %{public}u, layerId %{public}u", devId, layerId);
862     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
863     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
864     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
865     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE("fail"));
866 
867     return devCache->ClearLayerBuffer(layerId);
868 }
869 
SetDisplayActiveRegion(uint32_t devId,const IRect & rect)870 int32_t DisplayComposerService::SetDisplayActiveRegion(uint32_t devId, const IRect& rect)
871 {
872     HDF_LOGI("%{public}s: devId %{public}u, rect {%{public}u, %{public}u, %{public}u, %{public}u}",
873         __func__, devId, rect.x, rect.y, rect.w, rect.h);
874 
875     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
876     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayActiveRegion, HDF_ERR_NOT_SUPPORT);
877 
878     StartTrace(HITRACE_TAG_HDF, "vdiAdapter_->SetDisplayActiveRegion");
879     int32_t ret = vdiAdapter_->SetDisplayActiveRegion(devId, rect);
880     FinishTrace(HITRACE_TAG_HDF);
881 
882     if (ret != HDF_SUCCESS) {
883         HDF_LOGI("%{public}s: fail, ret %{public}d", __func__, ret);
884     }
885 
886     return ret;
887 }
888 
889 } // namespace Composer
890 } // namespace Display
891 } // namespace HDI
892 } // namespace OHOS
893