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