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 
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 HDF_ERR_NOT_SUPPORT;
81 }
82 
CreateDisplayBufferVdi()83 extern "C" IDisplayBufferVdi* CreateDisplayBufferVdi()
84 {
85     return new DisplayBufferVdiImpl();
86 }
87 
DestroyDisplayBufferVdi(IDisplayBufferVdi * vdi)88 extern "C" void DestroyDisplayBufferVdi(IDisplayBufferVdi* vdi)
89 {
90     delete vdi;
91 }
92 } // namespace DISPLAY
93 } // namespace HDI
94 } // namespace OHOS
95