From 8eafdd86e7b6dffdfaf21d25219d27b86835d95e Mon Sep 17 00:00:00 2001 From: koron393 Date: Mon, 30 Nov 2020 02:51:05 +0900 Subject: shinano-common: libshim_camera: Update GraphicBuffer sources to Android 11 Signed-off-by: koron393 Change-Id: I25387250e4369a2bd0a097a32a85258e0951db10 --- libshims/include/ui/GraphicBuffer.h | 9 +-- libshims/include/ui/GraphicBufferAllocator.h | 69 +++++++++++++++------- libshims/include/ui/GraphicBufferMapper.h | 88 +++++++++++++++++++++++++++- 3 files changed, 134 insertions(+), 32 deletions(-) (limited to 'libshims/include/ui') 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 #include + struct ANativeWindowBuffer; namespace android { @@ -167,7 +168,6 @@ public: uint32_t getLayerCount() const { return static_cast(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> 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 #include -#include - namespace android { class GrallocAllocator; @@ -44,6 +42,29 @@ class GraphicBufferAllocator : public Singleton 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 sAllocList; @@ -75,7 +100,7 @@ private: GraphicBufferAllocator(); ~GraphicBufferAllocator(); - alloc_device_t *mAllocDev; + GraphicBufferMapper& mMapper; std::unique_ptr 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 +#include #include +#include #include - // 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 @@ -36,7 +37,6 @@ namespace android { // --------------------------------------------------------------------------- class GrallocMapper; -class Rect; class GraphicBufferMapper : public Singleton { @@ -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* 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* outSmpte2086); + status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); + status_t getSmpte2094_40(buffer_handle_t bufferHandle, + std::optional>* 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* outPlaneLayouts); + const GrallocMapper& getGrallocMapper() const { return reinterpret_cast(*mMapper); } -- cgit v1.2.3