aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoron393 <koron393@gmail.com>2020-11-30 02:51:05 +0900
committerArian <arian.kulmer@web.de>2021-04-05 13:53:21 +0200
commit8eafdd86e7b6dffdfaf21d25219d27b86835d95e (patch)
tree37641a991e78df27d7810509f27098c4aba8d068
parenta3db20af28dfdcae1d88e6516074f6a6dbcf9189 (diff)
shinano-common: libshim_camera: Update GraphicBuffer sources to Android 11
Signed-off-by: koron393 <koron393@gmail.com> Change-Id: I25387250e4369a2bd0a097a32a85258e0951db10
-rw-r--r--libshims/Android.mk2
-rw-r--r--libshims/include/ui/GraphicBuffer.h9
-rw-r--r--libshims/include/ui/GraphicBufferAllocator.h69
-rw-r--r--libshims/include/ui/GraphicBufferMapper.h88
-rw-r--r--libshims/ui/GraphicBuffer.cpp3
-rw-r--r--libshims/ui/GraphicBufferAllocator.cpp166
-rw-r--r--libshims/ui/GraphicBufferMapper.cpp227
7 files changed, 463 insertions, 101 deletions
diff --git a/libshims/Android.mk b/libshims/Android.mk
index 6ef9dc8..4633171 100644
--- a/libshims/Android.mk
+++ b/libshims/Android.mk
@@ -36,10 +36,12 @@ LOCAL_SHARED_LIBRARIES := \
android.frameworks.bufferhub@1.0 \
android.hardware.graphics.allocator@2.0 \
android.hardware.graphics.allocator@3.0 \
+ android.hardware.graphics.allocator@4.0 \
android.hardware.graphics.common@1.2 \
android.hardware.graphics.mapper@2.0 \
android.hardware.graphics.mapper@2.1 \
android.hardware.graphics.mapper@3.0 \
+ android.hardware.graphics.mapper@4.0 \
libbase \
libcutils \
libhardware \
diff --git a/libshims/include/ui/GraphicBuffer.h b/libshims/include/ui/GraphicBuffer.h
index fbf0af0..b45e1d2 100644
--- a/libshims/include/ui/GraphicBuffer.h
+++ b/libshims/include/ui/GraphicBuffer.h
@@ -35,6 +35,7 @@
#include <nativebase/nativebase.h>
#include <hardware/gralloc.h>
+
struct ANativeWindowBuffer;
namespace android {
@@ -167,7 +168,6 @@ public:
uint32_t getLayerCount() const { return static_cast<uint32_t>(layerCount); }
Rect getBounds() const { return Rect(width, height); }
uint64_t getId() const { return mId; }
- int32_t getBufferId() const { return mBufferId; }
uint32_t getGenerationNumber() const { return mGenerationNumber; }
void setGenerationNumber(uint32_t generation) {
@@ -278,12 +278,6 @@ private:
uint64_t mId;
- // System unique buffer ID. Note that this is different from mId, which is process unique. For
- // GraphicBuffer backed by BufferHub, the mBufferId is a system unique identifier that stays the
- // same cross process for the same chunck of underlying memory. Also note that this only applies
- // to GraphicBuffers that are backed by BufferHub.
- int32_t mBufferId = -1;
-
// Stores the generation number of this buffer. If this number does not
// match the BufferQueue's internal generation number (set through
// IGBP::setGenerationNumber), attempts to attach the buffer will fail.
@@ -302,7 +296,6 @@ private:
// and informs SurfaceFlinger that it should drop its strong pointer reference to the buffer.
std::vector<std::pair<GraphicBufferDeathCallback, void* /*mDeathCallbackContext*/>>
mDeathCallbacks;
-
};
}; // namespace android
diff --git a/libshims/include/ui/GraphicBufferAllocator.h b/libshims/include/ui/GraphicBufferAllocator.h
index 9804bea..3ed988c 100644
--- a/libshims/include/ui/GraphicBufferAllocator.h
+++ b/libshims/include/ui/GraphicBufferAllocator.h
@@ -1,19 +1,19 @@
/*
-**
-** Copyright 2009, 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.
-*/
+ *
+ * Copyright 2009, 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_BUFFER_ALLOCATOR_H
#define ANDROID_BUFFER_ALLOCATOR_H
@@ -32,8 +32,6 @@
#include <utils/Mutex.h>
#include <utils/Singleton.h>
-#include <hardware/gralloc.h>
-
namespace android {
class GrallocAllocator;
@@ -44,6 +42,29 @@ class GraphicBufferAllocator : public Singleton<GraphicBufferAllocator>
public:
static inline GraphicBufferAllocator& get() { return getInstance(); }
+ /**
+ * Allocates and imports a gralloc buffer.
+ *
+ * The handle must be freed with GraphicBufferAllocator::free() when no longer needed.
+ */
+ status_t allocate(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount,
+ uint64_t usage, buffer_handle_t* handle, uint32_t* stride,
+ std::string requestorName);
+
+ /**
+ * Allocates and does NOT import a gralloc buffer. Buffers cannot be used until they have
+ * been imported. This function is for advanced use cases only.
+ *
+ * The raw native handle must be freed by calling native_handle_close() followed by
+ * native_handle_delete().
+ */
+ status_t allocateRawHandle(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount,
+ uint64_t usage, buffer_handle_t* handle, uint32_t* stride,
+ std::string requestorName);
+
+ /**
+ * DEPRECATED: GraphicBufferAllocator does not use the graphicBufferId.
+ */
status_t allocate(uint32_t w, uint32_t h, PixelFormat format,
uint32_t layerCount, uint64_t usage,
buffer_handle_t* handle, uint32_t* stride, uint64_t graphicBufferId,
@@ -51,12 +72,12 @@ public:
status_t free(buffer_handle_t handle);
- size_t getTotalSize() const;
+ uint64_t getTotalSize() const;
- void dump(std::string& res) const;
- static void dumpToSystemLog();
+ void dump(std::string& res, bool less = true) const;
+ static void dumpToSystemLog(bool less = true);
-private:
+protected:
struct alloc_rec_t {
uint32_t width;
uint32_t height;
@@ -68,6 +89,10 @@ private:
std::string requestorName;
};
+ status_t allocateHelper(uint32_t w, uint32_t h, PixelFormat format, uint32_t layerCount,
+ uint64_t usage, buffer_handle_t* handle, uint32_t* stride,
+ std::string requestorName, bool importBuffer);
+
static Mutex sLock;
static KeyedVector<buffer_handle_t, alloc_rec_t> sAllocList;
@@ -75,7 +100,7 @@ private:
GraphicBufferAllocator();
~GraphicBufferAllocator();
- alloc_device_t *mAllocDev;
+ GraphicBufferMapper& mMapper;
std::unique_ptr<const GrallocAllocator> mAllocator;
};
diff --git a/libshims/include/ui/GraphicBufferMapper.h b/libshims/include/ui/GraphicBufferMapper.h
index 45f615a..8048989 100644
--- a/libshims/include/ui/GraphicBufferMapper.h
+++ b/libshims/include/ui/GraphicBufferMapper.h
@@ -22,10 +22,11 @@
#include <memory>
+#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>
+#include <ui/Rect.h>
#include <utils/Singleton.h>
-
// Needed by code that still uses the GRALLOC_USAGE_* constants.
// when/if we get rid of gralloc, we should provide aliases or fix call sites.
#include <hardware/gralloc.h>
@@ -36,7 +37,6 @@ namespace android {
// ---------------------------------------------------------------------------
class GrallocMapper;
-class Rect;
class GraphicBufferMapper : public Singleton<GraphicBufferMapper>
{
@@ -44,10 +44,14 @@ public:
enum Version {
GRALLOC_2,
GRALLOC_3,
+ GRALLOC_4,
};
static void preloadHal();
static inline GraphicBufferMapper& get() { return getInstance(); }
+ void dumpBuffer(buffer_handle_t bufferHandle, std::string& result, bool less = true) const;
+ static void dumpBufferToSystemLog(buffer_handle_t bufferHandle, bool less = true);
+
// The imported outHandle must be freed with freeBuffer when no longer
// needed. rawHandle is owned by the caller.
status_t importBuffer(buffer_handle_t rawHandle,
@@ -88,6 +92,86 @@ public:
status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format,
uint32_t layerCount, uint64_t usage, bool* outSupported);
+ /**
+ * Gets the gralloc metadata associated with the buffer.
+ *
+ * These functions are supported by gralloc 4.0+.
+ */
+ status_t getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId);
+ status_t getName(buffer_handle_t bufferHandle, std::string* outName);
+ status_t getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth);
+ status_t getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight);
+ status_t getLayerCount(buffer_handle_t bufferHandle, uint64_t* outLayerCount);
+ status_t getPixelFormatRequested(buffer_handle_t bufferHandle,
+ ui::PixelFormat* outPixelFormatRequested);
+ status_t getPixelFormatFourCC(buffer_handle_t bufferHandle, uint32_t* outPixelFormatFourCC);
+ status_t getPixelFormatModifier(buffer_handle_t bufferHandle, uint64_t* outPixelFormatModifier);
+ status_t getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage);
+ status_t getAllocationSize(buffer_handle_t bufferHandle, uint64_t* outAllocationSize);
+ status_t getProtectedContent(buffer_handle_t bufferHandle, uint64_t* outProtectedContent);
+ status_t getCompression(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outCompression);
+ status_t getCompression(buffer_handle_t bufferHandle, ui::Compression* outCompression);
+ status_t getInterlaced(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outInterlaced);
+ status_t getInterlaced(buffer_handle_t bufferHandle, ui::Interlaced* outInterlaced);
+ status_t getChromaSiting(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting);
+ status_t getChromaSiting(buffer_handle_t bufferHandle, ui::ChromaSiting* outChromaSiting);
+ status_t getPlaneLayouts(buffer_handle_t bufferHandle,
+ std::vector<ui::PlaneLayout>* outPlaneLayouts);
+ status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace);
+ status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode);
+ status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional<ui::Smpte2086>* outSmpte2086);
+ status_t getCta861_3(buffer_handle_t bufferHandle, std::optional<ui::Cta861_3>* outCta861_3);
+ status_t getSmpte2094_40(buffer_handle_t bufferHandle,
+ std::optional<std::vector<uint8_t>>* outSmpte2094_40);
+
+ /**
+ * Gets the default metadata for a gralloc buffer allocated with the given parameters.
+ *
+ * These functions are supported by gralloc 4.0+.
+ */
+ status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ uint32_t* outPixelFormatFourCC);
+ status_t getDefaultPixelFormatModifier(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ uint64_t* outPixelFormatModifier);
+ status_t getDefaultAllocationSize(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ uint64_t* outAllocationSize);
+ status_t getDefaultProtectedContent(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ uint64_t* outProtectedContent);
+ status_t getDefaultCompression(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outCompression);
+ status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ ui::Compression* outCompression);
+ status_t getDefaultInterlaced(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outInterlaced);
+ status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ ui::Interlaced* outInterlaced);
+ status_t getDefaultChromaSiting(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting);
+ status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ ui::ChromaSiting* outChromaSiting);
+ status_t getDefaultPlaneLayouts(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ std::vector<ui::PlaneLayout>* outPlaneLayouts);
+
const GrallocMapper& getGrallocMapper() const {
return reinterpret_cast<const GrallocMapper&>(*mMapper);
}
diff --git a/libshims/ui/GraphicBuffer.cpp b/libshims/ui/GraphicBuffer.cpp
index d70701d..c0423aa 100644
--- a/libshims/ui/GraphicBuffer.cpp
+++ b/libshims/ui/GraphicBuffer.cpp
@@ -23,7 +23,6 @@
#include <grallocusage/GrallocUsageConversion.h>
-#include <ui/Gralloc2.h>
#include <ui/GraphicBufferAllocator.h>
#include <ui/GraphicBufferMapper.h>
#include <utils/Trace.h>
@@ -450,8 +449,6 @@ status_t GraphicBuffer::unflatten(void const*& buffer, size_t& size, int const*&
} else if (buf[0] == 'GBFR') {
// old version, when usage bits were 32-bits
flattenWordCount = 12;
- } else if (buf[0] == 'BHBB') { // BufferHub backed buffer.
- return BAD_TYPE;
} else {
return BAD_TYPE;
}
diff --git a/libshims/ui/GraphicBufferAllocator.cpp b/libshims/ui/GraphicBufferAllocator.cpp
index 9543fd7..943d13e 100644
--- a/libshims/ui/GraphicBufferAllocator.cpp
+++ b/libshims/ui/GraphicBufferAllocator.cpp
@@ -20,6 +20,7 @@
#include <ui/GraphicBufferAllocator.h>
+#include <limits.h>
#include <stdio.h>
#include <grallocusage/GrallocUsageConversion.h>
@@ -32,6 +33,7 @@
#include <ui/Gralloc.h>
#include <ui/Gralloc2.h>
#include <ui/Gralloc3.h>
+#include <ui/Gralloc4.h>
#include <ui/GraphicBufferMapper.h>
namespace android {
@@ -45,43 +47,49 @@ Mutex GraphicBufferAllocator::sLock;
KeyedVector<buffer_handle_t,
GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList;
-GraphicBufferAllocator::GraphicBufferAllocator()
- : mAllocDev(0)
-{
- hw_module_t const* module;
- int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
- ALOGE_IF(err, "FATAL: can't find the %s module", GRALLOC_HARDWARE_MODULE_ID);
- if (err == 0) {
- gralloc_open(module, &mAllocDev);
+GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) {
+ mAllocator = std::make_unique<const Gralloc4Allocator>(
+ reinterpret_cast<const Gralloc4Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
+ }
+ mAllocator = std::make_unique<const Gralloc3Allocator>(
+ reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
+ }
+ mAllocator = std::make_unique<const Gralloc2Allocator>(
+ reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper()));
+ if (mAllocator->isLoaded()) {
+ return;
}
-}
-GraphicBufferAllocator::~GraphicBufferAllocator()
-{
- gralloc_close(mAllocDev);
+ LOG_ALWAYS_FATAL("gralloc-allocator is missing");
}
-size_t GraphicBufferAllocator::getTotalSize() const {
+GraphicBufferAllocator::~GraphicBufferAllocator() {}
+
+uint64_t GraphicBufferAllocator::getTotalSize() const {
Mutex::Autolock _l(sLock);
- size_t total = 0;
+ uint64_t total = 0;
for (size_t i = 0; i < sAllocList.size(); ++i) {
total += sAllocList.valueAt(i).size;
}
return total;
}
-void GraphicBufferAllocator::dump(std::string& result) const {
+void GraphicBufferAllocator::dump(std::string& result, bool less) const {
Mutex::Autolock _l(sLock);
KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- size_t total = 0;
- result.append("Allocated buffers:\n");
+ uint64_t total = 0;
+ result.append("GraphicBufferAllocator buffers:\n");
const size_t c = list.size();
for (size_t i=0 ; i<c ; i++) {
const alloc_rec_t& rec(list.valueAt(i));
if (rec.size) {
StringAppendF(&result,
"%10p: %7.2f KiB | %4u (%4u) x %4u | %4u | %8X | 0x%" PRIx64 " | %s\n",
- list.keyAt(i), rec.size / 1024.0, rec.width, rec.stride, rec.height,
+ list.keyAt(i), static_cast<double>(rec.size) / 1024.0, rec.width, rec.stride, rec.height,
rec.layerCount, rec.format, rec.usage, rec.requestorName.c_str());
} else {
StringAppendF(&result,
@@ -91,23 +99,22 @@ void GraphicBufferAllocator::dump(std::string& result) const {
}
total += rec.size;
}
- StringAppendF(&result, "Total allocated (estimate): %.2f KB\n", total / 1024.0);
+ StringAppendF(&result, "Total allocated by GraphicBufferAllocator (estimate): %.2f KB\n",
+ static_cast<double>(total) / 1024.0);
- result.append(mAllocator->dumpDebugInfo());
+ result.append(mAllocator->dumpDebugInfo(less));
}
-void GraphicBufferAllocator::dumpToSystemLog()
-{
+void GraphicBufferAllocator::dumpToSystemLog(bool less) {
std::string s;
- GraphicBufferAllocator::getInstance().dump(s);
+ GraphicBufferAllocator::getInstance().dump(s, less);
ALOGD("%s", s.c_str());
}
-status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height,
- PixelFormat format, uint32_t layerCount, uint64_t usage,
- buffer_handle_t* handle, uint32_t* stride,
- uint64_t /*graphicBufferId*/, std::string requestorName)
-{
+status_t GraphicBufferAllocator::allocateHelper(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ buffer_handle_t* handle, uint32_t* stride,
+ std::string requestorName, bool importBuffer) {
ATRACE_CALL();
// make sure to not allocate a N x 0 or 0 x N buffer, since this is
@@ -115,6 +122,14 @@ status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height,
if (!width || !height)
width = height = 1;
+ const uint32_t bpp = bytesPerPixel(format);
+ if (std::numeric_limits<size_t>::max() / width / height < static_cast<size_t>(bpp)) {
+ ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
+ "usage %" PRIx64 ": Requesting too large a buffer size",
+ width, height, layerCount, format, usage);
+ return BAD_VALUE;
+ }
+
// Ensure that layerCount is valid.
if (layerCount < 1)
layerCount = 1;
@@ -122,47 +137,82 @@ status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height,
// TODO(b/72323293, b/72703005): Remove these invalid bits from callers
usage &= ~static_cast<uint64_t>((1 << 10) | (1 << 13));
- status_t error =
- mAllocator->allocate(width, height, format, layerCount, usage, 1, stride, handle);
- if (error == NO_ERROR) {
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- uint32_t bpp = bytesPerPixel(format);
- alloc_rec_t rec;
- rec.width = width;
- rec.height = height;
- rec.stride = *stride;
- rec.format = format;
- rec.layerCount = layerCount;
- rec.usage = usage;
- rec.size = static_cast<size_t>(height * (*stride) * bpp);
- rec.requestorName = std::move(requestorName);
- list.add(*handle, rec);
+ status_t error = mAllocator->allocate(requestorName, width, height, format, layerCount, usage,
+ 1, stride, handle, importBuffer);
+ if (error != NO_ERROR) {
+ ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
+ "usage %" PRIx64 ": %d",
+ width, height, layerCount, format, usage, error);
+ return NO_MEMORY;
+ }
+ if (!importBuffer) {
return NO_ERROR;
+ }
+ size_t bufSize;
+
+ // if stride has no meaning or is too large,
+ // approximate size with the input width instead
+ if ((*stride) != 0 &&
+ std::numeric_limits<size_t>::max() / height / (*stride) < static_cast<size_t>(bpp)) {
+ bufSize = static_cast<size_t>(width) * height * bpp;
} else {
- ALOGE("Failed to allocate (%u x %u) layerCount %u format %d "
- "usage %" PRIx64 ": %d",
- width, height, layerCount, format, usage,
- error);
- return NO_MEMORY;
+ bufSize = static_cast<size_t>((*stride)) * height * bpp;
}
+
+ Mutex::Autolock _l(sLock);
+ KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
+ alloc_rec_t rec;
+ rec.width = width;
+ rec.height = height;
+ rec.stride = *stride;
+ rec.format = format;
+ rec.layerCount = layerCount;
+ rec.usage = usage;
+ rec.size = bufSize;
+ rec.requestorName = std::move(requestorName);
+ list.add(*handle, rec);
+
+ return NO_ERROR;
+}
+status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ buffer_handle_t* handle, uint32_t* stride,
+ std::string requestorName) {
+ return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
+ true);
+}
+
+status_t GraphicBufferAllocator::allocateRawHandle(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage, buffer_handle_t* handle,
+ uint32_t* stride, std::string requestorName) {
+ return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
+ false);
+}
+
+// DEPRECATED
+status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t layerCount, uint64_t usage,
+ buffer_handle_t* handle, uint32_t* stride,
+ uint64_t /*graphicBufferId*/, std::string requestorName) {
+ return allocateHelper(width, height, format, layerCount, usage, handle, stride, requestorName,
+ true);
}
status_t GraphicBufferAllocator::free(buffer_handle_t handle)
{
- status_t err;
+ ATRACE_CALL();
- err = mAllocDev->free(mAllocDev, handle);
+ // We allocated a buffer from the allocator and imported it into the
+ // mapper to get the handle. We just need to free the handle now.
+ mMapper.freeBuffer(handle);
- ALOGW_IF(err, "free(...) failed %d (%s)", err, strerror(-err));
- if (err == NO_ERROR) {
- Mutex::Autolock _l(sLock);
- KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
- list.removeItem(handle);
- }
+ Mutex::Autolock _l(sLock);
+ KeyedVector<buffer_handle_t, alloc_rec_t>& list(sAllocList);
+ list.removeItem(handle);
- return err;
+ return NO_ERROR;
}
// ---------------------------------------------------------------------------
diff --git a/libshims/ui/GraphicBufferMapper.cpp b/libshims/ui/GraphicBufferMapper.cpp
index 1efad90..95dc12c 100644
--- a/libshims/ui/GraphicBufferMapper.cpp
+++ b/libshims/ui/GraphicBufferMapper.cpp
@@ -35,6 +35,7 @@
#include <ui/Gralloc.h>
#include <ui/Gralloc2.h>
#include <ui/Gralloc3.h>
+#include <ui/Gralloc4.h>
#include <ui/GraphicBuffer.h>
#include <system/graphics.h>
@@ -47,20 +48,38 @@ ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper )
void GraphicBufferMapper::preloadHal() {
Gralloc2Mapper::preload();
Gralloc3Mapper::preload();
+ Gralloc4Mapper::preload();
}
GraphicBufferMapper::GraphicBufferMapper() {
+ mMapper = std::make_unique<const Gralloc4Mapper>();
+ if (mMapper->isLoaded()) {
+ mMapperVersion = Version::GRALLOC_4;
+ return;
+ }
mMapper = std::make_unique<const Gralloc3Mapper>();
- if (!mMapper->isLoaded()) {
- mMapper = std::make_unique<const Gralloc2Mapper>();
- mMapperVersion = Version::GRALLOC_2;
- } else {
+ if (mMapper->isLoaded()) {
mMapperVersion = Version::GRALLOC_3;
+ return;
}
-
- if (!mMapper->isLoaded()) {
- LOG_ALWAYS_FATAL("gralloc-mapper is missing");
+ mMapper = std::make_unique<const Gralloc2Mapper>();
+ if (mMapper->isLoaded()) {
+ mMapperVersion = Version::GRALLOC_2;
+ return;
}
+
+ LOG_ALWAYS_FATAL("gralloc-mapper is missing");
+}
+
+void GraphicBufferMapper::dumpBuffer(buffer_handle_t bufferHandle, std::string& result,
+ bool less) const {
+ result.append(mMapper->dumpBuffer(bufferHandle, less));
+}
+
+void GraphicBufferMapper::dumpBufferToSystemLog(buffer_handle_t bufferHandle, bool less) {
+ std::string s;
+ GraphicBufferMapper::getInstance().dumpBuffer(bufferHandle, s, less);
+ ALOGD("%s", s.c_str());
}
status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle,
@@ -115,7 +134,7 @@ status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage, const
status_t GraphicBufferMapper::lock(buffer_handle_t handle, uint32_t usage,
const Rect& bounds, void** vaddr)
{
- return lock(handle, usage, bounds, vaddr, 0, 0);
+ return lockAsync(handle, usage, bounds, vaddr, -1, nullptr, nullptr);
}
status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, uint32_t usage,
@@ -176,5 +195,197 @@ status_t GraphicBufferMapper::isSupported(uint32_t width, uint32_t height,
uint64_t usage, bool* outSupported) {
return mMapper->isSupported(width, height, format, layerCount, usage, outSupported);
}
+
+status_t GraphicBufferMapper::getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) {
+ return mMapper->getBufferId(bufferHandle, outBufferId);
+}
+
+status_t GraphicBufferMapper::getName(buffer_handle_t bufferHandle, std::string* outName) {
+ return mMapper->getName(bufferHandle, outName);
+}
+
+status_t GraphicBufferMapper::getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth) {
+ return mMapper->getWidth(bufferHandle, outWidth);
+}
+
+status_t GraphicBufferMapper::getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight) {
+ return mMapper->getHeight(bufferHandle, outHeight);
+}
+
+status_t GraphicBufferMapper::getLayerCount(buffer_handle_t bufferHandle, uint64_t* outLayerCount) {
+ return mMapper->getLayerCount(bufferHandle, outLayerCount);
+}
+
+status_t GraphicBufferMapper::getPixelFormatRequested(buffer_handle_t bufferHandle,
+ ui::PixelFormat* outPixelFormatRequested) {
+ return mMapper->getPixelFormatRequested(bufferHandle, outPixelFormatRequested);
+}
+
+status_t GraphicBufferMapper::getPixelFormatFourCC(buffer_handle_t bufferHandle,
+ uint32_t* outPixelFormatFourCC) {
+ return mMapper->getPixelFormatFourCC(bufferHandle, outPixelFormatFourCC);
+}
+
+status_t GraphicBufferMapper::getPixelFormatModifier(buffer_handle_t bufferHandle,
+ uint64_t* outPixelFormatModifier) {
+ return mMapper->getPixelFormatModifier(bufferHandle, outPixelFormatModifier);
+}
+
+status_t GraphicBufferMapper::getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage) {
+ return mMapper->getUsage(bufferHandle, outUsage);
+}
+
+status_t GraphicBufferMapper::getAllocationSize(buffer_handle_t bufferHandle,
+ uint64_t* outAllocationSize) {
+ return mMapper->getAllocationSize(bufferHandle, outAllocationSize);
+}
+
+status_t GraphicBufferMapper::getProtectedContent(buffer_handle_t bufferHandle,
+ uint64_t* outProtectedContent) {
+ return mMapper->getProtectedContent(bufferHandle, outProtectedContent);
+}
+
+status_t GraphicBufferMapper::getCompression(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outCompression) {
+ return mMapper->getCompression(bufferHandle, outCompression);
+}
+
+status_t GraphicBufferMapper::getCompression(buffer_handle_t bufferHandle,
+ ui::Compression* outCompression) {
+ return mMapper->getCompression(bufferHandle, outCompression);
+}
+
+status_t GraphicBufferMapper::getInterlaced(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) {
+ return mMapper->getInterlaced(bufferHandle, outInterlaced);
+}
+
+status_t GraphicBufferMapper::getInterlaced(buffer_handle_t bufferHandle,
+ ui::Interlaced* outInterlaced) {
+ return mMapper->getInterlaced(bufferHandle, outInterlaced);
+}
+
+status_t GraphicBufferMapper::getChromaSiting(
+ buffer_handle_t bufferHandle,
+ aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting) {
+ return mMapper->getChromaSiting(bufferHandle, outChromaSiting);
+}
+
+status_t GraphicBufferMapper::getChromaSiting(buffer_handle_t bufferHandle,
+ ui::ChromaSiting* outChromaSiting) {
+ return mMapper->getChromaSiting(bufferHandle, outChromaSiting);
+}
+
+status_t GraphicBufferMapper::getPlaneLayouts(buffer_handle_t bufferHandle,
+ std::vector<ui::PlaneLayout>* outPlaneLayouts) {
+ return mMapper->getPlaneLayouts(bufferHandle, outPlaneLayouts);
+}
+
+status_t GraphicBufferMapper::getDataspace(buffer_handle_t bufferHandle,
+ ui::Dataspace* outDataspace) {
+ return mMapper->getDataspace(bufferHandle, outDataspace);
+}
+
+status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle,
+ ui::BlendMode* outBlendMode) {
+ return mMapper->getBlendMode(bufferHandle, outBlendMode);
+}
+
+status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle,
+ std::optional<ui::Smpte2086>* outSmpte2086) {
+ return mMapper->getSmpte2086(bufferHandle, outSmpte2086);
+}
+
+status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle,
+ std::optional<ui::Cta861_3>* outCta861_3) {
+ return mMapper->getCta861_3(bufferHandle, outCta861_3);
+}
+
+status_t GraphicBufferMapper::getSmpte2094_40(
+ buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>>* outSmpte2094_40) {
+ return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40);
+}
+
+status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ uint32_t* outPixelFormatFourCC) {
+ return mMapper->getDefaultPixelFormatFourCC(width, height, format, layerCount, usage,
+ outPixelFormatFourCC);
+}
+
+status_t GraphicBufferMapper::getDefaultPixelFormatModifier(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ uint64_t* outPixelFormatModifier) {
+ return mMapper->getDefaultPixelFormatModifier(width, height, format, layerCount, usage,
+ outPixelFormatModifier);
+}
+
+status_t GraphicBufferMapper::getDefaultAllocationSize(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ uint64_t* outAllocationSize) {
+ return mMapper->getDefaultAllocationSize(width, height, format, layerCount, usage,
+ outAllocationSize);
+}
+
+status_t GraphicBufferMapper::getDefaultProtectedContent(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ uint64_t* outProtectedContent) {
+ return mMapper->getDefaultProtectedContent(width, height, format, layerCount, usage,
+ outProtectedContent);
+}
+
+status_t GraphicBufferMapper::getDefaultCompression(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outCompression) {
+ return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression);
+}
+
+status_t GraphicBufferMapper::getDefaultCompression(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ ui::Compression* outCompression) {
+ return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression);
+}
+
+status_t GraphicBufferMapper::getDefaultInterlaced(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) {
+ return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced);
+}
+
+status_t GraphicBufferMapper::getDefaultInterlaced(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage, ui::Interlaced* outInterlaced) {
+ return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced);
+}
+
+status_t GraphicBufferMapper::getDefaultChromaSiting(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage,
+ aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting) {
+ return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage,
+ outChromaSiting);
+}
+
+status_t GraphicBufferMapper::getDefaultChromaSiting(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage,
+ ui::ChromaSiting* outChromaSiting) {
+ return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage,
+ outChromaSiting);
+}
+
+status_t GraphicBufferMapper::getDefaultPlaneLayouts(
+ uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage,
+ std::vector<ui::PlaneLayout>* outPlaneLayouts) {
+ return mMapper->getDefaultPlaneLayouts(width, height, format, layerCount, usage,
+ outPlaneLayouts);
+}
+
// ---------------------------------------------------------------------------
}; // namespace android