diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-07-28 23:21:44 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-07-28 23:21:44 +0000 |
commit | b4681a25618aeacdf3621fb2e78180f863ab6ed8 (patch) | |
tree | 5832ae50ed07fc861aa254868ec2a154f4213b69 | |
parent | dcb837b50d9df78f55c9744446d28037fe02d1af (diff) | |
parent | eedb45ab30c034b228565a07b7cc15453804fd00 (diff) | |
download | display-android13-d1-s2-release.tar.gz |
Snap for 8881713 from eedb45ab30c034b228565a07b7cc15453804fd00 to tm-d1-releaseandroid-13.0.0_r9android-13.0.0_r15android-13.0.0_r14android-13.0.0_r13android-13.0.0_r11android-13.0.0_r10android13-d1-s3-releaseandroid13-d1-s2-releaseandroid13-d1-s1-releaseandroid13-d1-release
Change-Id: I601c5686682c5cf5207760466cc0fca78beb4f0d
-rw-r--r-- | gralloc/gr_buf_mgr.cpp | 69 |
1 files changed, 44 insertions, 25 deletions
diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp index 172083e7..72b72fb7 100644 --- a/gralloc/gr_buf_mgr.cpp +++ b/gralloc/gr_buf_mgr.cpp @@ -17,6 +17,43 @@ * limitations under the License. */ +/* +* Changes from Qualcomm Innovation Center are provided under the following license: +* +* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted (subject to the limitations in the +* disclaimer below) provided that the following conditions are met: +* +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* * Redistributions in binary form must reproduce the above +* copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided +* with the distribution. +* +* * Neither the name of Qualcomm Innovation Center, Inc. nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE +* GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT +* HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER +* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN +* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + #define DEBUG 0 #include "gr_buf_mgr.h" @@ -67,7 +104,8 @@ static uint64_t getMetaDataSize(uint64_t reserved_region_size) { static_cast<uint32_t>(reserved_region_size))); } -static void unmapAndReset(private_handle_t *handle, uint64_t reserved_region_size = 0) { +static void unmapAndReset(private_handle_t *handle) { + uint64_t reserved_region_size = handle->reserved_size; if (private_handle_t::validate(handle) == 0 && handle->base_metadata) { munmap(reinterpret_cast<void *>(handle->base_metadata), static_cast<uint32_t>(getMetaDataSize(reserved_region_size))); @@ -75,7 +113,7 @@ static void unmapAndReset(private_handle_t *handle, uint64_t reserved_region_siz } } -static int validateAndMap(private_handle_t *handle, uint64_t reserved_region_size = 0) { +static int validateAndMap(private_handle_t *handle) { if (private_handle_t::validate(handle)) { ALOGE("%s: Private handle is invalid - handle:%p", __func__, handle); return -1; @@ -86,6 +124,7 @@ static int validateAndMap(private_handle_t *handle, uint64_t reserved_region_siz } if (!handle->base_metadata) { + uint64_t reserved_region_size = handle->reserved_size; uint64_t size = getMetaDataSize(reserved_region_size); void *base = mmap(NULL, static_cast<uint32_t>(size), PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd_metadata, 0); @@ -95,23 +134,6 @@ static int validateAndMap(private_handle_t *handle, uint64_t reserved_region_siz return -1; } handle->base_metadata = (uintptr_t)base; -#ifdef METADATA_V2 - // The allocator process gets the reserved region size from the BufferDescriptor. - // When importing to another process, the reserved size is unknown until mapping the metadata, - // hence the re-mapping below - auto metadata = reinterpret_cast<MetaData_t *>(handle->base_metadata); - if (reserved_region_size == 0 && metadata->reservedSize) { - size = getMetaDataSize(metadata->reservedSize); - unmapAndReset(handle); - void *new_base = mmap(NULL, static_cast<uint32_t>(size), PROT_READ | PROT_WRITE, MAP_SHARED, handle->fd_metadata, 0); - if (new_base == reinterpret_cast<void *>(MAP_FAILED)) { - ALOGE("%s: metadata mmap failed - handle:%p fd: %d err: %s", __func__, handle, - handle->fd_metadata, strerror(errno)); - return -1; - } - handle->base_metadata = (uintptr_t)new_base; - } -#endif } return 0; } @@ -743,7 +765,7 @@ Error BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) { return Error::BAD_BUFFER; } - auto meta_size = getMetaDataSize(buf->reserved_size); + auto meta_size = getMetaDataSize(hnd->reserved_size); if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset, hnd->fd, buf->ion_handle_main) != 0) { @@ -1068,6 +1090,7 @@ Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_h data.fd, e_data.fd, INT(flags), INT(alignedw), INT(alignedh), descriptor.GetWidth(), descriptor.GetHeight(), format, buffer_type, data.size, usage); + hnd->reserved_size = static_cast<unsigned int>(descriptor.GetReservedSize()); hnd->id = ++next_id_; hnd->base = 0; hnd->base_metadata = 0; @@ -1078,11 +1101,7 @@ Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_h setMetaDataAndUnmap(hnd, SET_GRAPHICS_METADATA, reinterpret_cast<void *>(&graphics_metadata)); } -#ifdef METADATA_V2 - auto error = validateAndMap(hnd, descriptor.GetReservedSize()); -#else auto error = validateAndMap(hnd); -#endif if (error != 0) { ALOGE("validateAndMap failed"); @@ -1104,7 +1123,7 @@ Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_h metadata->crop.right = hnd->width; metadata->crop.bottom = hnd->height; - unmapAndReset(hnd, descriptor.GetReservedSize()); + unmapAndReset(hnd); *handle = hnd; |