diff options
author | Steven Moreland <smoreland@google.com> | 2017-10-02 13:24:49 -0700 |
---|---|---|
committer | Steven Moreland <smoreland@google.com> | 2017-10-19 01:12:39 -0700 |
commit | cb9e4900dc5a42241a2b5027d6eb2cf098181789 (patch) | |
tree | 5d7094b2eac4b5a24332eb3917a7844a404f6d12 /transport/allocator/1.0 | |
parent | 9bc35c40a958afcc5711c5c4b306ddc7b68974b0 (diff) | |
download | libhidl-cb9e4900dc5a42241a2b5027d6eb2cf098181789.tar.gz |
libhidlallocatorutils: IMemoryHeap -> hidl_memory
Several places originally did this conversion itself.
However, it's gross for them to have to care about the hidl
detail that IAllocator ashmem corresponds to framework
IMemoryHeap. Instead, we hide that behind a hidl-provided
function which can modify the opaque data in lock-step
with the allocator hal.
Bug: 34234561
Test: boot and use with DRM
Change-Id: Ia6b9b70fe9573da1518f3ee870e8f3232a8738bb
Diffstat (limited to 'transport/allocator/1.0')
-rw-r--r-- | transport/allocator/1.0/utils/Android.bp | 39 | ||||
-rw-r--r-- | transport/allocator/1.0/utils/FrameworkUtils.cpp | 37 | ||||
-rw-r--r-- | transport/allocator/1.0/utils/include/hidlmemory/FrameworkUtils.h | 34 |
3 files changed, 110 insertions, 0 deletions
diff --git a/transport/allocator/1.0/utils/Android.bp b/transport/allocator/1.0/utils/Android.bp new file mode 100644 index 0000000..b1a3f41 --- /dev/null +++ b/transport/allocator/1.0/utils/Android.bp @@ -0,0 +1,39 @@ +// Copyright (C) 2017 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_library { + name: "libhidlallocatorutils", + vendor_available: true, + vndk: { + enabled: true, + }, + defaults: ["libhidl-defaults"], + shared_libs: [ + "libbinder", + "libcutils", + "libhidlbase", + "libhidltransport", + "android.hidl.memory@1.0" + ], + export_include_dirs: ["include"], + + export_shared_lib_headers: [ + "libbinder", + "libhidlbase" + ], + + srcs: [ + "FrameworkUtils.cpp" + ], +} diff --git a/transport/allocator/1.0/utils/FrameworkUtils.cpp b/transport/allocator/1.0/utils/FrameworkUtils.cpp new file mode 100644 index 0000000..1fc6f3f --- /dev/null +++ b/transport/allocator/1.0/utils/FrameworkUtils.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <hidlmemory/FrameworkUtils.h> + +namespace android { + +namespace hardware { + +sp<HidlMemory> fromHeap(const sp<IMemoryHeap>& heap) { + int fd = dup(heap->getHeapID()); + + if (fd < 0) { + return HidlMemory::getInstance(hidl_memory()); + } + + // Only being used because this library is paired with the IAllocator + // ashmem. Other places should not make assumptions about the contents + // of this memory. + return HidlMemory::getInstance("ashmem", fd, heap->getSize()); +} + +} // namespace hardware +} // namespace android diff --git a/transport/allocator/1.0/utils/include/hidlmemory/FrameworkUtils.h b/transport/allocator/1.0/utils/include/hidlmemory/FrameworkUtils.h new file mode 100644 index 0000000..0a62575 --- /dev/null +++ b/transport/allocator/1.0/utils/include/hidlmemory/FrameworkUtils.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <binder/IMemory.h> +#include <hidl/HidlSupport.h> + +namespace android { + +namespace hardware { + +/** + * Returns a new IMemory instance corresponding to a framework IMemoryHeap object. + * This encapsulates the idea that IMemoryHeap and the ashmem instance of hidl + * IMemory are backed by the same object. + * + * Return is never nullptr. May be an invalid hidl_memory object. + */ +sp<HidlMemory> fromHeap(const sp<IMemoryHeap>& heap); + +} // namespace hardware +} // namespace android |