gralloc: Add allocator and mapper HALs
Implement the hidl .hal interfaces directly instead of using the default shims. This is required since new additions to .hal will no longer be added to the legacy gralloc1 C header. Change-Id: If577a14f75d7d13da0ff656c96ab451d21c910ce
This commit is contained in:
committed by
Gerrit - the friendly Code Review server
parent
9b937a7018
commit
a422f35f04
@@ -1,6 +1,7 @@
|
|||||||
---
|
---
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
BasedOnStyle: Google
|
BasedOnStyle: Google
|
||||||
|
Standard : C++11
|
||||||
AllowShortIfStatementsOnASingleLine: false
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
AllowShortFunctionsOnASingleLine: Inline
|
AllowShortFunctionsOnASingleLine: Inline
|
||||||
|
|||||||
@@ -7,19 +7,16 @@ LOCAL_MODULE := gralloc.$(TARGET_BOARD_PLATFORM)
|
|||||||
LOCAL_VENDOR_MODULE := true
|
LOCAL_VENDOR_MODULE := true
|
||||||
LOCAL_MODULE_RELATIVE_PATH := hw
|
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
LOCAL_C_INCLUDES := $(common_includes) \
|
LOCAL_C_INCLUDES := $(common_includes)
|
||||||
external/libcxx/include/
|
|
||||||
|
|
||||||
LOCAL_HEADER_LIBRARIES := display_headers
|
LOCAL_HEADER_LIBRARIES := display_headers
|
||||||
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libgrallocutils
|
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libgrallocutils \
|
||||||
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -std=c++11 -Werror
|
libgralloccore android.hardware.graphics.mapper@2.0
|
||||||
|
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -std=c++14 -Werror
|
||||||
LOCAL_CFLAGS += -isystem $(kernel_includes)
|
LOCAL_CFLAGS += -isystem $(kernel_includes)
|
||||||
LOCAL_CLANG := true
|
LOCAL_CLANG := true
|
||||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
|
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
|
||||||
LOCAL_SRC_FILES := gr_ion_alloc.cpp \
|
LOCAL_SRC_FILES := gr_device_impl.cpp
|
||||||
gr_allocator.cpp \
|
|
||||||
gr_buf_mgr.cpp \
|
|
||||||
gr_device_impl.cpp
|
|
||||||
LOCAL_COPY_HEADERS_TO := $(common_header_export_path)
|
LOCAL_COPY_HEADERS_TO := $(common_header_export_path)
|
||||||
LOCAL_COPY_HEADERS := gr_device_impl.h gralloc_priv.h gr_priv_handle.h
|
LOCAL_COPY_HEADERS := gr_device_impl.h gralloc_priv.h gr_priv_handle.h
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
@@ -31,8 +28,81 @@ LOCAL_VENDOR_MODULE := true
|
|||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
|
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
|
||||||
LOCAL_HEADER_LIBRARIES := display_headers
|
LOCAL_HEADER_LIBRARIES := display_headers
|
||||||
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl
|
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl \
|
||||||
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"grallocutils\" -Wno-sign-conversion
|
android.hardware.graphics.mapper@2.0
|
||||||
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps)
|
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
|
||||||
|
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
|
||||||
LOCAL_SRC_FILES := gr_utils.cpp gr_adreno_info.cpp
|
LOCAL_SRC_FILES := gr_utils.cpp gr_adreno_info.cpp
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
#libgralloccore
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := libgralloccore
|
||||||
|
LOCAL_VENDOR_MODULE := true
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
|
||||||
|
LOCAL_HEADER_LIBRARIES := display_headers
|
||||||
|
LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl libgrallocutils \
|
||||||
|
android.hardware.graphics.mapper@2.0
|
||||||
|
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
|
||||||
|
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
|
||||||
|
LOCAL_SRC_FILES := gr_allocator.cpp gr_buf_mgr.cpp gr_ion_alloc.cpp
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
|
|
||||||
|
qti_mapper_version := $(shell \
|
||||||
|
if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/mapper/1.0" ];\
|
||||||
|
then echo QTI_MAPPER_1_0; fi)
|
||||||
|
|
||||||
|
qti_allocator_version := $(shell \
|
||||||
|
if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/allocator/1.0" ];\
|
||||||
|
then echo QTI_ALLOCATOR_1_0; fi)
|
||||||
|
|
||||||
|
|
||||||
|
ifeq ($(qti_mapper_version), QTI_MAPPER_1_0)
|
||||||
|
#mapper
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := android.hardware.graphics.mapper@2.0-impl-qti-display
|
||||||
|
LOCAL_VENDOR_MODULE := true
|
||||||
|
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
|
||||||
|
LOCAL_HEADER_LIBRARIES := display_headers
|
||||||
|
LOCAL_SHARED_LIBRARIES := $(common_libs) \
|
||||||
|
libhidlbase \
|
||||||
|
libhidltransport \
|
||||||
|
libqdMetaData \
|
||||||
|
libgrallocutils \
|
||||||
|
libgralloccore \
|
||||||
|
libsync \
|
||||||
|
vendor.qti.hardware.display.mapper@1.0 \
|
||||||
|
android.hardware.graphics.mapper@2.0
|
||||||
|
LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
|
||||||
|
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
|
||||||
|
LOCAL_SRC_FILES := QtiMapper.cpp
|
||||||
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
endif # QTI_MAPPER_1_0
|
||||||
|
|
||||||
|
ifeq ($(qti_allocator_version), QTI_ALLOCATOR_1_0)
|
||||||
|
#allocator service
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_MODULE := vendor.qti.hardware.display.allocator@1.0-service
|
||||||
|
LOCAL_VENDOR_MODULE := true
|
||||||
|
LOCAL_MODULE_RELATIVE_PATH := hw
|
||||||
|
LOCAL_MODULE_TAGS := optional
|
||||||
|
LOCAL_HEADER_LIBRARIES := display_headers
|
||||||
|
LOCAL_SHARED_LIBRARIES := $(common_libs) \
|
||||||
|
libhidlbase \
|
||||||
|
libhidltransport\
|
||||||
|
libqdMetaData \
|
||||||
|
libgrallocutils \
|
||||||
|
libgralloccore \
|
||||||
|
vendor.qti.hardware.display.allocator@1.0 \
|
||||||
|
android.hardware.graphics.allocator@2.0
|
||||||
|
LOCAL_CFLAGS := -DLOG_TAG=\"qdgralloc\" $(common_flags)
|
||||||
|
LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
|
||||||
|
LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes)
|
||||||
|
LOCAL_SRC_FILES := QtiAllocator.cpp service.cpp
|
||||||
|
LOCAL_INIT_RC := vendor.qti.hardware.display.allocator@1.0-service.rc
|
||||||
|
include $(BUILD_EXECUTABLE)
|
||||||
|
endif # QTI_ALLOCATOR_1_0
|
||||||
|
|||||||
113
gralloc/QtiAllocator.cpp
Normal file
113
gralloc/QtiAllocator.cpp
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted 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 The Linux Foundation. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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 "QtiAllocator.h"
|
||||||
|
|
||||||
|
#include <log/log.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "gr_utils.h"
|
||||||
|
|
||||||
|
namespace vendor {
|
||||||
|
namespace qti {
|
||||||
|
namespace hardware {
|
||||||
|
namespace display {
|
||||||
|
namespace allocator {
|
||||||
|
namespace V1_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
using android::hardware::hidl_handle;
|
||||||
|
using gralloc::BufferDescriptor;
|
||||||
|
|
||||||
|
QtiAllocator::QtiAllocator() {
|
||||||
|
buf_mgr_ = BufferManager::GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow.
|
||||||
|
Return<void> QtiAllocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
|
||||||
|
std::ostringstream os;
|
||||||
|
buf_mgr_->Dump(&os);
|
||||||
|
hidl_string reply;
|
||||||
|
reply.setToExternal(os.str().c_str(), os.str().length());
|
||||||
|
hidl_cb(reply);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiAllocator::allocate(const hidl_vec<uint32_t> &descriptor, uint32_t count,
|
||||||
|
allocate_cb hidl_cb) {
|
||||||
|
ALOGD_IF(DEBUG, "Allocating buffers count: %d", count);
|
||||||
|
gralloc::BufferDescriptor desc;
|
||||||
|
|
||||||
|
auto err = desc.Decode(descriptor);
|
||||||
|
if (err != Error::NONE) {
|
||||||
|
hidl_cb(err, 0, hidl_vec<hidl_handle>());
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<hidl_handle> buffers;
|
||||||
|
buffers.reserve(count);
|
||||||
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
|
buffer_handle_t buffer;
|
||||||
|
ALOGD_IF(DEBUG, "buffer: %p", &buffer);
|
||||||
|
err = buf_mgr_->AllocateBuffer(desc, &buffer);
|
||||||
|
if (err != Error::NONE) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buffers.emplace_back(hidl_handle(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t stride = 0;
|
||||||
|
hidl_vec<hidl_handle> hidl_buffers;
|
||||||
|
if (err == Error::NONE && buffers.size() > 0) {
|
||||||
|
stride = static_cast<uint32_t>(PRIV_HANDLE_CONST(buffers[0].getNativeHandle())->width);
|
||||||
|
hidl_buffers.setToExternal(buffers.data(), buffers.size());
|
||||||
|
}
|
||||||
|
hidl_cb(err, stride, hidl_buffers);
|
||||||
|
|
||||||
|
for (const auto &b : buffers) {
|
||||||
|
buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(b.getNativeHandle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||||
|
|
||||||
|
IQtiAllocator *HIDL_FETCH_IQtiAllocator(const char * /* name */) {
|
||||||
|
return new QtiAllocator();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V1_0
|
||||||
|
} // namespace allocator
|
||||||
|
} // namespace display
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace qti
|
||||||
|
} // namespace vendor
|
||||||
84
gralloc/QtiAllocator.h
Normal file
84
gralloc/QtiAllocator.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted 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 The Linux Foundation. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __QTIALLOCATOR_H__
|
||||||
|
#define __QTIALLOCATOR_H__
|
||||||
|
|
||||||
|
#include <hidl/MQDescriptor.h>
|
||||||
|
#include <hidl/Status.h>
|
||||||
|
#include <vendor/qti/hardware/display/allocator/1.0/IQtiAllocator.h>
|
||||||
|
|
||||||
|
#include "gr_buf_mgr.h"
|
||||||
|
|
||||||
|
namespace vendor {
|
||||||
|
namespace qti {
|
||||||
|
namespace hardware {
|
||||||
|
namespace display {
|
||||||
|
namespace allocator {
|
||||||
|
namespace V1_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
using ::android::hardware::Return;
|
||||||
|
using ::android::hardware::Void;
|
||||||
|
using ::android::hardware::graphics::allocator::V2_0::IAllocator;
|
||||||
|
using ::android::hardware::graphics::mapper::V2_0::Error;
|
||||||
|
using ::android::hardware::hidl_array;
|
||||||
|
using ::android::hardware::hidl_memory;
|
||||||
|
using ::android::hardware::hidl_string;
|
||||||
|
using ::android::hardware::hidl_vec;
|
||||||
|
using ::android::hidl::base::V1_0::DebugInfo;
|
||||||
|
using ::android::hidl::base::V1_0::IBase;
|
||||||
|
using ::android::sp;
|
||||||
|
using ::vendor::qti::hardware::display::allocator::V1_0::IQtiAllocator;
|
||||||
|
using gralloc::BufferManager;
|
||||||
|
|
||||||
|
class QtiAllocator : public IQtiAllocator {
|
||||||
|
public:
|
||||||
|
QtiAllocator();
|
||||||
|
// Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow.
|
||||||
|
Return<void> dumpDebugInfo(dumpDebugInfo_cb _hidl_cb) override;
|
||||||
|
Return<void> allocate(const hidl_vec<uint32_t> &descriptor, uint32_t count,
|
||||||
|
allocate_cb _hidl_cb) override;
|
||||||
|
|
||||||
|
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||||
|
private:
|
||||||
|
BufferManager *buf_mgr_ = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" IQtiAllocator *HIDL_FETCH_IQtiAllocator(const char *name);
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V1_0
|
||||||
|
} // namespace allocator
|
||||||
|
} // namespace display
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace qti
|
||||||
|
} // namespace vendor
|
||||||
|
|
||||||
|
#endif // __QTIALLOCATOR_H__
|
||||||
347
gralloc/QtiMapper.cpp
Normal file
347
gralloc/QtiMapper.cpp
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted 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 The Linux Foundation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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 ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
|
||||||
|
#define DEBUG 0
|
||||||
|
#include "QtiMapper.h"
|
||||||
|
#include <cutils/trace.h>
|
||||||
|
#include <qdMetaData.h>
|
||||||
|
#include <sync/sync.h>
|
||||||
|
#include "gr_utils.h"
|
||||||
|
|
||||||
|
namespace vendor {
|
||||||
|
namespace qti {
|
||||||
|
namespace hardware {
|
||||||
|
namespace display {
|
||||||
|
namespace mapper {
|
||||||
|
namespace V1_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
using gralloc::BufferInfo;
|
||||||
|
|
||||||
|
QtiMapper::QtiMapper() {
|
||||||
|
buf_mgr_ = BufferManager::GetInstance();
|
||||||
|
ALOGD_IF(DEBUG, "Created QtiMapper instance");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtiMapper::ValidDescriptor(const IMapper::BufferDescriptorInfo &bd) {
|
||||||
|
if (bd.width == 0 || bd.height == 0 || (static_cast<int32_t>(bd.format) <= 0) ||
|
||||||
|
bd.layerCount != 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
|
||||||
|
Return<void> QtiMapper::createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info,
|
||||||
|
createDescriptor_cb hidl_cb) {
|
||||||
|
ALOGD_IF(DEBUG,
|
||||||
|
"BufferDescriptorInfo: wxh: %dx%d usage: 0x%" PRIu64 " format: %d layer_count: %d",
|
||||||
|
descriptor_info.width, descriptor_info.height, descriptor_info.usage,
|
||||||
|
static_cast<uint32_t>(descriptor_info.format), descriptor_info.layerCount);
|
||||||
|
|
||||||
|
if (ValidDescriptor(descriptor_info)) {
|
||||||
|
auto vec = gralloc::BufferDescriptor::Encode(descriptor_info);
|
||||||
|
hidl_cb(Error::NONE, vec);
|
||||||
|
} else {
|
||||||
|
hidl_cb(Error::BAD_VALUE, hidl_vec<uint32_t>());
|
||||||
|
}
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) {
|
||||||
|
if (!raw_handle.getNativeHandle()) {
|
||||||
|
ALOGE("%s: Unable to import handle", __FUNCTION__);
|
||||||
|
hidl_cb(Error::BAD_BUFFER, nullptr);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
native_handle_t *buffer_handle = native_handle_clone(raw_handle.getNativeHandle());
|
||||||
|
if (!buffer_handle) {
|
||||||
|
ALOGE("%s: Unable to clone handle", __FUNCTION__);
|
||||||
|
hidl_cb(Error::NO_RESOURCES, nullptr);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto error = buf_mgr_->RetainBuffer(PRIV_HANDLE_CONST(buffer_handle));
|
||||||
|
if (error != Error::NONE) {
|
||||||
|
ALOGE("%s: Unable to retain handle: %p", __FUNCTION__, buffer_handle);
|
||||||
|
native_handle_close(buffer_handle);
|
||||||
|
native_handle_delete(buffer_handle);
|
||||||
|
|
||||||
|
hidl_cb(error, nullptr);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
ALOGD_IF(DEBUG, "Imported handle: %p id: %" PRIu64, buffer_handle,
|
||||||
|
PRIV_HANDLE_CONST(buffer_handle)->id);
|
||||||
|
hidl_cb(Error::NONE, buffer_handle);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Error> QtiMapper::freeBuffer(void *buffer) {
|
||||||
|
if (!buffer) {
|
||||||
|
return Error::BAD_BUFFER;
|
||||||
|
}
|
||||||
|
return buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtiMapper::GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd) {
|
||||||
|
auto handle = fence_handle.getNativeHandle();
|
||||||
|
if (handle && handle->numFds > 1) {
|
||||||
|
ALOGE("invalid fence handle with %d fds", handle->numFds);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*outFenceFd = (handle && handle->numFds == 1) ? handle->data[0] : -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtiMapper::WaitFenceFd(int fence_fd) {
|
||||||
|
if (fence_fd < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int timeout = 3000;
|
||||||
|
ATRACE_BEGIN("fence wait");
|
||||||
|
const int error = sync_wait(fence_fd, timeout);
|
||||||
|
ATRACE_END();
|
||||||
|
if (error < 0) {
|
||||||
|
ALOGE("QtiMapper: lock fence %d didn't signal in %u ms - error: %s", fence_fd, timeout,
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Error QtiMapper::LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence) {
|
||||||
|
if (!buffer) {
|
||||||
|
return Error::BAD_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fence_fd;
|
||||||
|
if (!GetFenceFd(acquire_fence, &fence_fd)) {
|
||||||
|
return Error::BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fence_fd > 0) {
|
||||||
|
WaitFenceFd(fence_fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
|
|
||||||
|
return buf_mgr_->LockBuffer(hnd, usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::lock(void *buffer, uint64_t cpu_usage,
|
||||||
|
const IMapper::Rect & /*access_region*/,
|
||||||
|
const hidl_handle &acquire_fence, lock_cb hidl_cb) {
|
||||||
|
auto err = LockBuffer(buffer, cpu_usage, acquire_fence);
|
||||||
|
if (err != Error::NONE) {
|
||||||
|
hidl_cb(err, nullptr);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
|
auto *out_data = reinterpret_cast<void *>(hnd->base);
|
||||||
|
hidl_cb(Error::NONE, out_data);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::lockYCbCr(void *buffer, uint64_t cpu_usage,
|
||||||
|
const IMapper::Rect & /*access_region*/,
|
||||||
|
const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) {
|
||||||
|
YCbCrLayout layout = {};
|
||||||
|
auto err = LockBuffer(buffer, cpu_usage, acquire_fence);
|
||||||
|
if (err != Error::NONE) {
|
||||||
|
hidl_cb(err, layout);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
|
android_ycbcr yuv_plane_info[2];
|
||||||
|
if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) != 0) {
|
||||||
|
hidl_cb(Error::BAD_VALUE, layout);
|
||||||
|
}
|
||||||
|
layout.y = yuv_plane_info[0].y;
|
||||||
|
layout.cr = yuv_plane_info[0].cr;
|
||||||
|
layout.cb = yuv_plane_info[0].cb;
|
||||||
|
layout.yStride = static_cast<uint32_t>(yuv_plane_info[0].ystride);
|
||||||
|
layout.cStride = static_cast<uint32_t>(yuv_plane_info[0].cstride);
|
||||||
|
layout.chromaStep = static_cast<uint32_t>(yuv_plane_info[0].chroma_step);
|
||||||
|
hidl_cb(Error::NONE, layout);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::unlock(void *buffer, unlock_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
if (buffer != nullptr) {
|
||||||
|
err = buf_mgr_->UnlockBuffer(PRIV_HANDLE_CONST(buffer));
|
||||||
|
}
|
||||||
|
// We don't have a release fence
|
||||||
|
hidl_cb(err, hidl_handle(nullptr));
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
int *map_secure_buffer = 0;
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
|
||||||
|
*map_secure_buffer = 0;
|
||||||
|
} else {
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hidl_cb(err, *map_secure_buffer != 0);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getInterlacedFlag(void *buffer, getInterlacedFlag_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
int *interlaced_flag = nullptr;
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, interlaced_flag) != 0) {
|
||||||
|
*interlaced_flag = 0;
|
||||||
|
} else {
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hidl_cb(err, *interlaced_flag != 0);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getCustomDimensions(void *buffer, getCustomDimensions_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
int stride = 0;
|
||||||
|
int height = 0;
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
stride = hnd->width;
|
||||||
|
height = hnd->height;
|
||||||
|
gralloc::GetCustomDimensions(hnd, &stride, &height);
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
hidl_cb(err, stride, height);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getRgbDataAddress(void *buffer, getRgbDataAddress_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
void *rgb_data = nullptr;
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
if (gralloc::GetRgbDataAddress(hnd, &rgb_data) == 0) {
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hidl_cb(err, rgb_data);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::calculateBufferAttributes(int32_t width, int32_t height, int32_t format,
|
||||||
|
uint64_t usage,
|
||||||
|
calculateBufferAttributes_cb hidl_cb) {
|
||||||
|
unsigned int alignedw, alignedh;
|
||||||
|
BufferInfo info(width, height, format, usage);
|
||||||
|
gralloc::GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
||||||
|
bool ubwc_enabled = gralloc::IsUBwcEnabled(format, usage);
|
||||||
|
hidl_cb(Error::NONE, alignedw, alignedh, ubwc_enabled);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getColorSpace(void *buffer, getColorSpace_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
int color_space = 0;
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
gralloc::GetColorSpaceFromMetadata(hnd, &color_space);
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
hidl_cb(err, color_space);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<void> QtiMapper::getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb hidl_cb) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
hidl_vec<YCbCrLayout> layout;
|
||||||
|
layout.resize(2);
|
||||||
|
android_ycbcr yuv_plane_info[2];
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) == 0) {
|
||||||
|
err = Error::NONE;
|
||||||
|
for (int i=0; i < 2; i++) {
|
||||||
|
layout[i].y = yuv_plane_info[i].y;
|
||||||
|
layout[i].cr = yuv_plane_info[i].cr;
|
||||||
|
layout[i].cb = yuv_plane_info[i].cb;
|
||||||
|
layout[i].yStride = static_cast<uint32_t>(yuv_plane_info[i].ystride);
|
||||||
|
layout[i].cStride = static_cast<uint32_t>(yuv_plane_info[i].cstride);
|
||||||
|
layout[i].chromaStep = static_cast<uint32_t>(yuv_plane_info[i].chroma_step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hidl_cb(err, layout);
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Return<Error> QtiMapper::setSingleBufferMode(void *buffer, bool enable) {
|
||||||
|
auto err = Error::BAD_BUFFER;
|
||||||
|
auto hnd = static_cast<private_handle_t *>(buffer);
|
||||||
|
if (buffer != nullptr && private_handle_t::validate(hnd) != 0) {
|
||||||
|
if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, &enable) != 0) {
|
||||||
|
err = Error::UNSUPPORTED;
|
||||||
|
} else {
|
||||||
|
err = Error::NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Methods from ::android::hidl::base::V1_0::IBase follow.
|
||||||
|
|
||||||
|
// When we are in passthrough mode, this method is used
|
||||||
|
// by hidl to obtain the SP HAL object
|
||||||
|
IMapper *HIDL_FETCH_IMapper(const char * /* name */) {
|
||||||
|
ALOGD_IF(DEBUG, "Fetching IMapper from QtiMapper");
|
||||||
|
auto mapper = new QtiMapper();
|
||||||
|
return static_cast<IMapper *>(mapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
IQtiMapper *HIDL_FETCH_IQtiMapper(const char * /* name */) {
|
||||||
|
ALOGD_IF(DEBUG, "Fetching QtiMapper");
|
||||||
|
return new QtiMapper();
|
||||||
|
}
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V1_0
|
||||||
|
} // namespace mapper
|
||||||
|
} // namespace display
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace qti
|
||||||
|
} // namespace vendor
|
||||||
105
gralloc/QtiMapper.h
Normal file
105
gralloc/QtiMapper.h
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted 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 The Linux Foundation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __QTIMAPPER_H__
|
||||||
|
#define __QTIMAPPER_H__
|
||||||
|
|
||||||
|
#include <hidl/MQDescriptor.h>
|
||||||
|
#include <hidl/Status.h>
|
||||||
|
#include <vendor/qti/hardware/display/mapper/1.0/IQtiMapper.h>
|
||||||
|
|
||||||
|
#include "gr_buf_mgr.h"
|
||||||
|
namespace vendor {
|
||||||
|
namespace qti {
|
||||||
|
namespace hardware {
|
||||||
|
namespace display {
|
||||||
|
namespace mapper {
|
||||||
|
namespace V1_0 {
|
||||||
|
namespace implementation {
|
||||||
|
|
||||||
|
using ::android::hardware::Return;
|
||||||
|
using ::android::hardware::Void;
|
||||||
|
using ::android::hardware::graphics::mapper::V2_0::Error;
|
||||||
|
using ::android::hardware::graphics::mapper::V2_0::IMapper;
|
||||||
|
using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout;
|
||||||
|
using ::android::hardware::hidl_array;
|
||||||
|
using ::android::hardware::hidl_handle;
|
||||||
|
using ::android::hardware::hidl_memory;
|
||||||
|
using ::android::hardware::hidl_string;
|
||||||
|
using ::android::hardware::hidl_vec;
|
||||||
|
using ::android::hidl::base::V1_0::DebugInfo;
|
||||||
|
using ::android::hidl::base::V1_0::IBase;
|
||||||
|
using ::android::sp;
|
||||||
|
using ::vendor::qti::hardware::display::mapper::V1_0::IQtiMapper;
|
||||||
|
using gralloc::BufferManager;
|
||||||
|
|
||||||
|
class QtiMapper : public IQtiMapper {
|
||||||
|
public:
|
||||||
|
QtiMapper();
|
||||||
|
// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow.
|
||||||
|
Return<void> createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info,
|
||||||
|
createDescriptor_cb hidl_cb) override;
|
||||||
|
Return<void> importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override;
|
||||||
|
Return<Error> freeBuffer(void *buffer) override;
|
||||||
|
Return<void> lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
|
||||||
|
const hidl_handle &acquire_fence, lock_cb hidl_cb) override;
|
||||||
|
Return<void> lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region,
|
||||||
|
const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override;
|
||||||
|
Return<void> unlock(void *buffer, unlock_cb hidl_cb) override;
|
||||||
|
Return<void> getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb _hidl_cb) override;
|
||||||
|
Return<void> getInterlacedFlag(void *buffer, getInterlacedFlag_cb _hidl_cb) override;
|
||||||
|
Return<void> getCustomDimensions(void *buffer, getCustomDimensions_cb _hidl_cb) override;
|
||||||
|
Return<void> getRgbDataAddress(void *buffer, getRgbDataAddress_cb _hidl_cb) override;
|
||||||
|
Return<void> calculateBufferAttributes(int32_t width, int32_t height, int32_t format,
|
||||||
|
uint64_t usage,
|
||||||
|
calculateBufferAttributes_cb _hidl_cb) override;
|
||||||
|
Return<void> getColorSpace(void *buffer, getColorSpace_cb _hidl_cb) override;
|
||||||
|
Return<void> getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb _hidl_cb) override;
|
||||||
|
Return<Error> setSingleBufferMode(void *buffer, bool enable) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BufferManager *buf_mgr_ = nullptr;
|
||||||
|
bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd);
|
||||||
|
bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd);
|
||||||
|
void WaitFenceFd(int fence_fd);
|
||||||
|
Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" IMapper *HIDL_FETCH_IMapper(const char *name);
|
||||||
|
extern "C" IQtiMapper *HIDL_FETCH_IQtiMapper(const char *name);
|
||||||
|
|
||||||
|
} // namespace implementation
|
||||||
|
} // namespace V1_0
|
||||||
|
} // namespace mapper
|
||||||
|
} // namespace display
|
||||||
|
} // namespace hardware
|
||||||
|
} // namespace qti
|
||||||
|
} // namespace vendor
|
||||||
|
|
||||||
|
#endif // __QTIMAPPER_H__
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -32,14 +32,14 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "gralloc_priv.h"
|
|
||||||
#include "gr_adreno_info.h"
|
#include "gr_adreno_info.h"
|
||||||
#include "gr_utils.h"
|
#include "gr_utils.h"
|
||||||
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
using std::lock_guard;
|
using std::lock_guard;
|
||||||
using std::mutex;
|
using std::mutex;
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
AdrenoMemInfo *AdrenoMemInfo::s_instance = nullptr;
|
AdrenoMemInfo *AdrenoMemInfo::s_instance = nullptr;
|
||||||
|
|
||||||
@@ -130,9 +130,9 @@ void AdrenoMemInfo::AlignUnCompressedRGB(int width, int height, int format, int
|
|||||||
// num_samples is 1 always. We may have to add uitility function to
|
// num_samples is 1 always. We may have to add uitility function to
|
||||||
// find out these if there is a need to call this API for YUV formats.
|
// find out these if there is a need to call this API for YUV formats.
|
||||||
LINK_adreno_compute_fmt_aligned_width_and_height(
|
LINK_adreno_compute_fmt_aligned_width_and_height(
|
||||||
width, height, 0/*plane_id*/, GetGpuPixelFormat(format), 1/*num_samples*/,
|
width, height, 0 /*plane_id*/, GetGpuPixelFormat(format), 1 /*num_samples*/, tile_enabled,
|
||||||
tile_enabled, raster_mode, padding_threshold,
|
raster_mode, padding_threshold, reinterpret_cast<int *>(aligned_w),
|
||||||
reinterpret_cast<int *>(aligned_w), reinterpret_cast<int *>(aligned_h));
|
reinterpret_cast<int *>(aligned_h));
|
||||||
} else if (LINK_adreno_compute_aligned_width_and_height) {
|
} else if (LINK_adreno_compute_aligned_width_and_height) {
|
||||||
LINK_adreno_compute_aligned_width_and_height(
|
LINK_adreno_compute_aligned_width_and_height(
|
||||||
width, height, bpp, tile_enabled, raster_mode, padding_threshold,
|
width, height, bpp, tile_enabled, raster_mode, padding_threshold,
|
||||||
@@ -223,4 +223,4 @@ ADRENOPIXELFORMAT AdrenoMemInfo::GetGpuPixelFormat(int hal_format) {
|
|||||||
return ADRENO_PIXELFORMAT_UNKNOWN;
|
return ADRENO_PIXELFORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
#include <media/msm_media_info.h>
|
#include <media/msm_media_info.h>
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
// Adreno Pixel Formats
|
// Adreno Pixel Formats
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -149,6 +149,6 @@ class AdrenoMemInfo {
|
|||||||
static AdrenoMemInfo *s_instance;
|
static AdrenoMemInfo *s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_ADRENO_INFO_H__
|
#endif // __GR_ADRENO_INFO_H__
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -31,8 +31,8 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gr_utils.h"
|
|
||||||
#include "gr_allocator.h"
|
#include "gr_allocator.h"
|
||||||
|
#include "gr_utils.h"
|
||||||
#include "gralloc_priv.h"
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
#include "qd_utils.h"
|
#include "qd_utils.h"
|
||||||
@@ -65,18 +65,17 @@
|
|||||||
#define ION_SC_PREVIEW_FLAGS ION_SECURE
|
#define ION_SC_PREVIEW_FLAGS ION_SECURE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using std::vector;
|
|
||||||
using std::shared_ptr;
|
using std::shared_ptr;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) {
|
static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) {
|
||||||
return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(),
|
return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(),
|
||||||
descriptor.GetProducerUsage(), descriptor.GetConsumerUsage());
|
descriptor.GetUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
Allocator::Allocator() : ion_allocator_(NULL) {
|
Allocator::Allocator() : ion_allocator_(nullptr) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool Allocator::Init() {
|
bool Allocator::Init() {
|
||||||
ion_allocator_ = new IonAlloc();
|
ion_allocator_ = new IonAlloc();
|
||||||
@@ -93,14 +92,12 @@ Allocator::~Allocator() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Allocator::AllocateMem(AllocData *alloc_data, gralloc1_producer_usage_t prod_usage,
|
int Allocator::AllocateMem(AllocData *alloc_data, uint64_t usage) {
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
|
||||||
int ret;
|
int ret;
|
||||||
alloc_data->uncached = UseUncached(prod_usage, cons_usage);
|
alloc_data->uncached = UseUncached(usage);
|
||||||
|
|
||||||
// After this point we should have the right heap set, there is no fallback
|
// After this point we should have the right heap set, there is no fallback
|
||||||
GetIonHeapInfo(prod_usage, cons_usage, &alloc_data->heap_id, &alloc_data->alloc_type,
|
GetIonHeapInfo(usage, &alloc_data->heap_id, &alloc_data->alloc_type, &alloc_data->flags);
|
||||||
&alloc_data->flags);
|
|
||||||
|
|
||||||
ret = ion_allocator_->AllocBuffer(alloc_data);
|
ret = ion_allocator_->AllocBuffer(alloc_data);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
@@ -128,8 +125,7 @@ int Allocator::ImportBuffer(int fd) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd,
|
int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle) {
|
||||||
int handle) {
|
|
||||||
if (ion_allocator_) {
|
if (ion_allocator_) {
|
||||||
return ion_allocator_->FreeBuffer(base, size, offset, fd, handle);
|
return ion_allocator_->FreeBuffer(base, size, offset, fd, handle);
|
||||||
}
|
}
|
||||||
@@ -158,10 +154,8 @@ bool Allocator::CheckForBufferSharing(uint32_t num_descriptors,
|
|||||||
*max_index = -1;
|
*max_index = -1;
|
||||||
for (uint32_t i = 0; i < num_descriptors; i++) {
|
for (uint32_t i = 0; i < num_descriptors; i++) {
|
||||||
// Check Cached vs non-cached and all the ION flags
|
// Check Cached vs non-cached and all the ION flags
|
||||||
cur_uncached = UseUncached(descriptors[i]->GetProducerUsage(),
|
cur_uncached = UseUncached(descriptors[i]->GetUsage());
|
||||||
descriptors[i]->GetConsumerUsage());
|
GetIonHeapInfo(descriptors[i]->GetUsage(), &cur_heap_id, &cur_alloc_type, &cur_ion_flags);
|
||||||
GetIonHeapInfo(descriptors[i]->GetProducerUsage(), descriptors[i]->GetConsumerUsage(),
|
|
||||||
&cur_heap_id, &cur_alloc_type, &cur_ion_flags);
|
|
||||||
|
|
||||||
if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type ||
|
if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type ||
|
||||||
cur_ion_flags != prev_ion_flags)) {
|
cur_ion_flags != prev_ion_flags)) {
|
||||||
@@ -185,43 +179,42 @@ bool Allocator::CheckForBufferSharing(uint32_t num_descriptors,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Allocator::GetImplDefinedFormat(gralloc1_producer_usage_t prod_usage,
|
int Allocator::GetImplDefinedFormat(uint64_t usage, int format) {
|
||||||
gralloc1_consumer_usage_t cons_usage, int format) {
|
|
||||||
int gr_format = format;
|
int gr_format = format;
|
||||||
|
|
||||||
// If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
|
// If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on
|
||||||
// the usage bits, gralloc assigns a format.
|
// the usage bits, gralloc assigns a format.
|
||||||
if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
|
if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED ||
|
||||||
format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC) {
|
if (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) {
|
||||||
// Use of 10BIT_TP and 10BIT bits is supposed to be mutually exclusive.
|
// Use of 10BIT_TP and 10BIT bits is supposed to be mutually exclusive.
|
||||||
// Each bit maps to only one format. Here we will check one of the bits
|
// Each bit maps to only one format. Here we will check one of the bits
|
||||||
// and ignore the other.
|
// and ignore the other.
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT_TP) {
|
if (usage & GRALLOC_USAGE_PRIVATE_10BIT_TP) {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC;
|
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC;
|
||||||
} else if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT) {
|
} else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC;
|
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC;
|
||||||
} else {
|
} else {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
|
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC;
|
||||||
}
|
}
|
||||||
} else if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT) {
|
} else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS;
|
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS;
|
||||||
} else if (cons_usage & GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER) {
|
} else if (usage & BufferUsage::VIDEO_ENCODER) {
|
||||||
gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12
|
gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12
|
||||||
} else if (cons_usage & GRALLOC1_CONSUMER_USAGE_CAMERA) {
|
} else if (usage & BufferUsage::CAMERA_INPUT) {
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
|
if (usage & BufferUsage::CAMERA_OUTPUT) {
|
||||||
// Assumed ZSL if both producer and consumer camera flags set
|
// Assumed ZSL if both producer and consumer camera flags set
|
||||||
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
||||||
} else {
|
} else {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21
|
gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21
|
||||||
}
|
}
|
||||||
} else if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
|
} else if (usage & BufferUsage::CAMERA_OUTPUT) {
|
||||||
if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
||||||
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21
|
||||||
} else {
|
} else {
|
||||||
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview
|
gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview
|
||||||
}
|
}
|
||||||
} else if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
|
} else if (usage & BufferUsage::COMPOSER_OVERLAY) {
|
||||||
// XXX: If we still haven't set a format, default to RGBA8888
|
// XXX: If we still haven't set a format, default to RGBA8888
|
||||||
gr_format = HAL_PIXEL_FORMAT_RGBA_8888;
|
gr_format = HAL_PIXEL_FORMAT_RGBA_8888;
|
||||||
} else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
} else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
|
||||||
@@ -237,50 +230,44 @@ int Allocator::GetImplDefinedFormat(gralloc1_producer_usage_t prod_usage,
|
|||||||
/* The default policy is to return cached buffers unless the client explicity
|
/* The default policy is to return cached buffers unless the client explicity
|
||||||
* sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely
|
* sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely
|
||||||
* read or written in software. */
|
* read or written in software. */
|
||||||
bool Allocator::UseUncached(gralloc1_producer_usage_t prod_usage,
|
bool Allocator::UseUncached(uint64_t usage) {
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) {
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED) ||
|
|
||||||
(prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPU read rarely
|
// CPU read rarely
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ) &&
|
if ((usage & BufferUsage::CPU_READ_RARELY) && !(usage & BufferUsage::CPU_READ_OFTEN)) {
|
||||||
!(prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPU write rarely
|
// CPU write rarely
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE) &&
|
if ((usage & BufferUsage::CPU_WRITE_RARELY) && !(usage & BufferUsage::CPU_WRITE_OFTEN)) {
|
||||||
!(prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA) ||
|
if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) {
|
||||||
(cons_usage & GRALLOC1_CONSUMER_USAGE_GPU_DATA_BUFFER)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Allocator::GetIonHeapInfo(gralloc1_producer_usage_t prod_usage,
|
void Allocator::GetIonHeapInfo(uint64_t usage, unsigned int *ion_heap_id, unsigned int *alloc_type,
|
||||||
gralloc1_consumer_usage_t cons_usage, unsigned int *ion_heap_id,
|
unsigned int *ion_flags) {
|
||||||
unsigned int *alloc_type, unsigned int *ion_flags) {
|
|
||||||
unsigned int heap_id = 0;
|
unsigned int heap_id = 0;
|
||||||
unsigned int type = 0;
|
unsigned int type = 0;
|
||||||
uint32_t flags = 0;
|
uint32_t flags = 0;
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED) {
|
if (usage & GRALLOC_USAGE_PROTECTED) {
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
|
if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
|
||||||
heap_id = ION_HEAP(SD_HEAP_ID);
|
heap_id = ION_HEAP(SD_HEAP_ID);
|
||||||
/*
|
/*
|
||||||
* There is currently no flag in ION for Secure Display
|
* There is currently no flag in ION for Secure Display
|
||||||
* VM. Please add it to the define once available.
|
* VM. Please add it to the define once available.
|
||||||
*/
|
*/
|
||||||
flags |= UINT(ION_SD_FLAGS);
|
flags |= UINT(ION_SD_FLAGS);
|
||||||
} else if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
|
} else if (usage & BufferUsage::CAMERA_OUTPUT) {
|
||||||
heap_id = ION_HEAP(SD_HEAP_ID);
|
heap_id = ION_HEAP(SD_HEAP_ID);
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
|
if (usage & BufferUsage::COMPOSER_OVERLAY) {
|
||||||
flags |= UINT(ION_SC_PREVIEW_FLAGS);
|
flags |= UINT(ION_SC_PREVIEW_FLAGS);
|
||||||
} else {
|
} else {
|
||||||
flags |= UINT(ION_SC_FLAGS);
|
flags |= UINT(ION_SC_FLAGS);
|
||||||
@@ -289,15 +276,9 @@ void Allocator::GetIonHeapInfo(gralloc1_producer_usage_t prod_usage,
|
|||||||
heap_id = ION_HEAP(CP_HEAP_ID);
|
heap_id = ION_HEAP(CP_HEAP_ID);
|
||||||
flags |= UINT(ION_CP_FLAGS);
|
flags |= UINT(ION_CP_FLAGS);
|
||||||
}
|
}
|
||||||
} else if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP) {
|
|
||||||
// MM Heap is exclusively a secure heap.
|
|
||||||
// If it is used for non secure cases, fallback to IOMMU heap
|
|
||||||
ALOGW("MM_HEAP cannot be used as an insecure heap. Using system heap instead!!");
|
|
||||||
heap_id |= ION_HEAP(ION_SYSTEM_HEAP_ID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP ||
|
if (usage & BufferUsage::SENSOR_DIRECT_DATA) {
|
||||||
prod_usage & GRALLOC1_PRODUCER_USAGE_SENSOR_DIRECT_DATA) {
|
|
||||||
heap_id |= ION_HEAP(ION_ADSP_HEAP_ID);
|
heap_id |= ION_HEAP(ION_ADSP_HEAP_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,4 +297,4 @@ void Allocator::GetIonHeapInfo(gralloc1_producer_usage_t prod_usage,
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -38,11 +38,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "gralloc_priv.h"
|
|
||||||
#include "gr_buf_descriptor.h"
|
#include "gr_buf_descriptor.h"
|
||||||
#include "gr_ion_alloc.h"
|
#include "gr_ion_alloc.h"
|
||||||
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
class Allocator {
|
class Allocator {
|
||||||
public:
|
public:
|
||||||
@@ -53,23 +53,21 @@ class Allocator {
|
|||||||
int ImportBuffer(int fd);
|
int ImportBuffer(int fd);
|
||||||
int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle);
|
int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle);
|
||||||
int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op);
|
int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op);
|
||||||
int AllocateMem(AllocData *data, gralloc1_producer_usage_t prod_usage,
|
int AllocateMem(AllocData *data, uint64_t usage);
|
||||||
gralloc1_consumer_usage_t cons_usage);
|
|
||||||
// @return : index of the descriptor with maximum buffer size req
|
// @return : index of the descriptor with maximum buffer size req
|
||||||
bool CheckForBufferSharing(uint32_t num_descriptors,
|
bool CheckForBufferSharing(uint32_t num_descriptors,
|
||||||
const std::vector<std::shared_ptr<BufferDescriptor>> &descriptors,
|
const std::vector<std::shared_ptr<BufferDescriptor>> &descriptors,
|
||||||
ssize_t *max_index);
|
ssize_t *max_index);
|
||||||
int GetImplDefinedFormat(gralloc1_producer_usage_t prod_usage,
|
int GetImplDefinedFormat(uint64_t usage, int format);
|
||||||
gralloc1_consumer_usage_t cons_usage, int format);
|
bool UseUncached(uint64_t usage);
|
||||||
bool UseUncached(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GetIonHeapInfo(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage,
|
void GetIonHeapInfo(uint64_t usage, unsigned int *ion_heap_id, unsigned int *alloc_type,
|
||||||
unsigned int *ion_heap_id, unsigned int *alloc_type, unsigned int *ion_flags);
|
unsigned int *ion_flags);
|
||||||
|
|
||||||
IonAlloc *ion_allocator_ = NULL;
|
IonAlloc *ion_allocator_ = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_ALLOCATOR_H__
|
#endif // __GR_ALLOCATOR_H__
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -30,34 +30,48 @@
|
|||||||
#ifndef __GR_BUF_DESCRIPTOR_H__
|
#ifndef __GR_BUF_DESCRIPTOR_H__
|
||||||
#define __GR_BUF_DESCRIPTOR_H__
|
#define __GR_BUF_DESCRIPTOR_H__
|
||||||
|
|
||||||
#include <hardware/gralloc1.h>
|
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
using android::hardware::graphics::mapper::V2_0::Error;
|
||||||
|
using android::hardware::graphics::mapper::V2_0::IMapper;
|
||||||
|
using android::hardware::hidl_vec;
|
||||||
|
|
||||||
|
const uint32_t kBufferDescriptorSize = 7;
|
||||||
|
const uint32_t kMagicVersion = 0x76312E30; // v1.0
|
||||||
|
|
||||||
class BufferDescriptor {
|
class BufferDescriptor {
|
||||||
public:
|
public:
|
||||||
BufferDescriptor() : id_(next_id_++) {}
|
BufferDescriptor() {}
|
||||||
|
explicit BufferDescriptor(uint64_t id) : id_(id) {}
|
||||||
|
|
||||||
BufferDescriptor(int w, int h, int f)
|
static hidl_vec<uint32_t> Encode(const IMapper::BufferDescriptorInfo &bd_info) {
|
||||||
: width_(w),
|
hidl_vec<uint32_t> out;
|
||||||
height_(h),
|
out.resize(kBufferDescriptorSize);
|
||||||
format_(f),
|
out[0] = kMagicVersion;
|
||||||
producer_usage_(GRALLOC1_PRODUCER_USAGE_NONE),
|
out[1] = bd_info.width;
|
||||||
consumer_usage_(GRALLOC1_CONSUMER_USAGE_NONE),
|
out[2] = bd_info.height;
|
||||||
id_(next_id_++) {}
|
out[3] = bd_info.layerCount;
|
||||||
|
out[4] = static_cast<uint32_t>(bd_info.format);
|
||||||
|
out[5] = static_cast<uint32_t>(bd_info.usage);
|
||||||
|
out[6] = static_cast<uint32_t>(bd_info.usage >> 32);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
BufferDescriptor(int w, int h, int f, gralloc1_producer_usage_t prod_usage,
|
Error Decode(const hidl_vec<uint32_t> &in) {
|
||||||
gralloc1_consumer_usage_t cons_usage)
|
if (in.size() != kBufferDescriptorSize || in[0] != kMagicVersion) {
|
||||||
: width_(w),
|
return Error::BAD_DESCRIPTOR;
|
||||||
height_(h),
|
}
|
||||||
format_(f),
|
width_ = static_cast<int32_t>(in[1]);
|
||||||
producer_usage_(prod_usage),
|
height_ = static_cast<int32_t>(in[2]);
|
||||||
consumer_usage_(cons_usage),
|
layer_count_ = in[3];
|
||||||
id_(next_id_++) {}
|
format_ = static_cast<int32_t>(in[4]);
|
||||||
|
usage_ = static_cast<uint64_t>(in[6]) << 32 | in[5];
|
||||||
|
return Error::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
void SetConsumerUsage(gralloc1_consumer_usage_t usage) { consumer_usage_ = usage; }
|
void SetUsage(uint64_t usage) { usage_ |= usage; }
|
||||||
|
|
||||||
void SetProducerUsage(gralloc1_producer_usage_t usage) { producer_usage_ = usage; }
|
|
||||||
|
|
||||||
void SetDimensions(int w, int h) {
|
void SetDimensions(int w, int h) {
|
||||||
width_ = w;
|
width_ = w;
|
||||||
@@ -68,9 +82,7 @@ class BufferDescriptor {
|
|||||||
|
|
||||||
void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; }
|
void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; }
|
||||||
|
|
||||||
gralloc1_consumer_usage_t GetConsumerUsage() const { return consumer_usage_; }
|
uint64_t GetUsage() const { return usage_; }
|
||||||
|
|
||||||
gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage_; }
|
|
||||||
|
|
||||||
int GetWidth() const { return width_; }
|
int GetWidth() const { return width_; }
|
||||||
|
|
||||||
@@ -80,17 +92,15 @@ class BufferDescriptor {
|
|||||||
|
|
||||||
uint32_t GetLayerCount() const { return layer_count_; }
|
uint32_t GetLayerCount() const { return layer_count_; }
|
||||||
|
|
||||||
gralloc1_buffer_descriptor_t GetId() const { return id_; }
|
uint64_t GetId() const { return id_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int width_ = -1;
|
int width_ = -1;
|
||||||
int height_ = -1;
|
int height_ = -1;
|
||||||
int format_ = -1;
|
int format_ = -1;
|
||||||
uint32_t layer_count_ = 1;
|
uint32_t layer_count_ = 1;
|
||||||
gralloc1_producer_usage_t producer_usage_ = GRALLOC1_PRODUCER_USAGE_NONE;
|
uint64_t usage_ = 0;
|
||||||
gralloc1_consumer_usage_t consumer_usage_ = GRALLOC1_CONSUMER_USAGE_NONE;
|
const uint64_t id_ = 0;
|
||||||
const gralloc1_buffer_descriptor_t id_;
|
|
||||||
static std::atomic<gralloc1_buffer_descriptor_t> next_id_;
|
|
||||||
};
|
};
|
||||||
}; // namespace gralloc1
|
}; // namespace gralloc
|
||||||
#endif // __GR_BUF_DESCRIPTOR_H__
|
#endif // __GR_BUF_DESCRIPTOR_H__
|
||||||
|
|||||||
@@ -20,23 +20,22 @@
|
|||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
#include "qd_utils.h"
|
|
||||||
#include "gr_priv_handle.h"
|
|
||||||
#include "gr_buf_descriptor.h"
|
#include "gr_buf_descriptor.h"
|
||||||
#include "gr_utils.h"
|
|
||||||
#include "gr_buf_mgr.h"
|
#include "gr_buf_mgr.h"
|
||||||
|
#include "gr_priv_handle.h"
|
||||||
|
#include "gr_utils.h"
|
||||||
#include "qdMetaData.h"
|
#include "qdMetaData.h"
|
||||||
|
#include "qd_utils.h"
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
std::atomic<gralloc1_buffer_descriptor_t> BufferDescriptor::next_id_(1);
|
|
||||||
|
|
||||||
static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) {
|
static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) {
|
||||||
return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(),
|
return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(),
|
||||||
descriptor.GetProducerUsage(), descriptor.GetConsumerUsage());
|
descriptor.GetUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferManager::BufferManager() : next_id_(0) {
|
BufferManager::BufferManager() : next_id_(0) {
|
||||||
@@ -54,25 +53,9 @@ BufferManager::BufferManager() : next_id_(0) {
|
|||||||
allocator_->Init();
|
allocator_->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BufferManager *BufferManager::GetInstance() {
|
||||||
gralloc1_error_t BufferManager::CreateBufferDescriptor(
|
static BufferManager *instance = new BufferManager();
|
||||||
gralloc1_buffer_descriptor_t *descriptor_id) {
|
return instance;
|
||||||
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
|
||||||
auto descriptor = std::make_shared<BufferDescriptor>();
|
|
||||||
descriptors_map_.emplace(descriptor->GetId(), descriptor);
|
|
||||||
*descriptor_id = descriptor->GetId();
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::DestroyBufferDescriptor(
|
|
||||||
gralloc1_buffer_descriptor_t descriptor_id) {
|
|
||||||
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
|
||||||
const auto descriptor = descriptors_map_.find(descriptor_id);
|
|
||||||
if (descriptor == descriptors_map_.end()) {
|
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
|
||||||
}
|
|
||||||
descriptors_map_.erase(descriptor);
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferManager::~BufferManager() {
|
BufferManager::~BufferManager() {
|
||||||
@@ -81,133 +64,24 @@ BufferManager::~BufferManager() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::AllocateBuffers(uint32_t num_descriptors,
|
Error BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
|
||||||
const gralloc1_buffer_descriptor_t *descriptor_ids,
|
|
||||||
buffer_handle_t *out_buffers) {
|
|
||||||
bool shared = true;
|
|
||||||
gralloc1_error_t status = GRALLOC1_ERROR_NONE;
|
|
||||||
|
|
||||||
// since GRALLOC1_CAPABILITY_TEST_ALLOCATE capability is supported
|
|
||||||
// client can ask to test the allocation by passing NULL out_buffers
|
|
||||||
bool test_allocate = !out_buffers;
|
|
||||||
|
|
||||||
// Validate descriptors
|
|
||||||
std::lock_guard<std::mutex> descriptor_lock(descriptor_lock_);
|
|
||||||
std::vector<std::shared_ptr<BufferDescriptor>> descriptors;
|
|
||||||
for (uint32_t i = 0; i < num_descriptors; i++) {
|
|
||||||
const auto map_descriptor = descriptors_map_.find(descriptor_ids[i]);
|
|
||||||
if (map_descriptor == descriptors_map_.end()) {
|
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
|
||||||
} else {
|
|
||||||
descriptors.push_back(map_descriptor->second);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve implementation defined formats
|
|
||||||
for (auto &descriptor : descriptors) {
|
|
||||||
descriptor->SetColorFormat(allocator_->GetImplDefinedFormat(descriptor->GetProducerUsage(),
|
|
||||||
descriptor->GetConsumerUsage(),
|
|
||||||
descriptor->GetFormat()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if input descriptors can be supported AND
|
|
||||||
// Find out if a single buffer can be shared for all the given input descriptors
|
|
||||||
uint32_t i = 0;
|
|
||||||
ssize_t max_buf_index = -1;
|
|
||||||
shared = allocator_->CheckForBufferSharing(num_descriptors, descriptors, &max_buf_index);
|
|
||||||
|
|
||||||
if (test_allocate) {
|
|
||||||
status = shared ? GRALLOC1_ERROR_NOT_SHARED : status;
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> buffer_lock(buffer_lock_);
|
|
||||||
if (shared && (max_buf_index >= 0)) {
|
|
||||||
// Allocate one and duplicate/copy the handles for each descriptor
|
|
||||||
if (AllocateBufferLocked(*descriptors[UINT(max_buf_index)], &out_buffers[max_buf_index])) {
|
|
||||||
return GRALLOC1_ERROR_NO_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < num_descriptors; i++) {
|
|
||||||
// Create new handle for a given descriptor.
|
|
||||||
// Current assumption is even MetaData memory would be same
|
|
||||||
// Need to revisit if there is a need for own metadata memory
|
|
||||||
if (i != UINT(max_buf_index)) {
|
|
||||||
CreateSharedHandle(out_buffers[max_buf_index], *descriptors[i], &out_buffers[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Buffer sharing is not feasible.
|
|
||||||
// Allocate separate buffer for each descriptor
|
|
||||||
for (i = 0; i < num_descriptors; i++) {
|
|
||||||
if (AllocateBufferLocked(*descriptors[i], &out_buffers[i])) {
|
|
||||||
return GRALLOC1_ERROR_NO_RESOURCES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocation is successful. If backstore is not shared inform the client.
|
|
||||||
if (!shared) {
|
|
||||||
return GRALLOC1_ERROR_NOT_SHARED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BufferManager::CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor,
|
|
||||||
buffer_handle_t *outbuffer) {
|
|
||||||
// TODO(user): This path is not verified
|
|
||||||
private_handle_t const *input = reinterpret_cast<private_handle_t const *>(inbuffer);
|
|
||||||
|
|
||||||
// Get Buffer attributes or dimension
|
|
||||||
unsigned int alignedw = 0, alignedh = 0;
|
|
||||||
BufferInfo info = GetBufferInfo(descriptor);
|
|
||||||
|
|
||||||
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
|
||||||
|
|
||||||
// create new handle from input reference handle and given descriptor
|
|
||||||
int flags = GetHandleFlags(descriptor.GetFormat(), descriptor.GetProducerUsage(),
|
|
||||||
descriptor.GetConsumerUsage());
|
|
||||||
int buffer_type = GetBufferType(descriptor.GetFormat());
|
|
||||||
|
|
||||||
// Duplicate the fds
|
|
||||||
// TODO(user): Not sure what to do for fb_id. Use duped fd and new dimensions?
|
|
||||||
private_handle_t *out_hnd = new private_handle_t(dup(input->fd),
|
|
||||||
dup(input->fd_metadata),
|
|
||||||
flags,
|
|
||||||
INT(alignedw),
|
|
||||||
INT(alignedh),
|
|
||||||
descriptor.GetWidth(),
|
|
||||||
descriptor.GetHeight(),
|
|
||||||
descriptor.GetFormat(),
|
|
||||||
buffer_type,
|
|
||||||
input->size,
|
|
||||||
descriptor.GetProducerUsage(),
|
|
||||||
descriptor.GetConsumerUsage());
|
|
||||||
out_hnd->id = ++next_id_;
|
|
||||||
// TODO(user): Base address of shared handle and ion handles
|
|
||||||
RegisterHandleLocked(out_hnd, -1, -1);
|
|
||||||
*outbuffer = out_hnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
|
|
||||||
auto hnd = buf->handle;
|
auto hnd = buf->handle;
|
||||||
ALOGD_IF(DEBUG, "FreeBuffer handle:%p", hnd);
|
ALOGD_IF(DEBUG, "FreeBuffer handle:%p", hnd);
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
ALOGE("FreeBuffer: Invalid handle: %p", hnd);
|
ALOGE("FreeBuffer: Invalid handle: %p", hnd);
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
|
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset, hnd->fd,
|
||||||
hnd->fd, buf->ion_handle_main) != 0) {
|
buf->ion_handle_main) != 0) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
|
unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE);
|
||||||
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base_metadata), meta_size,
|
if (allocator_->FreeBuffer(reinterpret_cast<void *>(hnd->base_metadata), meta_size,
|
||||||
hnd->offset_metadata, hnd->fd_metadata, buf->ion_handle_meta) != 0) {
|
hnd->offset_metadata, hnd->fd_metadata, buf->ion_handle_meta) != 0) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private_handle_t *handle = const_cast<private_handle_t *>(hnd);
|
private_handle_t *handle = const_cast<private_handle_t *>(hnd);
|
||||||
@@ -216,38 +90,37 @@ gralloc1_error_t BufferManager::FreeBuffer(std::shared_ptr<Buffer> buf) {
|
|||||||
if (!(handle->flags & private_handle_t::PRIV_FLAGS_CLIENT_ALLOCATED)) {
|
if (!(handle->flags & private_handle_t::PRIV_FLAGS_CLIENT_ALLOCATED)) {
|
||||||
delete handle;
|
delete handle;
|
||||||
}
|
}
|
||||||
return GRALLOC1_ERROR_NONE;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferManager::RegisterHandleLocked(const private_handle_t *hnd,
|
void BufferManager::RegisterHandleLocked(const private_handle_t *hnd, int ion_handle,
|
||||||
int ion_handle,
|
|
||||||
int ion_handle_meta) {
|
int ion_handle_meta) {
|
||||||
auto buffer = std::make_shared<Buffer>(hnd, ion_handle, ion_handle_meta);
|
auto buffer = std::make_shared<Buffer>(hnd, ion_handle, ion_handle_meta);
|
||||||
handles_map_.emplace(std::make_pair(hnd, buffer));
|
handles_map_.emplace(std::make_pair(hnd, buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::ImportHandleLocked(private_handle_t *hnd) {
|
Error BufferManager::ImportHandleLocked(private_handle_t *hnd) {
|
||||||
ALOGD_IF(DEBUG, "Importing handle:%p id: %" PRIu64, hnd, hnd->id);
|
ALOGD_IF(DEBUG, "Importing handle:%p id: %" PRIu64, hnd, hnd->id);
|
||||||
int ion_handle = allocator_->ImportBuffer(hnd->fd);
|
int ion_handle = allocator_->ImportBuffer(hnd->fd);
|
||||||
if (ion_handle < 0) {
|
if (ion_handle < 0) {
|
||||||
ALOGE("Failed to import ion buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd, hnd->fd, hnd->id);
|
ALOGE("Failed to import ion buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd, hnd->fd, hnd->id);
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
int ion_handle_meta = allocator_->ImportBuffer(hnd->fd_metadata);
|
int ion_handle_meta = allocator_->ImportBuffer(hnd->fd_metadata);
|
||||||
if (ion_handle_meta < 0) {
|
if (ion_handle_meta < 0) {
|
||||||
ALOGE("Failed to import ion metadata buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd,
|
ALOGE("Failed to import ion metadata buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd, hnd->fd,
|
||||||
hnd->fd, hnd->id);
|
hnd->id);
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
// Set base pointers to NULL since the data here was received over binder
|
// Set base pointers to NULL since the data here was received over binder
|
||||||
hnd->base = 0;
|
hnd->base = 0;
|
||||||
hnd->base_metadata = 0;
|
hnd->base_metadata = 0;
|
||||||
RegisterHandleLocked(hnd, ion_handle, ion_handle_meta);
|
RegisterHandleLocked(hnd, ion_handle, ion_handle_meta);
|
||||||
return GRALLOC1_ERROR_NONE;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<BufferManager::Buffer>
|
std::shared_ptr<BufferManager::Buffer> BufferManager::GetBufferFromHandleLocked(
|
||||||
BufferManager::GetBufferFromHandleLocked(const private_handle_t *hnd) {
|
const private_handle_t *hnd) {
|
||||||
auto it = handles_map_.find(hnd);
|
auto it = handles_map_.find(hnd);
|
||||||
if (it != handles_map_.end()) {
|
if (it != handles_map_.end()) {
|
||||||
return it->second;
|
return it->second;
|
||||||
@@ -256,21 +129,21 @@ BufferManager::GetBufferFromHandleLocked(const private_handle_t *hnd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::MapBuffer(private_handle_t const *handle) {
|
Error BufferManager::MapBuffer(private_handle_t const *handle) {
|
||||||
private_handle_t *hnd = const_cast<private_handle_t *>(handle);
|
private_handle_t *hnd = const_cast<private_handle_t *>(handle);
|
||||||
ALOGD_IF(DEBUG, "Map buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
ALOGD_IF(DEBUG, "Map buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
||||||
|
|
||||||
hnd->base = 0;
|
hnd->base = 0;
|
||||||
if (allocator_->MapBuffer(reinterpret_cast<void **>(&hnd->base), hnd->size, hnd->offset,
|
if (allocator_->MapBuffer(reinterpret_cast<void **>(&hnd->base), hnd->size, hnd->offset,
|
||||||
hnd->fd) != 0) {
|
hnd->fd) != 0) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
return GRALLOC1_ERROR_NONE;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) {
|
Error BufferManager::RetainBuffer(private_handle_t const *hnd) {
|
||||||
ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
||||||
gralloc1_error_t err = GRALLOC1_ERROR_NONE;
|
auto err = Error::NONE;
|
||||||
std::lock_guard<std::mutex> lock(buffer_lock_);
|
std::lock_guard<std::mutex> lock(buffer_lock_);
|
||||||
auto buf = GetBufferFromHandleLocked(hnd);
|
auto buf = GetBufferFromHandleLocked(hnd);
|
||||||
if (buf != nullptr) {
|
if (buf != nullptr) {
|
||||||
@@ -282,13 +155,13 @@ gralloc1_error_t BufferManager::RetainBuffer(private_handle_t const *hnd) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
|
Error BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
|
||||||
ALOGD_IF(DEBUG, "Release buffer handle:%p", hnd);
|
ALOGD_IF(DEBUG, "Release buffer handle:%p", hnd);
|
||||||
std::lock_guard<std::mutex> lock(buffer_lock_);
|
std::lock_guard<std::mutex> lock(buffer_lock_);
|
||||||
auto buf = GetBufferFromHandleLocked(hnd);
|
auto buf = GetBufferFromHandleLocked(hnd);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
ALOGE("Could not find handle: %p id: %" PRIu64, hnd, hnd->id);
|
ALOGE("Could not find handle: %p id: %" PRIu64, hnd, hnd->id);
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
} else {
|
} else {
|
||||||
if (buf->DecRef()) {
|
if (buf->DecRef()) {
|
||||||
handles_map_.erase(hnd);
|
handles_map_.erase(hnd);
|
||||||
@@ -296,24 +169,22 @@ gralloc1_error_t BufferManager::ReleaseBuffer(private_handle_t const *hnd) {
|
|||||||
FreeBuffer(buf);
|
FreeBuffer(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GRALLOC1_ERROR_NONE;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::LockBuffer(const private_handle_t *hnd,
|
Error BufferManager::LockBuffer(const private_handle_t *hnd, uint64_t usage) {
|
||||||
gralloc1_producer_usage_t prod_usage,
|
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
|
||||||
std::lock_guard<std::mutex> lock(buffer_lock_);
|
std::lock_guard<std::mutex> lock(buffer_lock_);
|
||||||
gralloc1_error_t err = GRALLOC1_ERROR_NONE;
|
auto err = Error::NONE;
|
||||||
ALOGD_IF(DEBUG, "LockBuffer buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
ALOGD_IF(DEBUG, "LockBuffer buffer handle:%p id: %" PRIu64, hnd, hnd->id);
|
||||||
|
|
||||||
// If buffer is not meant for CPU return err
|
// If buffer is not meant for CPU return err
|
||||||
if (!CpuCanAccess(prod_usage, cons_usage)) {
|
if (!CpuCanAccess(usage)) {
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
return Error::BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto buf = GetBufferFromHandleLocked(hnd);
|
auto buf = GetBufferFromHandleLocked(hnd);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hnd->base == 0) {
|
if (hnd->base == 0) {
|
||||||
@@ -326,16 +197,16 @@ gralloc1_error_t BufferManager::LockBuffer(const private_handle_t *hnd,
|
|||||||
// only read/written in software.
|
// only read/written in software.
|
||||||
|
|
||||||
// todo use handle here
|
// todo use handle here
|
||||||
if (!err && (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) &&
|
if (err == Error::NONE && (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) &&
|
||||||
(hnd->flags & private_handle_t::PRIV_FLAGS_CACHED)) {
|
(hnd->flags & private_handle_t::PRIV_FLAGS_CACHED)) {
|
||||||
if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
|
if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
|
||||||
buf->ion_handle_main, CACHE_INVALIDATE)) {
|
buf->ion_handle_main, CACHE_INVALIDATE)) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the buffer to be flushed after CPU write.
|
// Mark the buffer to be flushed after CPU write.
|
||||||
if (!err && CpuCanWrite(prod_usage)) {
|
if (err == Error::NONE && CpuCanWrite(usage)) {
|
||||||
private_handle_t *handle = const_cast<private_handle_t *>(hnd);
|
private_handle_t *handle = const_cast<private_handle_t *>(hnd);
|
||||||
handle->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
|
handle->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
|
||||||
}
|
}
|
||||||
@@ -343,20 +214,20 @@ gralloc1_error_t BufferManager::LockBuffer(const private_handle_t *hnd,
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::UnlockBuffer(const private_handle_t *handle) {
|
Error BufferManager::UnlockBuffer(const private_handle_t *handle) {
|
||||||
std::lock_guard<std::mutex> lock(buffer_lock_);
|
std::lock_guard<std::mutex> lock(buffer_lock_);
|
||||||
gralloc1_error_t status = GRALLOC1_ERROR_NONE;
|
auto status = Error::NONE;
|
||||||
|
|
||||||
private_handle_t *hnd = const_cast<private_handle_t *>(handle);
|
private_handle_t *hnd = const_cast<private_handle_t *>(handle);
|
||||||
auto buf = GetBufferFromHandleLocked(hnd);
|
auto buf = GetBufferFromHandleLocked(hnd);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
return Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
|
if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
|
||||||
if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
|
if (allocator_->CleanBuffer(reinterpret_cast<void *>(hnd->base), hnd->size, hnd->offset,
|
||||||
buf->ion_handle_main, CACHE_CLEAN) != 0) {
|
buf->ion_handle_main, CACHE_CLEAN) != 0) {
|
||||||
status = GRALLOC1_ERROR_BAD_HANDLE;
|
status = Error::BAD_BUFFER;
|
||||||
}
|
}
|
||||||
hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
|
hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
|
||||||
}
|
}
|
||||||
@@ -364,16 +235,14 @@ gralloc1_error_t BufferManager::UnlockBuffer(const private_handle_t *handle) {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t BufferManager::GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
|
uint32_t BufferManager::GetDataAlignment(int format, uint64_t usage) {
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
|
||||||
uint32_t align = UINT(getpagesize());
|
uint32_t align = UINT(getpagesize());
|
||||||
if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
|
if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) {
|
||||||
align = 8192;
|
align = 8192;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_PROTECTED) {
|
if (usage & BufferUsage::PROTECTED) {
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) ||
|
if ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) {
|
||||||
(cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY)) {
|
|
||||||
// The alignment here reflects qsee mmu V7L/V8L requirement
|
// The alignment here reflects qsee mmu V7L/V8L requirement
|
||||||
align = SZ_2M;
|
align = SZ_2M;
|
||||||
} else {
|
} else {
|
||||||
@@ -384,53 +253,46 @@ uint32_t BufferManager::GetDataAlignment(int format, gralloc1_producer_usage_t p
|
|||||||
return align;
|
return align;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferManager::GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
|
int BufferManager::GetHandleFlags(int format, uint64_t usage) {
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER) {
|
if (usage & BufferUsage::VIDEO_ENCODER) {
|
||||||
flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
|
flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_CAMERA) {
|
if (usage & BufferUsage::CAMERA_OUTPUT) {
|
||||||
flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
|
flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prod_usage & GRALLOC1_CONSUMER_USAGE_CAMERA) {
|
if (usage & BufferUsage::CAMERA_INPUT) {
|
||||||
flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
|
flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
|
if (usage & BufferUsage::COMPOSER_OVERLAY) {
|
||||||
flags |= private_handle_t::PRIV_FLAGS_HW_COMPOSER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prod_usage & GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IsUBwcEnabled(format, prod_usage, cons_usage)) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prod_usage & (GRALLOC1_PRODUCER_USAGE_CPU_READ | GRALLOC1_PRODUCER_USAGE_CPU_WRITE)) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(user): is this correct???
|
|
||||||
if ((cons_usage &
|
|
||||||
(GRALLOC1_CONSUMER_USAGE_VIDEO_ENCODER | GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET)) ||
|
|
||||||
(prod_usage & (GRALLOC1_PRODUCER_USAGE_CAMERA | GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET))) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_HWCOMPOSER) {
|
|
||||||
flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
|
flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allocator_->UseUncached(prod_usage, cons_usage)) {
|
if (usage & BufferUsage::GPU_TEXTURE) {
|
||||||
|
flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) {
|
||||||
|
flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsUBwcEnabled(format, usage)) {
|
||||||
|
flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) {
|
||||||
|
flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER |
|
||||||
|
BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) {
|
||||||
|
flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allocator_->UseUncached(usage)) {
|
||||||
flags |= private_handle_t::PRIV_FLAGS_CACHED;
|
flags |= private_handle_t::PRIV_FLAGS_CACHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,14 +309,14 @@ int BufferManager::GetBufferType(int inputFormat) {
|
|||||||
return buffer_type;
|
return buffer_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BufferManager::AllocateBufferLocked(const BufferDescriptor &descriptor, buffer_handle_t *handle,
|
Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
|
||||||
unsigned int bufferSize) {
|
unsigned int bufferSize) {
|
||||||
if (!handle)
|
if (!handle)
|
||||||
return -EINVAL;
|
return Error::BAD_BUFFER;
|
||||||
|
std::lock_guard<std::mutex> buffer_lock(buffer_lock_);
|
||||||
|
|
||||||
gralloc1_producer_usage_t prod_usage = descriptor.GetProducerUsage();
|
uint64_t usage = descriptor.GetUsage();
|
||||||
gralloc1_consumer_usage_t cons_usage = descriptor.GetConsumerUsage();
|
int format = allocator_->GetImplDefinedFormat(usage, descriptor.GetFormat());
|
||||||
int format = allocator_->GetImplDefinedFormat(prod_usage, cons_usage, descriptor.GetFormat());
|
|
||||||
uint32_t layer_count = descriptor.GetLayerCount();
|
uint32_t layer_count = descriptor.GetLayerCount();
|
||||||
|
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
@@ -469,17 +331,17 @@ int BufferManager::AllocateBufferLocked(const BufferDescriptor &descriptor, buff
|
|||||||
int flags = 0;
|
int flags = 0;
|
||||||
auto page_size = UINT(getpagesize());
|
auto page_size = UINT(getpagesize());
|
||||||
AllocData data;
|
AllocData data;
|
||||||
data.align = GetDataAlignment(format, prod_usage, cons_usage);
|
data.align = GetDataAlignment(format, usage);
|
||||||
size = ALIGN(size, data.align) * layer_count;
|
size = ALIGN(size, data.align) * layer_count;
|
||||||
data.size = size;
|
data.size = size;
|
||||||
data.handle = (uintptr_t)handle;
|
data.handle = (uintptr_t)handle;
|
||||||
data.uncached = allocator_->UseUncached(prod_usage, cons_usage);
|
data.uncached = allocator_->UseUncached(usage);
|
||||||
|
|
||||||
// Allocate buffer memory
|
// Allocate buffer memory
|
||||||
err = allocator_->AllocateMem(&data, prod_usage, cons_usage);
|
err = allocator_->AllocateMem(&data, usage);
|
||||||
if (err) {
|
if (err) {
|
||||||
ALOGE("gralloc failed to allocate err=%s", strerror(-err));
|
ALOGE("gralloc failed to allocate err=%s", strerror(-err));
|
||||||
return err;
|
return Error::NO_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate memory for MetaData
|
// Allocate memory for MetaData
|
||||||
@@ -488,29 +350,19 @@ int BufferManager::AllocateBufferLocked(const BufferDescriptor &descriptor, buff
|
|||||||
e_data.handle = data.handle;
|
e_data.handle = data.handle;
|
||||||
e_data.align = page_size;
|
e_data.align = page_size;
|
||||||
|
|
||||||
err =
|
err = allocator_->AllocateMem(&e_data, 0);
|
||||||
allocator_->AllocateMem(&e_data, GRALLOC1_PRODUCER_USAGE_NONE, GRALLOC1_CONSUMER_USAGE_NONE);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err));
|
ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err));
|
||||||
return err;
|
return Error::NO_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
flags = GetHandleFlags(format, prod_usage, cons_usage);
|
flags = GetHandleFlags(format, usage);
|
||||||
flags |= data.alloc_type;
|
flags |= data.alloc_type;
|
||||||
|
|
||||||
// Create handle
|
// Create handle
|
||||||
private_handle_t *hnd = new private_handle_t(data.fd,
|
private_handle_t *hnd = new private_handle_t(
|
||||||
e_data.fd,
|
data.fd, e_data.fd, flags, INT(alignedw), INT(alignedh), descriptor.GetWidth(),
|
||||||
flags,
|
descriptor.GetHeight(), format, buffer_type, data.size, usage);
|
||||||
INT(alignedw),
|
|
||||||
INT(alignedh),
|
|
||||||
descriptor.GetWidth(),
|
|
||||||
descriptor.GetHeight(),
|
|
||||||
format,
|
|
||||||
buffer_type,
|
|
||||||
data.size,
|
|
||||||
prod_usage,
|
|
||||||
cons_usage);
|
|
||||||
|
|
||||||
hnd->id = ++next_id_;
|
hnd->id = ++next_id_;
|
||||||
hnd->base = 0;
|
hnd->base = 0;
|
||||||
@@ -525,364 +377,10 @@ int BufferManager::AllocateBufferLocked(const BufferDescriptor &descriptor, buff
|
|||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
private_handle_t::Dump(hnd);
|
private_handle_t::Dump(hnd);
|
||||||
}
|
}
|
||||||
return err;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::Perform(int operation, va_list args) {
|
Error BufferManager::Dump(std::ostringstream *os) {
|
||||||
switch (operation) {
|
|
||||||
case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER: {
|
|
||||||
int fd = va_arg(args, int);
|
|
||||||
unsigned int size = va_arg(args, unsigned int);
|
|
||||||
unsigned int offset = va_arg(args, unsigned int);
|
|
||||||
void *base = va_arg(args, void *);
|
|
||||||
int width = va_arg(args, int);
|
|
||||||
int height = va_arg(args, int);
|
|
||||||
int format = va_arg(args, int);
|
|
||||||
|
|
||||||
native_handle_t **handle = va_arg(args, native_handle_t **);
|
|
||||||
if (!handle) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private_handle_t *hnd = reinterpret_cast<private_handle_t *>(
|
|
||||||
native_handle_create(private_handle_t::kNumFds, private_handle_t::NumInts()));
|
|
||||||
if (hnd) {
|
|
||||||
unsigned int alignedw = 0, alignedh = 0;
|
|
||||||
hnd->magic = private_handle_t::kMagic;
|
|
||||||
hnd->fd = fd;
|
|
||||||
hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
|
|
||||||
hnd->size = size;
|
|
||||||
hnd->offset = offset;
|
|
||||||
hnd->base = uint64_t(base);
|
|
||||||
hnd->gpuaddr = 0;
|
|
||||||
BufferInfo info(width, height, format);
|
|
||||||
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
|
||||||
hnd->unaligned_width = width;
|
|
||||||
hnd->unaligned_height = height;
|
|
||||||
hnd->width = INT(alignedw);
|
|
||||||
hnd->height = INT(alignedh);
|
|
||||||
hnd->format = format;
|
|
||||||
*handle = reinterpret_cast<native_handle_t *>(hnd);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_STRIDE: {
|
|
||||||
int width = va_arg(args, int);
|
|
||||||
int format = va_arg(args, int);
|
|
||||||
int *stride = va_arg(args, int *);
|
|
||||||
unsigned int alignedw = 0, alignedh = 0;
|
|
||||||
|
|
||||||
if (!stride) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferInfo info(width, width, format);
|
|
||||||
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
|
||||||
*stride = INT(alignedw);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *stride = va_arg(args, int *);
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stride) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferDim_t buffer_dim;
|
|
||||||
if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
|
||||||
*stride = buffer_dim.sliceWidth;
|
|
||||||
} else {
|
|
||||||
*stride = hnd->width;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
// TODO(user) : this alone should be sufficient, ask gfx to get rid of above
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *stride = va_arg(args, int *);
|
|
||||||
int *height = va_arg(args, int *);
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!stride || !height) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferDim_t buffer_dim;
|
|
||||||
int interlaced = 0;
|
|
||||||
|
|
||||||
*stride = hnd->width;
|
|
||||||
*height = hnd->height;
|
|
||||||
if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
|
||||||
*stride = buffer_dim.sliceWidth;
|
|
||||||
*height = buffer_dim.sliceHeight;
|
|
||||||
} else if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, &interlaced) == 0) {
|
|
||||||
if (interlaced && IsUBwcFormat(hnd->format)) {
|
|
||||||
unsigned int alignedw = 0, alignedh = 0;
|
|
||||||
// Get re-aligned height for single ubwc interlaced field and
|
|
||||||
// multiple by 2 to get frame height.
|
|
||||||
BufferInfo info(hnd->width, ((hnd->height+1)>>1), hnd->format);
|
|
||||||
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
|
||||||
*stride = static_cast<int>(alignedw);
|
|
||||||
*height = static_cast<int>(alignedh * 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: {
|
|
||||||
// TODO(user): Usage is split now. take care of it from Gfx client.
|
|
||||||
// see if we can directly expect descriptor from gfx client.
|
|
||||||
int width = va_arg(args, int);
|
|
||||||
int height = va_arg(args, int);
|
|
||||||
int format = va_arg(args, int);
|
|
||||||
uint64_t producer_usage = va_arg(args, uint64_t);
|
|
||||||
uint64_t consumer_usage = va_arg(args, uint64_t);
|
|
||||||
gralloc1_producer_usage_t prod_usage = static_cast<gralloc1_producer_usage_t>(producer_usage);
|
|
||||||
gralloc1_consumer_usage_t cons_usage = static_cast<gralloc1_consumer_usage_t>(consumer_usage);
|
|
||||||
|
|
||||||
int *aligned_width = va_arg(args, int *);
|
|
||||||
int *aligned_height = va_arg(args, int *);
|
|
||||||
int *tile_enabled = va_arg(args, int *);
|
|
||||||
if (!aligned_width || !aligned_height || !tile_enabled) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int alignedw, alignedh;
|
|
||||||
BufferInfo info(width, height, format, prod_usage, cons_usage);
|
|
||||||
*tile_enabled = IsUBwcEnabled(format, prod_usage, cons_usage);
|
|
||||||
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
|
||||||
*aligned_width = INT(alignedw);
|
|
||||||
*aligned_height = INT(alignedh);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *color_space = va_arg(args, int *);
|
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!color_space) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
*color_space = 0;
|
|
||||||
#ifdef USE_COLOR_METADATA
|
|
||||||
ColorMetaData color_metadata;
|
|
||||||
if (getMetaData(hnd, GET_COLOR_METADATA, &color_metadata) == 0) {
|
|
||||||
switch (color_metadata.colorPrimaries) {
|
|
||||||
case ColorPrimaries_BT709_5:
|
|
||||||
*color_space = HAL_CSC_ITU_R_709;
|
|
||||||
break;
|
|
||||||
case ColorPrimaries_BT601_6_525:
|
|
||||||
case ColorPrimaries_BT601_6_625:
|
|
||||||
*color_space = ((color_metadata.range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601);
|
|
||||||
break;
|
|
||||||
case ColorPrimaries_BT2020:
|
|
||||||
*color_space = (color_metadata.range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ALOGE("Unknown Color Space = %d", color_metadata.colorPrimaries);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else if (getMetaData(hnd, GET_COLOR_SPACE, color_space) != 0) {
|
|
||||||
*color_space = 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (getMetaData(hnd, GET_COLOR_SPACE, color_space) != 0) {
|
|
||||||
*color_space = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} break;
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *);
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ycbcr) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetYUVPlaneInfo(hnd, ycbcr)) {
|
|
||||||
return GRALLOC1_ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *map_secure_buffer = va_arg(args, int *);
|
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!map_secure_buffer) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
|
|
||||||
*map_secure_buffer = 0;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *flag = va_arg(args, int *);
|
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!flag) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
*flag = hnd->flags &private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
|
||||||
int linear_format = 0;
|
|
||||||
if (getMetaData(hnd, GET_LINEAR_FORMAT, &linear_format) == 0) {
|
|
||||||
if (linear_format) {
|
|
||||||
*flag = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
void **rgb_data = va_arg(args, void **);
|
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rgb_data) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetRgbDataAddress(hnd, rgb_data)) {
|
|
||||||
return GRALLOC1_ERROR_UNDEFINED;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS: {
|
|
||||||
int width = va_arg(args, int);
|
|
||||||
int height = va_arg(args, int);
|
|
||||||
int format = va_arg(args, int);
|
|
||||||
uint64_t p_usage = va_arg(args, uint64_t);
|
|
||||||
uint64_t c_usage = va_arg(args, uint64_t);
|
|
||||||
gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(p_usage);
|
|
||||||
gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(c_usage);
|
|
||||||
uint32_t *aligned_width = va_arg(args, uint32_t *);
|
|
||||||
uint32_t *aligned_height = va_arg(args, uint32_t *);
|
|
||||||
uint32_t *size = va_arg(args, uint32_t *);
|
|
||||||
|
|
||||||
if (!aligned_width || !aligned_height || !size) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto info = BufferInfo(width, height, format, producer_usage, consumer_usage);
|
|
||||||
GetBufferSizeAndDimensions(info, size, aligned_width, aligned_height);
|
|
||||||
// Align size
|
|
||||||
auto align = GetDataAlignment(format, producer_usage, consumer_usage);
|
|
||||||
*size = ALIGN(*size, align);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG: {
|
|
||||||
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
|
||||||
int *flag = va_arg(args, int *);
|
|
||||||
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!flag) {
|
|
||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, flag) != 0) {
|
|
||||||
*flag = 0;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE: {
|
|
||||||
private_handle_t* hnd = va_arg(args, private_handle_t*);
|
|
||||||
uint32_t *enable = va_arg(args, uint32_t*);
|
|
||||||
if (private_handle_t::validate(hnd) != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable) != 0) {
|
|
||||||
return GRALLOC1_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::GetNumFlexPlanes(const private_handle_t *hnd,
|
|
||||||
uint32_t *out_num_planes) {
|
|
||||||
if (!IsYuvFormat(hnd)) {
|
|
||||||
return GRALLOC1_ERROR_UNSUPPORTED;
|
|
||||||
} else {
|
|
||||||
*out_num_planes = 3;
|
|
||||||
}
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::GetFlexLayout(const private_handle_t *hnd,
|
|
||||||
struct android_flex_layout *layout) {
|
|
||||||
if (!IsYuvFormat(hnd)) {
|
|
||||||
return GRALLOC1_ERROR_UNSUPPORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
android_ycbcr yuvPlaneInfo[2];
|
|
||||||
int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
|
|
||||||
|
|
||||||
if (err != 0) {
|
|
||||||
return GRALLOC1_ERROR_BAD_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
layout->format = FLEX_FORMAT_YCbCr;
|
|
||||||
layout->num_planes = 3;
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < layout->num_planes; i++) {
|
|
||||||
layout->planes[i].bits_per_component = 8;
|
|
||||||
layout->planes[i].bits_used = 8;
|
|
||||||
layout->planes[i].h_increment = 1;
|
|
||||||
layout->planes[i].v_increment = 1;
|
|
||||||
layout->planes[i].h_subsampling = 2;
|
|
||||||
layout->planes[i].v_subsampling = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are only returning flex layout for progressive or single field formats.
|
|
||||||
struct android_ycbcr ycbcr = yuvPlaneInfo[0];
|
|
||||||
layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y);
|
|
||||||
layout->planes[0].component = FLEX_COMPONENT_Y;
|
|
||||||
layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride);
|
|
||||||
|
|
||||||
layout->planes[1].top_left = static_cast<uint8_t *>(ycbcr.cb);
|
|
||||||
layout->planes[1].component = FLEX_COMPONENT_Cb;
|
|
||||||
layout->planes[1].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
|
|
||||||
layout->planes[1].v_increment = static_cast<int32_t>(ycbcr.cstride);
|
|
||||||
|
|
||||||
layout->planes[2].top_left = static_cast<uint8_t *>(ycbcr.cr);
|
|
||||||
layout->planes[2].component = FLEX_COMPONENT_Cr;
|
|
||||||
layout->planes[2].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
|
|
||||||
layout->planes[2].v_increment = static_cast<int32_t>(ycbcr.cstride);
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gralloc1_error_t BufferManager::Dump(std::ostringstream *os) {
|
|
||||||
for (auto it : handles_map_) {
|
for (auto it : handles_map_) {
|
||||||
auto buf = it.second;
|
auto buf = it.second;
|
||||||
auto hnd = buf->handle;
|
auto hnd = buf->handle;
|
||||||
@@ -894,13 +392,15 @@ gralloc1_error_t BufferManager::Dump(std::ostringstream *os) {
|
|||||||
*os << std::setw(4) << hnd->unaligned_height;
|
*os << std::setw(4) << hnd->unaligned_height;
|
||||||
*os << " size: " << std::setw(9) << hnd->size;
|
*os << " size: " << std::setw(9) << hnd->size;
|
||||||
*os << std::hex << std::setfill('0');
|
*os << std::hex << std::setfill('0');
|
||||||
*os << " priv_flags: " << "0x" << std::setw(8) << hnd->flags;
|
*os << " priv_flags: "
|
||||||
*os << " prod_usage: " << "0x" << std::setw(8) << hnd->producer_usage;
|
<< "0x" << std::setw(8) << hnd->flags;
|
||||||
*os << " cons_usage: " << "0x" << std::setw(8) << hnd->consumer_usage;
|
*os << " usage: "
|
||||||
|
<< "0x" << std::setw(8) << hnd->usage;
|
||||||
// TODO(user): get format string from qdutils
|
// TODO(user): get format string from qdutils
|
||||||
*os << " format: " << "0x" << std::setw(8) << hnd->format;
|
*os << " format: "
|
||||||
|
<< "0x" << std::setw(8) << hnd->format;
|
||||||
*os << std::dec << std::setfill(' ') << std::endl;
|
*os << std::dec << std::setfill(' ') << std::endl;
|
||||||
}
|
}
|
||||||
return GRALLOC1_ERROR_NONE;
|
return Error::NONE;
|
||||||
}
|
}
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution
|
* Not a Contribution
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
@@ -21,69 +21,41 @@
|
|||||||
#define __GR_BUF_MGR_H__
|
#define __GR_BUF_MGR_H__
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <mutex>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#include "gralloc_priv.h"
|
|
||||||
#include "gr_allocator.h"
|
#include "gr_allocator.h"
|
||||||
#include "gr_buf_descriptor.h"
|
#include "gr_buf_descriptor.h"
|
||||||
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
|
using android::hardware::graphics::mapper::V2_0::Error;
|
||||||
|
|
||||||
class BufferManager {
|
class BufferManager {
|
||||||
public:
|
public:
|
||||||
~BufferManager();
|
~BufferManager();
|
||||||
gralloc1_error_t CreateBufferDescriptor(gralloc1_buffer_descriptor_t *descriptor_id);
|
|
||||||
gralloc1_error_t DestroyBufferDescriptor(gralloc1_buffer_descriptor_t descriptor_id);
|
|
||||||
gralloc1_error_t AllocateBuffers(uint32_t num_descriptors,
|
|
||||||
const gralloc1_buffer_descriptor_t *descriptor_ids,
|
|
||||||
buffer_handle_t *out_buffers);
|
|
||||||
gralloc1_error_t RetainBuffer(private_handle_t const *hnd);
|
|
||||||
gralloc1_error_t ReleaseBuffer(private_handle_t const *hnd);
|
|
||||||
gralloc1_error_t LockBuffer(const private_handle_t *hnd, gralloc1_producer_usage_t prod_usage,
|
|
||||||
gralloc1_consumer_usage_t cons_usage);
|
|
||||||
gralloc1_error_t UnlockBuffer(const private_handle_t *hnd);
|
|
||||||
gralloc1_error_t Perform(int operation, va_list args);
|
|
||||||
gralloc1_error_t GetFlexLayout(const private_handle_t *hnd, struct android_flex_layout *layout);
|
|
||||||
gralloc1_error_t GetNumFlexPlanes(const private_handle_t *hnd, uint32_t *out_num_planes);
|
|
||||||
gralloc1_error_t Dump(std::ostringstream *os);
|
|
||||||
|
|
||||||
template <typename... Args>
|
Error AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle,
|
||||||
gralloc1_error_t CallBufferDescriptorFunction(gralloc1_buffer_descriptor_t descriptor_id,
|
unsigned int bufferSize = 0);
|
||||||
void (BufferDescriptor::*member)(Args...),
|
Error RetainBuffer(private_handle_t const *hnd);
|
||||||
Args... args) {
|
Error ReleaseBuffer(private_handle_t const *hnd);
|
||||||
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
Error LockBuffer(const private_handle_t *hnd, uint64_t usage);
|
||||||
const auto map_descriptor = descriptors_map_.find(descriptor_id);
|
Error UnlockBuffer(const private_handle_t *hnd);
|
||||||
if (map_descriptor == descriptors_map_.end()) {
|
Error Dump(std::ostringstream *os);
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
static BufferManager *GetInstance();
|
||||||
}
|
|
||||||
const auto descriptor = map_descriptor->second;
|
|
||||||
(descriptor.get()->*member)(std::forward<Args>(args)...);
|
|
||||||
return GRALLOC1_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BufferManager* GetInstance() {
|
|
||||||
static BufferManager *instance = new BufferManager();
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BufferManager();
|
BufferManager();
|
||||||
gralloc1_error_t MapBuffer(private_handle_t const *hnd);
|
Error MapBuffer(private_handle_t const *hnd);
|
||||||
int GetBufferType(int format);
|
int GetBufferType(int format);
|
||||||
int AllocateBufferLocked(const BufferDescriptor &descriptor, buffer_handle_t *handle,
|
uint32_t GetDataAlignment(int format, uint64_t usage);
|
||||||
unsigned int bufferSize = 0);
|
int GetHandleFlags(int format, uint64_t usage);
|
||||||
uint32_t GetDataAlignment(int format, gralloc1_producer_usage_t prod_usage,
|
|
||||||
gralloc1_consumer_usage_t cons_usage);
|
|
||||||
int GetHandleFlags(int format, gralloc1_producer_usage_t prod_usage,
|
|
||||||
gralloc1_consumer_usage_t cons_usage);
|
|
||||||
void CreateSharedHandle(buffer_handle_t inbuffer, const BufferDescriptor &descriptor,
|
|
||||||
buffer_handle_t *out_buffer);
|
|
||||||
|
|
||||||
// Imports the ion fds into the current process. Returns an error for invalid handles
|
// Imports the ion fds into the current process. Returns an error for invalid handles
|
||||||
gralloc1_error_t ImportHandleLocked(private_handle_t *hnd);
|
Error ImportHandleLocked(private_handle_t *hnd);
|
||||||
|
|
||||||
// Creates a Buffer from the valid private handle and adds it to the map
|
// Creates a Buffer from the valid private handle and adds it to the map
|
||||||
void RegisterHandleLocked(const private_handle_t *hnd, int ion_handle, int ion_handle_meta);
|
void RegisterHandleLocked(const private_handle_t *hnd, int ion_handle, int ion_handle_meta);
|
||||||
@@ -103,16 +75,13 @@ class BufferManager {
|
|||||||
int ion_handle_meta = -1;
|
int ion_handle_meta = -1;
|
||||||
|
|
||||||
Buffer() = delete;
|
Buffer() = delete;
|
||||||
explicit Buffer(const private_handle_t* h, int ih_main = -1, int ih_meta = -1):
|
explicit Buffer(const private_handle_t *h, int ih_main = -1, int ih_meta = -1)
|
||||||
handle(h),
|
: handle(h), ion_handle_main(ih_main), ion_handle_meta(ih_meta) {}
|
||||||
ion_handle_main(ih_main),
|
|
||||||
ion_handle_meta(ih_meta) {
|
|
||||||
}
|
|
||||||
void IncRef() { ++ref_count; }
|
void IncRef() { ++ref_count; }
|
||||||
bool DecRef() { return --ref_count == 0; }
|
bool DecRef() { return --ref_count == 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
gralloc1_error_t FreeBuffer(std::shared_ptr<Buffer> buf);
|
Error FreeBuffer(std::shared_ptr<Buffer> buf);
|
||||||
|
|
||||||
// Get the wrapper Buffer object from the handle, returns nullptr if handle is not found
|
// Get the wrapper Buffer object from the handle, returns nullptr if handle is not found
|
||||||
std::shared_ptr<Buffer> GetBufferFromHandleLocked(const private_handle_t *hnd);
|
std::shared_ptr<Buffer> GetBufferFromHandleLocked(const private_handle_t *hnd);
|
||||||
@@ -120,16 +89,10 @@ class BufferManager {
|
|||||||
bool map_fb_mem_ = false;
|
bool map_fb_mem_ = false;
|
||||||
Allocator *allocator_ = NULL;
|
Allocator *allocator_ = NULL;
|
||||||
std::mutex buffer_lock_;
|
std::mutex buffer_lock_;
|
||||||
std::mutex descriptor_lock_;
|
|
||||||
// TODO(user): The private_handle_t is used as a key because the unique ID generated
|
|
||||||
// from next_id_ is not unique across processes. The correct way to resolve this would
|
|
||||||
// be to use the allocator over hwbinder
|
|
||||||
std::unordered_map<const private_handle_t *, std::shared_ptr<Buffer>> handles_map_ = {};
|
std::unordered_map<const private_handle_t *, std::shared_ptr<Buffer>> handles_map_ = {};
|
||||||
std::unordered_map<gralloc1_buffer_descriptor_t,
|
|
||||||
std::shared_ptr<BufferDescriptor>> descriptors_map_ = {};
|
|
||||||
std::atomic<uint64_t> next_id_;
|
std::atomic<uint64_t> next_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_BUF_MGR_H__
|
#endif // __GR_BUF_MGR_H__
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -29,19 +29,19 @@
|
|||||||
|
|
||||||
#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
|
#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
|
||||||
#include <cutils/log.h>
|
#include <cutils/log.h>
|
||||||
#include <utils/Trace.h>
|
|
||||||
#include <cutils/trace.h>
|
#include <cutils/trace.h>
|
||||||
#include <sync/sync.h>
|
#include <sync/sync.h>
|
||||||
|
#include <utils/Trace.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gr_device_impl.h"
|
|
||||||
#include "gr_buf_descriptor.h"
|
#include "gr_buf_descriptor.h"
|
||||||
#include "gralloc_priv.h"
|
#include "gr_device_impl.h"
|
||||||
#include "qd_utils.h"
|
|
||||||
#include "qdMetaData.h"
|
|
||||||
#include "gr_utils.h"
|
#include "gr_utils.h"
|
||||||
|
#include "gralloc_priv.h"
|
||||||
|
#include "qdMetaData.h"
|
||||||
|
#include "qd_utils.h"
|
||||||
|
|
||||||
int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device);
|
int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device);
|
||||||
|
|
||||||
@@ -50,6 +50,7 @@ int gralloc_device_close(struct hw_device_t *device);
|
|||||||
static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open};
|
static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open};
|
||||||
|
|
||||||
struct gralloc_module_t HAL_MODULE_INFO_SYM = {
|
struct gralloc_module_t HAL_MODULE_INFO_SYM = {
|
||||||
|
// clang-format off
|
||||||
.common = {
|
.common = {
|
||||||
.tag = HARDWARE_MODULE_TAG,
|
.tag = HARDWARE_MODULE_TAG,
|
||||||
.module_api_version = GRALLOC_MODULE_API_VERSION_1_0,
|
.module_api_version = GRALLOC_MODULE_API_VERSION_1_0,
|
||||||
@@ -61,12 +62,13 @@ struct gralloc_module_t HAL_MODULE_INFO_SYM = {
|
|||||||
.dso = 0,
|
.dso = 0,
|
||||||
.reserved = {0},
|
.reserved = {0},
|
||||||
},
|
},
|
||||||
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) {
|
int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) {
|
||||||
int status = -EINVAL;
|
int status = -EINVAL;
|
||||||
if (module && device && !strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
|
if (module && device && !strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) {
|
||||||
gralloc1::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc1::GrallocImpl::GetInstance(module);
|
gralloc::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc::GrallocImpl::GetInstance(module);
|
||||||
*device = reinterpret_cast<hw_device_t *>(dev);
|
*device = reinterpret_cast<hw_device_t *>(dev);
|
||||||
if (dev) {
|
if (dev) {
|
||||||
status = 0;
|
status = 0;
|
||||||
@@ -77,7 +79,9 @@ int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_d
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
|
std::atomic<uint64_t> GrallocImpl::next_descriptor_id_(1);
|
||||||
|
|
||||||
GrallocImpl::GrallocImpl(const hw_module_t *module) {
|
GrallocImpl::GrallocImpl(const hw_module_t *module) {
|
||||||
common.tag = HARDWARE_DEVICE_TAG;
|
common.tag = HARDWARE_DEVICE_TAG;
|
||||||
@@ -87,7 +91,58 @@ GrallocImpl::GrallocImpl(const hw_module_t *module) {
|
|||||||
getFunction = GetFunction;
|
getFunction = GetFunction;
|
||||||
getCapabilities = GetCapabilities;
|
getCapabilities = GetCapabilities;
|
||||||
|
|
||||||
initalized_ = Init();
|
initialized_ = Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline gralloc1_error_t ToError(Error error) {
|
||||||
|
switch (error) {
|
||||||
|
case Error::NONE:
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
|
case Error::BAD_DESCRIPTOR:
|
||||||
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
|
case Error::BAD_BUFFER:
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
case Error::BAD_VALUE:
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
case Error::NO_RESOURCES:
|
||||||
|
return GRALLOC1_ERROR_NO_RESOURCES;
|
||||||
|
case Error::UNSUPPORTED:
|
||||||
|
default:
|
||||||
|
return GRALLOC1_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t ProducerUsageToBufferUsage(gralloc1_producer_usage_t producer_usage) {
|
||||||
|
uint64_t usage = producer_usage & ~(GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN |
|
||||||
|
GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN);
|
||||||
|
if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) ==
|
||||||
|
GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) {
|
||||||
|
usage |= BufferUsage::CPU_READ_OFTEN;
|
||||||
|
} else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ) ==
|
||||||
|
GRALLOC1_PRODUCER_USAGE_CPU_READ) {
|
||||||
|
usage |= BufferUsage::CPU_READ_RARELY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) ==
|
||||||
|
GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) {
|
||||||
|
usage |= BufferUsage::CPU_WRITE_OFTEN;
|
||||||
|
} else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE) ==
|
||||||
|
GRALLOC1_PRODUCER_USAGE_CPU_WRITE) {
|
||||||
|
usage |= BufferUsage::CPU_WRITE_RARELY;
|
||||||
|
}
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint64_t ConsumerUsageToBufferUsage(gralloc1_consumer_usage_t consumer_usage) {
|
||||||
|
uint64_t usage = consumer_usage & ~(GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN);
|
||||||
|
if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) ==
|
||||||
|
GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) {
|
||||||
|
usage |= BufferUsage::CPU_READ_OFTEN;
|
||||||
|
} else if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ) ==
|
||||||
|
GRALLOC1_CONSUMER_USAGE_CPU_READ) {
|
||||||
|
usage |= BufferUsage::CPU_READ_RARELY;
|
||||||
|
}
|
||||||
|
return usage;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GrallocImpl::Init() {
|
bool GrallocImpl::Init() {
|
||||||
@@ -95,7 +150,26 @@ bool GrallocImpl::Init() {
|
|||||||
return buf_mgr_ != nullptr;
|
return buf_mgr_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrallocImpl::~GrallocImpl() {
|
GrallocImpl::~GrallocImpl() {}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::CreateBufferDescriptorLocked(
|
||||||
|
gralloc1_buffer_descriptor_t *descriptor_id) {
|
||||||
|
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
||||||
|
auto descriptor = std::make_shared<BufferDescriptor>(next_descriptor_id_++);
|
||||||
|
*descriptor_id = static_cast<gralloc1_buffer_descriptor_t>(descriptor->GetId());
|
||||||
|
descriptors_map_.emplace(*descriptor_id, descriptor);
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::DestroyBufferDescriptorLocked(
|
||||||
|
gralloc1_buffer_descriptor_t descriptor_id) {
|
||||||
|
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
||||||
|
const auto descriptor = descriptors_map_.find(descriptor_id);
|
||||||
|
if (descriptor == descriptors_map_.end()) {
|
||||||
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
|
}
|
||||||
|
descriptors_map_.erase(descriptor);
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GrallocImpl::CloseDevice(hw_device_t *device __unused) {
|
int GrallocImpl::CloseDevice(hw_device_t *device __unused) {
|
||||||
@@ -216,8 +290,8 @@ gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device,
|
|||||||
if (!device || !out_descriptor) {
|
if (!device || !out_descriptor) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
}
|
}
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CreateBufferDescriptor(out_descriptor);
|
return dev->CreateBufferDescriptorLocked(out_descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device,
|
gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device,
|
||||||
@@ -225,8 +299,8 @@ gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
}
|
}
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->DestroyBufferDescriptor(descriptor);
|
return dev->DestroyBufferDescriptorLocked(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device,
|
gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device,
|
||||||
@@ -235,9 +309,9 @@ gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
} else {
|
} else {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetUsage,
|
||||||
&BufferDescriptor::SetConsumerUsage, usage);
|
ConsumerUsageToBufferUsage(usage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +321,8 @@ gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
} else {
|
} else {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetDimensions,
|
||||||
&BufferDescriptor::SetDimensions,
|
|
||||||
INT(width), INT(height));
|
INT(width), INT(height));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,9 +333,8 @@ gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
} else {
|
} else {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetColorFormat, format);
|
||||||
&BufferDescriptor::SetColorFormat, format);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,9 +344,8 @@ gralloc1_error_t GrallocImpl::SetLayerCount(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
} else {
|
} else {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetLayerCount,
|
||||||
&BufferDescriptor::SetLayerCount,
|
|
||||||
layer_count);
|
layer_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,9 +356,9 @@ gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device,
|
|||||||
if (!device) {
|
if (!device) {
|
||||||
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
} else {
|
} else {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
return dev->buf_mgr_->CallBufferDescriptorFunction(descriptor,
|
return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetUsage,
|
||||||
&BufferDescriptor::SetProducerUsage, usage);
|
ProducerUsageToBufferUsage(usage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +378,7 @@ gralloc1_error_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer
|
|||||||
gralloc1_consumer_usage_t *outUsage) {
|
gralloc1_consumer_usage_t *outUsage) {
|
||||||
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
||||||
if (status == GRALLOC1_ERROR_NONE) {
|
if (status == GRALLOC1_ERROR_NONE) {
|
||||||
*outUsage = PRIV_HANDLE_CONST(buffer)->GetConsumerUsage();
|
*outUsage = static_cast<gralloc1_consumer_usage_t>(PRIV_HANDLE_CONST(buffer)->GetUsage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -353,8 +424,7 @@ gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer
|
|||||||
|
|
||||||
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
||||||
if (status == GRALLOC1_ERROR_NONE) {
|
if (status == GRALLOC1_ERROR_NONE) {
|
||||||
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
*outUsage = static_cast<gralloc1_producer_usage_t>(PRIV_HANDLE_CONST(buffer)->GetUsage());
|
||||||
*outUsage = hnd->GetProducerUsage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -374,6 +444,28 @@ gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::AllocateBuffer(const gralloc1_buffer_descriptor_t *descriptor_ids,
|
||||||
|
buffer_handle_t *out_buffers) {
|
||||||
|
gralloc1_error_t status = GRALLOC1_ERROR_NONE;
|
||||||
|
|
||||||
|
// Validate descriptor
|
||||||
|
std::lock_guard<std::mutex> descriptor_lock(descriptor_lock_);
|
||||||
|
std::shared_ptr<gralloc::BufferDescriptor> descriptor;
|
||||||
|
const auto map_descriptor = descriptors_map_.find(descriptor_ids[0]);
|
||||||
|
if (map_descriptor == descriptors_map_.end()) {
|
||||||
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
|
} else {
|
||||||
|
descriptor = map_descriptor->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate separate buffer for each descriptor
|
||||||
|
if (buf_mgr_->AllocateBuffer(*descriptor, &out_buffers[0]) != Error::NONE) {
|
||||||
|
return GRALLOC1_ERROR_NO_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors,
|
gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors,
|
||||||
const gralloc1_buffer_descriptor_t *descriptors,
|
const gralloc1_buffer_descriptor_t *descriptors,
|
||||||
buffer_handle_t *out_buffers) {
|
buffer_handle_t *out_buffers) {
|
||||||
@@ -385,9 +477,12 @@ gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_
|
|||||||
return GRALLOC1_ERROR_BAD_VALUE;
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
if (num_descriptors != 1) {
|
||||||
gralloc1_error_t status = dev->buf_mgr_->AllocateBuffers(num_descriptors, descriptors,
|
return GRALLOC1_ERROR_UNSUPPORTED;
|
||||||
out_buffers);
|
}
|
||||||
|
|
||||||
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
|
gralloc1_error_t status = dev->AllocateBuffer(descriptors, out_buffers);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -397,7 +492,7 @@ gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_han
|
|||||||
if (status == GRALLOC1_ERROR_NONE) {
|
if (status == GRALLOC1_ERROR_NONE) {
|
||||||
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
||||||
status = dev->buf_mgr_->RetainBuffer(hnd);
|
status = ToError(dev->buf_mgr_->RetainBuffer(hnd));
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -410,7 +505,50 @@ gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_ha
|
|||||||
|
|
||||||
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
||||||
return dev->buf_mgr_->ReleaseBuffer(hnd);
|
return ToError(dev->buf_mgr_->ReleaseBuffer(hnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
gralloc1_error_t GrallocImpl::GetFlexLayout(const private_handle_t *hnd,
|
||||||
|
struct android_flex_layout *layout) {
|
||||||
|
if (!IsYuvFormat(hnd)) {
|
||||||
|
return GRALLOC1_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
android_ycbcr yuvPlaneInfo[2];
|
||||||
|
int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
|
||||||
|
|
||||||
|
if (err != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
layout->format = FLEX_FORMAT_YCbCr;
|
||||||
|
layout->num_planes = 3;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < layout->num_planes; i++) {
|
||||||
|
layout->planes[i].bits_per_component = 8;
|
||||||
|
layout->planes[i].bits_used = 8;
|
||||||
|
layout->planes[i].h_increment = 1;
|
||||||
|
layout->planes[i].v_increment = 1;
|
||||||
|
layout->planes[i].h_subsampling = 2;
|
||||||
|
layout->planes[i].v_subsampling = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We are only returning flex layout for progressive or single field formats.
|
||||||
|
struct android_ycbcr ycbcr = yuvPlaneInfo[0];
|
||||||
|
layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y);
|
||||||
|
layout->planes[0].component = FLEX_COMPONENT_Y;
|
||||||
|
layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride);
|
||||||
|
|
||||||
|
layout->planes[1].top_left = static_cast<uint8_t *>(ycbcr.cb);
|
||||||
|
layout->planes[1].component = FLEX_COMPONENT_Cb;
|
||||||
|
layout->planes[1].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
|
||||||
|
layout->planes[1].v_increment = static_cast<int32_t>(ycbcr.cstride);
|
||||||
|
|
||||||
|
layout->planes[2].top_left = static_cast<uint8_t *>(ycbcr.cr);
|
||||||
|
layout->planes[2].component = FLEX_COMPONENT_Cr;
|
||||||
|
layout->planes[2].h_increment = static_cast<int32_t>(ycbcr.chroma_step);
|
||||||
|
layout->planes[2].v_increment = static_cast<int32_t>(ycbcr.cstride);
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
|
gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer,
|
||||||
@@ -421,9 +559,12 @@ gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer
|
|||||||
|
|
||||||
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
gralloc1_error_t status = CheckDeviceAndHandle(device, buffer);
|
||||||
if (status == GRALLOC1_ERROR_NONE) {
|
if (status == GRALLOC1_ERROR_NONE) {
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
|
||||||
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
status = dev->buf_mgr_->GetNumFlexPlanes(hnd, out_num_planes);
|
if (!IsYuvFormat(hnd)) {
|
||||||
|
status = GRALLOC1_ERROR_UNSUPPORTED;
|
||||||
|
} else {
|
||||||
|
*out_num_planes = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -469,8 +610,8 @@ gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handl
|
|||||||
// return GRALLOC1_ERROR_BAD_VALUE;
|
// return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(user): Need to check if buffer was allocated with the same flags
|
status = ToError(dev->buf_mgr_->LockBuffer(
|
||||||
status = dev->buf_mgr_->LockBuffer(hnd, prod_usage, cons_usage);
|
hnd, ProducerUsageToBufferUsage(prod_usage) | ConsumerUsageToBufferUsage(cons_usage)));
|
||||||
*out_data = reinterpret_cast<void *>(hnd->base);
|
*out_data = reinterpret_cast<void *>(hnd->base);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@@ -494,9 +635,9 @@ gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
auto *dev = reinterpret_cast<GrallocImpl *>(device);
|
||||||
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer);
|
||||||
dev->buf_mgr_->GetFlexLayout(hnd, out_flex_layout);
|
dev->GetFlexLayout(hnd, out_flex_layout);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -516,7 +657,200 @@ gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_han
|
|||||||
|
|
||||||
*release_fence = -1;
|
*release_fence = -1;
|
||||||
|
|
||||||
return dev->buf_mgr_->UnlockBuffer(hnd);
|
return ToError(dev->buf_mgr_->UnlockBuffer(hnd));
|
||||||
|
}
|
||||||
|
|
||||||
|
static gralloc1_error_t Perform(int operation, va_list args) {
|
||||||
|
switch (operation) {
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_STRIDE: {
|
||||||
|
int width = va_arg(args, int);
|
||||||
|
int format = va_arg(args, int);
|
||||||
|
int *stride = va_arg(args, int *);
|
||||||
|
unsigned int alignedw = 0, alignedh = 0;
|
||||||
|
|
||||||
|
if (!stride) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferInfo info(width, width, format);
|
||||||
|
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
||||||
|
*stride = INT(alignedw);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *stride = va_arg(args, int *);
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stride) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferDim_t buffer_dim;
|
||||||
|
if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
||||||
|
*stride = buffer_dim.sliceWidth;
|
||||||
|
} else {
|
||||||
|
*stride = hnd->width;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *stride = va_arg(args, int *);
|
||||||
|
int *height = va_arg(args, int *);
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stride || !height) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetCustomDimensions(hnd, stride, height);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: {
|
||||||
|
int width = va_arg(args, int);
|
||||||
|
int height = va_arg(args, int);
|
||||||
|
int format = va_arg(args, int);
|
||||||
|
uint64_t usage = va_arg(args, uint64_t);
|
||||||
|
usage |= va_arg(args, uint64_t);
|
||||||
|
|
||||||
|
int *aligned_width = va_arg(args, int *);
|
||||||
|
int *aligned_height = va_arg(args, int *);
|
||||||
|
int *tile_enabled = va_arg(args, int *);
|
||||||
|
if (!aligned_width || !aligned_height || !tile_enabled) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int alignedw, alignedh;
|
||||||
|
BufferInfo info(width, height, format, usage);
|
||||||
|
*tile_enabled = IsUBwcEnabled(format, usage);
|
||||||
|
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
||||||
|
*aligned_width = INT(alignedw);
|
||||||
|
*aligned_height = INT(alignedh);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *color_space = va_arg(args, int *);
|
||||||
|
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!color_space) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*color_space = 0;
|
||||||
|
GetColorSpaceFromMetadata(hnd, color_space);
|
||||||
|
} break;
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *);
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ycbcr) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetYUVPlaneInfo(hnd, ycbcr)) {
|
||||||
|
return GRALLOC1_ERROR_UNDEFINED;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *map_secure_buffer = va_arg(args, int *);
|
||||||
|
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!map_secure_buffer) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
|
||||||
|
*map_secure_buffer = 0;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *flag = va_arg(args, int *);
|
||||||
|
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
||||||
|
int linear_format = 0;
|
||||||
|
if (getMetaData(hnd, GET_LINEAR_FORMAT, &linear_format) == 0) {
|
||||||
|
if (linear_format) {
|
||||||
|
*flag = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
void **rgb_data = va_arg(args, void **);
|
||||||
|
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rgb_data) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GetRgbDataAddress(hnd, rgb_data)) {
|
||||||
|
return GRALLOC1_ERROR_UNDEFINED;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
int *flag = va_arg(args, int *);
|
||||||
|
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!flag) {
|
||||||
|
return GRALLOC1_ERROR_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, flag) != 0) {
|
||||||
|
*flag = 0;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE: {
|
||||||
|
private_handle_t *hnd = va_arg(args, private_handle_t *);
|
||||||
|
uint32_t *enable = va_arg(args, uint32_t *);
|
||||||
|
if (private_handle_t::validate(hnd) != 0) {
|
||||||
|
return GRALLOC1_ERROR_BAD_HANDLE;
|
||||||
|
}
|
||||||
|
if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable) != 0) {
|
||||||
|
return GRALLOC1_ERROR_UNSUPPORTED;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) {
|
gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) {
|
||||||
@@ -526,11 +860,10 @@ gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int ope
|
|||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, operation);
|
va_start(args, operation);
|
||||||
GrallocImpl const *dev = GRALLOC_IMPL(device);
|
gralloc1_error_t err = Perform(operation, args);
|
||||||
gralloc1_error_t err = dev->buf_mgr_->Perform(operation, args);
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
#ifndef __GR_DEVICE_IMPL_H__
|
#ifndef __GR_DEVICE_IMPL_H__
|
||||||
#define __GR_DEVICE_IMPL_H__
|
#define __GR_DEVICE_IMPL_H__
|
||||||
|
|
||||||
#include <hardware/hardware.h>
|
|
||||||
#include <hardware/gralloc1.h>
|
#include <hardware/gralloc1.h>
|
||||||
|
#include <hardware/hardware.h>
|
||||||
#include "gr_buf_mgr.h"
|
#include "gr_buf_mgr.h"
|
||||||
|
|
||||||
struct private_module_t {
|
struct private_module_t {
|
||||||
@@ -40,7 +40,7 @@ struct private_module_t {
|
|||||||
|
|
||||||
#define GRALLOC_IMPL(exp) reinterpret_cast<GrallocImpl const *>(exp)
|
#define GRALLOC_IMPL(exp) reinterpret_cast<GrallocImpl const *>(exp)
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
class GrallocImpl : public gralloc1_device_t {
|
class GrallocImpl : public gralloc1_device_t {
|
||||||
public:
|
public:
|
||||||
@@ -119,15 +119,39 @@ class GrallocImpl : public gralloc1_device_t {
|
|||||||
int32_t *release_fence);
|
int32_t *release_fence);
|
||||||
static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...);
|
static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...);
|
||||||
|
|
||||||
|
gralloc1_error_t CreateBufferDescriptorLocked(gralloc1_buffer_descriptor_t *descriptor_id);
|
||||||
|
gralloc1_error_t DestroyBufferDescriptorLocked(gralloc1_buffer_descriptor_t descriptor_id);
|
||||||
|
gralloc1_error_t AllocateBuffer(const gralloc1_buffer_descriptor_t *descriptor_ids,
|
||||||
|
buffer_handle_t *out_buffers);
|
||||||
|
gralloc1_error_t GetFlexLayout(const private_handle_t *hnd, struct android_flex_layout *layout);
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
gralloc1_error_t CallBufferDescriptorFunction(gralloc1_buffer_descriptor_t descriptor_id,
|
||||||
|
void (BufferDescriptor::*member)(Args...),
|
||||||
|
Args... args) {
|
||||||
|
std::lock_guard<std::mutex> lock(descriptor_lock_);
|
||||||
|
const auto map_descriptor = descriptors_map_.find(descriptor_id);
|
||||||
|
if (map_descriptor == descriptors_map_.end()) {
|
||||||
|
return GRALLOC1_ERROR_BAD_DESCRIPTOR;
|
||||||
|
}
|
||||||
|
const auto descriptor = map_descriptor->second;
|
||||||
|
(descriptor.get()->*member)(std::forward<Args>(args)...);
|
||||||
|
return GRALLOC1_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
explicit GrallocImpl(const hw_module_t *module);
|
explicit GrallocImpl(const hw_module_t *module);
|
||||||
~GrallocImpl();
|
~GrallocImpl();
|
||||||
bool Init();
|
bool Init();
|
||||||
bool IsInitialized() const { return initalized_; }
|
bool IsInitialized() const { return initialized_; }
|
||||||
|
|
||||||
BufferManager *buf_mgr_ = NULL;
|
BufferManager *buf_mgr_ = NULL;
|
||||||
bool initalized_ = false;
|
bool initialized_ = false;
|
||||||
|
std::mutex descriptor_lock_;
|
||||||
|
std::unordered_map<gralloc1_buffer_descriptor_t, std::shared_ptr<gralloc::BufferDescriptor>>
|
||||||
|
descriptors_map_ = {};
|
||||||
|
static std::atomic<uint64_t> next_descriptor_id_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_DEVICE_IMPL_H__
|
#endif // __GR_DEVICE_IMPL_H__
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -29,21 +29,21 @@
|
|||||||
|
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
|
#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
|
||||||
|
#include <cutils/log.h>
|
||||||
|
#include <cutils/trace.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <cutils/log.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <utils/Trace.h>
|
#include <utils/Trace.h>
|
||||||
#include <cutils/trace.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "gralloc_priv.h"
|
|
||||||
#include "gr_utils.h"
|
|
||||||
#include "gr_ion_alloc.h"
|
#include "gr_ion_alloc.h"
|
||||||
|
#include "gr_utils.h"
|
||||||
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
bool IonAlloc::Init() {
|
bool IonAlloc::Init() {
|
||||||
if (ion_dev_fd_ == FD_INIT) {
|
if (ion_dev_fd_ == FD_INIT) {
|
||||||
@@ -105,8 +105,8 @@ int IonAlloc::AllocBuffer(AllocData *data) {
|
|||||||
|
|
||||||
data->fd = fd_data.fd;
|
data->fd = fd_data.fd;
|
||||||
data->ion_handle = handle_data.handle;
|
data->ion_handle = handle_data.handle;
|
||||||
ALOGD_IF(DEBUG, "ion: Allocated buffer size:%zu fd:%d handle:0x%x",
|
ALOGD_IF(DEBUG, "ion: Allocated buffer size:%zu fd:%d handle:0x%x", ion_alloc_data.len, data->fd,
|
||||||
ion_alloc_data.len, data->fd, data->ion_handle);
|
data->ion_handle);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -210,4 +210,4 @@ int IonAlloc::CleanBuffer(void *base, unsigned int size, unsigned int offset, in
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#define FD_INIT -1
|
#define FD_INIT -1
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CACHE_CLEAN = 0x1,
|
CACHE_CLEAN = 0x1,
|
||||||
@@ -79,6 +79,6 @@ class IonAlloc {
|
|||||||
int ion_dev_fd_;
|
int ion_dev_fd_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_ION_ALLOC_H__
|
#endif // __GR_ION_ALLOC_H__
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution
|
* Not a Contribution
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 The Android Open Source Project
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
#define __GR_PRIV_HANDLE_H__
|
#define __GR_PRIV_HANDLE_H__
|
||||||
|
|
||||||
#include <cutils/log.h>
|
#include <cutils/log.h>
|
||||||
#include <hardware/gralloc1.h>
|
|
||||||
#include <hardware/gralloc.h>
|
#include <hardware/gralloc.h>
|
||||||
|
#include <hardware/gralloc1.h>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
|
||||||
#define GRALLOC1_FUNCTION_PERFORM 0x00001000
|
#define GRALLOC1_FUNCTION_PERFORM 0x00001000
|
||||||
@@ -73,37 +73,26 @@ struct private_handle_t : public native_handle_t {
|
|||||||
int unaligned_height; // holds height client asked to allocate
|
int unaligned_height; // holds height client asked to allocate
|
||||||
int format;
|
int format;
|
||||||
int buffer_type;
|
int buffer_type;
|
||||||
|
unsigned int layer_count;
|
||||||
|
uint64_t id __attribute__((aligned(8)));
|
||||||
|
uint64_t usage __attribute__((aligned(8)));
|
||||||
|
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
unsigned int offset;
|
unsigned int offset;
|
||||||
unsigned int offset_metadata;
|
unsigned int offset_metadata;
|
||||||
uint64_t base __attribute__((aligned(8)));
|
uint64_t base __attribute__((aligned(8)));
|
||||||
uint64_t base_metadata __attribute__((aligned(8)));
|
uint64_t base_metadata __attribute__((aligned(8)));
|
||||||
uint64_t gpuaddr __attribute__((aligned(8)));
|
uint64_t gpuaddr __attribute__((aligned(8)));
|
||||||
uint64_t id __attribute__((aligned(8)));
|
|
||||||
gralloc1_producer_usage_t producer_usage __attribute__((aligned(8)));
|
|
||||||
gralloc1_consumer_usage_t consumer_usage __attribute__((aligned(8)));
|
|
||||||
unsigned int layer_count;
|
|
||||||
|
|
||||||
static const int kNumFds = 2;
|
static const int kNumFds = 2;
|
||||||
static const int kMagic = 'gmsm';
|
static const int kMagic = 'gmsm';
|
||||||
|
|
||||||
static inline int NumInts() {
|
static inline int NumInts() {
|
||||||
return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int))
|
return ((sizeof(private_handle_t) - sizeof(native_handle_t)) / sizeof(int)) - kNumFds;
|
||||||
- kNumFds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private_handle_t(int fd,
|
private_handle_t(int fd, int meta_fd, int flags, int width, int height, int uw, int uh,
|
||||||
int meta_fd,
|
int format, int buf_type, unsigned int size, uint64_t usage = 0)
|
||||||
int flags,
|
|
||||||
int width,
|
|
||||||
int height,
|
|
||||||
int uw,
|
|
||||||
int uh,
|
|
||||||
int format,
|
|
||||||
int buf_type,
|
|
||||||
unsigned int size,
|
|
||||||
gralloc1_producer_usage_t prod_usage = GRALLOC1_PRODUCER_USAGE_NONE,
|
|
||||||
gralloc1_consumer_usage_t cons_usage = GRALLOC1_CONSUMER_USAGE_NONE)
|
|
||||||
: fd(fd),
|
: fd(fd),
|
||||||
fd_metadata(meta_fd),
|
fd_metadata(meta_fd),
|
||||||
magic(kMagic),
|
magic(kMagic),
|
||||||
@@ -114,16 +103,15 @@ struct private_handle_t : public native_handle_t {
|
|||||||
unaligned_height(uh),
|
unaligned_height(uh),
|
||||||
format(format),
|
format(format),
|
||||||
buffer_type(buf_type),
|
buffer_type(buf_type),
|
||||||
|
layer_count(1),
|
||||||
|
id(0),
|
||||||
|
usage(usage),
|
||||||
size(size),
|
size(size),
|
||||||
offset(0),
|
offset(0),
|
||||||
offset_metadata(0),
|
offset_metadata(0),
|
||||||
base(0),
|
base(0),
|
||||||
base_metadata(0),
|
base_metadata(0),
|
||||||
gpuaddr(0),
|
gpuaddr(0) {
|
||||||
id(0),
|
|
||||||
producer_usage(prod_usage),
|
|
||||||
consumer_usage(cons_usage),
|
|
||||||
layer_count(1) {
|
|
||||||
version = static_cast<int>(sizeof(native_handle));
|
version = static_cast<int>(sizeof(native_handle));
|
||||||
numInts = NumInts();
|
numInts = NumInts();
|
||||||
numFds = kNumFds;
|
numFds = kNumFds;
|
||||||
@@ -132,9 +120,7 @@ struct private_handle_t : public native_handle_t {
|
|||||||
// Legacy constructor used by some clients
|
// Legacy constructor used by some clients
|
||||||
private_handle_t(int fd, unsigned int size, int usage, int buf_type, int format, int w, int h)
|
private_handle_t(int fd, unsigned int size, int usage, int buf_type, int format, int w, int h)
|
||||||
: private_handle_t(fd, -1, PRIV_FLAGS_CLIENT_ALLOCATED, w, h, 0, 0, format, buf_type, size,
|
: private_handle_t(fd, -1, PRIV_FLAGS_CLIENT_ALLOCATED, w, h, 0, 0, format, buf_type, size,
|
||||||
static_cast<gralloc1_producer_usage_t>(usage),
|
static_cast<uint64_t>(usage)) {}
|
||||||
static_cast<gralloc1_consumer_usage_t>(usage)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
~private_handle_t() {
|
~private_handle_t() {
|
||||||
magic = 0;
|
magic = 0;
|
||||||
@@ -142,7 +128,7 @@ struct private_handle_t : public native_handle_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int validate(const native_handle *h) {
|
static int validate(const native_handle *h) {
|
||||||
const private_handle_t *hnd = (const private_handle_t *)h;
|
auto *hnd = static_cast<const private_handle_t *>(h);
|
||||||
if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() ||
|
if (!h || h->version != sizeof(native_handle) || h->numInts != NumInts() ||
|
||||||
h->numFds != kNumFds || hnd->magic != kMagic) {
|
h->numFds != kNumFds || hnd->magic != kMagic) {
|
||||||
ALOGE(
|
ALOGE(
|
||||||
@@ -162,11 +148,11 @@ struct private_handle_t : public native_handle_t {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void Dump(const private_handle_t *hnd) {
|
static void Dump(const private_handle_t *hnd) {
|
||||||
ALOGD("handle id:%" PRIu64 " wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
|
ALOGD("handle id:%" PRIu64
|
||||||
"prod_usage:0x%" PRIx64" cons_usage:0x%" PRIx64 " format:0x%x layer_count: %d",
|
" wxh:%dx%d uwxuh:%dx%d size: %d fd:%d fd_meta:%d flags:0x%x "
|
||||||
|
"usage:0x%" PRIx64 " format:0x%x layer_count: %d",
|
||||||
hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
|
hnd->id, hnd->width, hnd->height, hnd->unaligned_width, hnd->unaligned_height, hnd->size,
|
||||||
hnd->fd, hnd->fd_metadata, hnd->flags, hnd->producer_usage, hnd->consumer_usage,
|
hnd->fd, hnd->fd_metadata, hnd->flags, hnd->usage, hnd->format, hnd->layer_count);
|
||||||
hnd->format, hnd->layer_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetUnalignedWidth() const { return unaligned_width; }
|
int GetUnalignedWidth() const { return unaligned_width; }
|
||||||
@@ -182,9 +168,7 @@ struct private_handle_t : public native_handle_t {
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_consumer_usage_t GetConsumerUsage() const { return consumer_usage; }
|
uint64_t GetUsage() const { return usage; }
|
||||||
|
|
||||||
gralloc1_producer_usage_t GetProducerUsage() const { return producer_usage; }
|
|
||||||
|
|
||||||
uint64_t GetBackingstore() const { return id; }
|
uint64_t GetBackingstore() const { return id; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -30,8 +30,8 @@
|
|||||||
#include <media/msm_media_info.h>
|
#include <media/msm_media_info.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "gr_utils.h"
|
|
||||||
#include "gr_adreno_info.h"
|
#include "gr_adreno_info.h"
|
||||||
|
#include "gr_utils.h"
|
||||||
#include "qdMetaData.h"
|
#include "qdMetaData.h"
|
||||||
|
|
||||||
#define ASTC_BLOCK_SIZE 16
|
#define ASTC_BLOCK_SIZE 16
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
#define COLOR_FMT_P010_UBWC 9
|
#define COLOR_FMT_P010_UBWC 9
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace gralloc1 {
|
namespace gralloc {
|
||||||
|
|
||||||
bool IsYuvFormat(const private_handle_t *hnd) {
|
bool IsYuvFormat(const private_handle_t *hnd) {
|
||||||
switch (hnd->format) {
|
switch (hnd->format) {
|
||||||
@@ -177,24 +177,20 @@ uint32_t GetBppForUncompressedRGB(int format) {
|
|||||||
return bpp;
|
return bpp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CpuCanAccess(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage) {
|
bool CpuCanAccess(uint64_t usage) {
|
||||||
return CpuCanRead(prod_usage, cons_usage) || CpuCanWrite(prod_usage);
|
return CpuCanRead(usage) || CpuCanWrite(usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CpuCanRead(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage) {
|
bool CpuCanRead(uint64_t usage) {
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ) {
|
if (usage & BufferUsage::CPU_READ_MASK) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cons_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CpuCanWrite(gralloc1_producer_usage_t prod_usage) {
|
bool CpuCanWrite(uint64_t usage) {
|
||||||
if (prod_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE) {
|
if (usage & BufferUsage::CPU_WRITE_MASK) {
|
||||||
// Application intends to use CPU for rendering
|
// Application intends to use CPU for rendering
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -202,16 +198,14 @@ bool CpuCanWrite(gralloc1_producer_usage_t prod_usage) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int GetSize(const BufferInfo &info, unsigned int alignedw,
|
unsigned int GetSize(const BufferInfo &info, unsigned int alignedw, unsigned int alignedh) {
|
||||||
unsigned int alignedh) {
|
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
int format = info.format;
|
int format = info.format;
|
||||||
int width = info.width;
|
int width = info.width;
|
||||||
int height = info.height;
|
int height = info.height;
|
||||||
gralloc1_producer_usage_t prod_usage = info.prod_usage;
|
uint64_t usage = info.usage;
|
||||||
gralloc1_consumer_usage_t cons_usage = info.cons_usage;
|
|
||||||
|
|
||||||
if (IsUBwcEnabled(format, prod_usage, cons_usage)) {
|
if (IsUBwcEnabled(format, usage)) {
|
||||||
return GetUBwcSize(width, height, format, alignedw, alignedh);
|
return GetUBwcSize(width, height, format, alignedw, alignedh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,14 +302,14 @@ unsigned int GetSize(const BufferInfo &info, unsigned int alignedw,
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetBufferSizeAndDimensions(const BufferInfo &info, unsigned int *size,
|
void GetBufferSizeAndDimensions(const BufferInfo &info, unsigned int *size, unsigned int *alignedw,
|
||||||
unsigned int *alignedw, unsigned int *alignedh) {
|
unsigned int *alignedh) {
|
||||||
GetAlignedWidthAndHeight(info, alignedw, alignedh);
|
GetAlignedWidthAndHeight(info, alignedw, alignedh);
|
||||||
*size = GetSize(info, *alignedw, *alignedh);
|
*size = GetSize(info, *alignedw, *alignedh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height,
|
void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, int color_format,
|
||||||
int color_format, struct android_ycbcr *ycbcr) {
|
struct android_ycbcr *ycbcr) {
|
||||||
// UBWC buffer has these 4 planes in the following sequence:
|
// UBWC buffer has these 4 planes in the following sequence:
|
||||||
// Y_Meta_Plane, Y_Plane, UV_Meta_Plane, UV_Plane
|
// Y_Meta_Plane, Y_Plane, UV_Meta_Plane, UV_Plane
|
||||||
unsigned int y_meta_stride, y_meta_height, y_meta_size;
|
unsigned int y_meta_stride, y_meta_height, y_meta_size;
|
||||||
@@ -383,8 +377,7 @@ int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2])
|
|||||||
uint32_t width = UINT(hnd->width);
|
uint32_t width = UINT(hnd->width);
|
||||||
uint32_t height = UINT(hnd->height);
|
uint32_t height = UINT(hnd->height);
|
||||||
int format = hnd->format;
|
int format = hnd->format;
|
||||||
gralloc1_producer_usage_t prod_usage = hnd->GetProducerUsage();
|
uint64_t usage = hnd->usage;
|
||||||
gralloc1_consumer_usage_t cons_usage = hnd->GetConsumerUsage();
|
|
||||||
unsigned int ystride, cstride;
|
unsigned int ystride, cstride;
|
||||||
bool interlaced = false;
|
bool interlaced = false;
|
||||||
|
|
||||||
@@ -392,29 +385,21 @@ int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2])
|
|||||||
|
|
||||||
// Check if UBWC buffer has been rendered in linear format.
|
// Check if UBWC buffer has been rendered in linear format.
|
||||||
int linear_format = 0;
|
int linear_format = 0;
|
||||||
if (getMetaData(const_cast<private_handle_t *>(hnd),
|
if (getMetaData(const_cast<private_handle_t *>(hnd), GET_LINEAR_FORMAT, &linear_format) == 0) {
|
||||||
GET_LINEAR_FORMAT, &linear_format) == 0) {
|
|
||||||
format = INT(linear_format);
|
format = INT(linear_format);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check metadata if the geometry has been updated.
|
// Check metadata if the geometry has been updated.
|
||||||
BufferDim_t buffer_dim;
|
BufferDim_t buffer_dim;
|
||||||
if (getMetaData(const_cast<private_handle_t *>(hnd),
|
if (getMetaData(const_cast<private_handle_t *>(hnd), GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
||||||
GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
BufferInfo info(buffer_dim.sliceWidth, buffer_dim.sliceHeight, format, usage);
|
||||||
int usage = 0;
|
|
||||||
if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) {
|
|
||||||
usage = GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferInfo info(buffer_dim.sliceWidth, buffer_dim.sliceHeight, format,
|
|
||||||
prod_usage, cons_usage);
|
|
||||||
GetAlignedWidthAndHeight(info, &width, &height);
|
GetAlignedWidthAndHeight(info, &width, &height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check metadata for interlaced content.
|
// Check metadata for interlaced content.
|
||||||
int interlace_flag = 0;
|
int interlace_flag = 0;
|
||||||
if (getMetaData(const_cast<private_handle_t *>(hnd),
|
if (getMetaData(const_cast<private_handle_t *>(hnd), GET_PP_PARAM_INTERLACED, &interlace_flag) ==
|
||||||
GET_PP_PARAM_INTERLACED, &interlace_flag) == 0) {
|
0) {
|
||||||
interlaced = interlace_flag;
|
interlaced = interlace_flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,8 +442,8 @@ int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2])
|
|||||||
ystride = VENUS_Y_STRIDE(COLOR_FMT_P010, width);
|
ystride = VENUS_Y_STRIDE(COLOR_FMT_P010, width);
|
||||||
cstride = VENUS_UV_STRIDE(COLOR_FMT_P010, width);
|
cstride = VENUS_UV_STRIDE(COLOR_FMT_P010, width);
|
||||||
ycbcr->y = reinterpret_cast<void *>(hnd->base);
|
ycbcr->y = reinterpret_cast<void *>(hnd->base);
|
||||||
ycbcr->cb = reinterpret_cast<void *>(hnd->base +
|
ycbcr->cb =
|
||||||
ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height));
|
reinterpret_cast<void *>(hnd->base + ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height));
|
||||||
ycbcr->cr = reinterpret_cast<void *>(hnd->base +
|
ycbcr->cr = reinterpret_cast<void *>(hnd->base +
|
||||||
ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height) + 1);
|
ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height) + 1);
|
||||||
ycbcr->ystride = ystride;
|
ycbcr->ystride = ystride;
|
||||||
@@ -543,8 +528,7 @@ bool IsUBwcSupported(int format) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsUBwcEnabled(int format, gralloc1_producer_usage_t prod_usage,
|
bool IsUBwcEnabled(int format, uint64_t usage) {
|
||||||
gralloc1_consumer_usage_t cons_usage) {
|
|
||||||
// Allow UBWC, if client is using an explicitly defined UBWC pixel format.
|
// Allow UBWC, if client is using an explicitly defined UBWC pixel format.
|
||||||
if (IsUBwcFormat(format)) {
|
if (IsUBwcFormat(format)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -553,18 +537,17 @@ bool IsUBwcEnabled(int format, gralloc1_producer_usage_t prod_usage,
|
|||||||
// Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP
|
// Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP
|
||||||
// support the format. OR if a non-OpenGL client like Rotator, sets UBWC
|
// support the format. OR if a non-OpenGL client like Rotator, sets UBWC
|
||||||
// usage flag and MDP supports the format.
|
// usage flag and MDP supports the format.
|
||||||
if ((prod_usage & GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC) && IsUBwcSupported(format)) {
|
if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) && IsUBwcSupported(format)) {
|
||||||
bool enable = true;
|
bool enable = true;
|
||||||
// Query GPU for UBWC only if buffer is intended to be used by GPU.
|
// Query GPU for UBWC only if buffer is intended to be used by GPU.
|
||||||
if ((cons_usage & GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE) ||
|
if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) {
|
||||||
(prod_usage & GRALLOC1_PRODUCER_USAGE_GPU_RENDER_TARGET)) {
|
|
||||||
if (AdrenoMemInfo::GetInstance()) {
|
if (AdrenoMemInfo::GetInstance()) {
|
||||||
enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format);
|
enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow UBWC, only if CPU usage flags are not set
|
// Allow UBWC, only if CPU usage flags are not set
|
||||||
if (enable && !(CpuCanAccess(prod_usage, cons_usage))) {
|
if (enable && !(CpuCanAccess(usage))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -683,7 +666,7 @@ int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data) {
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
// This api is for RGB* formats
|
// This api is for RGB* formats
|
||||||
if (!gralloc1::IsUncompressedRGBFormat(hnd->format)) {
|
if (!IsUncompressedRGBFormat(hnd->format)) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -713,16 +696,60 @@ int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GetCustomDimensions(private_handle_t *hnd, int *stride, int *height) {
|
||||||
|
BufferDim_t buffer_dim;
|
||||||
|
int interlaced = 0;
|
||||||
|
|
||||||
|
*stride = hnd->width;
|
||||||
|
*height = hnd->height;
|
||||||
|
if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) {
|
||||||
|
*stride = buffer_dim.sliceWidth;
|
||||||
|
*height = buffer_dim.sliceHeight;
|
||||||
|
} else if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, &interlaced) == 0) {
|
||||||
|
if (interlaced && IsUBwcFormat(hnd->format)) {
|
||||||
|
unsigned int alignedw = 0, alignedh = 0;
|
||||||
|
// Get re-aligned height for single ubwc interlaced field and
|
||||||
|
// multiply by 2 to get frame height.
|
||||||
|
BufferInfo info(hnd->width, ((hnd->height + 1) >> 1), hnd->format);
|
||||||
|
GetAlignedWidthAndHeight(info, &alignedw, &alignedh);
|
||||||
|
*stride = static_cast<int>(alignedw);
|
||||||
|
*height = static_cast<int>(alignedh * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GetColorSpaceFromMetadata(private_handle_t *hnd, int *color_space) {
|
||||||
|
ColorMetaData color_metadata;
|
||||||
|
if (getMetaData(hnd, GET_COLOR_METADATA, &color_metadata) == 0) {
|
||||||
|
switch (color_metadata.colorPrimaries) {
|
||||||
|
case ColorPrimaries_BT709_5:
|
||||||
|
*color_space = HAL_CSC_ITU_R_709;
|
||||||
|
break;
|
||||||
|
case ColorPrimaries_BT601_6_525:
|
||||||
|
case ColorPrimaries_BT601_6_625:
|
||||||
|
*color_space = ((color_metadata.range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601);
|
||||||
|
break;
|
||||||
|
case ColorPrimaries_BT2020:
|
||||||
|
*color_space = (color_metadata.range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ALOGE("Unknown Color Space = %d", color_metadata.colorPrimaries);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (getMetaData(hnd, GET_COLOR_SPACE, color_space) != 0) {
|
||||||
|
*color_space = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw,
|
void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw,
|
||||||
unsigned int *alignedh) {
|
unsigned int *alignedh) {
|
||||||
int width = info.width;
|
int width = info.width;
|
||||||
int height = info.height;
|
int height = info.height;
|
||||||
int format = info.format;
|
int format = info.format;
|
||||||
gralloc1_producer_usage_t prod_usage = info.prod_usage;
|
uint64_t usage = info.usage;
|
||||||
gralloc1_consumer_usage_t cons_usage = info.cons_usage;
|
|
||||||
|
|
||||||
// Currently surface padding is only computed for RGB* surfaces.
|
// Currently surface padding is only computed for RGB* surfaces.
|
||||||
bool ubwc_enabled = IsUBwcEnabled(format, prod_usage, cons_usage);
|
bool ubwc_enabled = IsUBwcEnabled(format, usage);
|
||||||
int tile = ubwc_enabled;
|
int tile = ubwc_enabled;
|
||||||
|
|
||||||
if (IsUncompressedRGBFormat(format)) {
|
if (IsUncompressedRGBFormat(format)) {
|
||||||
@@ -815,8 +842,8 @@ void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw,
|
|||||||
*alignedh = (unsigned int)aligned_h;
|
*alignedh = (unsigned int)aligned_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4],
|
int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4], uint32_t offset[4],
|
||||||
uint32_t offset[4], uint32_t *num_planes) {
|
uint32_t *num_planes) {
|
||||||
if (!hnd || !stride || !offset || !num_planes) {
|
if (!hnd || !stride || !offset || !num_planes) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -903,4 +930,4 @@ int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4],
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace gralloc1
|
} // namespace gralloc
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2016, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2011-2016,2018, The Linux Foundation. All rights reserved.
|
||||||
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
#ifndef __GR_UTILS_H__
|
#ifndef __GR_UTILS_H__
|
||||||
#define __GR_UTILS_H__
|
#define __GR_UTILS_H__
|
||||||
|
|
||||||
|
#include <android/hardware/graphics/common/1.0/types.h>
|
||||||
#include "gralloc_priv.h"
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
#define SZ_2M 0x200000
|
#define SZ_2M 0x200000
|
||||||
@@ -42,17 +43,16 @@
|
|||||||
#define INT(exp) static_cast<int>(exp)
|
#define INT(exp) static_cast<int>(exp)
|
||||||
#define UINT(exp) static_cast<unsigned int>(exp)
|
#define UINT(exp) static_cast<unsigned int>(exp)
|
||||||
|
|
||||||
namespace gralloc1 {
|
using android::hardware::graphics::common::V1_0::BufferUsage;
|
||||||
|
|
||||||
|
namespace gralloc {
|
||||||
struct BufferInfo {
|
struct BufferInfo {
|
||||||
BufferInfo(int w, int h, int f, gralloc1_producer_usage_t prod = GRALLOC1_PRODUCER_USAGE_NONE,
|
BufferInfo(int w, int h, int f, uint64_t usage = 0)
|
||||||
gralloc1_consumer_usage_t cons = GRALLOC1_CONSUMER_USAGE_NONE) : width(w), height(h),
|
: width(w), height(h), format(f), usage(usage) {}
|
||||||
format(f), prod_usage(prod), cons_usage(cons) {}
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
int format;
|
int format;
|
||||||
gralloc1_producer_usage_t prod_usage;
|
uint64_t usage;
|
||||||
gralloc1_consumer_usage_t cons_usage;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Type1, class Type2>
|
template <class Type1, class Type2>
|
||||||
@@ -64,20 +64,21 @@ bool IsYuvFormat(const private_handle_t *hnd);
|
|||||||
bool IsCompressedRGBFormat(int format);
|
bool IsCompressedRGBFormat(int format);
|
||||||
bool IsUncompressedRGBFormat(int format);
|
bool IsUncompressedRGBFormat(int format);
|
||||||
uint32_t GetBppForUncompressedRGB(int format);
|
uint32_t GetBppForUncompressedRGB(int format);
|
||||||
bool CpuCanAccess(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage);
|
bool CpuCanAccess(uint64_t usage);
|
||||||
bool CpuCanRead(gralloc1_producer_usage_t prod_usage, gralloc1_consumer_usage_t cons_usage);
|
bool CpuCanRead(uint64_t usage);
|
||||||
bool CpuCanWrite(gralloc1_producer_usage_t prod_usage);
|
bool CpuCanWrite(uint64_t usage);
|
||||||
unsigned int GetSize(const BufferInfo &d, unsigned int alignedw, unsigned int alignedh);
|
unsigned int GetSize(const BufferInfo &d, unsigned int alignedw, unsigned int alignedh);
|
||||||
void GetBufferSizeAndDimensions(const BufferInfo &d, unsigned int *size,
|
void GetBufferSizeAndDimensions(const BufferInfo &d, unsigned int *size, unsigned int *alignedw,
|
||||||
unsigned int *alignedw, unsigned int *alignedh);
|
unsigned int *alignedh);
|
||||||
|
void GetCustomDimensions(private_handle_t *hnd, int *stride, int *height);
|
||||||
|
void GetColorSpaceFromMetadata(private_handle_t *hnd, int *color_space);
|
||||||
void GetAlignedWidthAndHeight(const BufferInfo &d, unsigned int *aligned_w,
|
void GetAlignedWidthAndHeight(const BufferInfo &d, unsigned int *aligned_w,
|
||||||
unsigned int *aligned_h);
|
unsigned int *aligned_h);
|
||||||
int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]);
|
int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]);
|
||||||
int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data);
|
int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data);
|
||||||
bool IsUBwcFormat(int format);
|
bool IsUBwcFormat(int format);
|
||||||
bool IsUBwcSupported(int format);
|
bool IsUBwcSupported(int format);
|
||||||
bool IsUBwcEnabled(int format, gralloc1_producer_usage_t prod_usage,
|
bool IsUBwcEnabled(int format, uint64_t usage);
|
||||||
gralloc1_consumer_usage_t cons_usage);
|
|
||||||
void GetYuvUBwcWidthAndHeight(int width, int height, int format, unsigned int *aligned_w,
|
void GetYuvUBwcWidthAndHeight(int width, int height, int format, unsigned int *aligned_w,
|
||||||
unsigned int *aligned_h);
|
unsigned int *aligned_h);
|
||||||
void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t bpp,
|
void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t bpp,
|
||||||
@@ -90,8 +91,9 @@ void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height);
|
|||||||
unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp);
|
unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp);
|
||||||
unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw,
|
unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw,
|
||||||
unsigned int alignedh);
|
unsigned int alignedh);
|
||||||
int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4],
|
int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4], uint32_t offset[4],
|
||||||
uint32_t offset[4], uint32_t *num_planes);
|
uint32_t *num_planes);
|
||||||
} // namespace gralloc1
|
|
||||||
|
} // namespace gralloc
|
||||||
|
|
||||||
#endif // __GR_UTILS_H__
|
#endif // __GR_UTILS_H__
|
||||||
|
|||||||
@@ -30,62 +30,45 @@ inline int roundUpToPageSize(int x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Gralloc usage bits indicating the type of allocation that should be used */
|
/* Gralloc usage bits indicating the type of allocation that should be used */
|
||||||
/* Refer gralloc1_producer_usage_t & gralloc1_consumer_usage-t in gralloc1.h */
|
/* Refer to BufferUsage in hardware/interfaces/graphics/common/<ver>/types.hal */
|
||||||
|
|
||||||
/* Producer flags */
|
/* The bits below are in officially defined vendor space
|
||||||
|
* i.e bits 28-31 and 48-63*/
|
||||||
/* Non linear, Universal Bandwidth Compression */
|
/* Non linear, Universal Bandwidth Compression */
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC1_PRODUCER_USAGE_PRIVATE_0
|
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC 1 << 28
|
||||||
|
|
||||||
/* Set this for allocating uncached memory (using O_DSYNC),
|
/* Set this for allocating uncached memory (using O_DSYNC),
|
||||||
* cannot be used with noncontiguous heaps */
|
* cannot be used with noncontiguous heaps */
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC1_PRODUCER_USAGE_PRIVATE_1
|
#define GRALLOC_USAGE_PRIVATE_UNCACHED 1 << 29
|
||||||
|
|
||||||
/* This flag is used to indicate P010 format */
|
/* This flag is used to indicate P010 format */
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT GRALLOC1_PRODUCER_USAGE_PRIVATE_2
|
#define GRALLOC_USAGE_PRIVATE_10BIT 1 << 30
|
||||||
|
|
||||||
/* ADSP heap is a carveout heap, is not secured */
|
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_3
|
|
||||||
|
|
||||||
/* IOMMU heap comes from manually allocated pages, can be cached/uncached, is not secured */
|
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_IOMMU_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_4
|
|
||||||
|
|
||||||
/* MM heap is a carveout heap for video, can be secured */
|
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_5
|
|
||||||
|
|
||||||
/* Use legacy ZSL definition until we know the correct usage on gralloc1 */
|
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_CAMERA_ZSL GRALLOC_USAGE_HW_CAMERA_ZSL
|
|
||||||
|
|
||||||
/* TODO(user): move these to use producer private bits once 64-bit support available */
|
|
||||||
/* This flag is used to indicate 10-bit tight pack format (e.g. TP10) */
|
|
||||||
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT_TP 0x08000000
|
|
||||||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT_TP 0x08000000
|
|
||||||
|
|
||||||
|
|
||||||
/* Consumer flags */
|
|
||||||
/* TODO(user): Fix when producer and consumer flags are actually separated */
|
|
||||||
/* This flag is set for WFD usecase */
|
|
||||||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD 0x00200000
|
|
||||||
|
|
||||||
/* This flag is used for SECURE display usecase */
|
/* This flag is used for SECURE display usecase */
|
||||||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY 0x02000000
|
#define GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY 1 << 31
|
||||||
|
|
||||||
/* This flag is used to indicate P010 format */
|
/* unused legacy flags */
|
||||||
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT
|
#define GRALLOC_USAGE_PRIVATE_MM_HEAP 0
|
||||||
|
#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP 0
|
||||||
|
|
||||||
/* Unused flag */
|
/* TODO(user): move these to use sanctioned vendor bits
|
||||||
#define GRALLOC1_USAGE_PRIVATE_UNUSED1 0x04000000
|
* once end to end 64-bit support is available */
|
||||||
|
/* This flag is set for WFD usecase */
|
||||||
|
#define GRALLOC_USAGE_PRIVATE_WFD 1 << 21
|
||||||
|
|
||||||
|
/* This flag is used to indicate 10-bit tight pack format (e.g. TP10) */
|
||||||
|
#define GRALLOC_USAGE_PRIVATE_10BIT_TP 1 << 27
|
||||||
|
|
||||||
/* Legacy gralloc0.x definitions */
|
/* Legacy gralloc1 definitions */
|
||||||
/* Some clients may still be using the old flags */
|
/* Some clients may still be using the old flags */
|
||||||
#define GRALLOC_USAGE_PRIVATE_ALLOC_UBWC GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ADSP_HEAP GRALLOC_USAGE_PRIVATE_ADSP_HEAP
|
||||||
#define GRALLOC_USAGE_PRIVATE_UNCACHED GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_ALLOC_UBWC GRALLOC_USAGE_PRIVATE_ALLOC_UBWC
|
||||||
#define GRALLOC_USAGE_PRIVATE_IOMMU_HEAP GRALLOC1_PRODUCER_USAGE_PRIVATE_IOMMU_HEAP
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_UNCACHED GRALLOC_USAGE_PRIVATE_UNCACHED
|
||||||
#define GRALLOC_USAGE_PRIVATE_WFD GRALLOC1_CONSUMER_USAGE_PRIVATE_WFD
|
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY
|
||||||
#define GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY GRALLOC1_CONSUMER_USAGE_PRIVATE_SECURE_DISPLAY
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_MM_HEAP GRALLOC_USAGE_PRIVATE_MM_HEAP
|
||||||
#define GRALLOC_USAGE_PRIVATE_MM_HEAP 0x0
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT GRALLOC_USAGE_PRIVATE_10BIT
|
||||||
|
#define GRALLOC1_PRODUCER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP
|
||||||
|
#define GRALLOC1_CONSUMER_USAGE_PRIVATE_10BIT_TP GRALLOC_USAGE_PRIVATE_10BIT_TP
|
||||||
|
|
||||||
// for PERFORM API :
|
// for PERFORM API :
|
||||||
#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1
|
#define GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER 1
|
||||||
|
|||||||
48
gralloc/service.cpp
Normal file
48
gralloc/service.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, The Linux Foundation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted 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 The Linux Foundation. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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.
|
||||||
|
*/
|
||||||
|
#include <binder/ProcessState.h>
|
||||||
|
#include <hidl/LegacySupport.h>
|
||||||
|
#include "QtiAllocator.h"
|
||||||
|
|
||||||
|
using android::hardware::configureRpcThreadpool;
|
||||||
|
using android::hardware::joinRpcThreadpool;
|
||||||
|
using vendor::qti::hardware::display::allocator::V1_0::IQtiAllocator;
|
||||||
|
using vendor::qti::hardware::display::allocator::V1_0::implementation::QtiAllocator;
|
||||||
|
|
||||||
|
int main(int, char **) {
|
||||||
|
android::sp<IQtiAllocator> service = new QtiAllocator();
|
||||||
|
configureRpcThreadpool(1, true /*callerWillJoin*/);
|
||||||
|
if (service->registerAsService() != android::OK) {
|
||||||
|
ALOGE("Cannot register QTI Allocator service");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
ALOGI("Initialized qti-allocator");
|
||||||
|
joinRpcThreadpool();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
service vendor.qti.hardware.display.allocator /vendor/bin/hw/vendor.qti.hardware.display.allocator@1.0-service
|
||||||
|
class hal animation
|
||||||
|
user system
|
||||||
|
group graphics drmrpc
|
||||||
|
capabilities SYS_NICE
|
||||||
|
onrestart restart surfaceflinger
|
||||||
@@ -17,9 +17,11 @@ LOCAL_CFLAGS := -Wno-missing-field-initializers -Wno-unused-par
|
|||||||
LOCAL_CLANG := true
|
LOCAL_CLANG := true
|
||||||
|
|
||||||
LOCAL_SHARED_LIBRARIES := libsdmcore libqservice libbinder libhardware libhardware_legacy \
|
LOCAL_SHARED_LIBRARIES := libsdmcore libqservice libbinder libhardware libhardware_legacy \
|
||||||
libutils libcutils libsync libqdutils libqdMetaData libdl \
|
libutils libcutils libsync libqdutils libqdMetaData \
|
||||||
libsdmutils libc++ liblog libgrallocutils libui libgpu_tonemapper \
|
libsdmutils libc++ liblog libgrallocutils libui libgpu_tonemapper \
|
||||||
libhidlbase libhidltransport vendor.display.config@1.0_vendor
|
libhidlbase libhidltransport vendor.display.config@1.0_vendor \
|
||||||
|
android.hardware.graphics.mapper@2.0\
|
||||||
|
android.hardware.graphics.allocator@2.0
|
||||||
|
|
||||||
ifeq ($(display_config_version), DISPLAY_CONFIG_1_1)
|
ifeq ($(display_config_version), DISPLAY_CONFIG_1_1)
|
||||||
LOCAL_SHARED_LIBRARIES += vendor.display.config@1.1_vendor
|
LOCAL_SHARED_LIBRARIES += vendor.display.config@1.1_vendor
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -33,75 +33,38 @@
|
|||||||
#include <utils/constants.h>
|
#include <utils/constants.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
|
|
||||||
|
#include "gr_utils.h"
|
||||||
#include "hwc_buffer_allocator.h"
|
#include "hwc_buffer_allocator.h"
|
||||||
#include "hwc_debugger.h"
|
#include "hwc_debugger.h"
|
||||||
#include "gr_utils.h"
|
|
||||||
|
|
||||||
#define __CLASS__ "HWCBufferAllocator"
|
#define __CLASS__ "HWCBufferAllocator"
|
||||||
|
|
||||||
|
using android::hardware::graphics::common::V1_0::PixelFormat;
|
||||||
|
using android::hardware::graphics::mapper::V2_0::BufferDescriptor;
|
||||||
|
using android::hardware::graphics::mapper::V2_0::Error;
|
||||||
|
using android::hardware::hidl_handle;
|
||||||
|
using android::hardware::hidl_vec;
|
||||||
|
|
||||||
namespace sdm {
|
namespace sdm {
|
||||||
|
|
||||||
DisplayError HWCBufferAllocator::Init() {
|
DisplayError HWCBufferAllocator::Init() {
|
||||||
int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module_);
|
allocator_ = IAllocator::getService();
|
||||||
if (err != 0) {
|
mapper_ = IMapper::getService();
|
||||||
DLOGE("FATAL: can not get GRALLOC module");
|
|
||||||
return kErrorResources;
|
if (mapper_ == nullptr || allocator_ == nullptr) {
|
||||||
|
DLOGE("Unable to get mapper or allocator");
|
||||||
|
return kErrorCriticalResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gralloc1_open(module_, &gralloc_device_);
|
|
||||||
if (err != 0) {
|
|
||||||
DLOGE("FATAL: can not open GRALLOC device");
|
|
||||||
return kErrorResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gralloc_device_ == nullptr) {
|
|
||||||
DLOGE("FATAL: gralloc device is null");
|
|
||||||
return kErrorResources;
|
|
||||||
}
|
|
||||||
|
|
||||||
CreateBufferDescriptor_ = reinterpret_cast<GRALLOC1_PFN_CREATE_DESCRIPTOR>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_CREATE_DESCRIPTOR));
|
|
||||||
DestroyBufferDescriptor_ = reinterpret_cast<GRALLOC1_PFN_DESTROY_DESCRIPTOR>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR));
|
|
||||||
AllocateBuffer_ = reinterpret_cast<GRALLOC1_PFN_ALLOCATE>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_ALLOCATE));
|
|
||||||
ReleaseBuffer_ = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE));
|
|
||||||
SetBufferDimensions_ = reinterpret_cast<GRALLOC1_PFN_SET_DIMENSIONS>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_SET_DIMENSIONS));
|
|
||||||
SetBufferFormat_ = reinterpret_cast<GRALLOC1_PFN_SET_FORMAT>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_SET_FORMAT));
|
|
||||||
SetConsumerUsage_ = reinterpret_cast<GRALLOC1_PFN_SET_CONSUMER_USAGE>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_SET_CONSUMER_USAGE));
|
|
||||||
SetProducerUsage_ = reinterpret_cast<GRALLOC1_PFN_SET_PRODUCER_USAGE>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_SET_PRODUCER_USAGE));
|
|
||||||
LockBuffer_ = reinterpret_cast<GRALLOC1_PFN_LOCK>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_LOCK));
|
|
||||||
UnlockBuffer_ = reinterpret_cast<GRALLOC1_PFN_UNLOCK>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_UNLOCK));
|
|
||||||
Perform_ = reinterpret_cast<GRALLOC1_PFN_PERFORM>(
|
|
||||||
gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM));
|
|
||||||
|
|
||||||
return kErrorNone;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayError HWCBufferAllocator::Deinit() {
|
DisplayError HWCBufferAllocator::Deinit() {
|
||||||
if (gralloc_device_ != nullptr) {
|
|
||||||
int err = gralloc1_close(gralloc_device_);
|
|
||||||
if (err != 0) {
|
|
||||||
DLOGE("FATAL: can not close GRALLOC device");
|
|
||||||
return kErrorResources;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return kErrorNone;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
|
DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
|
||||||
DisplayError sdm_err = kErrorNone;
|
|
||||||
const BufferConfig &buffer_config = buffer_info->buffer_config;
|
const BufferConfig &buffer_config = buffer_info->buffer_config;
|
||||||
AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info;
|
AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info;
|
||||||
uint32_t width = buffer_config.width;
|
|
||||||
uint32_t height = buffer_config.height;
|
|
||||||
int format;
|
int format;
|
||||||
uint64_t alloc_flags = 0;
|
uint64_t alloc_flags = 0;
|
||||||
int error = SetBufferInfo(buffer_config.format, &format, &alloc_flags);
|
int error = SetBufferInfo(buffer_config.format, &format, &alloc_flags);
|
||||||
@@ -110,11 +73,11 @@ DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_config.secure) {
|
if (buffer_config.secure) {
|
||||||
alloc_flags |= GRALLOC1_PRODUCER_USAGE_PROTECTED;
|
alloc_flags |= BufferUsage::PROTECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_config.secure_camera) {
|
if (buffer_config.secure_camera) {
|
||||||
alloc_flags |= GRALLOC1_PRODUCER_USAGE_CAMERA;
|
alloc_flags |= BufferUsage::CAMERA_OUTPUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buffer_config.cache) {
|
if (!buffer_config.cache) {
|
||||||
@@ -123,45 +86,51 @@ DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buffer_config.gfx_client) {
|
if (buffer_config.gfx_client) {
|
||||||
alloc_flags |= GRALLOC1_CONSUMER_USAGE_GPU_TEXTURE;
|
alloc_flags |= BufferUsage::GPU_TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gralloc1_producer_usage_t producer_usage = static_cast<gralloc1_producer_usage_t>(alloc_flags);
|
alloc_flags |= BufferUsage::COMPOSER_OVERLAY;
|
||||||
gralloc1_consumer_usage_t consumer_usage = static_cast<gralloc1_consumer_usage_t>(alloc_flags |
|
|
||||||
GRALLOC1_CONSUMER_USAGE_HWCOMPOSER);
|
IMapper::BufferDescriptorInfo descriptor_info;
|
||||||
gralloc1_buffer_descriptor_t descriptor_id = {};
|
descriptor_info.width = buffer_config.width;
|
||||||
buffer_handle_t buf = nullptr;
|
descriptor_info.height = buffer_config.height;
|
||||||
|
descriptor_info.layerCount = 1;
|
||||||
|
descriptor_info.format = static_cast<PixelFormat>(format);
|
||||||
|
descriptor_info.usage = alloc_flags;
|
||||||
|
auto descriptor = BufferDescriptor();
|
||||||
|
auto hidl_err = Error::NONE;
|
||||||
|
|
||||||
|
mapper_->createDescriptor(descriptor_info, [&](const auto &_error, const auto &_descriptor) {
|
||||||
|
hidl_err = _error;
|
||||||
|
descriptor = _descriptor;
|
||||||
|
});
|
||||||
|
if (hidl_err != Error::NONE) {
|
||||||
|
DLOGE("Failed to create descriptor");
|
||||||
|
return kErrorMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
hidl_handle raw_handle = nullptr;
|
||||||
private_handle_t *hnd = nullptr;
|
private_handle_t *hnd = nullptr;
|
||||||
|
|
||||||
// CreateBuffer
|
allocator_->allocate(descriptor, 1,
|
||||||
if (CreateBufferDescriptor_(gralloc_device_, &descriptor_id) != GRALLOC1_ERROR_NONE) {
|
[&](const auto &_error, const auto &_stride, const auto &_buffers) {
|
||||||
DLOGE("CreateBufferDescriptor failed gr_device=%p", gralloc_device_);
|
hidl_err = _error;
|
||||||
return kErrorParameters;
|
raw_handle = _buffers[0];
|
||||||
|
});
|
||||||
|
if (hidl_err != Error::NONE) {
|
||||||
|
DLOGE("Failed to allocate buffer");
|
||||||
|
return kErrorMemory;
|
||||||
}
|
}
|
||||||
if (SetBufferDimensions_(gralloc_device_, descriptor_id, width, height) != GRALLOC1_ERROR_NONE) {
|
|
||||||
DLOGE("SetBufferDimensions failed gr_device=%x desc=%d", gralloc_device_, descriptor_id);
|
const native_handle_t *buf = nullptr;
|
||||||
sdm_err = kErrorParameters;
|
mapper_->importBuffer(raw_handle, [&](const auto &_error, const auto &_buffer) {
|
||||||
goto CleanupOnError;
|
hidl_err = _error;
|
||||||
}
|
buf = static_cast<const native_handle_t *>(_buffer);
|
||||||
if (SetBufferFormat_(gralloc_device_, descriptor_id, format) != GRALLOC1_ERROR_NONE) {
|
});
|
||||||
DLOGE("SetBufferFormat failed gr_device=%x desc=%d", gralloc_device_, descriptor_id);
|
|
||||||
sdm_err = kErrorParameters;
|
if (hidl_err != Error::NONE) {
|
||||||
goto CleanupOnError;
|
DLOGE("Failed to import buffer into HWC");
|
||||||
}
|
return kErrorMemory;
|
||||||
if (SetConsumerUsage_(gralloc_device_, descriptor_id, consumer_usage) != GRALLOC1_ERROR_NONE) {
|
|
||||||
DLOGE("SetConsumerUsage failed gr_device=%x desc=%d", gralloc_device_, descriptor_id);
|
|
||||||
sdm_err = kErrorParameters;
|
|
||||||
goto CleanupOnError;
|
|
||||||
}
|
|
||||||
if (SetProducerUsage_(gralloc_device_, descriptor_id, producer_usage) != GRALLOC1_ERROR_NONE) {
|
|
||||||
DLOGE("SetProducerUsage failed gr_device=%x desc=%d", gralloc_device_, descriptor_id);
|
|
||||||
sdm_err = kErrorParameters;
|
|
||||||
goto CleanupOnError;
|
|
||||||
}
|
|
||||||
if (AllocateBuffer_(gralloc_device_, 1, &descriptor_id, &buf) != GRALLOC1_ERROR_NONE) {
|
|
||||||
DLOGE("AllocateBuffer failed gr_device=%x desc=%d", gralloc_device_, descriptor_id);
|
|
||||||
sdm_err = kErrorMemory;
|
|
||||||
goto CleanupOnError;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hnd = (private_handle_t *)buf; // NOLINT
|
hnd = (private_handle_t *)buf; // NOLINT
|
||||||
@@ -172,45 +141,45 @@ DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) {
|
|||||||
alloc_buffer_info->size = hnd->size;
|
alloc_buffer_info->size = hnd->size;
|
||||||
|
|
||||||
buffer_info->private_data = reinterpret_cast<void *>(hnd);
|
buffer_info->private_data = reinterpret_cast<void *>(hnd);
|
||||||
CleanupOnError:
|
return kErrorNone;
|
||||||
DestroyBufferDescriptor_(gralloc_device_, descriptor_id);
|
|
||||||
return sdm_err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayError HWCBufferAllocator::FreeBuffer(BufferInfo *buffer_info) {
|
DisplayError HWCBufferAllocator::FreeBuffer(BufferInfo *buffer_info) {
|
||||||
DisplayError err = kErrorNone;
|
DisplayError err = kErrorNone;
|
||||||
buffer_handle_t hnd = static_cast<buffer_handle_t>(buffer_info->private_data);
|
auto hnd = reinterpret_cast<void *>(buffer_info->private_data);
|
||||||
ReleaseBuffer_(gralloc_device_, hnd);
|
mapper_->freeBuffer(hnd);
|
||||||
AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info;
|
AllocatedBufferInfo &alloc_buffer_info = buffer_info->alloc_buffer_info;
|
||||||
|
|
||||||
alloc_buffer_info->fd = -1;
|
alloc_buffer_info.fd = -1;
|
||||||
alloc_buffer_info->stride = 0;
|
alloc_buffer_info.stride = 0;
|
||||||
alloc_buffer_info->size = 0;
|
alloc_buffer_info.size = 0;
|
||||||
buffer_info->private_data = NULL;
|
buffer_info->private_data = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWCBufferAllocator::GetCustomWidthAndHeight(const private_handle_t *handle, int *width,
|
void HWCBufferAllocator::GetCustomWidthAndHeight(const private_handle_t *handle, int *width,
|
||||||
int *height) {
|
int *height) {
|
||||||
Perform_(gralloc_device_, GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE, handle,
|
*width = handle->width;
|
||||||
width, height);
|
*height = handle->height;
|
||||||
|
gralloc::GetCustomDimensions(const_cast<private_handle_t *>(handle), width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWCBufferAllocator::GetAlignedWidthAndHeight(int width, int height, int format,
|
void HWCBufferAllocator::GetAlignedWidthAndHeight(int width, int height, int format,
|
||||||
uint32_t alloc_type, int *aligned_width,
|
uint32_t alloc_type, int *aligned_width,
|
||||||
int *aligned_height) {
|
int *aligned_height) {
|
||||||
int tile_enabled;
|
uint64_t usage = 0;
|
||||||
gralloc1_producer_usage_t producer_usage = GRALLOC1_PRODUCER_USAGE_NONE;
|
|
||||||
gralloc1_consumer_usage_t consumer_usage = GRALLOC1_CONSUMER_USAGE_NONE;
|
|
||||||
if (alloc_type & GRALLOC_USAGE_HW_FB) {
|
if (alloc_type & GRALLOC_USAGE_HW_FB) {
|
||||||
consumer_usage = GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET;
|
usage |= BufferUsage::COMPOSER_CLIENT_TARGET;
|
||||||
}
|
}
|
||||||
if (alloc_type & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) {
|
if (alloc_type & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) {
|
||||||
producer_usage = GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
|
usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
|
||||||
}
|
}
|
||||||
|
uint32_t aligned_w = UINT(width);
|
||||||
Perform_(gralloc_device_, GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES, width, height, format,
|
uint32_t aligned_h = UINT(height);
|
||||||
producer_usage, consumer_usage, aligned_width, aligned_height, &tile_enabled);
|
gralloc::BufferInfo info(width, height, format, usage);
|
||||||
|
gralloc::GetAlignedWidthAndHeight(info, &aligned_w, &aligned_h);
|
||||||
|
*aligned_width = INT(aligned_w);
|
||||||
|
*aligned_height = INT(aligned_h);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t HWCBufferAllocator::GetBufferSize(BufferInfo *buffer_info) {
|
uint32_t HWCBufferAllocator::GetBufferSize(BufferInfo *buffer_info) {
|
||||||
@@ -235,12 +204,7 @@ uint32_t HWCBufferAllocator::GetBufferSize(BufferInfo *buffer_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0;
|
uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0;
|
||||||
gralloc1_producer_usage_t producer_usage = GRALLOC1_PRODUCER_USAGE_NONE;
|
gralloc::BufferInfo info(width, height, format, alloc_flags);
|
||||||
gralloc1_consumer_usage_t consumer_usage = GRALLOC1_CONSUMER_USAGE_NONE;
|
|
||||||
// TODO(user): Currently both flags are treated similarly in gralloc
|
|
||||||
producer_usage = gralloc1_producer_usage_t(alloc_flags);
|
|
||||||
consumer_usage = gralloc1_consumer_usage_t(alloc_flags);
|
|
||||||
gralloc1::BufferInfo info(width, height, format, producer_usage, consumer_usage);
|
|
||||||
GetBufferSizeAndDimensions(info, &buffer_size, &aligned_width, &aligned_height);
|
GetBufferSizeAndDimensions(info, &buffer_size, &aligned_width, &aligned_height);
|
||||||
return buffer_size;
|
return buffer_size;
|
||||||
}
|
}
|
||||||
@@ -391,12 +355,7 @@ DisplayError HWCBufferAllocator::GetAllocatedBufferInfo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0;
|
uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0;
|
||||||
gralloc1_producer_usage_t producer_usage = GRALLOC1_PRODUCER_USAGE_NONE;
|
gralloc::BufferInfo info(width, height, format, alloc_flags);
|
||||||
gralloc1_consumer_usage_t consumer_usage = GRALLOC1_CONSUMER_USAGE_NONE;
|
|
||||||
// TODO(user): Currently both flags are treated similarly in gralloc
|
|
||||||
producer_usage = gralloc1_producer_usage_t(alloc_flags);
|
|
||||||
consumer_usage = gralloc1_consumer_usage_t(alloc_flags);
|
|
||||||
gralloc1::BufferInfo info(width, height, format, producer_usage, consumer_usage);
|
|
||||||
GetBufferSizeAndDimensions(info, &buffer_size, &aligned_width, &aligned_height);
|
GetBufferSizeAndDimensions(info, &buffer_size, &aligned_width, &aligned_height);
|
||||||
allocated_buffer_info->stride = UINT32(aligned_width);
|
allocated_buffer_info->stride = UINT32(aligned_width);
|
||||||
allocated_buffer_info->aligned_width = UINT32(aligned_width);
|
allocated_buffer_info->aligned_width = UINT32(aligned_width);
|
||||||
@@ -423,7 +382,7 @@ DisplayError HWCBufferAllocator::GetBufferLayout(const AllocatedBufferInfo &buf_
|
|||||||
hnd.flags = private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
hnd.flags = private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = gralloc1::GetBufferLayout(&hnd, stride, offset, num_planes);
|
int ret = gralloc::GetBufferLayout(&hnd, stride, offset, num_planes);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
DLOGE("GetBufferLayout failed");
|
DLOGE("GetBufferLayout failed");
|
||||||
return kErrorParameters;
|
return kErrorParameters;
|
||||||
@@ -434,23 +393,41 @@ DisplayError HWCBufferAllocator::GetBufferLayout(const AllocatedBufferInfo &buf_
|
|||||||
|
|
||||||
DisplayError HWCBufferAllocator::MapBuffer(const private_handle_t *handle, int acquire_fence) {
|
DisplayError HWCBufferAllocator::MapBuffer(const private_handle_t *handle, int acquire_fence) {
|
||||||
void *buffer_ptr = NULL;
|
void *buffer_ptr = NULL;
|
||||||
const gralloc1_rect_t accessRegion = {
|
const IMapper::Rect access_region = {.left = 0, .top = 0, .width = 0, .height = 0};
|
||||||
.left = 0,
|
|
||||||
.top = 0,
|
NATIVE_HANDLE_DECLARE_STORAGE(acquire_fence_storage, 1, 0);
|
||||||
.width = 0,
|
hidl_handle acquire_fence_handle;
|
||||||
.height = 0
|
if (acquire_fence >= 0) {
|
||||||
};
|
auto h = native_handle_init(acquire_fence_storage, 1, 0);
|
||||||
LockBuffer_(gralloc_device_, handle, GRALLOC1_PRODUCER_USAGE_CPU_READ,
|
h->data[0] = acquire_fence;
|
||||||
GRALLOC1_CONSUMER_USAGE_NONE, &accessRegion, &buffer_ptr, acquire_fence);
|
acquire_fence_handle = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hnd = const_cast<private_handle_t *>(handle);
|
||||||
|
mapper_->lock(reinterpret_cast<void *>(hnd), (uint64_t)BufferUsage::CPU_READ_OFTEN,
|
||||||
|
access_region, acquire_fence_handle, [&](const auto &_error, const auto &_buffer) {
|
||||||
|
if (_error == Error::NONE) {
|
||||||
|
buffer_ptr = _buffer;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!buffer_ptr) {
|
if (!buffer_ptr) {
|
||||||
return kErrorUndefined;
|
return kErrorUndefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return kErrorNone;
|
return kErrorNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayError HWCBufferAllocator::UnmapBuffer(const private_handle_t *handle, int *release_fence) {
|
DisplayError HWCBufferAllocator::UnmapBuffer(const private_handle_t *handle, int *release_fence) {
|
||||||
return (DisplayError)(UnlockBuffer_(gralloc_device_, handle, release_fence));
|
DisplayError err = kErrorNone;
|
||||||
|
*release_fence = -1;
|
||||||
|
auto hnd = const_cast<private_handle_t *>(handle);
|
||||||
|
mapper_->unlock(reinterpret_cast<void *>(hnd),
|
||||||
|
[&](const auto &_error, const auto &_release_fence) {
|
||||||
|
if (_error != Error::NONE) {
|
||||||
|
err = kErrorUndefined;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sdm
|
} // namespace sdm
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -26,16 +26,19 @@
|
|||||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
||||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
#ifdef USE_GRALLOC1
|
|
||||||
#ifndef __HWC_BUFFER_ALLOCATOR_H__
|
#ifndef __HWC_BUFFER_ALLOCATOR_H__
|
||||||
#define __HWC_BUFFER_ALLOCATOR_H__
|
#define __HWC_BUFFER_ALLOCATOR_H__
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
#include <hardware/gralloc1.h>
|
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
|
||||||
|
#include <android/hardware/graphics/mapper/2.0/IMapper.h>
|
||||||
#include "gralloc_priv.h"
|
#include "gralloc_priv.h"
|
||||||
|
|
||||||
|
using android::hardware::graphics::allocator::V2_0::IAllocator;
|
||||||
|
using android::hardware::graphics::mapper::V2_0::IMapper;
|
||||||
|
|
||||||
namespace sdm {
|
namespace sdm {
|
||||||
|
|
||||||
template <class Type>
|
template <class Type>
|
||||||
@@ -56,32 +59,16 @@ class HWCBufferAllocator : public BufferAllocator {
|
|||||||
int *aligned_width, int *aligned_height);
|
int *aligned_width, int *aligned_height);
|
||||||
DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config,
|
DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config,
|
||||||
AllocatedBufferInfo *allocated_buffer_info);
|
AllocatedBufferInfo *allocated_buffer_info);
|
||||||
DisplayError GetBufferLayout(const AllocatedBufferInfo &buf_info,
|
DisplayError GetBufferLayout(const AllocatedBufferInfo &buf_info, uint32_t stride[4],
|
||||||
uint32_t stride[4], uint32_t offset[4],
|
uint32_t offset[4], uint32_t *num_planes);
|
||||||
uint32_t *num_planes);
|
|
||||||
int SetBufferInfo(LayerBufferFormat format, int *target, uint64_t *flags);
|
int SetBufferInfo(LayerBufferFormat format, int *target, uint64_t *flags);
|
||||||
DisplayError MapBuffer(const private_handle_t *handle, int acquire_fence);
|
DisplayError MapBuffer(const private_handle_t *handle, int acquire_fence);
|
||||||
DisplayError UnmapBuffer(const private_handle_t *handle, int *release_fence);
|
DisplayError UnmapBuffer(const private_handle_t *handle, int *release_fence);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
gralloc1_device_t *gralloc_device_ = nullptr;
|
android::sp<IMapper> mapper_;
|
||||||
const hw_module_t *module_ = nullptr;
|
android::sp<IAllocator> allocator_;
|
||||||
GRALLOC1_PFN_CREATE_DESCRIPTOR CreateBufferDescriptor_ = nullptr;
|
|
||||||
GRALLOC1_PFN_DESTROY_DESCRIPTOR DestroyBufferDescriptor_ = nullptr;
|
|
||||||
GRALLOC1_PFN_ALLOCATE AllocateBuffer_ = nullptr;
|
|
||||||
GRALLOC1_PFN_RELEASE ReleaseBuffer_ = nullptr;
|
|
||||||
GRALLOC1_PFN_SET_DIMENSIONS SetBufferDimensions_ = nullptr;
|
|
||||||
GRALLOC1_PFN_SET_FORMAT SetBufferFormat_ = nullptr;
|
|
||||||
GRALLOC1_PFN_SET_CONSUMER_USAGE SetConsumerUsage_ = nullptr;
|
|
||||||
GRALLOC1_PFN_SET_PRODUCER_USAGE SetProducerUsage_ = nullptr;
|
|
||||||
GRALLOC1_PFN_LOCK LockBuffer_ = nullptr;
|
|
||||||
GRALLOC1_PFN_UNLOCK UnlockBuffer_ = nullptr;
|
|
||||||
GRALLOC1_PFN_PERFORM Perform_ = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sdm
|
} // namespace sdm
|
||||||
#endif // __HWC_BUFFER_ALLOCATOR_H__
|
#endif // __HWC_BUFFER_ALLOCATOR_H__
|
||||||
#else
|
|
||||||
#include "../hwc/hwc_buffer_allocator.h"
|
|
||||||
#endif // __HWC_BUFFER_ALLOCATOR_H__
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution.
|
* Not a Contribution.
|
||||||
*
|
*
|
||||||
* Copyright 2015 The Android Open Source Project
|
* Copyright 2015 The Android Open Source Project
|
||||||
@@ -42,10 +42,6 @@
|
|||||||
#include "hwc_tonemapper.h"
|
#include "hwc_tonemapper.h"
|
||||||
#include "hwc_session.h"
|
#include "hwc_session.h"
|
||||||
|
|
||||||
#ifndef USE_GRALLOC1
|
|
||||||
#include <gr.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef QTI_BSP
|
#ifdef QTI_BSP
|
||||||
#include <hardware/display_defs.h>
|
#include <hardware/display_defs.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -521,11 +517,7 @@ void HWCDisplay::BuildLayerStack() {
|
|||||||
const private_handle_t *handle =
|
const private_handle_t *handle =
|
||||||
reinterpret_cast<const private_handle_t *>(layer->input_buffer.buffer_id);
|
reinterpret_cast<const private_handle_t *>(layer->input_buffer.buffer_id);
|
||||||
if (handle) {
|
if (handle) {
|
||||||
#ifdef USE_GRALLOC1
|
|
||||||
if (handle->buffer_type == BUFFER_TYPE_VIDEO) {
|
if (handle->buffer_type == BUFFER_TYPE_VIDEO) {
|
||||||
#else
|
|
||||||
if (handle->bufferType == BUFFER_TYPE_VIDEO) {
|
|
||||||
#endif
|
|
||||||
layer_stack_.flags.video_present = true;
|
layer_stack_.flags.video_present = true;
|
||||||
}
|
}
|
||||||
// TZ Protected Buffer - L1
|
// TZ Protected Buffer - L1
|
||||||
@@ -1683,13 +1675,8 @@ int HWCDisplay::SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels) {
|
|||||||
flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_GRALLOC1
|
|
||||||
buffer_allocator_->GetAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format, usage,
|
buffer_allocator_->GetAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format, usage,
|
||||||
&aligned_width, &aligned_height);
|
&aligned_width, &aligned_height);
|
||||||
#else
|
|
||||||
AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format,
|
|
||||||
INT(usage), aligned_width, aligned_height);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// TODO(user): How does the dirty region get set on the client target? File bug on Google
|
// TODO(user): How does the dirty region get set on the client target? File bug on Google
|
||||||
client_target_layer->composition = kCompositionGPUTarget;
|
client_target_layer->composition = kCompositionGPUTarget;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are
|
* modification, are permitted provided that the following conditions are
|
||||||
@@ -31,9 +31,6 @@
|
|||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
#include <sync/sync.h>
|
#include <sync/sync.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#ifndef USE_GRALLOC1
|
|
||||||
#include <gr.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "hwc_display_virtual.h"
|
#include "hwc_display_virtual.h"
|
||||||
#include "hwc_debugger.h"
|
#include "hwc_debugger.h"
|
||||||
|
|||||||
@@ -17,16 +17,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "hwc_layers.h"
|
||||||
|
#include <utils/debug.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <qdMetaData.h>
|
|
||||||
|
|
||||||
#include "hwc_layers.h"
|
|
||||||
#ifndef USE_GRALLOC1
|
|
||||||
#include <gr.h>
|
|
||||||
#endif
|
|
||||||
#include <utils/debug.h>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <qdMetaData.h>
|
||||||
|
|
||||||
#define __CLASS__ "HWCLayer"
|
#define __CLASS__ "HWCLayer"
|
||||||
|
|
||||||
@@ -220,11 +216,7 @@ HWC2::Error HWCLayer::SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fen
|
|||||||
|
|
||||||
LayerBuffer *layer_buffer = &layer_->input_buffer;
|
LayerBuffer *layer_buffer = &layer_->input_buffer;
|
||||||
int aligned_width, aligned_height;
|
int aligned_width, aligned_height;
|
||||||
#ifdef USE_GRALLOC1
|
|
||||||
buffer_allocator_->GetCustomWidthAndHeight(handle, &aligned_width, &aligned_height);
|
buffer_allocator_->GetCustomWidthAndHeight(handle, &aligned_width, &aligned_height);
|
||||||
#else
|
|
||||||
AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(handle, aligned_width, aligned_height);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LayerBufferFormat format = GetSDMFormat(handle->format, handle->flags);
|
LayerBufferFormat format = GetSDMFormat(handle->format, handle->flags);
|
||||||
if ((format != layer_buffer->format) || (UINT32(aligned_width) != layer_buffer->width) ||
|
if ((format != layer_buffer->format) || (UINT32(aligned_width) != layer_buffer->width) ||
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
|
* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
|
||||||
* Not a Contribution.
|
* Not a Contribution.
|
||||||
*
|
*
|
||||||
* Copyright 2015 The Android Open Source Project
|
* Copyright 2015 The Android Open Source Project
|
||||||
@@ -162,7 +162,7 @@ int HWCSession::Init() {
|
|||||||
|
|
||||||
DisplayError error = buffer_allocator_.Init();
|
DisplayError error = buffer_allocator_.Init();
|
||||||
if (error != kErrorNone) {
|
if (error != kErrorNone) {
|
||||||
ALOGE("%s::%s: Buffer allocaor initialization failed. Error = %d",
|
ALOGE("%s::%s: Buffer allocator initialization failed. Error = %d",
|
||||||
__CLASS__, __FUNCTION__, error);
|
__CLASS__, __FUNCTION__, error);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user