1 /* 2 * Copyright (c) 2024 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_2_DISPLAY_BUFFER_HDI_IMPL_H 17 #define OHOS_HDI_DISPLAY_V1_2_DISPLAY_BUFFER_HDI_IMPL_H 18 19 #include <iproxy_broker.h> 20 #include <unistd.h> 21 #include "hdf_log.h" 22 #include "hilog/log.h" 23 #include "v1_0/hdi_impl/display_buffer_hdi_impl.h" 24 #include "v1_0/imapper.h" 25 #include "v1_2/imapper.h" 26 #include "v1_1/include/idisplay_buffer.h" 27 #include "v1_2/include/idisplay_buffer.h" 28 #include "v1_1/hdi_impl/display_buffer_hdi_impl.h" 29 30 #undef LOG_TAG 31 #define LOG_TAG "DISP_HDI_BUFF" 32 #undef LOG_DOMAIN 33 #define LOG_DOMAIN 0xD002515 34 35 namespace OHOS { 36 namespace HDI { 37 namespace Display { 38 namespace Buffer { 39 namespace V1_2 { 40 template<typename Interface> 41 class DisplayBufferHdiImpl : public V1_1::DisplayBufferHdiImpl<Interface> { 42 public: 43 explicit DisplayBufferHdiImpl(bool isAllocLocal = false) : BaseType2_0(isAllocLocal), mapper_v1_2_(nullptr) 44 { 45 while ((mapper_v1_2_ = IMapper::Get(true)) == nullptr) { 46 // Waiting for metadata service ready 47 usleep(WAIT_TIME_INTERVAL); 48 } 49 } ~DisplayBufferHdiImpl()50 virtual ~DisplayBufferHdiImpl() {}; 51 GetImageLayout(const BufferHandle & handle,ImageLayout & layout)52 int32_t GetImageLayout(const BufferHandle& handle, ImageLayout& layout) const override 53 { 54 CHECK_NULLPOINTER_RETURN_VALUE(mapper_v1_2_, HDF_FAILURE); 55 sptr<NativeBuffer> hdiBuffer = new NativeBuffer(); 56 CHECK_NULLPOINTER_RETURN_VALUE(hdiBuffer, HDF_FAILURE); 57 hdiBuffer->SetBufferHandle(const_cast<BufferHandle*>(&handle)); 58 int32_t ret = mapper_v1_2_->GetImageLayout(hdiBuffer, layout); 59 return ret; 60 } 61 62 private: 63 using BaseType2_0 = V1_1::DisplayBufferHdiImpl<Interface>; 64 protected: 65 using BaseType2_0::WAIT_TIME_INTERVAL; 66 sptr<IMapper> mapper_v1_2_; 67 }; 68 using HdiDisplayBufferImpl = DisplayBufferHdiImpl<V1_2::IDisplayBuffer>; 69 } // namespace V1_2 70 } // namespace Buffer 71 } // namespace Display 72 } // namespace HDI 73 } // namespace OHOS 74 75 #endif // OHOS_HDI_DISPLAY_V1_1_DISPLAY_BUFFER_HDI_IMPL_H 76