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_buffer_vdi_impl.h"
17 #include "cinttypes"
18 #include "display_log.h"
19 #include "display_gralloc_gbm.h"
20 #include "hdf_base.h"
21 #include "v1_0/display_composer_type.h"
22
23 namespace OHOS {
24 namespace HDI {
25 namespace DISPLAY {
26 using namespace OHOS::HDI::Display::Composer::V1_0;
27 using namespace OHOS::HDI::Display::Buffer::V1_2;
DisplayBufferVdiImpl()28 DisplayBufferVdiImpl::DisplayBufferVdiImpl()
29 {
30 #ifdef GRALLOC_GBM_SUPPORT
31 int ret = GbmGrallocInitialize();
32 if (ret != HDF_SUCCESS) {
33 DISPLAY_LOGE("gbm construct failed");
34 }
35 #endif
36 }
37
~DisplayBufferVdiImpl()38 DisplayBufferVdiImpl::~DisplayBufferVdiImpl()
39 {
40 #ifdef GRALLOC_GBM_SUPPORT
41 if (GbmGrallocUninitialize() != HDF_SUCCESS) {
42 DISPLAY_LOGE("gbm distruct failed");
43 }
44 #endif
45 }
46
AllocMem(const AllocInfo & info,BufferHandle * & handle) const47 int32_t DisplayBufferVdiImpl::AllocMem(const AllocInfo& info, BufferHandle*& handle) const
48 {
49 return GbmAllocMem(&info, &handle);
50 }
51
FreeMem(const BufferHandle & handle) const52 void DisplayBufferVdiImpl::FreeMem(const BufferHandle& handle) const
53 {
54 GbmFreeMem(const_cast<BufferHandle *>(&handle));
55 }
56
Mmap(const BufferHandle & handle) const57 void* DisplayBufferVdiImpl::Mmap(const BufferHandle& handle) const
58 {
59 return GbmMmap(const_cast<BufferHandle *>(&handle));
60 }
61
Unmap(const BufferHandle & handle) const62 int32_t DisplayBufferVdiImpl::Unmap(const BufferHandle& handle) const
63 {
64 return GbmUnmap(const_cast<BufferHandle *>(&handle));
65 }
66
FlushCache(const BufferHandle & handle) const67 int32_t DisplayBufferVdiImpl::FlushCache(const BufferHandle& handle) const
68 {
69 return GbmFlushCache(const_cast<BufferHandle *>(&handle));
70 }
71
InvalidateCache(const BufferHandle & handle) const72 int32_t DisplayBufferVdiImpl::InvalidateCache(const BufferHandle& handle) const
73 {
74 return GbmInvalidateCache(const_cast<BufferHandle *>(&handle));
75 }
76
IsSupportedAlloc(const std::vector<VerifyAllocInfo> & infos,std::vector<bool> & supporteds) const77 int32_t DisplayBufferVdiImpl::IsSupportedAlloc(const std::vector<VerifyAllocInfo>& infos,
78 std::vector<bool>& supporteds) const
79 {
80 return DISPLAY_NOT_SUPPORT;
81 }
82
RegisterBuffer(const BufferHandle & handle)83 int32_t DisplayBufferVdiImpl::RegisterBuffer(const BufferHandle& handle)
84 {
85 DISPLAY_LOGE("%s is not supported", __func__);
86 return DISPLAY_NOT_SUPPORT;
87 }
88
SetMetadata(const BufferHandle & handle,uint32_t key,const std::vector<uint8_t> & value)89 int32_t DisplayBufferVdiImpl::SetMetadata(const BufferHandle& handle, uint32_t key, const std::vector<uint8_t>& value)
90 {
91 DISPLAY_LOGE("%s is not supported", __func__);
92 return DISPLAY_NOT_SUPPORT;
93 }
94
GetMetadata(const BufferHandle & handle,uint32_t key,std::vector<uint8_t> & value)95 int32_t DisplayBufferVdiImpl::GetMetadata(const BufferHandle& handle, uint32_t key, std::vector<uint8_t>& value)
96 {
97 DISPLAY_LOGE("%s is not supported", __func__);
98 return DISPLAY_NOT_SUPPORT;
99 }
100
ListMetadataKeys(const BufferHandle & handle,std::vector<uint32_t> & keys)101 int32_t DisplayBufferVdiImpl::ListMetadataKeys(const BufferHandle& handle, std::vector<uint32_t>& keys)
102 {
103 DISPLAY_LOGE("%s is not supported", __func__);
104 return DISPLAY_NOT_SUPPORT;
105 }
106
EraseMetadataKey(const BufferHandle & handle,uint32_t key)107 int32_t DisplayBufferVdiImpl::EraseMetadataKey(const BufferHandle& handle, uint32_t key)
108 {
109 DISPLAY_LOGE("%s is not supported", __func__);
110 return DISPLAY_NOT_SUPPORT;
111 }
112
GetImageLayout(const BufferHandle & handle,ImageLayout & layout) const113 int32_t DisplayBufferVdiImpl::GetImageLayout(const BufferHandle& handle, ImageLayout& layout) const
114 {
115 DISPLAY_LOGE("%s is not supported", __func__);
116 return DISPLAY_NOT_SUPPORT;
117 }
118
CreateDisplayBufferVdi()119 extern "C" IDisplayBufferVdi* CreateDisplayBufferVdi()
120 {
121 return new DisplayBufferVdiImpl();
122 }
123
DestroyDisplayBufferVdi(IDisplayBufferVdi * vdi)124 extern "C" void DestroyDisplayBufferVdi(IDisplayBufferVdi* vdi)
125 {
126 delete vdi;
127 }
128 } // namespace DISPLAY
129 } // namespace HDI
130 } // namespace OHOS
131