• 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_->UpdateHardwareCursor =
239         reinterpret_cast<UpdateHardwareCursorFunc>(dlsym(libHandle_, "UpdateHardwareCursor"));
240     vdiAdapter_->EnableHardwareCursorStats =
241         reinterpret_cast<EnableHardwareCursorStatsFunc>(dlsym(libHandle_, "EnableHardwareCursorStats"));
242     vdiAdapter_->GetHardwareCursorStats =
243         reinterpret_cast<GetHardwareCursorStatsFunc>(dlsym(libHandle_, "GetHardwareCursorStats"));
244     vdiAdapter_->FastPresent = reinterpret_cast<FastPresentFunc>(dlsym(libHandle_, "FastPresent"));
245 }
246 
LoadVdiFuncPart3()247 void DisplayComposerService::LoadVdiFuncPart3()
248 {
249     vdiAdapter_->SetDisplayActiveRegion =
250         reinterpret_cast<SetDisplayActiveRegionFunc>(dlsym(libHandle_, "SetDisplayActiveRegion"));
251     vdiAdapter_->ClearDisplayClientBuffer =
252         reinterpret_cast<ClearDisplayClientBufferFunc>(dlsym(libHandle_, "ClearDisplayClientBuffer"));
253     vdiAdapter_->ClearLayerBuffer =
254         reinterpret_cast<ClearLayerBufferFunc>(dlsym(libHandle_, "ClearLayerBuffer"));
255     vdiAdapter_->SetDisplayPerFrameParameter =
256         reinterpret_cast<SetDisplayPerFrameParameterFunc>(dlsym(libHandle_, "SetDisplayPerFrameParameter"));
257     vdiAdapter_->GetDisplayIdentificationData =
258         reinterpret_cast<GetDisplayIdentificationDataFunc>(dlsym(libHandle_, "GetDisplayIdentificationData"));
259 }
260 
HidumperInit()261 void DisplayComposerService::HidumperInit()
262 {
263 #ifdef DISPLAY_COMPOSER_SERVICE_HIDUMPER
264     VdiDumper& dumper = VdiDumper::GetInstance();
265     dumper.SetDumpInfoFunc(reinterpret_cast<GetDumpInfoFunc>(dlsym(libHandle_, "GetDumpInfo")));
266     dumper.SetConfigFunc(reinterpret_cast<UpdateConfigFunc>(dlsym(libHandle_, "UpdateConfig")));
267     (void)DevHostRegisterDumpHost(ComposerDumpEvent);
268 #endif
269 }
270 
LoadVdiSo()271 int32_t DisplayComposerService::LoadVdiSo()
272 {
273     const char* errStr = dlerror();
274     if (errStr != nullptr) {
275         DISPLAY_LOGD("composer load vdi, clear earlier dlerror: %{public}s", errStr);
276     }
277 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
278     libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY, RTLD_LAZY);
279     if (libHandle_ == nullptr) {
280         DISPLAY_LOGE("composer load vendor vdi default library failed: %{public}s",
281             DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
282 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
283         libHandle_ = dlopen(DISPLAY_COMPOSER_VDI_LIBRARY, RTLD_LAZY);
284         DISPLAY_LOGD("composer load vendor vdi library: %{public}s", DISPLAY_COMPOSER_VDI_LIBRARY);
285 #ifdef COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
286     } else {
287         DISPLAY_LOGD("composer load vendor vdi default library: %{public}s", DISPLAY_COMPOSER_VDI_DEFAULT_LIBRARY);
288     }
289 #endif // COMPOSER_VDI_DEFAULT_LIBRARY_ENABLE
290     CHECK_NULLPOINTER_RETURN_VALUE(libHandle_, HDF_FAILURE);
291 
292     return HDF_SUCCESS;
293 }
294 
CreateResponser()295 int32_t DisplayComposerService::DisplayComposerService::CreateResponser()
296 {
297     cacheMgr_ = DeviceCacheManager::GetInstance();
298     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
299     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
300     if (vdiAdapter_->RegDisplayVBlankIdleCallback != nullptr) {
301         DISPLAY_LOGI("%{public}s Enable Map", __func__);
302         cacheMgr_->SetNeedMap(true);
303     }
304     cmdResponser_ = V1_2::HdiDisplayCmdResponser::Create(vdiAdapter_, cacheMgr_);
305     CHECK_NULLPOINTER_RETURN_VALUE(cmdResponser_, HDF_FAILURE);
306     DISPLAY_LOGI("%{public}s out", __func__);
307     return HDF_SUCCESS;
308 }
309 
OnHotPlug(uint32_t outputId,bool connected,void * data)310 void DisplayComposerService::OnHotPlug(uint32_t outputId, bool connected, void* data)
311 {
312     if (data == nullptr) {
313         DISPLAY_LOGE("cb data is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
314         return;
315     }
316 
317     auto cacheMgr = reinterpret_cast<DisplayComposerService*>(data)->cacheMgr_;
318     if (cacheMgr == nullptr) {
319         DISPLAY_LOGE("CacheMgr_ is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
320         return;
321     }
322     if (connected) {
323         std::lock_guard<std::mutex> lock(cacheMgr->GetCacheMgrMutex());
324         // Add new device cache
325         if (cacheMgr->AddDeviceCache(outputId) != HDF_SUCCESS) {
326             DISPLAY_LOGE("Add device cache failed outputId:%{public}u, connected:%{public}d", outputId, connected);
327         }
328     }
329 
330     sptr<IHotPlugCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->hotPlugCb_;
331     if (remoteCb == nullptr) {
332         DISPLAY_LOGE("hotPlugCb_ is nullptr outputId:%{public}u, connected:%{public}d", outputId, connected);
333         return;
334     }
335     remoteCb->OnHotPlug(outputId, connected);
336 }
337 
OnVBlank(unsigned int sequence,uint64_t ns,void * data)338 void DisplayComposerService::OnVBlank(unsigned int sequence, uint64_t ns, void* data)
339 {
340     if (data == nullptr) {
341         DISPLAY_LOGE("cb data is nullptr sequence:%{public}u", sequence);
342         return;
343     }
344 
345     IVBlankCallback* remoteCb = reinterpret_cast<IVBlankCallback*>(data);
346     if (remoteCb == nullptr) {
347         DISPLAY_LOGE("vblankCb_ is nullptr sequence:%{public}u", sequence);
348         return;
349     }
350     remoteCb->OnVBlank(sequence, ns);
351 }
352 
RegHotPlugCallback(const sptr<IHotPlugCallback> & cb)353 int32_t DisplayComposerService::RegHotPlugCallback(const sptr<IHotPlugCallback>& cb)
354 {
355     DISPLAY_TRACE;
356 
357     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
358     hotPlugCb_ = cb;
359     int32_t ret = vdiAdapter_->RegHotPlugCallback(OnHotPlug, this);
360     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
361     return ret;
362 }
363 
SetClientBufferCacheCount(uint32_t devId,uint32_t count)364 int32_t DisplayComposerService::SetClientBufferCacheCount(uint32_t devId, uint32_t count)
365 {
366     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
367     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
368     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
369     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
370     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
371         DISPLAY_LOGE("%{public}s fail, devId:%{public}u, count:%{public}u", __func__, devId, count));
372 
373     DISPLAY_CHK_RETURN(devCache->SetClientBufferCacheCount(count) != HDF_SUCCESS, HDF_FAILURE,
374         DISPLAY_LOGE("%{public}s fail, devId:%{public}u, count:%{public}u", __func__, devId, count));
375     return HDF_SUCCESS;
376 }
377 
GetDisplayCapability(uint32_t devId,DisplayCapability & info)378 int32_t DisplayComposerService::GetDisplayCapability(uint32_t devId, DisplayCapability& info)
379 {
380     DISPLAY_TRACE;
381 
382     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
383     int32_t ret =  vdiAdapter_->GetDisplayCapability(devId, info);
384     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
385         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
386     DISPLAY_LOGI("%{public}s fail devId:%{public}u, width:%{public}u, height:%{public}u, count:%{public}u",
387         __func__, devId, info.phyWidth, info.phyHeight, info.propertyCount);
388     return HDF_SUCCESS;
389 }
390 
GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)391 int32_t DisplayComposerService::GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes)
392 {
393     DISPLAY_TRACE;
394 
395     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
396     int32_t ret =  vdiAdapter_->GetDisplaySupportedModes(devId, modes);
397     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
398         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
399     return ret;
400 }
401 
GetDisplayMode(uint32_t devId,uint32_t & modeId)402 int32_t DisplayComposerService::GetDisplayMode(uint32_t devId, uint32_t& modeId)
403 {
404     DISPLAY_TRACE;
405 
406     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
407     int32_t ret =  vdiAdapter_->GetDisplayMode(devId, modeId);
408     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
409         DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
410     return ret;
411 }
412 
SetDisplayMode(uint32_t devId,uint32_t modeId)413 int32_t DisplayComposerService::SetDisplayMode(uint32_t devId, uint32_t modeId)
414 {
415     DISPLAY_TRACE;
416 
417     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
418     int32_t ret =  vdiAdapter_->SetDisplayMode(devId, modeId);
419     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
420         DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
421     return ret;
422 }
423 
GetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus & status)424 int32_t DisplayComposerService::GetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus& status)
425 {
426     DISPLAY_TRACE;
427 
428     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
429     int32_t ret = vdiAdapter_->GetDisplayPowerStatus(devId, status);
430     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
431         DISPLAY_LOGE("%{public}s fail devId:%{public}u, status:%{public}u", __func__, devId, status));
432     return ret;
433 }
434 
SetDisplayPowerStatus(uint32_t devId,V1_0::DispPowerStatus status)435 int32_t DisplayComposerService::SetDisplayPowerStatus(uint32_t devId, V1_0::DispPowerStatus status)
436 {
437     DISPLAY_TRACE;
438 
439     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
440     int32_t ret = vdiAdapter_->SetDisplayPowerStatus(devId, status);
441     DISPLAY_LOGI("devid: %{public}u, status: %{public}u, vdi return %{public}d", devId, status, ret);
442     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(" fail"));
443     return ret;
444 }
445 
GetDisplayBacklight(uint32_t devId,uint32_t & level)446 int32_t DisplayComposerService::GetDisplayBacklight(uint32_t devId, uint32_t& level)
447 {
448     DISPLAY_TRACE;
449 
450     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
451     int32_t ret = vdiAdapter_->GetDisplayBacklight(devId, level);
452     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_SUCCESS, level = currentBacklightLevel_);
453     return ret;
454 }
455 
SetDisplayBacklight(uint32_t devId,uint32_t level)456 int32_t DisplayComposerService::SetDisplayBacklight(uint32_t devId, uint32_t level)
457 {
458     DISPLAY_TRACE;
459 
460     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
461     int32_t ret = vdiAdapter_->SetDisplayBacklight(devId, level);
462     DISPLAY_LOGD("devid: %{public}u, level: %{public}u, vdi return %{public}d", devId, level, ret);
463     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
464         DISPLAY_LOGE("%{public}s fail devId:%{public}u, level:%{public}u", __func__, devId, level));
465     currentBacklightLevel_ = level;
466     return ret;
467 }
468 
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)469 int32_t DisplayComposerService::GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value)
470 {
471     DISPLAY_TRACE;
472 
473     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
474     int32_t ret = vdiAdapter_->GetDisplayProperty(devId, id, value);
475     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
476     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
477         DISPLAY_LOGE("%{public}s fail devId:%{public}u, id:%{public}u", __func__, devId, id));
478     return ret;
479 }
480 
UpdateHardwareCursor(uint32_t devId,int32_t x,int32_t y,const sptr<NativeBuffer> & buffer)481 int32_t DisplayComposerService::UpdateHardwareCursor(uint32_t devId, int32_t x, int32_t y,
482     const sptr<NativeBuffer>& buffer)
483 {
484     DISPLAY_TRACE;
485     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
486     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->UpdateHardwareCursor, HDF_ERR_NOT_SUPPORT);
487     CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_ERR_NOT_SUPPORT);
488     BufferHandle* handle = buffer->GetBufferHandle();
489     int32_t ret = vdiAdapter_->UpdateHardwareCursor(devId, x, y, handle);
490     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
491         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
492     return ret;
493 }
494 
EnableHardwareCursorStats(uint32_t devId,bool enable)495 int32_t DisplayComposerService::EnableHardwareCursorStats(uint32_t devId, bool enable)
496 {
497     DISPLAY_TRACE;
498     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
499     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->EnableHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
500     int32_t ret = vdiAdapter_->EnableHardwareCursorStats(devId, enable);
501     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
502         DISPLAY_LOGE("%{public}s fail devId:%{public}u, enable:%{public}d", __func__, devId, enable));
503     return ret;
504 }
505 
GetHardwareCursorStats(uint32_t devId,uint32_t & frameCount,uint32_t & vsyncCount)506 int32_t DisplayComposerService::GetHardwareCursorStats(uint32_t devId, uint32_t& frameCount, uint32_t& vsyncCount)
507 {
508     DISPLAY_TRACE;
509     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
510     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHardwareCursorStats, HDF_ERR_NOT_SUPPORT);
511     int32_t ret = vdiAdapter_->GetHardwareCursorStats(devId, frameCount, vsyncCount);
512     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(
513         "%{public}s fail Id:%{public}u, frame:%{public}u, vsync:%{public}u", __func__, devId, frameCount, vsyncCount));
514     return ret;
515 }
516 
SetDisplayClientCrop(uint32_t devId,const IRect & rect)517 int32_t DisplayComposerService::SetDisplayClientCrop(uint32_t devId, const IRect& rect)
518 {
519     DISPLAY_TRACE;
520 
521     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
522     int32_t ret = vdiAdapter_->SetDisplayClientCrop(devId, rect);
523     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
524         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
525     return ret;
526 }
527 
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)528 int32_t DisplayComposerService::SetDisplayVsyncEnabled(uint32_t devId, bool enabled)
529 {
530     DISPLAY_TRACE;
531 
532     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
533     int32_t ret = vdiAdapter_->SetDisplayVsyncEnabled(devId, enabled);
534     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
535         DISPLAY_LOGE("%{public}s fail devId:%{public}u enabled:%{public}d", __func__, devId, enabled));
536     return ret;
537 }
538 
RegDisplayVBlankCallback(uint32_t devId,const sptr<IVBlankCallback> & cb)539 int32_t DisplayComposerService::RegDisplayVBlankCallback(uint32_t devId, const sptr<IVBlankCallback>& cb)
540 {
541     DISPLAY_TRACE;
542 
543     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
544     int32_t ret = vdiAdapter_->RegDisplayVBlankCallback(devId, OnVBlank, cb.GetRefPtr());
545     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
546         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
547     vBlankCb_ = cb;
548     return ret;
549 }
550 
GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<sptr<HdifdParcelable>> & fences)551 int32_t DisplayComposerService::GetDisplayReleaseFence(
552     uint32_t devId, std::vector<uint32_t>& layers, std::vector<sptr<HdifdParcelable>>& fences)
553 {
554     DISPLAY_TRACE;
555 
556     std::vector<int32_t> outFences;
557     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
558     int32_t ret = vdiAdapter_->GetDisplayReleaseFence(devId, layers, outFences);
559     for (uint i = 0; i < outFences.size(); i++) {
560         int32_t dupFd = outFences[i];
561         sptr<HdifdParcelable> hdifd(new HdifdParcelable());
562         CHECK_NULLPOINTER_RETURN_VALUE(hdifd, HDF_FAILURE);
563         hdifd->Init(dupFd);
564         fences.push_back(hdifd);
565     }
566     return ret;
567 }
568 
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)569 int32_t DisplayComposerService::CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId)
570 {
571     DISPLAY_TRACE;
572 
573     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
574     int32_t ret = vdiAdapter_->CreateVirtualDisplay(width, height, format, devId);
575     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(
576         "%{public}s fail width:%{public}u, height:%{public}u, format:%{public}d, devId:%{public}u",
577         __func__, width, height, format, devId));
578     return ret;
579 }
580 
DestroyVirtualDisplay(uint32_t devId)581 int32_t DisplayComposerService::DestroyVirtualDisplay(uint32_t devId)
582 {
583     DISPLAY_TRACE;
584 
585     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
586     int32_t ret = vdiAdapter_->DestroyVirtualDisplay(devId);
587     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
588         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
589     return ret;
590 }
591 
SetVirtualDisplayBuffer(uint32_t devId,const sptr<NativeBuffer> & buffer,const sptr<HdifdParcelable> & fence)592 int32_t DisplayComposerService::SetVirtualDisplayBuffer(
593     uint32_t devId, const sptr<NativeBuffer>& buffer, const sptr<HdifdParcelable>& fence)
594 {
595     DISPLAY_TRACE;
596 
597     CHECK_NULLPOINTER_RETURN_VALUE(buffer, HDF_FAILURE);
598     CHECK_NULLPOINTER_RETURN_VALUE(fence, HDF_FAILURE);
599     BufferHandle* handle = buffer->GetBufferHandle();
600     int32_t inFence = fence->GetFd();
601     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
602     CHECK_NULLPOINTER_RETURN_VALUE(handle, HDF_FAILURE);
603     int32_t ret = vdiAdapter_->SetVirtualDisplayBuffer(devId, *handle, inFence);
604     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
605         DISPLAY_LOGE("%{public}s fail devId:%{public}u, inFence:%{public}d", __func__, devId, inFence));
606     return ret;
607 }
608 
SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)609 int32_t DisplayComposerService::SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value)
610 {
611     DISPLAY_TRACE;
612 
613     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
614     int32_t ret = vdiAdapter_->SetDisplayProperty(devId, id, value);
615     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
616         DISPLAY_LOGE("%{public}s fail devId:%{public}u, id:%{public}u", __func__, devId, id));
617     return ret;
618 }
619 
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)620 int32_t DisplayComposerService::CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount,
621     uint32_t& layerId)
622 {
623     DISPLAY_TRACE;
624 
625     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
626     int32_t ret = vdiAdapter_->CreateLayer(devId, layerInfo, layerId);
627     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
628         DISPLAY_LOGE("%{public}s fail devId:%{public}u, cacheCount:%{public}u, layerId:%{public}u",
629         __func__, devId, cacheCount, layerId));
630 
631     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
632     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
633     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
634     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
635         DISPLAY_LOGE("%{public}s fail devId:%{public}u, cacheCount:%{public}u, layerId:%{public}u",
636         __func__, devId, cacheCount, layerId));
637 
638     return devCache->AddLayerCache(layerId, cacheCount);
639 }
640 
DestroyLayer(uint32_t devId,uint32_t layerId)641 int32_t DisplayComposerService::DestroyLayer(uint32_t devId, uint32_t layerId)
642 {
643     DISPLAY_TRACE;
644     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
645     int32_t ret = vdiAdapter_->DestroyLayer(devId, layerId);
646     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE,
647         DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
648 
649     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
650     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
651     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
652     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
653         DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
654 
655     return devCache->RemoveLayerCache(layerId);
656 }
657 
RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback> & cb)658 int32_t DisplayComposerService::RegSeamlessChangeCallback(const sptr<ISeamlessChangeCallback>& cb)
659 {
660     DISPLAY_TRACE;
661     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
662     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegSeamlessChangeCallback, HDF_ERR_NOT_SUPPORT);
663     int32_t ret = vdiAdapter_->RegSeamlessChangeCallback(OnSeamlessChange, this);
664     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
665     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
666         DISPLAY_LOGE("%{public}s fail", __func__));
667     if (ret == HDF_SUCCESS) {
668         seamlessChangeCb_ = cb;
669     }
670     return ret;
671 }
672 
GetDisplaySupportedModesExt(uint32_t devId,std::vector<DisplayModeInfoExt> & modes)673 int32_t DisplayComposerService::GetDisplaySupportedModesExt(uint32_t devId, std::vector<DisplayModeInfoExt>& modes)
674 {
675     DISPLAY_TRACE;
676     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
677     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedModesExt, HDF_ERR_NOT_SUPPORT);
678     int32_t ret = vdiAdapter_->GetDisplaySupportedModesExt(devId, modes);
679     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
680     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
681         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
682     return ret;
683 }
684 
OnMode(uint32_t modeId,uint64_t vBlankPeriod,void * data)685 void DisplayComposerService::OnMode(uint32_t modeId, uint64_t vBlankPeriod, void* data)
686 {
687     if (data == nullptr) {
688         DISPLAY_LOGE("data is nullptr");
689         return;
690     }
691 
692     sptr<IModeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->modeCb_;
693     if (remoteCb == nullptr) {
694         DISPLAY_LOGE("remoteCb is nullptr");
695         return;
696     }
697     remoteCb->OnMode(modeId, vBlankPeriod);
698 }
699 
SetDisplayModeAsync(uint32_t devId,uint32_t modeId,const sptr<IModeCallback> & cb)700 int32_t DisplayComposerService::SetDisplayModeAsync(uint32_t devId, uint32_t modeId, const sptr<IModeCallback>& cb)
701 {
702     DISPLAY_TRACE;
703     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
704     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayModeAsync, HDF_ERR_NOT_SUPPORT);
705     int32_t ret = vdiAdapter_->SetDisplayModeAsync(devId, modeId, OnMode, this);
706     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
707     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
708         DISPLAY_LOGE("%{public}s fail devId:%{public}u, modeId:%{public}u", __func__, devId, modeId));
709     if (ret == HDF_SUCCESS) {
710         modeCb_ = cb;
711     }
712     return ret;
713 }
714 
GetDisplayVBlankPeriod(uint32_t devId,uint64_t & period)715 int32_t DisplayComposerService::GetDisplayVBlankPeriod(uint32_t devId, uint64_t& period)
716 {
717     DISPLAY_TRACE;
718     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
719     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayVBlankPeriod, HDF_ERR_NOT_SUPPORT);
720     int32_t ret = vdiAdapter_->GetDisplayVBlankPeriod(devId, period);
721     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
722     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
723         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
724     return ret;
725 }
726 
OnSeamlessChange(uint32_t devId,void * data)727 void DisplayComposerService::OnSeamlessChange(uint32_t devId, void* data)
728 {
729     if (data == nullptr) {
730         DISPLAY_LOGE("data is nullptr");
731         return;
732     }
733 
734     sptr<ISeamlessChangeCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->seamlessChangeCb_;
735     if (remoteCb == nullptr) {
736         DISPLAY_LOGE("remoteCb is nullptr");
737         return;
738     }
739     remoteCb->OnSeamlessChange(devId);
740 }
741 
InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>> & request)742 int32_t DisplayComposerService::InitCmdRequest(const std::shared_ptr<SharedMemQueue<int32_t>>& request)
743 {
744     CHECK_NULLPOINTER_RETURN_VALUE(request, HDF_FAILURE);
745     int32_t ret = HDF_FAILURE;
746 
747     if (cmdResponser_ != nullptr) {
748         ret = cmdResponser_->InitCmdRequest(request);
749     }
750     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
751     DISPLAY_LOGI("%{public}s out", __func__);
752     return ret;
753 }
754 
CmdRequest(uint32_t inEleCnt,const std::vector<HdifdInfo> & inFds,uint32_t & outEleCnt,std::vector<HdifdInfo> & outFds)755 int32_t DisplayComposerService::CmdRequest(
756     uint32_t inEleCnt, const std::vector<HdifdInfo>& inFds, uint32_t& outEleCnt, std::vector<HdifdInfo>& outFds)
757 {
758     int32_t ret = HDF_FAILURE;
759 
760     if (cmdResponser_ != nullptr) {
761         ret = cmdResponser_->CmdRequest(inEleCnt, inFds, outEleCnt, outFds);
762     }
763     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE(
764         "%{public}s fail inEleCnt:%{public}u, outEleCnt:%{public}u", __func__, inEleCnt, outEleCnt));
765     return ret;
766 }
767 
GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>> & reply)768 int32_t DisplayComposerService::GetCmdReply(std::shared_ptr<SharedMemQueue<int32_t>>& reply)
769 {
770     int32_t ret = HDF_FAILURE;
771 
772     if (cmdResponser_ != nullptr) {
773         ret = cmdResponser_->GetCmdReply(reply);
774     }
775     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS, HDF_FAILURE, DISPLAY_LOGE("%{public}s fail", __func__));
776     return ret;
777 }
778 
SetLayerPerFrameParameter(uint32_t devId,uint32_t layerId,const std::string & key,const std::vector<int8_t> & value)779 int32_t DisplayComposerService::SetLayerPerFrameParameter(uint32_t devId, uint32_t layerId, const std::string& key,
780     const std::vector<int8_t>& value)
781 {
782     DISPLAY_TRACE;
783     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
784     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetLayerPerFrameParameter, HDF_ERR_NOT_SUPPORT);
785     int32_t ret = vdiAdapter_->SetLayerPerFrameParameter(devId, layerId, key, value);
786     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
787     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
788         DISPLAY_LOGE("%{public}s fail devId:%{public}u, layerId:%{public}u", __func__, devId, layerId));
789     return ret;
790 }
791 
GetSupportedLayerPerFrameParameterKey(std::vector<std::string> & keys)792 int32_t DisplayComposerService::GetSupportedLayerPerFrameParameterKey(std::vector<std::string>& keys)
793 {
794     DISPLAY_TRACE;
795     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
796     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetSupportedLayerPerFrameParameterKey, HDF_ERR_NOT_SUPPORT);
797     int32_t ret = vdiAdapter_->GetSupportedLayerPerFrameParameterKey(keys);
798     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
799     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
800         DISPLAY_LOGE("%{public}s fail", __func__));
801     return ret;
802 }
803 
SetDisplayOverlayResolution(uint32_t devId,uint32_t width,uint32_t height)804 int32_t DisplayComposerService::SetDisplayOverlayResolution(uint32_t devId, uint32_t width, uint32_t height)
805 {
806     DISPLAY_TRACE;
807     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
808     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayOverlayResolution, HDF_ERR_NOT_SUPPORT);
809     int32_t ret = vdiAdapter_->SetDisplayOverlayResolution(devId, width, height);
810     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
811     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(
812         "%{public}s fail devId:%{public}u, width:%{public}u, height:%{public}u", __func__, devId, width, height));
813     return ret;
814 }
815 
OnRefresh(uint32_t devId,void * data)816 void DisplayComposerService::OnRefresh(uint32_t devId, void *data)
817 {
818     if (data == nullptr) {
819         DISPLAY_LOGE("cb data is nullptr devId:%{public}u", devId);
820         return;
821     }
822 
823     sptr<IRefreshCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->refreshCb_;
824     if (remoteCb == nullptr) {
825         DISPLAY_LOGE("remoteCb is nullptr devId:%{public}u", devId);
826         return;
827     }
828     remoteCb->OnRefresh(devId);
829 }
830 
RegRefreshCallback(const sptr<IRefreshCallback> & cb)831 int32_t DisplayComposerService::RegRefreshCallback(const sptr<IRefreshCallback>& cb)
832 {
833     DISPLAY_TRACE;
834     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
835     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegRefreshCallback, HDF_ERR_NOT_SUPPORT);
836     int32_t ret = vdiAdapter_->RegRefreshCallback(OnRefresh, this);
837     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
838     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
839         DISPLAY_LOGE("%{public}s fail", __func__));
840     if (ret == HDF_SUCCESS) {
841         refreshCb_ = cb;
842     }
843     return ret;
844 }
845 
GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)846 int32_t DisplayComposerService::GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts)
847 {
848     DISPLAY_TRACE;
849     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
850     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplaySupportedColorGamuts, HDF_ERR_NOT_SUPPORT);
851     int32_t ret = vdiAdapter_->GetDisplaySupportedColorGamuts(devId, gamuts);
852     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
853     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
854         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
855     return ret;
856 }
857 
GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)858 int32_t DisplayComposerService::GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info)
859 {
860     DISPLAY_TRACE;
861     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
862     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetHDRCapabilityInfos, HDF_ERR_NOT_SUPPORT);
863     int32_t ret = vdiAdapter_->GetHDRCapabilityInfos(devId, info);
864     DISPLAY_CHK_RETURN(ret == DISPLAY_NOT_SUPPORT, HDF_ERR_NOT_SUPPORT);
865     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
866         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
867     return ret;
868 }
869 
OnVBlankIdleCallback(uint32_t devId,uint64_t ns,void * data)870 void DisplayComposerService::OnVBlankIdleCallback(uint32_t devId, uint64_t ns, void* data)
871 {
872     if (data == nullptr) {
873         DISPLAY_LOGE("cb data is nullptr devId:%{public}u", devId);
874         return;
875     }
876 
877     sptr<IVBlankIdleCallback> remoteCb = reinterpret_cast<DisplayComposerService*>(data)->VBlankIdleCb_;
878 
879     if (remoteCb == nullptr) {
880         DISPLAY_LOGE("VBlankIdleCb_ is nullptr devId:%{public}u", devId);
881         return;
882     }
883     remoteCb->OnVBlankIdleCallback(devId, ns);
884 }
885 
RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback> & cb)886 int32_t DisplayComposerService::RegDisplayVBlankIdleCallback(const sptr<IVBlankIdleCallback>& cb)
887 {
888     DISPLAY_TRACE;
889     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
890     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->RegDisplayVBlankIdleCallback, HDF_ERR_NOT_SUPPORT);
891     VBlankIdleCb_ = cb;
892     int32_t ret = vdiAdapter_->RegDisplayVBlankIdleCallback(OnVBlankIdleCallback, this);
893     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE, DISPLAY_LOGE(" fail"));
894     return ret;
895 }
896 
ClearClientBuffer(uint32_t devId)897 int32_t DisplayComposerService::ClearClientBuffer(uint32_t devId)
898 {
899     DISPLAY_LOGI("enter, devId %{public}u", devId);
900     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
901     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
902     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
903     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE,
904         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
905 
906     if (vdiAdapter_ != nullptr && vdiAdapter_->ClearDisplayClientBuffer != nullptr) {
907         vdiAdapter_->ClearDisplayClientBuffer(devId);
908     }
909     return devCache->ClearClientCache();
910 }
911 
ClearLayerBuffer(uint32_t devId,uint32_t layerId)912 int32_t DisplayComposerService::ClearLayerBuffer(uint32_t devId, uint32_t layerId)
913 {
914     DISPLAY_LOGI("enter, devId %{public}u, layerId %{public}u", devId, layerId);
915     CHECK_NULLPOINTER_RETURN_VALUE(cacheMgr_, HDF_FAILURE);
916     std::lock_guard<std::mutex> lock(cacheMgr_->GetCacheMgrMutex());
917     DeviceCache* devCache = cacheMgr_->DeviceCacheInstance(devId);
918     DISPLAY_CHK_RETURN(devCache == nullptr, HDF_FAILURE, DISPLAY_LOGE(
919         "%{public}s fail devId:%{public}u layerId %{public}u", __func__, devId, layerId));
920 
921     if (vdiAdapter_ != nullptr && vdiAdapter_->ClearLayerBuffer != nullptr) {
922         vdiAdapter_->ClearLayerBuffer(devId, layerId);
923     }
924     return devCache->ClearLayerBuffer(layerId);
925 }
926 
SetDisplayActiveRegion(uint32_t devId,const IRect & rect)927 int32_t DisplayComposerService::SetDisplayActiveRegion(uint32_t devId, const IRect& rect)
928 {
929     HDF_LOGI("%{public}s: devId %{public}u, rect {%{public}u, %{public}u, %{public}u, %{public}u}",
930         __func__, devId, rect.x, rect.y, rect.w, rect.h);
931 
932     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
933     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->SetDisplayActiveRegion, HDF_ERR_NOT_SUPPORT);
934 
935     StartTrace(HITRACE_TAG_HDF, "vdiAdapter_->SetDisplayActiveRegion");
936     int32_t ret = vdiAdapter_->SetDisplayActiveRegion(devId, rect);
937     FinishTrace(HITRACE_TAG_HDF);
938 
939     if (ret != HDF_SUCCESS) {
940         HDF_LOGI("%{public}s: fail, ret %{public}d", __func__, ret);
941     }
942 
943     return ret;
944 }
945 
GetDisplayIdentificationData(uint32_t devId,uint8_t & portId,std::vector<uint8_t> & edidData)946 int32_t DisplayComposerService::GetDisplayIdentificationData(uint32_t devId, uint8_t& portId,
947     std::vector<uint8_t>& edidData)
948 {
949     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
950     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->GetDisplayIdentificationData, HDF_ERR_NOT_SUPPORT);
951 
952     StartTrace(HITRACE_TAG_HDF, "vdiAdapter_->GetDisplayIdentificationData");
953     int32_t ret = vdiAdapter_->GetDisplayIdentificationData(devId, portId, edidData);
954     FinishTrace(HITRACE_TAG_HDF);
955 
956     DISPLAY_LOGI("%{public}s: ret %{public}d, devId {%{public}u, the param idx [{%{public}u],"
957         "the length of edidData [%{public}zu]", __func__, ret, devId, portId, edidData.size());
958 
959     return ret;
960 }
961 
FastPresent(uint32_t devId,const PresentParam & param,const std::vector<sptr<NativeBuffer>> & inHandles)962 int32_t DisplayComposerService::FastPresent(uint32_t devId, const PresentParam& param,
963     const std::vector<sptr<NativeBuffer>>& inHandles)
964 {
965     DISPLAY_TRACE;
966     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_, HDF_FAILURE);
967     CHECK_NULLPOINTER_RETURN_VALUE(vdiAdapter_->FastPresent, HDF_ERR_NOT_SUPPORT);
968 
969     std::vector<BufferHandle*> handles;
970     for (uint32_t i = 0; i < param.sliceNum; i++) {
971         handles.emplace_back(inHandles[i]->GetBufferHandle());
972     }
973 
974     int32_t ret = vdiAdapter_->FastPresent(devId, param, handles);
975     DISPLAY_CHK_RETURN(ret != HDF_SUCCESS && ret != HDF_ERR_NOT_SUPPORT, HDF_FAILURE,
976         DISPLAY_LOGE("%{public}s fail devId:%{public}u", __func__, devId));
977     return ret;
978 }
979 } // namespace Composer
980 } // namespace Display
981 } // namespace HDI
982 } // namespace OHOS
983