• 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 #ifndef OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H
17 #define OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H
18 
19 #include <unistd.h>
20 #include "hdf_trace.h"
21 #include "hilog/log.h"
22 #include "iproxy_broker.h"
23 #include "iremote_object.h"
24 #include "v1_0/display_command/display_cmd_requester.h"
25 #include "v1_0/display_composer_type.h"
26 #include "v1_0/idisplay_composer.h"
27 #include "v1_0/include/idisplay_composer_interface.h"
28 
29 #undef LOG_TAG
30 #define LOG_TAG "DISP_HDI_COMP"
31 #undef LOG_DOMAIN
32 #define LOG_DOMAIN 0xD002515
33 #define MAX_COUNT 10
34 
35 namespace OHOS {
36 namespace HDI {
37 namespace Display {
38 namespace Composer {
39 namespace V1_0 {
40 using namespace OHOS::HDI::Display::Composer::V1_0;
41 
42 #define DISPLAY_TRACE HdfTrace trace(__func__, "HDI:DISP:")
43 
44 #define COMPOSER_CHECK_NULLPTR_RETURN(ptr)                                                  \
45     if ((ptr) == nullptr) {                                                                 \
46         HDF_LOGE("%{public}d@%{public}s nullptr error", __LINE__, __func__);                \
47         return DISPLAY_NULL_PTR;                                                            \
48     }
49 
50 template <typename Interface, typename CompHdi, typename CmdReq>
51 class DisplayComposerHdiImpl : public Interface, public IHotPlugCallback, public IVBlankCallback {
52 public:
Create(bool needSMQ)53     static IDisplayComposerInterface* Create(bool needSMQ)
54     {
55         sptr<CompHdi> hdi;
56         std::shared_ptr<CmdReq> req = nullptr;
57         HDF_LOGI("%{public}s: hdi V1_0 start", __func__);
58         while ((hdi = CompHdi::Get()) == nullptr) {
59             // Waiting for display composer service ready
60             usleep(WAIT_TIME_INTERVAL);
61         }
62         HDF_LOGI("%{public}s: hdi V1_0 end", __func__);
63         if (needSMQ) {
64             req = CmdReq::Create(hdi);
65             if (req == nullptr) {
66                 HDF_LOGE("%{public}s: Create DisplayCmdRequester failed %{public}d", __func__, __LINE__);
67                 return nullptr;
68             }
69         }
70         return new DisplayComposerHdiImpl(hdi, req);
71     }
72 
DisplayComposerHdiImpl(sptr<CompHdi> hdi,std::shared_ptr<CmdReq> req)73     DisplayComposerHdiImpl(sptr<CompHdi> hdi, std::shared_ptr<CmdReq> req)
74         : hdi_(hdi),
75         req_(req),
76         hotPlugCb_(nullptr),
77         vBlankCb_(nullptr),
78         hotPlugCbData_(nullptr),
79         vBlankCbData_(nullptr),
80         recipient_(nullptr) {}
81 
~DisplayComposerHdiImpl()82     virtual ~DisplayComposerHdiImpl()
83     {
84         if (recipient_ != nullptr) {
85             sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_);
86             remoteObj->RemoveDeathRecipient(recipient_);
87             recipient_ = nullptr;
88         }
89     }
90 
AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient> & recipient)91     virtual bool AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient>& recipient) override
92     {
93         sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_);
94         if (recipient_ != nullptr) {
95             HDF_LOGI("%{public}s: the existing recipient is removed, and add the new. %{public}d",
96                 __func__, __LINE__);
97             remoteObj->RemoveDeathRecipient(recipient_);
98         }
99         bool ret = remoteObj->AddDeathRecipient(recipient);
100         if (ret) {
101             recipient_ = recipient;
102         } else {
103             recipient_ = nullptr;
104             HDF_LOGE("%{public}s: AddDeathRecipient failed %{public}d",  __func__, __LINE__);
105         }
106         return ret;
107     }
108 
RemoveDeathRecipient()109     virtual bool RemoveDeathRecipient() override
110     {
111         if (recipient_ != nullptr) {
112             sptr<IRemoteObject> remoteObj = OHOS::HDI::hdi_objcast<CompHdi>(hdi_);
113             remoteObj->RemoveDeathRecipient(recipient_);
114             recipient_ = nullptr;
115         }
116         return true;
117     }
118 
119     // device func
RegHotPlugCallback(HotPlugCallback cb,void * data)120     virtual int32_t RegHotPlugCallback(HotPlugCallback cb, void *data) override
121     {
122         hotPlugCb_ = cb;
123         hotPlugCbData_ = data;
124         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
125         return ToDispErrCode(hdi_->RegHotPlugCallback(this));
126     }
127 
SetClientBufferCacheCount(uint32_t devId,uint32_t cacheCount)128     virtual int32_t SetClientBufferCacheCount(uint32_t devId, uint32_t cacheCount) override
129     {
130         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
131         return ToDispErrCode(hdi_->SetClientBufferCacheCount(devId, cacheCount));
132     }
133 
GetDisplayCapability(uint32_t devId,DisplayCapability & info)134     virtual int32_t GetDisplayCapability(uint32_t devId, DisplayCapability& info) override
135     {
136         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
137         return ToDispErrCode(hdi_->GetDisplayCapability(devId, info));
138     }
139 
GetDisplaySupportedModes(uint32_t devId,std::vector<DisplayModeInfo> & modes)140     virtual int32_t GetDisplaySupportedModes(uint32_t devId, std::vector<DisplayModeInfo>& modes) override
141     {
142         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
143         return ToDispErrCode(hdi_->GetDisplaySupportedModes(devId, modes));
144     }
145 
GetDisplayMode(uint32_t devId,uint32_t & modeId)146     virtual int32_t GetDisplayMode(uint32_t devId, uint32_t& modeId) override
147     {
148         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
149         return ToDispErrCode(hdi_->GetDisplayMode(devId, modeId));
150     }
151 
SetDisplayMode(uint32_t devId,uint32_t modeId)152     virtual int32_t SetDisplayMode(uint32_t devId, uint32_t modeId) override
153     {
154         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
155         return ToDispErrCode(hdi_->SetDisplayMode(devId, modeId));
156     }
157 
GetDisplayPowerStatus(uint32_t devId,DispPowerStatus & status)158     virtual int32_t GetDisplayPowerStatus(uint32_t devId, DispPowerStatus& status) override
159     {
160         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
161         return ToDispErrCode(hdi_->GetDisplayPowerStatus(devId, status));
162     }
163 
SetDisplayPowerStatus(uint32_t devId,DispPowerStatus status)164     virtual int32_t SetDisplayPowerStatus(uint32_t devId, DispPowerStatus status) override
165     {
166         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
167         int32_t ret = hdi_->SetDisplayPowerStatus(devId, status);
168         HDF_LOGI("devId: %{public}u, status: %{public}u", devId, status);
169         return ToDispErrCode(ret);
170     }
171 
GetDisplayBacklight(uint32_t devId,uint32_t & level)172     virtual int32_t GetDisplayBacklight(uint32_t devId, uint32_t& level) override
173     {
174         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
175         return ToDispErrCode(hdi_->GetDisplayBacklight(devId, level));
176     }
177 
SetDisplayBacklight(uint32_t devId,uint32_t level)178     virtual int32_t SetDisplayBacklight(uint32_t devId, uint32_t level) override
179     {
180         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
181         return ToDispErrCode(hdi_->SetDisplayBacklight(devId, level));
182     }
183 
GetDisplayProperty(uint32_t devId,uint32_t id,uint64_t & value)184     virtual int32_t GetDisplayProperty(uint32_t devId, uint32_t id, uint64_t& value) override
185     {
186         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
187         return ToDispErrCode(hdi_->GetDisplayProperty(devId, id, value));
188     }
189 
GetDisplayCompChange(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & types)190     virtual int32_t GetDisplayCompChange(
191         uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& types) override
192     {
193         COMPOSER_CHECK_NULLPTR_RETURN(req_);
194         return ToDispErrCode(req_->GetDisplayCompChange(devId, layers, types));
195     }
196 
SetDisplayClientCrop(uint32_t devId,const IRect & rect)197     virtual int32_t SetDisplayClientCrop(uint32_t devId, const IRect& rect) override
198     {
199         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
200         return ToDispErrCode(hdi_->SetDisplayClientCrop(devId, rect));
201     }
202 
SetDisplayClientBuffer(uint32_t devId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence)203     virtual int32_t SetDisplayClientBuffer(uint32_t devId, const BufferHandle* buffer, uint32_t seqNo,
204         int32_t fence) override
205     {
206         COMPOSER_CHECK_NULLPTR_RETURN(req_);
207         return ToDispErrCode(req_->SetDisplayClientBuffer(devId, buffer, seqNo, fence));
208     }
209 
SetDisplayClientDamage(uint32_t devId,std::vector<IRect> & rects)210     virtual int32_t SetDisplayClientDamage(uint32_t devId, std::vector<IRect>& rects) override
211     {
212         COMPOSER_CHECK_NULLPTR_RETURN(req_);
213         return ToDispErrCode(req_->SetDisplayClientDamage(devId, rects));
214     }
215 
SetDisplayVsyncEnabled(uint32_t devId,bool enabled)216     virtual int32_t SetDisplayVsyncEnabled(uint32_t devId, bool enabled) override
217     {
218         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
219         return ToDispErrCode(hdi_->SetDisplayVsyncEnabled(devId, enabled));
220     }
221 
RegDisplayVBlankCallback(uint32_t devId,VBlankCallback cb,void * data)222     virtual int32_t RegDisplayVBlankCallback(uint32_t devId, VBlankCallback cb, void *data) override
223     {
224         vBlankCb_ = cb;
225         vBlankCbData_ = data;
226         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
227         return ToDispErrCode(hdi_->RegDisplayVBlankCallback(devId, this));
228     }
229 
GetDisplayReleaseFence(uint32_t devId,std::vector<uint32_t> & layers,std::vector<int32_t> & fences)230     virtual int32_t GetDisplayReleaseFence(
231         uint32_t devId, std::vector<uint32_t>& layers, std::vector<int32_t>& fences) override
232     {
233         std::vector<sptr<HdifdParcelable>> hdiFences;
234         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
235         int32_t ret = ToDispErrCode(hdi_->GetDisplayReleaseFence(devId, layers, hdiFences));
236         if (ret == DISPLAY_SUCCESS) {
237             for (uint32_t i = 0; i < hdiFences.size(); i++) {
238                 if (hdiFences[i] == nullptr) {
239                     HDF_LOGE("%{public}s: GetReleaseFence contains nullptr", __func__);
240                     continue;
241                 }
242                 fences.push_back(hdiFences[i]->Move());
243             }
244         }
245         return ret;
246     }
247 
CreateVirtualDisplay(uint32_t width,uint32_t height,int32_t & format,uint32_t & devId)248     virtual int32_t CreateVirtualDisplay(uint32_t width, uint32_t height, int32_t& format, uint32_t& devId) override
249     {
250         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
251         return ToDispErrCode(hdi_->CreateVirtualDisplay(width, height, format, devId));
252     }
253 
DestroyVirtualDisplay(uint32_t devId)254     virtual int32_t DestroyVirtualDisplay(uint32_t devId) override
255     {
256         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
257         return ToDispErrCode(hdi_->DestroyVirtualDisplay(devId));
258     }
259 
SetVirtualDisplayBuffer(uint32_t devId,const BufferHandle & buffer,const int32_t fence)260     virtual int32_t SetVirtualDisplayBuffer(uint32_t devId, const BufferHandle& buffer, const int32_t fence) override
261     {
262         int32_t ret = DISPLAY_SUCCESS;
263 
264         sptr<NativeBuffer> hdiBuffer = new NativeBuffer();
265         if (hdiBuffer == nullptr) {
266             ret = DISPLAY_FAILURE;
267         } else {
268             hdiBuffer->SetBufferHandle(const_cast<BufferHandle*>(&buffer));
269             sptr<HdifdParcelable> hdiFence(new HdifdParcelable);
270             hdiFence->Init(fence);
271             ret = ToDispErrCode(hdi_->SetVirtualDisplayBuffer(devId, hdiBuffer, hdiFence));
272         }
273 
274         return ret;
275     }
276 
SetDisplayProperty(uint32_t devId,uint32_t id,uint64_t value)277     virtual int32_t SetDisplayProperty(uint32_t devId, uint32_t id, uint64_t value) override
278     {
279         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
280         return ToDispErrCode(hdi_->SetDisplayProperty(devId, id, value));
281     }
282 
Commit(uint32_t devId,int32_t & fence)283     virtual int32_t Commit(uint32_t devId, int32_t& fence) override
284     {
285         COMPOSER_CHECK_NULLPTR_RETURN(req_);
286         return ToDispErrCode(req_->Commit(devId, fence));
287     }
288 
GetDisplaySupportedColorGamuts(uint32_t devId,std::vector<ColorGamut> & gamuts)289     virtual int32_t GetDisplaySupportedColorGamuts(uint32_t devId, std::vector<ColorGamut>& gamuts) override
290     {
291         return DISPLAY_NOT_SUPPORT;
292     }
GetDisplayColorGamut(uint32_t devId,ColorGamut & gamut)293     virtual int32_t GetDisplayColorGamut(uint32_t devId, ColorGamut& gamut) override
294     {
295         return DISPLAY_NOT_SUPPORT;
296     }
297 
SetDisplayColorGamut(uint32_t devId,const ColorGamut & gamut)298     virtual int32_t SetDisplayColorGamut(uint32_t devId, const ColorGamut& gamut) override
299     {
300         return DISPLAY_NOT_SUPPORT;
301     }
302 
GetDisplayGamutMap(uint32_t devId,GamutMap & gamutMap)303     virtual int32_t GetDisplayGamutMap(uint32_t devId, GamutMap& gamutMap) override
304     {
305         return DISPLAY_NOT_SUPPORT;
306     }
307 
SetDisplayGamutMap(uint32_t devId,const GamutMap & gamutMap)308     virtual int32_t SetDisplayGamutMap(uint32_t devId, const GamutMap& gamutMap) override
309     {
310         return DISPLAY_NOT_SUPPORT;
311     }
312 
SetDisplayColorTransform(uint32_t devId,const std::vector<float> & matrix)313     virtual int32_t SetDisplayColorTransform(uint32_t devId, const std::vector<float>& matrix) override
314     {
315         return DISPLAY_NOT_SUPPORT;
316     }
317 
GetHDRCapabilityInfos(uint32_t devId,HDRCapability & info)318     virtual int32_t GetHDRCapabilityInfos(uint32_t devId, HDRCapability& info) override
319     {
320         return DISPLAY_NOT_SUPPORT;
321     }
322 
GetSupportedMetadataKey(uint32_t devId,std::vector<HDRMetadataKey> & keys)323     virtual int32_t GetSupportedMetadataKey(uint32_t devId, std::vector<HDRMetadataKey>& keys) override
324     {
325         return DISPLAY_NOT_SUPPORT;
326     }
327 
328     // layer func
CreateLayer(uint32_t devId,const LayerInfo & layerInfo,uint32_t cacheCount,uint32_t & layerId)329     virtual int32_t CreateLayer(uint32_t devId, const LayerInfo& layerInfo, uint32_t cacheCount,
330         uint32_t& layerId) override
331     {
332         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
333         return ToDispErrCode(hdi_->CreateLayer(devId, layerInfo, cacheCount, layerId));
334     }
335 
DestroyLayer(uint32_t devId,uint32_t layerId)336     virtual int32_t DestroyLayer(uint32_t devId, uint32_t layerId) override
337     {
338         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
339         return ToDispErrCode(hdi_->DestroyLayer(devId, layerId));
340     }
341 
PrepareDisplayLayers(uint32_t devId,bool & needFlushFb)342     virtual int32_t PrepareDisplayLayers(uint32_t devId, bool& needFlushFb) override
343     {
344         COMPOSER_CHECK_NULLPTR_RETURN(req_);
345         return ToDispErrCode(req_->PrepareDisplayLayers(devId, needFlushFb));
346     }
347 
SetLayerAlpha(uint32_t devId,uint32_t layerId,const LayerAlpha & alpha)348     virtual int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, const LayerAlpha& alpha) override
349     {
350         COMPOSER_CHECK_NULLPTR_RETURN(req_);
351         return ToDispErrCode(req_->SetLayerAlpha(devId, layerId, alpha));
352     }
353 
SetLayerRegion(uint32_t devId,uint32_t layerId,const IRect & rect)354     virtual int32_t SetLayerRegion(uint32_t devId, uint32_t layerId, const IRect& rect) override
355     {
356         COMPOSER_CHECK_NULLPTR_RETURN(req_);
357         return ToDispErrCode(req_->SetLayerRegion(devId, layerId, rect));
358     }
359 
SetLayerCrop(uint32_t devId,uint32_t layerId,const IRect & rect)360     virtual int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, const IRect& rect) override
361     {
362         COMPOSER_CHECK_NULLPTR_RETURN(req_);
363         return ToDispErrCode(req_->SetLayerCrop(devId, layerId, rect));
364     }
365 
SetLayerZorder(uint32_t devId,uint32_t layerId,uint32_t zorder)366     virtual int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder) override
367     {
368         COMPOSER_CHECK_NULLPTR_RETURN(req_);
369         return ToDispErrCode(req_->SetLayerZorder(devId, layerId, zorder));
370     }
371 
SetLayerPreMulti(uint32_t devId,uint32_t layerId,bool preMul)372     virtual int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul) override
373     {
374         COMPOSER_CHECK_NULLPTR_RETURN(req_);
375         return ToDispErrCode(req_->SetLayerPreMulti(devId, layerId, preMul));
376     }
377 
SetLayerTransformMode(uint32_t devId,uint32_t layerId,TransformType type)378     virtual int32_t SetLayerTransformMode(uint32_t devId, uint32_t layerId, TransformType type) override
379     {
380         COMPOSER_CHECK_NULLPTR_RETURN(req_);
381         return ToDispErrCode(req_->SetLayerTransformMode(devId, layerId, type));
382     }
383 
SetLayerDirtyRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)384     virtual int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override
385     {
386         COMPOSER_CHECK_NULLPTR_RETURN(req_);
387         return ToDispErrCode(req_->SetLayerDirtyRegion(devId, layerId, rects));
388     }
389 
SetLayerVisibleRegion(uint32_t devId,uint32_t layerId,std::vector<IRect> & rects)390     virtual int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, std::vector<IRect>& rects) override
391     {
392         COMPOSER_CHECK_NULLPTR_RETURN(req_);
393         return ToDispErrCode(req_->SetLayerVisibleRegion(devId, layerId, rects));
394     }
395 
SetLayerBuffer(uint32_t devId,uint32_t layerId,const BufferHandle * buffer,uint32_t seqNo,int32_t fence,const std::vector<uint32_t> & deletingList)396     virtual int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle* buffer, uint32_t seqNo,
397         int32_t fence, const std::vector<uint32_t>& deletingList) override
398     {
399         COMPOSER_CHECK_NULLPTR_RETURN(req_);
400         return ToDispErrCode(req_->SetLayerBuffer(devId, layerId, buffer, seqNo, fence, deletingList));
401     }
402 
SetLayerCompositionType(uint32_t devId,uint32_t layerId,CompositionType type)403     virtual int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type) override
404     {
405         COMPOSER_CHECK_NULLPTR_RETURN(req_);
406         return ToDispErrCode(req_->SetLayerCompositionType(devId, layerId, type));
407     }
408 
SetLayerBlendType(uint32_t devId,uint32_t layerId,BlendType type)409     virtual int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type) override
410     {
411         COMPOSER_CHECK_NULLPTR_RETURN(req_);
412         return ToDispErrCode(req_->SetLayerBlendType(devId, layerId, type));
413     }
414 
SetLayerMaskInfo(uint32_t devId,uint32_t layerId,const MaskInfo maskInfo)415     virtual int32_t SetLayerMaskInfo(uint32_t devId, uint32_t layerId, const MaskInfo maskInfo) override
416     {
417         COMPOSER_CHECK_NULLPTR_RETURN(hdi_);
418         return ToDispErrCode(req_->SetLayerMaskInfo(devId, layerId, maskInfo));
419     }
420 
SetLayerColorTransform(uint32_t devId,uint32_t layerId,const std::vector<float> & matrix)421     virtual int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, const std::vector<float>& matrix) override
422     {
423         return DISPLAY_NOT_SUPPORT;
424     }
425 
SetLayerColorDataSpace(uint32_t devId,uint32_t layerId,const ColorDataSpace colorSpace)426     virtual int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, const ColorDataSpace colorSpace) override
427     {
428         return DISPLAY_NOT_SUPPORT;
429     }
430 
GetLayerColorDataSpace(uint32_t devId,uint32_t layerId,ColorDataSpace & colorSpace)431     virtual int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, ColorDataSpace& colorSpace) override
432     {
433         return DISPLAY_NOT_SUPPORT;
434     }
435 
SetLayerMetaData(uint32_t devId,uint32_t layerId,const std::vector<HDRMetaData> & metaData)436     virtual int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId,
437         const std::vector<HDRMetaData>& metaData) override
438     {
439         return DISPLAY_NOT_SUPPORT;
440     }
441 
SetLayerMetaDataSet(uint32_t devId,uint32_t layerId,HDRMetadataKey key,const std::vector<uint8_t> & metaData)442     virtual int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key,
443         const std::vector<uint8_t>& metaData) override
444     {
445         return DISPLAY_NOT_SUPPORT;
446     }
447 
GetSupportedPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestampType & type)448     virtual int32_t GetSupportedPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestampType& type) override
449     {
450         return DISPLAY_NOT_SUPPORT;
451     }
452 
GetHwPresentTimestamp(uint32_t devId,uint32_t layerId,PresentTimestamp & pts)453     virtual int32_t GetHwPresentTimestamp(uint32_t devId, uint32_t layerId, PresentTimestamp& pts) override
454     {
455         return DISPLAY_NOT_SUPPORT;
456     }
457 
SetLayerTunnelHandle(uint32_t devId,uint32_t layerId,const ExtDataHandle & handle)458     virtual int32_t SetLayerTunnelHandle(uint32_t devId, uint32_t layerId, const ExtDataHandle& handle) override
459     {
460         return DISPLAY_NOT_SUPPORT;
461     }
462 
SetLayerColor(uint32_t devId,uint32_t layerId,const LayerColor & layerColor)463     virtual int32_t SetLayerColor(uint32_t devId, uint32_t layerId, const LayerColor& layerColor) override
464     {
465         COMPOSER_CHECK_NULLPTR_RETURN(req_);
466         return ToDispErrCode(req_->SetLayerColor(devId, layerId, layerColor));
467     }
468 
469     // Callback implement
OnHotPlug(uint32_t outputId,bool connected)470     virtual int32_t OnHotPlug(uint32_t outputId, bool connected) override
471     {
472         DISPLAY_TRACE;
473 
474         HDF_LOGI("OnHotPlug(%{public}u, %{public}u)", outputId, connected);
475         int32_t ret = HDF_SUCCESS;
476         if (hotPlugCb_ != nullptr) {
477             hotPlugCb_(outputId, connected, hotPlugCbData_);
478         } else {
479             HDF_LOGE("error: hot plug callback fn is nullptr");
480             ret = HDF_FAILURE;
481         }
482 
483         return ret;
484     }
485 
OnVBlank(uint32_t sequence,uint64_t ns)486     virtual int32_t OnVBlank(uint32_t sequence, uint64_t ns) override
487     {
488         DISPLAY_TRACE;
489 
490         int32_t ret = HDF_SUCCESS;
491         if (vBlankCb_ != nullptr) {
492             vBlankCb_(sequence, ns, vBlankCbData_);
493         } else {
494             HDF_LOGE("error: vblank callback fn is nullptr");
495             ret = HDF_FAILURE;
496         }
497 
498         return ret;
499     }
500 
501 protected:
ToDispErrCode(int32_t hdfStatus)502     int32_t ToDispErrCode(int32_t hdfStatus)
503     {
504         int32_t ec = DISPLAY_FAILURE;
505         switch (hdfStatus) {
506             case HDF_SUCCESS:
507                 ec = DISPLAY_SUCCESS;
508                 break;
509             case HDF_FAILURE:
510                 ec = DISPLAY_FAILURE;
511                 break;
512             case HDF_ERR_NOT_SUPPORT:
513                 ec = DISPLAY_NOT_SUPPORT;
514                 break;
515             case HDF_ERR_INVALID_PARAM:
516                 ec = DISPLAY_PARAM_ERR;
517                 break;
518             case HDF_ERR_DEVICE_BUSY:
519                 ec = DISPLAY_SYS_BUSY;
520                 break;
521             case HDF_ERR_BAD_FD:
522                 ec = DISPLAY_FD_ERR;
523                 break;
524             case HDF_ERR_NOPERM:
525                 ec = DISPLAY_NOT_PERM;
526                 break;
527             case HDF_DEV_ERR_NO_MEMORY:
528                 ec = DISPLAY_NOMEM;
529                 break;
530             case HDF_ERR_IO:
531             case HDF_ERR_INVALID_OBJECT:
532             case HDF_ERR_MALLOC_FAIL:
533             case HDF_ERR_TIMEOUT:
534             case HDF_ERR_THREAD_CREATE_FAIL:
535             case HDF_ERR_QUEUE_FULL:
536             case HDF_BSP_ERR_OP:
537             case HDF_ERR_BSP_PLT_API_ERR:
538             case HDF_PAL_ERR_DEV_CREATE:
539             case HDF_PAL_ERR_INNER:
540             case HDF_DEV_ERR_NO_DEVICE:
541             case HDF_DEV_ERR_NO_DEVICE_SERVICE:
542             case HDF_DEV_ERR_DEV_INIT_FAIL:
543             case HDF_DEV_ERR_PUBLISH_FAIL:
544             case HDF_DEV_ERR_ATTACHDEV_FAIL:
545             case HDF_DEV_ERR_NODATA:
546             case HDF_DEV_ERR_NORANGE:
547             case HDF_DEV_ERR_OP:
548             default:
549                 break;
550         }
551         return ec;
552     }
553 
554 protected:
555     static constexpr uint32_t WAIT_TIME_INTERVAL = 10000;
556     sptr<CompHdi> hdi_;
557     std::shared_ptr<CmdReq> req_;
558     HotPlugCallback hotPlugCb_;
559     VBlankCallback vBlankCb_;
560     void *hotPlugCbData_;
561     void *vBlankCbData_;
562     sptr<IRemoteObject::DeathRecipient> recipient_;
563 };
564 using HdiDisplayComposer = DisplayComposerHdiImpl<IDisplayComposerInterface, IDisplayComposer, HdiDisplayCmdRequester>;
565 } // namespace V1_0
566 } // namespace Composer
567 } // namespace Display
568 } // namespace HDI
569 } // namespace OHOS
570 #endif // OHOS_HDI_DISPLAY_V1_0_DISPLAY_COMPOSER_HDI_IMPL_H
571