graphics: revise gralloc interfaces
Revise IAllocator and IMapper to reduce IPC and to support gralloc0
devices.
Specifically, IAllocator is trimmed down to have essentially only
allocate(BufferDescriptor descriptor, uint32_t count)
generates (Error error,
uint32_t stride,
vec<handle> buffers);
The ability to allocate buffers with shared backing store is
removed. ProducerUsage and ConsumerUsage are moved to the
graphics.common package and are merged and renamed to BufferUsage.
BufferUsage's bits follow gralloc0.
IMapper gains
typedef vec<uint32_t> BufferDescriptor;
createDescriptor(BufferDescriptorInfo descriptorInfo)
generates (Error error,
BufferDescriptor descriptor);
where BufferDescriptor is an implementation-defined blob. lockFlex
is replaced by lockYCbCr. All getters are removed.
Reference counting with retain/release is replaced by
importBuffer/freeBuffer.
Most if not all gralloc1 features are not used by the runtime yet.
There is also not too much test written for them. As such, they
tend to behave differently between implementations and cannot be
used reliably.
Bug: 36481301
Test: builds and boots on Pixel
Change-Id: I1d31105120517ea2c128c7a19297acf3bfd312bb
diff --git a/graphics/allocator/2.0/Android.bp b/graphics/allocator/2.0/Android.bp
index 271f2ce..f707468 100644
--- a/graphics/allocator/2.0/Android.bp
+++ b/graphics/allocator/2.0/Android.bp
@@ -3,9 +3,7 @@
filegroup {
name: "android.hardware.graphics.allocator@2.0_hal",
srcs: [
- "types.hal",
"IAllocator.hal",
- "IAllocatorClient.hal",
],
}
@@ -17,9 +15,7 @@
":android.hardware.graphics.allocator@2.0_hal",
],
out: [
- "android/hardware/graphics/allocator/2.0/types.cpp",
"android/hardware/graphics/allocator/2.0/AllocatorAll.cpp",
- "android/hardware/graphics/allocator/2.0/AllocatorClientAll.cpp",
],
}
@@ -31,18 +27,11 @@
":android.hardware.graphics.allocator@2.0_hal",
],
out: [
- "android/hardware/graphics/allocator/2.0/types.h",
- "android/hardware/graphics/allocator/2.0/hwtypes.h",
"android/hardware/graphics/allocator/2.0/IAllocator.h",
"android/hardware/graphics/allocator/2.0/IHwAllocator.h",
"android/hardware/graphics/allocator/2.0/BnHwAllocator.h",
"android/hardware/graphics/allocator/2.0/BpHwAllocator.h",
"android/hardware/graphics/allocator/2.0/BsAllocator.h",
- "android/hardware/graphics/allocator/2.0/IAllocatorClient.h",
- "android/hardware/graphics/allocator/2.0/IHwAllocatorClient.h",
- "android/hardware/graphics/allocator/2.0/BnHwAllocatorClient.h",
- "android/hardware/graphics/allocator/2.0/BpHwAllocatorClient.h",
- "android/hardware/graphics/allocator/2.0/BsAllocatorClient.h",
],
}
@@ -59,6 +48,7 @@
"libutils",
"libcutils",
"android.hardware.graphics.common@1.0",
+ "android.hardware.graphics.mapper@2.0",
"android.hidl.base@1.0",
],
export_shared_lib_headers: [
@@ -67,6 +57,7 @@
"libhwbinder",
"libutils",
"android.hardware.graphics.common@1.0",
+ "android.hardware.graphics.mapper@2.0",
"android.hidl.base@1.0",
],
}
diff --git a/graphics/allocator/2.0/IAllocator.hal b/graphics/allocator/2.0/IAllocator.hal
index bf0e141..43a3916 100644
--- a/graphics/allocator/2.0/IAllocator.hal
+++ b/graphics/allocator/2.0/IAllocator.hal
@@ -16,38 +16,9 @@
package android.hardware.graphics.allocator@2.0;
-import IAllocatorClient;
+import android.hardware.graphics.mapper@2.0;
interface IAllocator {
- enum Capability : int32_t {
- /** reserved */
- INVALID = 0,
-
- /**
- * IAllocatorClient::testAllocate must always return UNDEFINED unless
- * this capability is supported.
- */
- TEST_ALLOCATE = 1,
-
- /**
- * IAllocatorClient::BufferDescriptorInfo::layerCount must be 1 unless
- * this capability is supported.
- */
- LAYERED_BUFFERS = 2,
- };
-
- /**
- * Provides a list of supported capabilities (as described in the
- * definition of Capability above). This list must not change after
- * initialization.
- *
- * @return capabilities is a list of supported capabilities.
- */
- @entry
- @exit
- @callflow(next="*")
- getCapabilities() generates (vec<Capability> capabilities);
-
/**
* Retrieves implementation-defined debug information, which will be
* displayed during, for example, `dumpsys SurfaceFlinger`.
@@ -60,15 +31,27 @@
dumpDebugInfo() generates (string debugInfo);
/**
- * Creates a client of the allocator. All resources created by the client
- * are owned by the client and are only visible to the client, unless they
- * are exported by exportHandle.
+ * Allocates buffers with the properties specified by the descriptor.
*
+ * @param descriptor specifies the properties of the buffers to allocate.
+ * @param count is the number of buffers to allocate.
* @return error is NONE upon success. Otherwise,
- * NO_RESOURCES when no more client can currently be created.
- * @return client is the newly created client.
+ * BAD_DESCRIPTOR when the descriptor is invalid.
+ * NO_RESOURCES when the allocation cannot be fulfilled at this
+ * time.
+ * UNSUPPORTED when any of the property encoded in the descriptor
+ * is not supported.
+ * @return stride is the number of pixels between two consecutive rows of
+ * the buffers, when the concept of consecutive rows is defined.
+ * Otherwise, it has no meaning.
+ * @return buffers is an array of raw handles to the newly allocated
+ * buffers.
*/
@entry
+ @exit
@callflow(next="*")
- createClient() generates (Error error, IAllocatorClient client);
+ allocate(BufferDescriptor descriptor, uint32_t count)
+ generates (Error error,
+ uint32_t stride,
+ vec<handle> buffers);
};
diff --git a/graphics/allocator/2.0/IAllocatorClient.hal b/graphics/allocator/2.0/IAllocatorClient.hal
deleted file mode 100644
index 8ca568f..0000000
--- a/graphics/allocator/2.0/IAllocatorClient.hal
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-package android.hardware.graphics.allocator@2.0;
-
-import android.hardware.graphics.common@1.0::PixelFormat;
-
-interface IAllocatorClient {
- struct BufferDescriptorInfo {
- /**
- * The width specifies how many columns of pixels must be in the
- * allocated buffer, but does not necessarily represent the offset in
- * columns between the same column in adjacent rows. The rows may be
- * padded.
- */
- uint32_t width;
-
- /**
- * The height specifies how many rows of pixels must be in the
- * allocated buffer.
- */
- uint32_t height;
-
- /**
- * The number of image layers that must be in the allocated buffer.
- */
- uint32_t layerCount;
-
- /** Buffer pixel format. */
- PixelFormat format;
-
- /**
- * Buffer producer usage mask; valid flags can be found in the
- * definition of ProducerUsage.
- */
- uint64_t producerUsageMask;
-
- /**
- * Buffer consumer usage mask; valid flags can be found in the
- * definition of ConsumerUsage.
- */
- uint64_t consumerUsageMask;
- };
-
- /**
- * Creates a new, opaque buffer descriptor.
- *
- * @param descriptorInfo specifies the attributes of the buffer
- * descriptor.
- * @return error is NONE upon success. Otherwise,
- * BAD_VALUE when any attribute in descriptorInfo is invalid.
- * NO_RESOURCES when no more descriptors can currently be created.
- * @return descriptor is the newly created buffer descriptor.
- */
- @entry
- @callflow(next="*")
- createDescriptor(BufferDescriptorInfo descriptorInfo)
- generates (Error error,
- BufferDescriptor descriptor);
-
- /**
- * Destroys an existing buffer descriptor.
- *
- * @param descriptor is the descriptor to destroy.
- * @return error is either NONE or BAD_DESCRIPTOR.
- */
- @exit
- @callflow(next="*")
- destroyDescriptor(BufferDescriptor descriptor) generates (Error error);
-
- /**
- * Tests whether a buffer allocation can succeed, ignoring potential
- * resource contention which might lead to a NO_RESOURCES error.
- *
- * @param descriptors is a list of buffer descriptors.
- * @return error is NONE or NOT_SHARED upon success;
- * NONE when buffers can be created and share a backing store.
- * NOT_SHARED when buffers can be created but require more than a
- * backing store.
- * Otherwise,
- * BAD_DESCRIPTOR when any of the descriptors is invalid.
- * UNSUPPORTED when any of the descriptors can never be satisfied.
- * UNDEFINED when TEST_ALLOCATE is not listed in getCapabilities.
- */
- @callflow(next="allocate")
- testAllocate(vec<BufferDescriptor> descriptors) generates (Error error);
-
- /**
- * Attempts to allocate a list of buffers sharing a backing store.
- *
- * Each buffer must correspond to one of the descriptors passed into the
- * function and must hold a reference to its backing store. If the device
- * is unable to share the backing store between the buffers, it must
- * attempt to allocate the buffers with different backing stores and
- * return NOT_SHARED if it is successful.
- *
- * @param descriptors is the buffer descriptors to attempt to allocate.
- * @return error is NONE or NOT_SHARED upon success;
- * NONE when buffers can be created and share a backing store.
- * NOT_SHARED when buffers can be created but require more than a
- * backing store.
- * Otherwise,
- * BAD_DESCRIPTOR when any of the descriptors is invalid.
- * UNSUPPORTED when any of the descriptors can never be satisfied.
- * NO_RESOURCES when any of the buffers cannot be created at this
- * time.
- * @return buffers is the allocated buffers.
- */
- @callflow(next="exportHandle")
- allocate(vec<BufferDescriptor> descriptors)
- generates (Error error,
- vec<Buffer> buffers);
-
- /**
- * Frees a buffer.
- *
- * @param buffer is the buffer to be freed.
- * @return error is NONE upon success. Otherwise,
- * BAD_BUFFER when the buffer is invalid.
- */
- @exit
- @callflow(next="*")
- free(Buffer buffer) generates (Error error);
-
- /**
- * Exports a buffer for use in other client libraries or for cross-process
- * sharing.
- *
- * The exported handle is a handle to the backing store of the buffer, not
- * to the buffer itself. It however may not hold any reference to the
- * backing store and may be considered invalid by client libraries. To use
- * it and, in most cases, to save it for later use, a client must make a
- * clone of the handle and have the cloned handle hold a reference to the
- * backing store. Such a cloned handle will stay valid even after the
- * original buffer is freed. Refer to native_handle_clone and IMapper for
- * how a handle is cloned and how a reference is added.
- *
- * @param descriptor is the descriptor used to allocate the buffer.
- * @param buffer is the buffer to be exported.
- * @return error is NONE upon success. Otherwise,
- * BAD_DESCRIPTOR when the descriptor is invalid.
- * BAD_BUFFER when the buffer is invalid.
- * BAD_VALUE when descriptor and buffer do not match.
- * NO_RESOURCES when the buffer cannot be exported at this time.
- * @return bufferHandle is the exported handle.
- */
- @callflow(next="free")
- exportHandle(BufferDescriptor descriptor,
- Buffer buffer)
- generates (Error error,
- handle bufferHandle);
-};
diff --git a/graphics/allocator/2.0/default/Android.bp b/graphics/allocator/2.0/default/Android.bp
index 0baef89..6adfa71 100644
--- a/graphics/allocator/2.0/default/Android.bp
+++ b/graphics/allocator/2.0/default/Android.bp
@@ -3,7 +3,7 @@
defaults: ["hidl_defaults"],
proprietary: true,
relative_install_path: "hw",
- srcs: ["Gralloc.cpp"],
+ srcs: ["Gralloc.cpp", "Gralloc0Allocator.cpp", "Gralloc1Allocator.cpp"],
cppflags: ["-Wall", "-Wextra"],
shared_libs: [
"android.hardware.graphics.allocator@2.0",
@@ -15,6 +15,7 @@
"liblog",
"libutils",
],
+ static_libs: ["libgrallocmapperincludes"],
}
cc_binary {
diff --git a/graphics/allocator/2.0/default/Gralloc.cpp b/graphics/allocator/2.0/default/Gralloc.cpp
index 0b9e863..273d3f5 100644
--- a/graphics/allocator/2.0/default/Gralloc.cpp
+++ b/graphics/allocator/2.0/default/Gralloc.cpp
@@ -16,17 +16,11 @@
#define LOG_TAG "GrallocPassthrough"
-#include <mutex>
-#include <type_traits>
-#include <unordered_set>
-#include <vector>
-
-#include <string.h>
-
-#include <hardware/gralloc1.h>
-#include <log/log.h>
-
#include "Gralloc.h"
+#include "Gralloc0Allocator.h"
+#include "Gralloc1Allocator.h"
+
+#include <log/log.h>
namespace android {
namespace hardware {
@@ -35,417 +29,6 @@
namespace V2_0 {
namespace implementation {
-class GrallocHal : public IAllocator {
-public:
- GrallocHal(const hw_module_t* module);
- virtual ~GrallocHal();
-
- // IAllocator interface
- Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
- Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createClient(createClient_cb hidl_cb) override;
-
- Error createDescriptor(
- const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
- BufferDescriptor* outDescriptor);
- Error destroyDescriptor(BufferDescriptor descriptor);
-
- Error testAllocate(const hidl_vec<BufferDescriptor>& descriptors);
- Error allocate(const hidl_vec<BufferDescriptor>& descriptors,
- hidl_vec<Buffer>* outBuffers);
- Error free(Buffer buffer);
-
- Error exportHandle(Buffer buffer, const native_handle_t** outHandle);
-
-private:
- void initCapabilities();
-
- template<typename T>
- void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn);
- void initDispatch();
-
- bool hasCapability(Capability capability) const;
-
- gralloc1_device_t* mDevice;
-
- std::unordered_set<Capability> mCapabilities;
-
- struct {
- GRALLOC1_PFN_DUMP dump;
- GRALLOC1_PFN_CREATE_DESCRIPTOR createDescriptor;
- GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor;
- GRALLOC1_PFN_SET_DIMENSIONS setDimensions;
- GRALLOC1_PFN_SET_FORMAT setFormat;
- GRALLOC1_PFN_SET_LAYER_COUNT setLayerCount;
- GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage;
- GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage;
- GRALLOC1_PFN_ALLOCATE allocate;
- GRALLOC1_PFN_RELEASE release;
- } mDispatch;
-};
-
-class GrallocClient : public IAllocatorClient {
-public:
- GrallocClient(GrallocHal& hal);
- virtual ~GrallocClient();
-
- // IAllocatorClient interface
- Return<void> createDescriptor(const BufferDescriptorInfo& descriptorInfo,
- createDescriptor_cb hidl_cb) override;
- Return<Error> destroyDescriptor(BufferDescriptor descriptor) override;
-
- Return<Error> testAllocate(
- const hidl_vec<BufferDescriptor>& descriptors) override;
- Return<void> allocate(const hidl_vec<BufferDescriptor>& descriptors,
- allocate_cb hidl_cb) override;
- Return<Error> free(Buffer buffer) override;
-
- Return<void> exportHandle(BufferDescriptor descriptor,
- Buffer buffer, exportHandle_cb hidl_cb) override;
-
-private:
- GrallocHal& mHal;
-
- std::mutex mMutex;
- std::unordered_set<BufferDescriptor> mDescriptors;
- std::unordered_set<Buffer> mBuffers;
-};
-
-GrallocHal::GrallocHal(const hw_module_t* module)
- : mDevice(nullptr), mDispatch()
-{
- int status = gralloc1_open(module, &mDevice);
- if (status) {
- LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s",
- strerror(-status));
- }
-
- initCapabilities();
- initDispatch();
-}
-
-GrallocHal::~GrallocHal()
-{
- gralloc1_close(mDevice);
-}
-
-void GrallocHal::initCapabilities()
-{
- uint32_t count = 0;
- mDevice->getCapabilities(mDevice, &count, nullptr);
-
- std::vector<Capability> caps(count);
- mDevice->getCapabilities(mDevice, &count, reinterpret_cast<
- std::underlying_type<Capability>::type*>(caps.data()));
- caps.resize(count);
-
- mCapabilities.insert(caps.cbegin(), caps.cend());
-}
-
-template<typename T>
-void GrallocHal::initDispatch(gralloc1_function_descriptor_t desc, T* outPfn)
-{
- auto pfn = mDevice->getFunction(mDevice, desc);
- if (!pfn) {
- LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc);
- }
-
- *outPfn = reinterpret_cast<T>(pfn);
-}
-
-void GrallocHal::initDispatch()
-{
- initDispatch(GRALLOC1_FUNCTION_DUMP, &mDispatch.dump);
- initDispatch(GRALLOC1_FUNCTION_CREATE_DESCRIPTOR,
- &mDispatch.createDescriptor);
- initDispatch(GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR,
- &mDispatch.destroyDescriptor);
- initDispatch(GRALLOC1_FUNCTION_SET_DIMENSIONS, &mDispatch.setDimensions);
- initDispatch(GRALLOC1_FUNCTION_SET_FORMAT, &mDispatch.setFormat);
- if (hasCapability(Capability::LAYERED_BUFFERS)) {
- initDispatch(GRALLOC1_FUNCTION_SET_LAYER_COUNT,
- &mDispatch.setLayerCount);
- }
- initDispatch(GRALLOC1_FUNCTION_SET_CONSUMER_USAGE,
- &mDispatch.setConsumerUsage);
- initDispatch(GRALLOC1_FUNCTION_SET_PRODUCER_USAGE,
- &mDispatch.setProducerUsage);
- initDispatch(GRALLOC1_FUNCTION_ALLOCATE, &mDispatch.allocate);
- initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release);
-}
-
-bool GrallocHal::hasCapability(Capability capability) const
-{
- return (mCapabilities.count(capability) > 0);
-}
-
-Return<void> GrallocHal::getCapabilities(getCapabilities_cb hidl_cb)
-{
- std::vector<Capability> caps(
- mCapabilities.cbegin(), mCapabilities.cend());
-
- hidl_vec<Capability> reply;
- reply.setToExternal(caps.data(), caps.size());
- hidl_cb(reply);
-
- return Void();
-}
-
-Return<void> GrallocHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
-{
- uint32_t len = 0;
- mDispatch.dump(mDevice, &len, nullptr);
-
- std::vector<char> buf(len + 1);
- mDispatch.dump(mDevice, &len, buf.data());
- buf.resize(len + 1);
- buf[len] = '\0';
-
- hidl_string reply;
- reply.setToExternal(buf.data(), len);
- hidl_cb(reply);
-
- return Void();
-}
-
-Return<void> GrallocHal::createClient(createClient_cb hidl_cb)
-{
- sp<IAllocatorClient> client = new GrallocClient(*this);
- hidl_cb(Error::NONE, client);
-
- return Void();
-}
-
-Error GrallocHal::createDescriptor(
- const IAllocatorClient::BufferDescriptorInfo& descriptorInfo,
- BufferDescriptor* outDescriptor)
-{
- gralloc1_buffer_descriptor_t descriptor;
- int32_t err = mDispatch.createDescriptor(mDevice, &descriptor);
- if (err != GRALLOC1_ERROR_NONE) {
- return static_cast<Error>(err);
- }
-
- err = mDispatch.setDimensions(mDevice, descriptor,
- descriptorInfo.width, descriptorInfo.height);
- if (err == GRALLOC1_ERROR_NONE) {
- err = mDispatch.setFormat(mDevice, descriptor,
- static_cast<int32_t>(descriptorInfo.format));
- }
- if (err == GRALLOC1_ERROR_NONE) {
- if (hasCapability(Capability::LAYERED_BUFFERS)) {
- err = mDispatch.setLayerCount(mDevice, descriptor,
- descriptorInfo.layerCount);
- } else if (descriptorInfo.layerCount != 1) {
- err = GRALLOC1_ERROR_BAD_VALUE;
- }
- }
- if (err == GRALLOC1_ERROR_NONE) {
- uint64_t producerUsageMask = descriptorInfo.producerUsageMask;
- if (producerUsageMask & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) {
- producerUsageMask |= GRALLOC1_PRODUCER_USAGE_CPU_READ;
- }
- if (producerUsageMask & GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) {
- producerUsageMask |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE;
- }
- err = mDispatch.setProducerUsage(mDevice, descriptor,
- descriptorInfo.producerUsageMask);
- }
- if (err == GRALLOC1_ERROR_NONE) {
- uint64_t consumerUsageMask = descriptorInfo.consumerUsageMask;
- if (consumerUsageMask & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) {
- consumerUsageMask |= GRALLOC1_CONSUMER_USAGE_CPU_READ;
- }
- err = mDispatch.setConsumerUsage(mDevice, descriptor,
- consumerUsageMask);
- }
-
- if (err == GRALLOC1_ERROR_NONE) {
- *outDescriptor = descriptor;
- } else {
- mDispatch.destroyDescriptor(mDevice, descriptor);
- }
-
- return static_cast<Error>(err);
-}
-
-Error GrallocHal::destroyDescriptor(BufferDescriptor descriptor)
-{
- int32_t err = mDispatch.destroyDescriptor(mDevice, descriptor);
- return static_cast<Error>(err);
-}
-
-Error GrallocHal::testAllocate(const hidl_vec<BufferDescriptor>& descriptors)
-{
- if (!hasCapability(Capability::TEST_ALLOCATE)) {
- return Error::UNDEFINED;
- }
-
- int32_t err = mDispatch.allocate(mDevice, descriptors.size(),
- descriptors.data(), nullptr);
- return static_cast<Error>(err);
-}
-
-Error GrallocHal::allocate(const hidl_vec<BufferDescriptor>& descriptors,
- hidl_vec<Buffer>* outBuffers)
-{
- std::vector<buffer_handle_t> buffers(descriptors.size());
- int32_t err = mDispatch.allocate(mDevice, descriptors.size(),
- descriptors.data(), buffers.data());
- if (err == GRALLOC1_ERROR_NONE || err == GRALLOC1_ERROR_NOT_SHARED) {
- outBuffers->resize(buffers.size());
- for (size_t i = 0; i < outBuffers->size(); i++) {
- (*outBuffers)[i] = static_cast<Buffer>(
- reinterpret_cast<uintptr_t>(buffers[i]));
- }
- }
-
- return static_cast<Error>(err);
-}
-
-Error GrallocHal::free(Buffer buffer)
-{
- buffer_handle_t handle = reinterpret_cast<buffer_handle_t>(
- static_cast<uintptr_t>(buffer));
-
- int32_t err = mDispatch.release(mDevice, handle);
- return static_cast<Error>(err);
-}
-
-Error GrallocHal::exportHandle(Buffer buffer,
- const native_handle_t** outHandle)
-{
- // we rely on the caller to validate buffer here
- *outHandle = reinterpret_cast<buffer_handle_t>(
- static_cast<uintptr_t>(buffer));
- return Error::NONE;
-}
-
-GrallocClient::GrallocClient(GrallocHal& hal)
- : mHal(hal)
-{
-}
-
-GrallocClient::~GrallocClient()
-{
- if (!mBuffers.empty()) {
- ALOGW("client destroyed with valid buffers");
- for (auto buf : mBuffers) {
- mHal.free(buf);
- }
- }
-
- if (!mDescriptors.empty()) {
- ALOGW("client destroyed with valid buffer descriptors");
- for (auto desc : mDescriptors) {
- mHal.destroyDescriptor(desc);
- }
- }
-}
-
-Return<void> GrallocClient::createDescriptor(
- const BufferDescriptorInfo& descriptorInfo,
- createDescriptor_cb hidl_cb)
-{
- BufferDescriptor descriptor = 0;
- Error err = mHal.createDescriptor(descriptorInfo, &descriptor);
-
- if (err == Error::NONE) {
- std::lock_guard<std::mutex> lock(mMutex);
-
- auto result = mDescriptors.insert(descriptor);
- if (!result.second) {
- ALOGW("duplicated buffer descriptor id returned");
- mHal.destroyDescriptor(descriptor);
- err = Error::NO_RESOURCES;
- }
- }
-
- hidl_cb(err, descriptor);
- return Void();
-}
-
-Return<Error> GrallocClient::destroyDescriptor(BufferDescriptor descriptor)
-{
- {
- std::lock_guard<std::mutex> lock(mMutex);
- if (!mDescriptors.erase(descriptor)) {
- return Error::BAD_DESCRIPTOR;
- }
- }
-
- return mHal.destroyDescriptor(descriptor);
-}
-
-Return<Error> GrallocClient::testAllocate(
- const hidl_vec<BufferDescriptor>& descriptors)
-{
- return mHal.testAllocate(descriptors);
-}
-
-Return<void> GrallocClient::allocate(
- const hidl_vec<BufferDescriptor>& descriptors,
- allocate_cb hidl_cb) {
- hidl_vec<Buffer> buffers;
- Error err = mHal.allocate(descriptors, &buffers);
-
- if (err == Error::NONE || err == Error::NOT_SHARED) {
- std::lock_guard<std::mutex> lock(mMutex);
-
- for (size_t i = 0; i < buffers.size(); i++) {
- auto result = mBuffers.insert(buffers[i]);
- if (!result.second) {
- ALOGW("duplicated buffer id returned");
-
- for (size_t j = 0; j < buffers.size(); j++) {
- if (j < i) {
- mBuffers.erase(buffers[i]);
- }
- mHal.free(buffers[i]);
- }
-
- buffers = hidl_vec<Buffer>();
- err = Error::NO_RESOURCES;
- break;
- }
- }
- }
-
- hidl_cb(err, buffers);
- return Void();
-}
-
-Return<Error> GrallocClient::free(Buffer buffer)
-{
- {
- std::lock_guard<std::mutex> lock(mMutex);
- if (!mBuffers.erase(buffer)) {
- return Error::BAD_BUFFER;
- }
- }
-
- return mHal.free(buffer);
-}
-
-Return<void> GrallocClient::exportHandle(BufferDescriptor /*descriptor*/,
- Buffer buffer, exportHandle_cb hidl_cb)
-{
- const native_handle_t* handle = nullptr;
-
- {
- std::lock_guard<std::mutex> lock(mMutex);
- if (mBuffers.count(buffer) == 0) {
- hidl_cb(Error::BAD_BUFFER, handle);
- return Void();
- }
- }
-
- Error err = mHal.exportHandle(buffer, &handle);
-
- hidl_cb(err, handle);
- return Void();
-}
-
IAllocator* HIDL_FETCH_IAllocator(const char* /* name */) {
const hw_module_t* module = nullptr;
int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
@@ -455,12 +38,15 @@
}
uint8_t major = (module->module_api_version >> 8) & 0xff;
- if (major != 1) {
- ALOGE("unknown gralloc module major version %d", major);
- return nullptr;
+ switch (major) {
+ case 1:
+ return new Gralloc1Allocator(module);
+ case 0:
+ return new Gralloc0Allocator(module);
+ default:
+ ALOGE("unknown gralloc module major version %d", major);
+ return nullptr;
}
-
- return new GrallocHal(module);
}
} // namespace implementation
diff --git a/graphics/allocator/2.0/default/Gralloc0Allocator.cpp b/graphics/allocator/2.0/default/Gralloc0Allocator.cpp
new file mode 100644
index 0000000..3b62bb3
--- /dev/null
+++ b/graphics/allocator/2.0/default/Gralloc0Allocator.cpp
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2016 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.
+ */
+
+#define LOG_TAG "Gralloc0Allocator"
+
+#include "Gralloc0Allocator.h"
+#include "GrallocBufferDescriptor.h"
+
+#include <vector>
+
+#include <string.h>
+
+#include <log/log.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace implementation {
+
+using android::hardware::graphics::mapper::V2_0::implementation::
+ grallocDecodeBufferDescriptor;
+
+Gralloc0Allocator::Gralloc0Allocator(const hw_module_t* module) {
+ int result = gralloc_open(module, &mDevice);
+ if (result) {
+ LOG_ALWAYS_FATAL("failed to open gralloc0 device: %s",
+ strerror(-result));
+ }
+}
+
+Gralloc0Allocator::~Gralloc0Allocator() {
+ gralloc_close(mDevice);
+}
+
+Return<void> Gralloc0Allocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
+ char buf[4096] = {};
+ if (mDevice->dump) {
+ mDevice->dump(mDevice, buf, sizeof(buf));
+ buf[sizeof(buf) - 1] = '\0';
+ }
+
+ hidl_cb(hidl_string(buf));
+
+ return Void();
+}
+
+Return<void> Gralloc0Allocator::allocate(const BufferDescriptor& descriptor,
+ uint32_t count, allocate_cb hidl_cb) {
+ IMapper::BufferDescriptorInfo descriptorInfo;
+ if (!grallocDecodeBufferDescriptor(descriptor, &descriptorInfo)) {
+ hidl_cb(Error::BAD_DESCRIPTOR, 0, hidl_vec<hidl_handle>());
+ return Void();
+ }
+
+ Error error = Error::NONE;
+ uint32_t stride = 0;
+ std::vector<hidl_handle> buffers;
+ buffers.reserve(count);
+
+ // allocate the buffers
+ for (uint32_t i = 0; i < count; i++) {
+ buffer_handle_t tmpBuffer;
+ uint32_t tmpStride;
+ error = allocateOne(descriptorInfo, &tmpBuffer, &tmpStride);
+ if (error != Error::NONE) {
+ break;
+ }
+
+ if (stride == 0) {
+ stride = tmpStride;
+ } else if (stride != tmpStride) {
+ // non-uniform strides
+ mDevice->free(mDevice, tmpBuffer);
+ stride = 0;
+ error = Error::UNSUPPORTED;
+ break;
+ }
+
+ buffers.emplace_back(hidl_handle(tmpBuffer));
+ }
+
+ // return the buffers
+ hidl_vec<hidl_handle> hidl_buffers;
+ if (error == Error::NONE) {
+ hidl_buffers.setToExternal(buffers.data(), buffers.size());
+ }
+ hidl_cb(error, stride, hidl_buffers);
+
+ // free the buffers
+ for (const auto& buffer : buffers) {
+ mDevice->free(mDevice, buffer.getNativeHandle());
+ }
+
+ return Void();
+}
+
+Error Gralloc0Allocator::allocateOne(const IMapper::BufferDescriptorInfo& info,
+ buffer_handle_t* outBuffer,
+ uint32_t* outStride) {
+ if (info.layerCount > 1 || (info.usage >> 32) != 0) {
+ return Error::BAD_VALUE;
+ }
+
+ buffer_handle_t buffer = nullptr;
+ int stride = 0;
+ int result = mDevice->alloc(mDevice, info.width, info.height,
+ static_cast<int>(info.format), info.usage,
+ &buffer, &stride);
+ if (result) {
+ switch (result) {
+ case -EINVAL:
+ return Error::BAD_VALUE;
+ default:
+ return Error::NO_RESOURCES;
+ }
+ }
+
+ *outBuffer = buffer;
+ *outStride = stride;
+
+ return Error::NONE;
+}
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace allocator
+} // namespace graphics
+} // namespace hardware
+} // namespace android
diff --git a/graphics/allocator/2.0/default/Gralloc0Allocator.h b/graphics/allocator/2.0/default/Gralloc0Allocator.h
new file mode 100644
index 0000000..0e90527
--- /dev/null
+++ b/graphics/allocator/2.0/default/Gralloc0Allocator.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC0ALLOCATOR_H
+#define ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC0ALLOCATOR_H
+
+#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <hardware/gralloc.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace implementation {
+
+using android::hardware::graphics::mapper::V2_0::IMapper;
+using android::hardware::graphics::mapper::V2_0::BufferDescriptor;
+using android::hardware::graphics::mapper::V2_0::Error;
+
+class Gralloc0Allocator : public IAllocator {
+ public:
+ Gralloc0Allocator(const hw_module_t* module);
+ virtual ~Gralloc0Allocator();
+
+ // IAllocator interface
+ Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
+ Return<void> allocate(const BufferDescriptor& descriptor, uint32_t count,
+ allocate_cb hidl_cb) override;
+
+ private:
+ Error allocateOne(const IMapper::BufferDescriptorInfo& info,
+ buffer_handle_t* outBuffer, uint32_t* outStride);
+
+ alloc_device_t* mDevice;
+};
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace allocator
+} // namespace graphics
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC0ALLOCATOR_H
diff --git a/graphics/allocator/2.0/default/Gralloc1Allocator.cpp b/graphics/allocator/2.0/default/Gralloc1Allocator.cpp
new file mode 100644
index 0000000..c0a5e1e
--- /dev/null
+++ b/graphics/allocator/2.0/default/Gralloc1Allocator.cpp
@@ -0,0 +1,321 @@
+/*
+ * Copyright 2016 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.
+ */
+
+#define LOG_TAG "Gralloc1Allocator"
+
+#include "Gralloc1Allocator.h"
+#include "GrallocBufferDescriptor.h"
+
+#include <vector>
+
+#include <string.h>
+
+#include <log/log.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace implementation {
+
+using android::hardware::graphics::common::V1_0::BufferUsage;
+using android::hardware::graphics::mapper::V2_0::implementation::
+ grallocDecodeBufferDescriptor;
+
+Gralloc1Allocator::Gralloc1Allocator(const hw_module_t* module)
+ : mDevice(nullptr), mCapabilities(), mDispatch() {
+ int result = gralloc1_open(module, &mDevice);
+ if (result) {
+ LOG_ALWAYS_FATAL("failed to open gralloc1 device: %s",
+ strerror(-result));
+ }
+
+ initCapabilities();
+ initDispatch();
+}
+
+Gralloc1Allocator::~Gralloc1Allocator() {
+ gralloc1_close(mDevice);
+}
+
+void Gralloc1Allocator::initCapabilities() {
+ uint32_t count = 0;
+ mDevice->getCapabilities(mDevice, &count, nullptr);
+
+ std::vector<int32_t> capabilities(count);
+ mDevice->getCapabilities(mDevice, &count, capabilities.data());
+ capabilities.resize(count);
+
+ for (auto capability : capabilities) {
+ if (capability == GRALLOC1_CAPABILITY_LAYERED_BUFFERS) {
+ mCapabilities.layeredBuffers = true;
+ break;
+ }
+ }
+}
+
+template <typename T>
+void Gralloc1Allocator::initDispatch(gralloc1_function_descriptor_t desc,
+ T* outPfn) {
+ auto pfn = mDevice->getFunction(mDevice, desc);
+ if (!pfn) {
+ LOG_ALWAYS_FATAL("failed to get gralloc1 function %d", desc);
+ }
+
+ *outPfn = reinterpret_cast<T>(pfn);
+}
+
+void Gralloc1Allocator::initDispatch() {
+ initDispatch(GRALLOC1_FUNCTION_DUMP, &mDispatch.dump);
+ initDispatch(GRALLOC1_FUNCTION_CREATE_DESCRIPTOR,
+ &mDispatch.createDescriptor);
+ initDispatch(GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR,
+ &mDispatch.destroyDescriptor);
+ initDispatch(GRALLOC1_FUNCTION_SET_DIMENSIONS, &mDispatch.setDimensions);
+ initDispatch(GRALLOC1_FUNCTION_SET_FORMAT, &mDispatch.setFormat);
+ if (mCapabilities.layeredBuffers) {
+ initDispatch(GRALLOC1_FUNCTION_SET_LAYER_COUNT,
+ &mDispatch.setLayerCount);
+ }
+ initDispatch(GRALLOC1_FUNCTION_SET_CONSUMER_USAGE,
+ &mDispatch.setConsumerUsage);
+ initDispatch(GRALLOC1_FUNCTION_SET_PRODUCER_USAGE,
+ &mDispatch.setProducerUsage);
+ initDispatch(GRALLOC1_FUNCTION_GET_STRIDE, &mDispatch.getStride);
+ initDispatch(GRALLOC1_FUNCTION_ALLOCATE, &mDispatch.allocate);
+ initDispatch(GRALLOC1_FUNCTION_RELEASE, &mDispatch.release);
+}
+
+Return<void> Gralloc1Allocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
+ uint32_t len = 0;
+ mDispatch.dump(mDevice, &len, nullptr);
+
+ std::vector<char> buf(len + 1);
+ mDispatch.dump(mDevice, &len, buf.data());
+ buf.resize(len + 1);
+ buf[len] = '\0';
+
+ hidl_string reply;
+ reply.setToExternal(buf.data(), len);
+ hidl_cb(reply);
+
+ return Void();
+}
+
+Return<void> Gralloc1Allocator::allocate(const BufferDescriptor& descriptor,
+ uint32_t count, allocate_cb hidl_cb) {
+ IMapper::BufferDescriptorInfo descriptorInfo;
+ if (!grallocDecodeBufferDescriptor(descriptor, &descriptorInfo)) {
+ hidl_cb(Error::BAD_DESCRIPTOR, 0, hidl_vec<hidl_handle>());
+ return Void();
+ }
+
+ gralloc1_buffer_descriptor_t desc;
+ Error error = createDescriptor(descriptorInfo, &desc);
+ if (error != Error::NONE) {
+ hidl_cb(error, 0, hidl_vec<hidl_handle>());
+ return Void();
+ }
+
+ uint32_t stride = 0;
+ std::vector<hidl_handle> buffers;
+ buffers.reserve(count);
+
+ // allocate the buffers
+ for (uint32_t i = 0; i < count; i++) {
+ buffer_handle_t tmpBuffer;
+ uint32_t tmpStride;
+ error = allocateOne(desc, &tmpBuffer, &tmpStride);
+ if (error != Error::NONE) {
+ break;
+ }
+
+ if (stride == 0) {
+ stride = tmpStride;
+ } else if (stride != tmpStride) {
+ // non-uniform strides
+ mDispatch.release(mDevice, tmpBuffer);
+ stride = 0;
+ error = Error::UNSUPPORTED;
+ break;
+ }
+
+ buffers.emplace_back(hidl_handle(tmpBuffer));
+ }
+
+ mDispatch.destroyDescriptor(mDevice, desc);
+
+ // return the buffers
+ hidl_vec<hidl_handle> hidl_buffers;
+ if (error == Error::NONE) {
+ hidl_buffers.setToExternal(buffers.data(), buffers.size());
+ }
+ hidl_cb(error, stride, hidl_buffers);
+
+ // free the buffers
+ for (const auto& buffer : buffers) {
+ mDispatch.release(mDevice, buffer.getNativeHandle());
+ }
+
+ return Void();
+}
+
+Error Gralloc1Allocator::toError(int32_t error) {
+ switch (error) {
+ case GRALLOC1_ERROR_NONE:
+ return Error::NONE;
+ case GRALLOC1_ERROR_BAD_DESCRIPTOR:
+ return Error::BAD_DESCRIPTOR;
+ case GRALLOC1_ERROR_BAD_HANDLE:
+ return Error::BAD_BUFFER;
+ case GRALLOC1_ERROR_BAD_VALUE:
+ return Error::BAD_VALUE;
+ case GRALLOC1_ERROR_NOT_SHARED:
+ return Error::NONE; // this is fine
+ case GRALLOC1_ERROR_NO_RESOURCES:
+ return Error::NO_RESOURCES;
+ case GRALLOC1_ERROR_UNDEFINED:
+ case GRALLOC1_ERROR_UNSUPPORTED:
+ default:
+ return Error::UNSUPPORTED;
+ }
+}
+
+uint64_t Gralloc1Allocator::toProducerUsage(uint64_t usage) {
+ // this is potentially broken as we have no idea which private flags
+ // should be filtered out
+ uint64_t producerUsage =
+ usage &
+ ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK |
+ BufferUsage::CPU_WRITE_MASK);
+
+ switch (usage & BufferUsage::CPU_WRITE_MASK) {
+ case static_cast<uint64_t>(BufferUsage::CPU_WRITE_RARELY):
+ producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE;
+ break;
+ case static_cast<uint64_t>(BufferUsage::CPU_WRITE_OFTEN):
+ producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN;
+ break;
+ default:
+ break;
+ }
+
+ switch (usage & BufferUsage::CPU_READ_MASK) {
+ case static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY):
+ producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_READ;
+ break;
+ case static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN):
+ producerUsage |= GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN;
+ break;
+ default:
+ break;
+ }
+
+ return producerUsage;
+}
+
+uint64_t Gralloc1Allocator::toConsumerUsage(uint64_t usage) {
+ // this is potentially broken as we have no idea which private flags
+ // should be filtered out
+ uint64_t consumerUsage =
+ usage &
+ ~static_cast<uint64_t>(BufferUsage::CPU_READ_MASK |
+ BufferUsage::CPU_WRITE_MASK);
+
+ switch (usage & BufferUsage::CPU_READ_MASK) {
+ case static_cast<uint64_t>(BufferUsage::CPU_READ_RARELY):
+ consumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ;
+ break;
+ case static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN):
+ consumerUsage |= GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN;
+ break;
+ default:
+ break;
+ }
+
+ return consumerUsage;
+}
+
+Error Gralloc1Allocator::createDescriptor(
+ const IMapper::BufferDescriptorInfo& info,
+ gralloc1_buffer_descriptor_t* outDescriptor) {
+ gralloc1_buffer_descriptor_t descriptor;
+
+ int32_t error = mDispatch.createDescriptor(mDevice, &descriptor);
+
+ if (error == GRALLOC1_ERROR_NONE) {
+ error = mDispatch.setDimensions(mDevice, descriptor, info.width,
+ info.height);
+ }
+ if (error == GRALLOC1_ERROR_NONE) {
+ error = mDispatch.setFormat(mDevice, descriptor,
+ static_cast<int32_t>(info.format));
+ }
+ if (error == GRALLOC1_ERROR_NONE) {
+ if (mCapabilities.layeredBuffers) {
+ error =
+ mDispatch.setLayerCount(mDevice, descriptor, info.layerCount);
+ } else if (info.layerCount > 1) {
+ error = GRALLOC1_ERROR_UNSUPPORTED;
+ }
+ }
+ if (error == GRALLOC1_ERROR_NONE) {
+ error = mDispatch.setProducerUsage(mDevice, descriptor,
+ toProducerUsage(info.usage));
+ }
+ if (error == GRALLOC1_ERROR_NONE) {
+ error = mDispatch.setConsumerUsage(mDevice, descriptor,
+ toConsumerUsage(info.usage));
+ }
+
+ if (error == GRALLOC1_ERROR_NONE) {
+ *outDescriptor = descriptor;
+ } else {
+ mDispatch.destroyDescriptor(mDevice, descriptor);
+ }
+
+ return toError(error);
+}
+
+Error Gralloc1Allocator::allocateOne(gralloc1_buffer_descriptor_t descriptor,
+ buffer_handle_t* outBuffer,
+ uint32_t* outStride) {
+ buffer_handle_t buffer = nullptr;
+ int32_t error = mDispatch.allocate(mDevice, 1, &descriptor, &buffer);
+ if (error != GRALLOC1_ERROR_NONE && error != GRALLOC1_ERROR_NOT_SHARED) {
+ return toError(error);
+ }
+
+ uint32_t stride = 0;
+ error = mDispatch.getStride(mDevice, buffer, &stride);
+ if (error != GRALLOC1_ERROR_NONE && error != GRALLOC1_ERROR_UNDEFINED) {
+ mDispatch.release(mDevice, buffer);
+ return toError(error);
+ }
+
+ *outBuffer = buffer;
+ *outStride = stride;
+
+ return Error::NONE;
+}
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace allocator
+} // namespace graphics
+} // namespace hardware
+} // namespace android
diff --git a/graphics/allocator/2.0/default/Gralloc1Allocator.h b/graphics/allocator/2.0/default/Gralloc1Allocator.h
new file mode 100644
index 0000000..7b5a966
--- /dev/null
+++ b/graphics/allocator/2.0/default/Gralloc1Allocator.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 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.
+ */
+
+#ifndef ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H
+#define ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H
+
+#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <hardware/gralloc1.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace allocator {
+namespace V2_0 {
+namespace implementation {
+
+using android::hardware::graphics::mapper::V2_0::IMapper;
+using android::hardware::graphics::mapper::V2_0::BufferDescriptor;
+using android::hardware::graphics::mapper::V2_0::Error;
+
+class Gralloc1Allocator : public IAllocator {
+ public:
+ Gralloc1Allocator(const hw_module_t* module);
+ virtual ~Gralloc1Allocator();
+
+ // IAllocator interface
+ Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
+ Return<void> allocate(const BufferDescriptor& descriptor, uint32_t count,
+ allocate_cb hidl_cb) override;
+
+ private:
+ void initCapabilities();
+
+ template <typename T>
+ void initDispatch(gralloc1_function_descriptor_t desc, T* outPfn);
+ void initDispatch();
+
+ static Error toError(int32_t error);
+ static uint64_t toProducerUsage(uint64_t usage);
+ static uint64_t toConsumerUsage(uint64_t usage);
+
+ Error createDescriptor(const IMapper::BufferDescriptorInfo& info,
+ gralloc1_buffer_descriptor_t* outDescriptor);
+ Error allocateOne(gralloc1_buffer_descriptor_t descriptor,
+ buffer_handle_t* outBuffer, uint32_t* outStride);
+
+ gralloc1_device_t* mDevice;
+
+ struct {
+ bool layeredBuffers;
+ } mCapabilities;
+
+ struct {
+ GRALLOC1_PFN_DUMP dump;
+ GRALLOC1_PFN_CREATE_DESCRIPTOR createDescriptor;
+ GRALLOC1_PFN_DESTROY_DESCRIPTOR destroyDescriptor;
+ GRALLOC1_PFN_SET_DIMENSIONS setDimensions;
+ GRALLOC1_PFN_SET_FORMAT setFormat;
+ GRALLOC1_PFN_SET_LAYER_COUNT setLayerCount;
+ GRALLOC1_PFN_SET_CONSUMER_USAGE setConsumerUsage;
+ GRALLOC1_PFN_SET_PRODUCER_USAGE setProducerUsage;
+ GRALLOC1_PFN_GET_STRIDE getStride;
+ GRALLOC1_PFN_ALLOCATE allocate;
+ GRALLOC1_PFN_RELEASE release;
+ } mDispatch;
+};
+
+} // namespace implementation
+} // namespace V2_0
+} // namespace allocator
+} // namespace graphics
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_GRAPHICS_ALLOCATOR_V2_0_GRALLOC1ALLOCATOR_H
diff --git a/graphics/allocator/2.0/types.hal b/graphics/allocator/2.0/types.hal
deleted file mode 100644
index d9b184b..0000000
--- a/graphics/allocator/2.0/types.hal
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-package android.hardware.graphics.allocator@2.0;
-
-enum Error : int32_t {
- NONE = 0, /** no error */
- BAD_DESCRIPTOR = 1, /** invalid BufferDescriptor */
- BAD_BUFFER = 2, /** invalid Buffer */
- BAD_VALUE = 3, /** invalid width, height, etc. */
- NOT_SHARED = 4, /** buffers not sharing backing store */
- NO_RESOURCES = 5, /** temporary failure due to resource contention */
- UNDEFINED = 6, /** an operation has no defined meaning */
- UNSUPPORTED = 7, /** permanent failure */
-};
-
-enum ProducerUsage : uint64_t {
- /** bit 0 is reserved */
-
- /** buffer is read by CPU occasionally */
- CPU_READ = 1ULL << 1,
- /** buffer is read by CPU frequently */
- CPU_READ_OFTEN = 1ULL << 2,
-
- /** bit 3 is reserved */
- /** bit 4 is reserved */
-
- /** buffer is written by CPU occasionally */
- CPU_WRITE = 1ULL << 5,
- /** buffer is written by CPU frequently */
- CPU_WRITE_OFTEN = 1ULL << 6,
-
- /** bit 7 is reserved */
- /** bit 8 is reserved */
-
- /** buffer is used as a GPU render target */
- GPU_RENDER_TARGET = 1ULL << 9,
-
- /** bit 10 is reserved */
- /** bit 11 is reserved */
- /** bit 12 is reserved */
- /** bit 13 is reserved */
-
- /**
- * Buffer is allocated with hardware-level protection against copying the
- * contents (or information derived from the contents) into unprotected
- * memory.
- */
- PROTECTED = 1ULL << 14,
-
- /** bit 15 is reserved */
- /** bit 16 is reserved */
-
- /** buffer is used as a camera HAL output */
- CAMERA = 1ULL << 17,
-
- /** bit 18 is reserved */
- /** bit 19 is reserved */
- /** bit 20 is reserved */
- /** bit 21 is reserved */
-
- /** buffer is used as a video decoder output */
- VIDEO_DECODER = 1ULL << 22,
-
- /** buffer is used as a sensor direct report output */
- SENSOR_DIRECT_DATA = 1ULL << 23,
-
- /** bits 24-27 are reserved for future versions */
- /** bits 28-31 are reserved for vendor extensions */
-
- /** bits 32-47 are reserved for future versions */
- /** bits 48-63 are reserved for vendor extensions */
-};
-
-enum ConsumerUsage : uint64_t {
- /** bit 0 is reserved */
-
- /** buffer is read by CPU occasionally */
- CPU_READ = 1ULL << 1,
- /** buffer is read by CPU frequently */
- CPU_READ_OFTEN = 1ULL << 2,
-
- /** bit 3 is reserved */
- /** bit 4 is reserved */
- /** bit 5 is reserved */
- /** bit 6 is reserved */
- /** bit 7 is reserved */
-
- /** buffer is used as a GPU texture */
- GPU_TEXTURE = 1ULL << 8,
-
- /** bit 9 is reserved */
- /** bit 10 is reserved */
-
- /** buffer is used by hwcomposer HAL */
- HWCOMPOSER = 1ULL << 11,
- /** buffer is a hwcomposer HAL client target */
- CLIENT_TARGET = 1ULL << 12,
-
- /** bit 13 is reserved */
- /** bit 14 is reserved */
-
- /** buffer is used as a hwcomposer HAL cursor */
- CURSOR = 1ULL << 15,
-
- /** buffer is used as a video encoder input */
- VIDEO_ENCODER = 1ULL << 16,
-
- /** bit 17 is reserved */
-
- /** buffer is used as a camera HAL input */
- CAMERA = 1ULL << 18,
-
- /** bit 19 is reserved */
-
- /** buffer is used as a renderscript allocation */
- RENDERSCRIPT = 1ULL << 20,
-
- /** bit 21 is reserved */
- /** bit 22 is reserved */
-
- /**
- * buffer is used as as an OpenGL shader storage or uniform
- buffer object */
- GPU_DATA_BUFFER = 1ULL << 23,
-
- /** bits 24-27 are reserved for future versions */
- /** bits 28-31 are reserved for vendor extensions */
-
- /** bits 32-47 are reserved for future versions */
- /** bits 48-63 are reserved for vendor extensions */
-};
-
-typedef uint64_t BufferDescriptor;
-typedef uint64_t Buffer;
diff --git a/graphics/allocator/2.0/vts/functional/Android.bp b/graphics/allocator/2.0/vts/functional/Android.bp
deleted file mode 100644
index fb77ab3..0000000
--- a/graphics/allocator/2.0/vts/functional/Android.bp
+++ /dev/null
@@ -1,62 +0,0 @@
-//
-// Copyright (C) 2016 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_static {
- name: "libVtsHalGraphicsAllocatorTestUtils",
- defaults: ["hidl_defaults"],
- srcs: ["VtsHalGraphicsAllocatorTestUtils.cpp"],
- shared_libs: [
- "android.hardware.graphics.allocator@2.0",
- ],
- static_libs: [
- "VtsHalHidlTargetTestBase",
- ],
- cflags: [
- "-Wall",
- "-Wextra",
- "-Werror",
- "-O0",
- "-g",
- ],
- export_include_dirs: ["."],
-}
-
-cc_test {
- name: "VtsHalGraphicsAllocatorV2_0TargetTest",
- defaults: ["hidl_defaults"],
- srcs: ["VtsHalGraphicsAllocatorV2_0TargetTest.cpp"],
- shared_libs: [
- "libbase",
- "liblog",
- "libcutils",
- "libhidlbase",
- "libhidltransport",
- "libnativehelper",
- "libutils",
- "android.hardware.graphics.allocator@2.0",
- ],
- static_libs: [
- "libVtsHalGraphicsAllocatorTestUtils",
- "VtsHalHidlTargetTestBase",
- ],
- cflags: [
- "-Wall",
- "-Wextra",
- "-Werror",
- "-O0",
- "-g",
- ]
-}
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp
deleted file mode 100644
index 0dc43be..0000000
--- a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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 <VtsHalHidlTargetTestBase.h>
-
-#include "VtsHalGraphicsAllocatorTestUtils.h"
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace allocator {
-namespace V2_0 {
-namespace tests {
-
-Allocator::Allocator() { init(); }
-
-void Allocator::init() {
- mAllocator = ::testing::VtsHalHidlTargetTestBase::getService<IAllocator>();
- ASSERT_NE(nullptr, mAllocator.get()) << "failed to get allocator service";
-
- std::vector<IAllocator::Capability> capabilities = getCapabilities();
- mCapabilities.insert(capabilities.begin(), capabilities.end());
-}
-
-sp<IAllocator> Allocator::getRaw() const { return mAllocator; }
-
-bool Allocator::hasCapability(IAllocator::Capability capability) const {
- return mCapabilities.count(capability) > 0;
-}
-
-std::vector<IAllocator::Capability> Allocator::getCapabilities() {
- std::vector<IAllocator::Capability> capabilities;
- mAllocator->getCapabilities(
- [&](const auto& tmpCapabilities) { capabilities = tmpCapabilities; });
-
- return capabilities;
-}
-
-std::string Allocator::dumpDebugInfo() {
- std::string debugInfo;
- mAllocator->dumpDebugInfo(
- [&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); });
-
- return debugInfo;
-}
-
-std::unique_ptr<AllocatorClient> Allocator::createClient() {
- std::unique_ptr<AllocatorClient> client;
- mAllocator->createClient([&](const auto& tmpError, const auto& tmpClient) {
- ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
- client = std::make_unique<AllocatorClient>(tmpClient);
- });
-
- return client;
-}
-
-AllocatorClient::AllocatorClient(const sp<IAllocatorClient>& client)
- : mClient(client) {}
-
-AllocatorClient::~AllocatorClient() {
- for (auto buffer : mBuffers) {
- EXPECT_EQ(Error::NONE, mClient->free(buffer))
- << "failed to free buffer " << buffer;
- }
- mBuffers.clear();
-
- for (auto descriptor : mDescriptors) {
- EXPECT_EQ(Error::NONE, mClient->destroyDescriptor(descriptor))
- << "failed to destroy descriptor " << descriptor;
- }
- mDescriptors.clear();
-}
-
-sp<IAllocatorClient> AllocatorClient::getRaw() const { return mClient; }
-
-BufferDescriptor AllocatorClient::createDescriptor(
- const IAllocatorClient::BufferDescriptorInfo& info) {
- BufferDescriptor descriptor = 0;
- mClient->createDescriptor(
- info, [&](const auto& tmpError, const auto& tmpDescriptor) {
- ASSERT_EQ(Error::NONE, tmpError) << "failed to create descriptor";
- descriptor = tmpDescriptor;
-
- EXPECT_TRUE(mDescriptors.insert(descriptor).second)
- << "duplicated descriptor id " << descriptor;
- });
-
- return descriptor;
-}
-
-void AllocatorClient::destroyDescriptor(BufferDescriptor descriptor) {
- ASSERT_EQ(Error::NONE, mClient->destroyDescriptor(descriptor))
- << "failed to destroy descriptor " << descriptor;
-
- mDescriptors.erase(descriptor);
-}
-
-Error AllocatorClient::testAllocate(
- const std::vector<BufferDescriptor>& descriptors) {
- return mClient->testAllocate(descriptors);
-}
-
-bool AllocatorClient::testAllocate(BufferDescriptor descriptor) {
- std::vector<BufferDescriptor> descriptors(1, descriptor);
- Error error = testAllocate(descriptors);
- return (error == Error::NONE || error == Error::NOT_SHARED);
-}
-
-Error AllocatorClient::allocate(
- const std::vector<BufferDescriptor>& descriptors,
- std::vector<Buffer>& buffers) {
- Error error = Error::NO_RESOURCES;
- mClient->allocate(descriptors, [&](const auto& tmpError,
- const auto& tmpBuffers) {
- ASSERT_TRUE(tmpError == Error::NONE || tmpError == Error::NOT_SHARED)
- << "failed to allocate buffer";
- ASSERT_EQ(descriptors.size(), tmpBuffers.size()) << "invalid buffer count";
-
- error = tmpError;
- buffers = tmpBuffers;
-
- for (auto buffer : buffers) {
- EXPECT_TRUE(mBuffers.insert(buffer).second)
- << "duplicated buffer id " << buffer;
- }
- });
-
- return error;
-}
-
-Buffer AllocatorClient::allocate(BufferDescriptor descriptor) {
- std::vector<BufferDescriptor> descriptors(1, descriptor);
- std::vector<Buffer> buffers;
- allocate(descriptors, buffers);
- if (::testing::Test::HasFatalFailure()) {
- return 0;
- }
-
- return buffers[0];
-}
-
-void AllocatorClient::free(Buffer buffer) {
- ASSERT_EQ(Error::NONE, mClient->free(buffer))
- << "failed to free buffer " << buffer;
-
- mBuffers.erase(buffer);
-}
-
-native_handle_t* AllocatorClient::exportHandle(BufferDescriptor descriptor,
- Buffer buffer) {
- native_handle_t* handle;
- mClient->exportHandle(
- descriptor, buffer, [&](const auto& tmpError, const auto& tmpHandle) {
- ASSERT_EQ(Error::NONE, tmpError) << "failed to export buffer handle";
- ASSERT_NE(nullptr, tmpHandle.getNativeHandle())
- << "invalid buffer handle";
-
- handle = native_handle_clone(tmpHandle.getNativeHandle());
- ASSERT_NE(nullptr, handle) << "failed to clone handle";
- });
-
- return handle;
-}
-
-} // namespace tests
-} // namespace V2_0
-} // namespace allocator
-} // namespace graphics
-} // namespace hardware
-} // namespace android
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h
deleted file mode 100644
index c9bfe8f..0000000
--- a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorTestUtils.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef VTS_HAL_GRAPHICS_ALLOCATOR_UTILS
-#define VTS_HAL_GRAPHICS_ALLOCATOR_UTILS
-
-#include <memory>
-#include <string>
-#include <unordered_set>
-#include <vector>
-
-#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
-#include <utils/StrongPointer.h>
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace allocator {
-namespace V2_0 {
-namespace tests {
-
-class AllocatorClient;
-
-// A wrapper to IAllocator.
-class Allocator {
- public:
- Allocator();
-
- sp<IAllocator> getRaw() const;
-
- // Returns true when the allocator supports the specified capability.
- bool hasCapability(IAllocator::Capability capability) const;
-
- std::vector<IAllocator::Capability> getCapabilities();
- std::string dumpDebugInfo();
- std::unique_ptr<AllocatorClient> createClient();
-
- private:
- void init();
-
- sp<IAllocator> mAllocator;
- std::unordered_set<IAllocator::Capability> mCapabilities;
-};
-
-// A wrapper to IAllocatorClient.
-class AllocatorClient {
- public:
- AllocatorClient(const sp<IAllocatorClient>& client);
- ~AllocatorClient();
-
- sp<IAllocatorClient> getRaw() const;
-
- BufferDescriptor createDescriptor(
- const IAllocatorClient::BufferDescriptorInfo& info);
- void destroyDescriptor(BufferDescriptor descriptor);
-
- Error testAllocate(const std::vector<BufferDescriptor>& descriptors);
- bool testAllocate(BufferDescriptor descriptor);
-
- Error allocate(const std::vector<BufferDescriptor>& descriptors,
- std::vector<Buffer>& buffers);
- Buffer allocate(BufferDescriptor descriptor);
- void free(Buffer buffer);
-
- // Returns a handle to the buffer. The ownership of the handle is
- // transferred to the caller.
- native_handle_t* exportHandle(BufferDescriptor descriptor, Buffer buffer);
-
- private:
- sp<IAllocatorClient> mClient;
-
- // Keep track of all descriptors and buffers. When a test fails with
- // ASSERT_*, the destructor will clean up the resources for the test.
- std::unordered_set<BufferDescriptor> mDescriptors;
- std::unordered_set<Buffer> mBuffers;
-};
-
-} // namespace tests
-} // namespace V2_0
-} // namespace allocator
-} // namespace graphics
-} // namespace hardware
-} // namespace android
-
-#endif // VTS_HAL_GRAPHICS_ALLOCATOR_UTILS
diff --git a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp b/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp
deleted file mode 100644
index b1c764f..0000000
--- a/graphics/allocator/2.0/vts/functional/VtsHalGraphicsAllocatorV2_0TargetTest.cpp
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#define LOG_TAG "graphics_allocator_hidl_hal_test"
-
-#include <android-base/logging.h>
-#include <VtsHalHidlTargetTestBase.h>
-
-#include "VtsHalGraphicsAllocatorTestUtils.h"
-
-namespace android {
-namespace hardware {
-namespace graphics {
-namespace allocator {
-namespace V2_0 {
-namespace tests {
-namespace {
-
-using android::hardware::graphics::common::V1_0::PixelFormat;
-
-#define CHECK_FEATURE_OR_SKIP(FEATURE_NAME) \
- do { \
- if (!mAllocator->hasCapability(FEATURE_NAME)) { \
- std::cout << "[ SKIPPED ] Feature " << #FEATURE_NAME \
- << " not supported" << std::endl; \
- return; \
- } \
- } while (0)
-
-class GraphicsAllocatorHidlTest : public ::testing::VtsHalHidlTargetTestBase {
- protected:
- void SetUp() override {
- ASSERT_NO_FATAL_FAILURE(mAllocator = std::make_unique<Allocator>());
- ASSERT_NO_FATAL_FAILURE(mClient = mAllocator->createClient());
-
- mDummyDescriptorInfo.width = 64;
- mDummyDescriptorInfo.height = 64;
- mDummyDescriptorInfo.layerCount = 1;
- mDummyDescriptorInfo.format = PixelFormat::RGBA_8888;
- mDummyDescriptorInfo.producerUsageMask =
- static_cast<uint64_t>(ProducerUsage::CPU_WRITE);
- mDummyDescriptorInfo.consumerUsageMask =
- static_cast<uint64_t>(ConsumerUsage::CPU_READ);
- }
-
- void TearDown() override {}
-
- std::unique_ptr<Allocator> mAllocator;
- std::unique_ptr<AllocatorClient> mClient;
- IAllocatorClient::BufferDescriptorInfo mDummyDescriptorInfo{};
-};
-
-TEST_F(GraphicsAllocatorHidlTest, GetCapabilities) {
- auto capabilities = mAllocator->getCapabilities();
- for (auto cap : capabilities) {
- EXPECT_NE(IAllocator::Capability::INVALID, cap);
- }
-}
-
-TEST_F(GraphicsAllocatorHidlTest, DumpDebugInfo) {
- mAllocator->dumpDebugInfo();
-}
-
-TEST_F(GraphicsAllocatorHidlTest, CreateDestroyDescriptor) {
- BufferDescriptor descriptor;
- ASSERT_NO_FATAL_FAILURE(descriptor =
- mClient->createDescriptor(mDummyDescriptorInfo));
- mClient->destroyDescriptor(descriptor);
-}
-
-/**
- * Test testAllocate with a single buffer descriptor.
- */
-TEST_F(GraphicsAllocatorHidlTest, TestAllocateBasic) {
- CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
-
- BufferDescriptor descriptor;
- ASSERT_NO_FATAL_FAILURE(descriptor =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- ASSERT_TRUE(mClient->testAllocate(descriptor));
-}
-
-/**
- * Test testAllocate with two buffer descriptors.
- */
-TEST_F(GraphicsAllocatorHidlTest, TestAllocateArray) {
- CHECK_FEATURE_OR_SKIP(IAllocator::Capability::TEST_ALLOCATE);
-
- BufferDescriptor descriptor;
- ASSERT_NO_FATAL_FAILURE(descriptor =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- hidl_vec<BufferDescriptor> descriptors;
- descriptors.resize(2);
- descriptors[0] = descriptor;
- descriptors[1] = descriptor;
-
- auto error = mClient->testAllocate(descriptors);
- ASSERT_TRUE(error == Error::NONE || error == Error::NOT_SHARED);
-}
-
-/**
- * Test allocate/free with a single buffer descriptor.
- */
-TEST_F(GraphicsAllocatorHidlTest, AllocateFreeBasic) {
- BufferDescriptor descriptor;
- ASSERT_NO_FATAL_FAILURE(descriptor =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- Buffer buffer;
- ASSERT_NO_FATAL_FAILURE(buffer = mClient->allocate(descriptor));
-
- mClient->free(buffer);
-}
-
-/**
- * Test allocate/free with an array of buffer descriptors.
- */
-TEST_F(GraphicsAllocatorHidlTest, AllocateFreeArray) {
- BufferDescriptor descriptor1;
- ASSERT_NO_FATAL_FAILURE(descriptor1 =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- BufferDescriptor descriptor2;
- ASSERT_NO_FATAL_FAILURE(descriptor2 =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- hidl_vec<BufferDescriptor> descriptors;
- descriptors.resize(3);
- descriptors[0] = descriptor1;
- descriptors[1] = descriptor1;
- descriptors[2] = descriptor2;
-
- std::vector<Buffer> buffers;
- ASSERT_NO_FATAL_FAILURE(mClient->allocate(descriptors, buffers));
-
- for (auto buf : buffers) {
- mClient->free(buf);
- }
-}
-
-TEST_F(GraphicsAllocatorHidlTest, ExportHandle) {
- BufferDescriptor descriptor;
- ASSERT_NO_FATAL_FAILURE(descriptor =
- mClient->createDescriptor(mDummyDescriptorInfo));
-
- Buffer buffer;
- ASSERT_NO_FATAL_FAILURE(buffer = mClient->allocate(descriptor));
-
- native_handle_t* handle;
- ASSERT_NO_FATAL_FAILURE(handle = mClient->exportHandle(descriptor, buffer));
-
- native_handle_close(handle);
- native_handle_delete(handle);
-}
-
-} // namespace anonymous
-} // namespace tests
-} // namespace V2_0
-} // namespace allocator
-} // namespace graphics
-} // namespace hardware
-} // namespace android
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
-
- int status = RUN_ALL_TESTS();
- LOG(INFO) << "Test result = " << status;
-
- return status;
-}