1 /*
2 * Copyright (c) 2021 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 "mapper_adapter.h"
17 #include "hdf_base.h"
18 #include "hdf_log.h"
19
20 #define HDF_LOG_TAG HDI_DISP_MAPPER
21
22 namespace OHOS {
23 namespace HDI {
24 namespace Display {
25 namespace V1_0 {
MapperAdapter()26 MapperAdapter::MapperAdapter()
27 {
28 if (GrallocInitialize(&mapperFuncs_) != HDF_SUCCESS) {
29 HDF_LOGE("%{public}s: mapperFuncs_ init failed", __func__);
30 }
31 }
32
~MapperAdapter()33 MapperAdapter::~MapperAdapter()
34 {
35 if (GrallocUninitialize(mapperFuncs_) != HDF_SUCCESS) {
36 HDF_LOGE("%{public}s: mapperFuncs_ uninit failed", __func__);
37 }
38 }
39
IsReady() const40 bool MapperAdapter::IsReady() const
41 {
42 HDF_LOGI("%{public}s: entry", __func__);
43 return mapperFuncs_ != nullptr;
44 }
45
MapBuffer(const BufferHandle & handle,void * & outData) const46 int32_t MapperAdapter::MapBuffer(const BufferHandle& handle, void*& outData) const
47 {
48 int32_t ret = 0;
49 outData = mapperFuncs_->Mmap(const_cast<BufferHandle *>(&handle));
50 return ret;
51 }
52
UnmapBuffer(const BufferHandle & handle) const53 int32_t MapperAdapter::UnmapBuffer(const BufferHandle& handle) const
54 {
55 int32_t ret = 0;
56 ret = mapperFuncs_->Unmap(const_cast<BufferHandle *>(&handle));
57 return ret;
58 }
59
InvalidateCache(const BufferHandle & handle) const60 int32_t MapperAdapter::InvalidateCache(const BufferHandle& handle) const
61 {
62 int32_t ret = 0;
63 ret = mapperFuncs_->InvalidateCache(const_cast<BufferHandle *>(&handle));
64 return ret;
65 }
66
FlushCache(const BufferHandle & handle) const67 int32_t MapperAdapter::FlushCache(const BufferHandle& handle) const
68 {
69 int32_t ret = 0;
70 ret = mapperFuncs_->FlushCache(const_cast<BufferHandle *>(&handle));
71 return ret;
72 }
73
FreeBuffer(const BufferHandle & handle) const74 void MapperAdapter::FreeBuffer(const BufferHandle& handle) const
75 {
76 mapperFuncs_->FreeMem(const_cast<BufferHandle *>(&handle));
77 }
78 } // namespace V1_0
79 } // namespace Display
80 } // namespace HDI
81 } // namespace OHOS