From d6daa8ddf9ad758a9eaddd624dec57f543d51b44 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 8 Jan 2018 12:51:00 -0800 Subject: [PATCH] graphics: add allocator HAL support library Add a header-only library android.hardware.graphics.allocator@2.0-hal that can be used by implementations. An imlpementation can class VendorHal : public AllocatorHal { ... }; auto allocator = std::make_unique(); allocator->init(std::make_unique(...)); Or, if vendor extensions are to be added to the IAllocator, class AlocatorHalExt : public AllocatorHal { ... }; class VendorHal : public AllocatorHalExt { ... }; class AllocatorExt : public AllocatorImpl { ... }; auto allocator = std::make_unique(); allocator->init(std::make_unique(...)); Test: builds Change-Id: I7cb7a4888316b871e5c49d96524b1642fc708f2d --- graphics/allocator/2.0/utils/hal/Android.bp | 14 +++ .../hal/include/allocator-hal/2.0/Allocator.h | 89 +++++++++++++++++++ .../include/allocator-hal/2.0/AllocatorHal.h | 56 ++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 graphics/allocator/2.0/utils/hal/Android.bp create mode 100644 graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/Allocator.h create mode 100644 graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/AllocatorHal.h diff --git a/graphics/allocator/2.0/utils/hal/Android.bp b/graphics/allocator/2.0/utils/hal/Android.bp new file mode 100644 index 0000000000..ac642ce99f --- /dev/null +++ b/graphics/allocator/2.0/utils/hal/Android.bp @@ -0,0 +1,14 @@ +cc_library_headers { + name: "android.hardware.graphics.allocator@2.0-hal", + defaults: ["hidl_defaults"], + vendor: true, + shared_libs: [ + "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.mapper@2.0", + ], + export_shared_lib_headers: [ + "android.hardware.graphics.allocator@2.0", + "android.hardware.graphics.mapper@2.0", + ], + export_include_dirs: ["include"], +} diff --git a/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/Allocator.h b/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/Allocator.h new file mode 100644 index 0000000000..2f3022e440 --- /dev/null +++ b/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/Allocator.h @@ -0,0 +1,89 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#ifndef LOG_TAG +#warning "Allocator.h included without LOG_TAG" +#endif + +#include + +#include +#include +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace allocator { +namespace V2_0 { +namespace hal { + +using mapper::V2_0::BufferDescriptor; +using mapper::V2_0::Error; + +namespace detail { + +// AllocatorImpl implements IAllocator on top of AllocatorHal +template +class AllocatorImpl : public IALLOCATOR { + public: + bool init(std::unique_ptr hal) { + mHal = std::move(hal); + return true; + } + + // IAllocator 2.0 interface + Return dumpDebugInfo(IAllocator::dumpDebugInfo_cb hidl_cb) override { + hidl_cb(mHal->dumpDebugInfo()); + return Void(); + } + + Return allocate(const BufferDescriptor& descriptor, uint32_t count, + IAllocator::allocate_cb hidl_cb) override { + uint32_t stride; + std::vector buffers; + Error error = mHal->allocateBuffers(descriptor, count, &stride, &buffers); + if (error != Error::NONE) { + hidl_cb(error, 0, hidl_vec()); + return Void(); + } + + hidl_vec hidlBuffers(buffers.cbegin(), buffers.cend()); + hidl_cb(Error::NONE, stride, hidlBuffers); + + // free the local handles + mHal->freeBuffers(buffers); + + return Void(); + } + + protected: + std::unique_ptr mHal; +}; + +} // namespace detail + +using Allocator = detail::AllocatorImpl; + +} // namespace hal +} // namespace V2_0 +} // namespace allocator +} // namespace graphics +} // namespace hardware +} // namespace android diff --git a/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/AllocatorHal.h b/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/AllocatorHal.h new file mode 100644 index 0000000000..dec377a9e3 --- /dev/null +++ b/graphics/allocator/2.0/utils/hal/include/allocator-hal/2.0/AllocatorHal.h @@ -0,0 +1,56 @@ +/* + * Copyright 2018 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. + */ + +#pragma once + +#include +#include + +#include +#include + +namespace android { +namespace hardware { +namespace graphics { +namespace allocator { +namespace V2_0 { +namespace hal { + +using mapper::V2_0::BufferDescriptor; +using mapper::V2_0::Error; + +class AllocatorHal { + public: + virtual ~AllocatorHal() = default; + + // dump the debug information + virtual std::string dumpDebugInfo() = 0; + + // allocate buffers + virtual Error allocateBuffers(const BufferDescriptor& descriptor, uint32_t count, + uint32_t* outStride, + std::vector* outBuffers) = 0; + + // free buffers + virtual void freeBuffers(const std::vector& buffers) = 0; +}; + +} // namespace hal +} // namespace V2_0 +} // namespace allocator +} // namespace graphics +} // namespace hardware +} // namespace android