From 6457d5b6b5201fc37f9c9b01b1f4102f338a2fdf Mon Sep 17 00:00:00 2001 From: Naseer Ahmed Date: Fri, 27 Jan 2017 17:32:21 -0500 Subject: [PATCH] sdm: enable gralloc1 from hwc2 Add support for hwc2 to call into gralloc1 CRs-Fixed: 2007392 Change-Id: Iade3b7cba7d3b99685530a8f4dcde67228e78f68 --- msm8996/common.mk | 13 +- msm8996/sdm/libs/hwc2/Android.mk | 8 +- .../sdm/libs/hwc2/hwc_buffer_allocator.cpp | 313 ++++++++++++++++++ msm8996/sdm/libs/hwc2/hwc_buffer_allocator.h | 74 +++++ msm8996/sdm/libs/hwc2/hwc_display.cpp | 49 ++- msm8996/sdm/libs/hwc2/hwc_display.h | 3 +- msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp | 19 +- msm8996/sdm/libs/hwc2/hwc_layers.cpp | 19 +- msm8996/sdm/libs/hwc2/hwc_layers.h | 9 +- msm8996/sdm/libs/hwc2/hwc_session.cpp | 4 +- 10 files changed, 466 insertions(+), 45 deletions(-) create mode 100644 msm8996/sdm/libs/hwc2/hwc_buffer_allocator.cpp create mode 100644 msm8996/sdm/libs/hwc2/hwc_buffer_allocator.h diff --git a/msm8996/common.mk b/msm8996/common.mk index 4dba5c07..1dd17eb4 100644 --- a/msm8996/common.mk +++ b/msm8996/common.mk @@ -19,7 +19,18 @@ common_libs := liblog libutils libcutils libhardware #Common C flags common_flags := -DDEBUG_CALC_FPS -Wno-missing-field-initializers common_flags += -Wconversion -Wall -Werror -common_flags += -isystem $(display_top)/libgralloc +ifeq ($(TARGET_IS_HEADLESS), true) + LOCAL_CLANG := false +else + LOCAL_CLANG := true +endif + +ifneq ($(TARGET_USES_GRALLOC1), true) + common_flags += -isystem $(display_top)/libgralloc +else + common_flags += -isystem $(display_top)/libgralloc1 + common_flags += -DUSE_GRALLOC1 +endif ifeq ($(TARGET_USES_POST_PROCESSING),true) common_flags += -DUSES_POST_PROCESSING diff --git a/msm8996/sdm/libs/hwc2/Android.mk b/msm8996/sdm/libs/hwc2/Android.mk index d9dc1087..ce63c48d 100644 --- a/msm8996/sdm/libs/hwc2/Android.mk +++ b/msm8996/sdm/libs/hwc2/Android.mk @@ -30,13 +30,17 @@ LOCAL_SRC_FILES := hwc_session.cpp \ hwc_display_external.cpp \ hwc_display_virtual.cpp \ ../hwc/hwc_debugger.cpp \ - ../hwc/hwc_buffer_allocator.cpp \ ../hwc/hwc_buffer_sync_handler.cpp \ hwc_color_manager.cpp \ hwc_layers.cpp \ hwc_callbacks.cpp \ - ../hwc/blit_engine_c2d.cpp \ ../hwc/cpuhint.cpp +ifneq ($(TARGET_USES_GRALLOC1), true) + LOCAL_SRC_FILES += ../hwc/hwc_buffer_allocator.cpp +else + LOCAL_SRC_FILES += hwc_buffer_allocator.cpp +endif + include $(BUILD_SHARED_LIBRARY) endif diff --git a/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.cpp b/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.cpp new file mode 100644 index 00000000..987cb51c --- /dev/null +++ b/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.cpp @@ -0,0 +1,313 @@ +/* +* Copyright (c) 2015-2017, 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 + +#include +#include +#include + +#include "hwc_buffer_allocator.h" +#include "hwc_debugger.h" + +#define __CLASS__ "HWCBufferAllocator" +namespace sdm { + +HWCBufferAllocator::HWCBufferAllocator() { + int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module_); + if (err != 0) { + DLOGE("FATAL: can not open GRALLOC module"); + } else { + gralloc1_open(module_, &gralloc_device_); + } + ReleaseBuffer_ = reinterpret_cast( + gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_RELEASE)); + Perform_ = reinterpret_cast( + gralloc_device_->getFunction(gralloc_device_, GRALLOC1_FUNCTION_PERFORM)); +} + +HWCBufferAllocator::~HWCBufferAllocator() { + if (gralloc_device_ != nullptr) { + gralloc1_close(gralloc_device_); + } +} + +DisplayError HWCBufferAllocator::AllocateBuffer(BufferInfo *buffer_info) { + const BufferConfig &buffer_config = buffer_info->buffer_config; + AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info; + uint32_t width = buffer_config.width; + uint32_t height = buffer_config.height; + int format; + int alloc_flags = 0; + int error = SetBufferInfo(buffer_config.format, &format, &alloc_flags); + if (error != 0) { + return kErrorParameters; + } + + if (buffer_config.secure) { + alloc_flags |= GRALLOC1_PRODUCER_USAGE_PROTECTED; + } + + if (!buffer_config.cache) { + // Allocate uncached buffers + alloc_flags |= GRALLOC_USAGE_PRIVATE_UNCACHED; + } + uint64_t producer_usage = UINT64(alloc_flags); + uint64_t consumer_usage = UINT64(alloc_flags); + // CreateBuffer + private_handle_t *hnd = nullptr; + Perform_(gralloc_device_, GRALLOC1_MODULE_PERFORM_ALLOCATE_BUFFER, width, height, format, + producer_usage, consumer_usage, &hnd); + + if (hnd) { + alloc_buffer_info->fd = hnd->fd; + alloc_buffer_info->stride = UINT32(hnd->width); + alloc_buffer_info->size = hnd->size; + } else { + DLOGE("Failed to allocate memory"); + return kErrorMemory; + } + + buffer_info->private_data = reinterpret_cast(hnd); + return kErrorNone; +} + +DisplayError HWCBufferAllocator::FreeBuffer(BufferInfo *buffer_info) { + DisplayError err = kErrorNone; + buffer_handle_t hnd = static_cast(buffer_info->private_data); + ReleaseBuffer_(gralloc_device_, hnd); + AllocatedBufferInfo *alloc_buffer_info = &buffer_info->alloc_buffer_info; + alloc_buffer_info->fd = -1; + alloc_buffer_info->stride = 0; + alloc_buffer_info->size = 0; + // Works around b/36355756 + if (hnd != nullptr) { + delete hnd; + } + buffer_info->private_data = NULL; + return err; +} + +void HWCBufferAllocator::GetCustomWidthAndHeight(const private_handle_t *handle, int *width, + int *height) { + Perform_(gralloc_device_, GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE, handle, + width, height); +} + +void HWCBufferAllocator::GetAlignedWidthAndHeight(int width, int height, int format, + uint32_t alloc_type, int *aligned_width, + int *aligned_height) { + int tile_enabled; + 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) { + consumer_usage = GRALLOC1_CONSUMER_USAGE_CLIENT_TARGET; + } + + Perform_(gralloc_device_, GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES, width, height, format, + producer_usage, consumer_usage, aligned_width, aligned_height, &tile_enabled); +} + +uint32_t HWCBufferAllocator::GetBufferSize(BufferInfo *buffer_info) { + const BufferConfig &buffer_config = buffer_info->buffer_config; + int alloc_flags = INT(GRALLOC_USAGE_PRIVATE_IOMMU_HEAP); + + int width = INT(buffer_config.width); + int height = INT(buffer_config.height); + int format; + + if (buffer_config.secure) { + alloc_flags |= INT(GRALLOC_USAGE_PROTECTED); + } + + if (!buffer_config.cache) { + // Allocate uncached buffers + alloc_flags |= GRALLOC_USAGE_PRIVATE_UNCACHED; + } + + if (SetBufferInfo(buffer_config.format, &format, &alloc_flags) < 0) { + return 0; + } + + uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0; + uint64_t producer_usage = GRALLOC1_PRODUCER_USAGE_NONE; + uint64_t consumer_usage = GRALLOC1_CONSUMER_USAGE_NONE; + // TODO(user): Currently both flags are treated similarly in gralloc + producer_usage = UINT64(alloc_flags); + consumer_usage = producer_usage; + Perform_(gralloc_device_, GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS, width, height, + format, producer_usage, consumer_usage, &aligned_width, &aligned_height, &buffer_size); + return buffer_size; +} + +int HWCBufferAllocator::SetBufferInfo(LayerBufferFormat format, int *target, int *flags) { + switch (format) { + case kFormatRGBA8888: + *target = HAL_PIXEL_FORMAT_RGBA_8888; + break; + case kFormatRGBX8888: + *target = HAL_PIXEL_FORMAT_RGBX_8888; + break; + case kFormatRGB888: + *target = HAL_PIXEL_FORMAT_RGB_888; + break; + case kFormatRGB565: + *target = HAL_PIXEL_FORMAT_RGB_565; + break; + case kFormatBGR565: + *target = HAL_PIXEL_FORMAT_BGR_565; + break; + case kFormatBGRA8888: + *target = HAL_PIXEL_FORMAT_BGRA_8888; + break; + case kFormatYCrCb420PlanarStride16: + *target = HAL_PIXEL_FORMAT_YV12; + break; + case kFormatYCrCb420SemiPlanar: + *target = HAL_PIXEL_FORMAT_YCrCb_420_SP; + break; + case kFormatYCbCr420SemiPlanar: + *target = HAL_PIXEL_FORMAT_YCbCr_420_SP; + break; + case kFormatYCbCr422H2V1Packed: + *target = HAL_PIXEL_FORMAT_YCbCr_422_I; + break; + case kFormatYCbCr422H2V1SemiPlanar: + *target = HAL_PIXEL_FORMAT_YCbCr_422_SP; + break; + case kFormatYCbCr420SemiPlanarVenus: + *target = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; + break; + case kFormatYCrCb420SemiPlanarVenus: + *target = HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS; + break; + case kFormatYCbCr420SPVenusUbwc: + *target = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC; + break; + case kFormatRGBA5551: + *target = HAL_PIXEL_FORMAT_RGBA_5551; + break; + case kFormatRGBA4444: + *target = HAL_PIXEL_FORMAT_RGBA_4444; + break; + case kFormatRGBA1010102: + *target = HAL_PIXEL_FORMAT_RGBA_1010102; + break; + case kFormatARGB2101010: + *target = HAL_PIXEL_FORMAT_ARGB_2101010; + break; + case kFormatRGBX1010102: + *target = HAL_PIXEL_FORMAT_RGBX_1010102; + break; + case kFormatXRGB2101010: + *target = HAL_PIXEL_FORMAT_XRGB_2101010; + break; + case kFormatBGRA1010102: + *target = HAL_PIXEL_FORMAT_BGRA_1010102; + break; + case kFormatABGR2101010: + *target = HAL_PIXEL_FORMAT_ABGR_2101010; + break; + case kFormatBGRX1010102: + *target = HAL_PIXEL_FORMAT_BGRX_1010102; + break; + case kFormatXBGR2101010: + *target = HAL_PIXEL_FORMAT_XBGR_2101010; + break; + case kFormatYCbCr420P010: + *target = HAL_PIXEL_FORMAT_YCbCr_420_P010; + break; + case kFormatYCbCr420TP10Ubwc: + *target = HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC; + break; + case kFormatRGBA8888Ubwc: + *target = HAL_PIXEL_FORMAT_RGBA_8888; + *flags |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; + break; + case kFormatRGBX8888Ubwc: + *target = HAL_PIXEL_FORMAT_RGBX_8888; + *flags |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; + break; + case kFormatBGR565Ubwc: + *target = HAL_PIXEL_FORMAT_BGR_565; + *flags |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; + break; + case kFormatRGBA1010102Ubwc: + *target = HAL_PIXEL_FORMAT_RGBA_1010102; + *flags |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; + break; + case kFormatRGBX1010102Ubwc: + *target = HAL_PIXEL_FORMAT_RGBX_1010102; + *flags |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; + break; + default: + DLOGE("Unsupported format = 0x%x", format); + return -EINVAL; + } + return 0; +} + +DisplayError HWCBufferAllocator::GetAllocatedBufferInfo( + const BufferConfig &buffer_config, AllocatedBufferInfo *allocated_buffer_info) { + // TODO(user): This API should pass the buffer_info of the already allocated buffer + // The private_data can then be typecast to the private_handle and used directly. + int alloc_flags = INT(GRALLOC_USAGE_PRIVATE_IOMMU_HEAP); + + int width = INT(buffer_config.width); + int height = INT(buffer_config.height); + int format; + + if (buffer_config.secure) { + alloc_flags |= INT(GRALLOC_USAGE_PROTECTED); + } + + if (!buffer_config.cache) { + // Allocate uncached buffers + alloc_flags |= GRALLOC_USAGE_PRIVATE_UNCACHED; + } + + if (SetBufferInfo(buffer_config.format, &format, &alloc_flags) < 0) { + return kErrorParameters; + } + + uint32_t aligned_width = 0, aligned_height = 0, buffer_size = 0; + uint64_t producer_usage = GRALLOC1_PRODUCER_USAGE_NONE; + uint64_t consumer_usage = GRALLOC1_CONSUMER_USAGE_NONE; + // TODO(user): Currently both flags are treated similarly in gralloc + producer_usage = UINT64(alloc_flags); + consumer_usage = producer_usage; + Perform_(gralloc_device_, GRALLOC1_MODULE_PERFORM_GET_BUFFER_SIZE_AND_DIMENSIONS, width, height, + format, producer_usage, consumer_usage, &aligned_width, &aligned_height, &buffer_size); + allocated_buffer_info->stride = UINT32(aligned_width); + allocated_buffer_info->size = UINT32(buffer_size); + + return kErrorNone; +} + +} // namespace sdm diff --git a/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.h b/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.h new file mode 100644 index 00000000..c28a94ef --- /dev/null +++ b/msm8996/sdm/libs/hwc2/hwc_buffer_allocator.h @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2015-2017, 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. +*/ +#ifdef USE_GRALLOC1 +#ifndef __HWC_BUFFER_ALLOCATOR_H__ +#define __HWC_BUFFER_ALLOCATOR_H__ + +#include +#include + +#include +#include "gralloc_priv.h" + +namespace sdm { + +template +inline Type ALIGN(Type x, Type align) { + return (x + align - 1) & ~(align - 1); +} + +class HWCBufferAllocator : public BufferAllocator { + public: + HWCBufferAllocator(); + ~HWCBufferAllocator(); + + DisplayError AllocateBuffer(BufferInfo *buffer_info); + DisplayError FreeBuffer(BufferInfo *buffer_info); + uint32_t GetBufferSize(BufferInfo *buffer_info); + + void GetCustomWidthAndHeight(const private_handle_t *handle, int *width, int *height); + void GetAlignedWidthAndHeight(int width, int height, int format, uint32_t alloc_type, + int *aligned_width, int *aligned_height); + DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config, + AllocatedBufferInfo *allocated_buffer_info); + int SetBufferInfo(LayerBufferFormat format, int *target, int *flags); + + private: + gralloc1_device_t *gralloc_device_ = nullptr; + const hw_module_t *module_; + GRALLOC1_PFN_RELEASE ReleaseBuffer_ = nullptr; + GRALLOC1_PFN_PERFORM Perform_ = nullptr; +}; + +} // namespace sdm +#endif // __HWC_BUFFER_ALLOCATOR_H__ +#else +#include "../hwc/hwc_buffer_allocator.h" +#endif // __HWC_BUFFER_ALLOCATOR_H__ + diff --git a/msm8996/sdm/libs/hwc2/hwc_display.cpp b/msm8996/sdm/libs/hwc2/hwc_display.cpp index 46f3c0b0..d8b64d36 100644 --- a/msm8996/sdm/libs/hwc2/hwc_display.cpp +++ b/msm8996/sdm/libs/hwc2/hwc_display.cpp @@ -21,8 +21,6 @@ #include #include #include -#include -#include #include #include #include @@ -40,6 +38,9 @@ #include "hwc_display.h" #include "hwc_debugger.h" #include "blit_engine_c2d.h" +#ifndef USE_GRALLOC1 +#include +#endif #ifdef QTI_BSP #include @@ -237,21 +238,14 @@ int HWCDisplay::Init() { swap_interval_zero_ = true; } + buffer_allocator_ = new HWCBufferAllocator(); + + client_target_ = new HWCLayer(id_, buffer_allocator_); - client_target_ = new HWCLayer(id_); int blit_enabled = 0; HWCDebugHandler::Get()->GetProperty("persist.hwc.blit.comp", &blit_enabled); if (needs_blit_ && blit_enabled) { - blit_engine_ = new BlitEngineC2d(); - if (!blit_engine_) { - DLOGI("Create Blit Engine C2D failed"); - } else { - if (blit_engine_->Init() < 0) { - DLOGI("Blit Engine Init failed, Blit Composition will not be used!!"); - delete blit_engine_; - blit_engine_ = NULL; - } - } + // TODO(user): Add blit engine when needed } display_intf_->GetRefreshRateRange(&min_refresh_rate_, &max_refresh_rate_); @@ -269,10 +263,9 @@ int HWCDisplay::Deinit() { delete client_target_; - if (blit_engine_) { - blit_engine_->DeInit(); - delete blit_engine_; - blit_engine_ = NULL; + if (buffer_allocator_) { + delete buffer_allocator_; + buffer_allocator_ = NULL; } if (color_mode_) { @@ -285,7 +278,7 @@ int HWCDisplay::Deinit() { // LayerStack operations HWC2::Error HWCDisplay::CreateLayer(hwc2_layer_t *out_layer_id) { - HWCLayer *layer = *layer_set_.emplace(new HWCLayer(id_)); + HWCLayer *layer = *layer_set_.emplace(new HWCLayer(id_, buffer_allocator_)); layer_map_.emplace(std::make_pair(layer->GetId(), layer)); *out_layer_id = layer->GetId(); geometry_changes_ |= GeometryChanges::kAdded; @@ -352,7 +345,11 @@ void HWCDisplay::BuildLayerStack() { const private_handle_t *handle = reinterpret_cast(layer->input_buffer->buffer_id); if (handle) { +#ifdef USE_GRALLOC1 + if (handle->buffer_type == BUFFER_TYPE_VIDEO) { +#else if (handle->bufferType == BUFFER_TYPE_VIDEO) { +#endif layer_stack_.flags.video_present = true; } // TZ Protected Buffer - L1 @@ -687,10 +684,6 @@ void HWCDisplay::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type dump_frame_index_ = 0; dump_input_layers_ = ((bit_mask_layer_type & (1 << INPUT_LAYER_DUMP)) != 0); - if (blit_engine_) { - blit_engine_->SetFrameDumpConfig(count); - } - DLOGI("num_frame_dump %d, input_layer_dump_enable %d", dump_frame_count_, dump_input_layers_); } @@ -1312,7 +1305,7 @@ int HWCDisplay::SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels) { int aligned_width; int aligned_height; - int usage = GRALLOC_USAGE_HW_FB; + uint32_t usage = GRALLOC_USAGE_HW_FB; int format = HAL_PIXEL_FORMAT_RGBA_8888; int ubwc_enabled = 0; int flags = 0; @@ -1321,8 +1314,14 @@ int HWCDisplay::SetFrameBufferResolution(uint32_t x_pixels, uint32_t y_pixels) { usage |= GRALLOC_USAGE_PRIVATE_ALLOC_UBWC; flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; } - AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format, usage, - aligned_width, aligned_height); + +#ifdef USE_GRALLOC1 + buffer_allocator_->GetAlignedWidthAndHeight(INT(x_pixels), INT(y_pixels), format, usage, + &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 client_target_layer->composition = kCompositionGPUTarget; diff --git a/msm8996/sdm/libs/hwc2/hwc_display.h b/msm8996/sdm/libs/hwc2/hwc_display.h index cc90694d..304d399d 100644 --- a/msm8996/sdm/libs/hwc2/hwc_display.h +++ b/msm8996/sdm/libs/hwc2/hwc_display.h @@ -32,6 +32,7 @@ #include #include +#include "hwc_buffer_allocator.h" #include "hwc_callbacks.h" #include "hwc_layers.h" @@ -222,6 +223,7 @@ class HWCDisplay : public DisplayEventHandler { CoreInterface *core_intf_ = nullptr; HWCCallbacks *callbacks_ = nullptr; + HWCBufferAllocator *buffer_allocator_ = NULL; DisplayType type_; hwc2_display_t id_; bool needs_blit_ = false; @@ -262,7 +264,6 @@ class HWCDisplay : public DisplayEventHandler { private: void DumpInputBuffers(void); - BlitEngine *blit_engine_ = NULL; qService::QService *qservice_ = NULL; DisplayClass display_class_; uint32_t geometry_changes_ = GeometryChanges::kNone; diff --git a/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp b/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp index 90e3015d..7035148f 100644 --- a/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp +++ b/msm8996/sdm/libs/hwc2/hwc_display_virtual.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved. +* Copyright (c) 2014-2017, 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 @@ -31,7 +31,9 @@ #include #include #include +#ifndef USE_GRALLOC1 #include +#endif #include "hwc_display_virtual.h" #include "hwc_debugger.h" @@ -187,13 +189,16 @@ HWC2::Error HWCDisplayVirtual::SetOutputBuffer(buffer_handle_t buf, int32_t rele return HWC2::Error::BadParameter; } - int output_buffer_width, output_buffer_height; - AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(output_handle, output_buffer_width, - output_buffer_height); + int aligned_width, aligned_height; +#ifdef USE_GRALLOC1 + buffer_allocator_->GetCustomWidthAndHeight(output_handle, &aligned_width, &aligned_height); +#else + AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(output_handle, aligned_width, + aligned_height); +#endif - output_buffer_->width = UINT32(output_buffer_width); - output_buffer_->height = UINT32(output_buffer_height); - // TODO(mkavm): Handle DRC and metadata changes + output_buffer_->width = UINT32(aligned_width); + output_buffer_->height = UINT32(aligned_height); output_buffer_->flags.secure = 0; output_buffer_->flags.video = 0; diff --git a/msm8996/sdm/libs/hwc2/hwc_layers.cpp b/msm8996/sdm/libs/hwc2/hwc_layers.cpp index a18cb4a8..537005af 100644 --- a/msm8996/sdm/libs/hwc2/hwc_layers.cpp +++ b/msm8996/sdm/libs/hwc2/hwc_layers.cpp @@ -18,7 +18,9 @@ */ #include "hwc_layers.h" +#ifndef USE_GRALLOC1 #include +#endif #include #include @@ -29,7 +31,8 @@ namespace sdm { std::atomic HWCLayer::next_id_(1); // Layer operations -HWCLayer::HWCLayer(hwc2_display_t display_id) : id_(next_id_++), display_id_(display_id) { +HWCLayer::HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator) + : id_(next_id_++), display_id_(display_id), buffer_allocator_(buf_allocator) { layer_ = new Layer(); layer_->input_buffer = new LayerBuffer(); // Fences are deferred, so the first time this layer is presented, return -1 @@ -75,6 +78,7 @@ HWC2::Error HWCLayer::SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fen } LayerBuffer *layer_buffer = layer_->input_buffer; + layer_buffer->width = UINT32(handle->width); layer_buffer->height = UINT32(handle->height); layer_buffer->format = GetSDMFormat(handle->format, handle->flags); @@ -82,7 +86,12 @@ HWC2::Error HWCLayer::SetLayerBuffer(buffer_handle_t buffer, int32_t acquire_fen return HWC2::Error::BadLayer; } - if (handle->bufferType == BUFFER_TYPE_VIDEO) { +#ifdef USE_GRALLOC1 + // TODO(user): Clean this up + if (handle->buffer_type == BUFFER_TYPE_VIDEO) { +#else + if (handle->bufferType == BUFFER_TYPE_VIDEO) { +#endif layer_buffer->flags.video = true; } // TZ Protected Buffer - L1 @@ -459,7 +468,11 @@ DisplayError HWCLayer::SetMetaData(const private_handle_t *pvt_handle, Layer *la if (meta_data->operation & UPDATE_BUFFER_GEOMETRY) { int actual_width = pvt_handle->width; int actual_height = pvt_handle->height; - AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(pvt_handle, actual_width, actual_height); +#ifdef USE_GRALLOC1 + buffer_allocator_->GetCustomWidthAndHeight(pvt_handle, &actual_width, &actual_height); +#else + AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(handle, aligned_width, aligned_height); +#endif layer_buffer->width = UINT32(actual_width); layer_buffer->height = UINT32(actual_height); } diff --git a/msm8996/sdm/libs/hwc2/hwc_layers.h b/msm8996/sdm/libs/hwc2/hwc_layers.h index ed93a5a3..1d5d023f 100644 --- a/msm8996/sdm/libs/hwc2/hwc_layers.h +++ b/msm8996/sdm/libs/hwc2/hwc_layers.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -31,9 +31,11 @@ #include #undef HWC2_INCLUDE_STRINGIFICATION #undef HWC2_USE_CPP11 -#include #include #include +#include +#include "core/buffer_allocator.h" +#include "hwc_buffer_allocator.h" namespace sdm { @@ -52,7 +54,7 @@ enum GeometryChanges { class HWCLayer { public: - explicit HWCLayer(hwc2_display_t display_id); + explicit HWCLayer(hwc2_display_t display_id, HWCBufferAllocator *buf_allocator); ~HWCLayer(); uint32_t GetZ() const { return z_; } hwc2_layer_t GetId() const { return id_; } @@ -87,6 +89,7 @@ class HWCLayer { static std::atomic next_id_; std::queue release_fences_; int ion_fd_ = -1; + HWCBufferAllocator *buffer_allocator_ = NULL; // Composition requested by client(SF) HWC2::Composition client_requested_ = HWC2::Composition::Device; diff --git a/msm8996/sdm/libs/hwc2/hwc_session.cpp b/msm8996/sdm/libs/hwc2/hwc_session.cpp index 0e252aee..f44ef078 100644 --- a/msm8996/sdm/libs/hwc2/hwc_session.cpp +++ b/msm8996/sdm/libs/hwc2/hwc_session.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include #include #include