From 187218450fbb33df85fbd6448e7bc712b6b91b5d Mon Sep 17 00:00:00 2001 From: Ramakant Singh Date: Fri, 22 Mar 2019 18:52:13 +0530 Subject: sf: Allow VDS to use HWC -- Preserve VDS layer pixel format based on GRALLOC flags. -- skip color layer for vds CRs-Fixed: 2178626 Change-Id: I36d0fe6edb72732a9fe5d2e66ca2d95f3ef7e1dc --- services/surfaceflinger/Android.bp | 1 + services/surfaceflinger/SurfaceFlinger.cpp | 47 ++++++++++++++++++++++++++++-- services/surfaceflinger/SurfaceFlinger.h | 5 ++++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 531913f52..4d9188a48 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -71,6 +71,7 @@ cc_defaults { "android.hardware.graphics.composer@2.1-command-buffer", "android.hardware.graphics.composer@2.2-command-buffer", "android.hardware.graphics.composer@2.3-command-buffer", + "display_intf_headers", ], export_static_lib_headers: [ "libcompositionengine", diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 7720880a6..08ca84f06 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -120,6 +120,7 @@ #include #include "SurfaceFlingerProperties.h" +#include "gralloc_priv.h" namespace android { @@ -243,6 +244,7 @@ Dataspace SurfaceFlinger::defaultCompositionDataspace = Dataspace::V0_SRGB; ui::PixelFormat SurfaceFlinger::defaultCompositionPixelFormat = ui::PixelFormat::RGBA_8888; Dataspace SurfaceFlinger::wideColorGamutCompositionDataspace = Dataspace::V0_SRGB; ui::PixelFormat SurfaceFlinger::wideColorGamutCompositionPixelFormat = ui::PixelFormat::RGBA_8888; +bool SurfaceFlinger::sDirectStreaming; std::string getHwcServiceName() { char value[PROPERTY_VALUE_MAX] = {}; @@ -2833,8 +2835,21 @@ void SurfaceFlinger::processDisplayChangesLocked() { ALOGE_IF(status != NO_ERROR, "Unable to query format (%d)", status); auto format = static_cast(intFormat); - displayId = - getHwComposer().allocateVirtualDisplay(width, height, &format); + if (maxVirtualDisplaySize == 0 || + ((uint64_t)width <= maxVirtualDisplaySize && + (uint64_t)height <= maxVirtualDisplaySize)) { + uint64_t usage = 0; + // Replace with native_window_get_consumer_usage ? + status = state.surface->getConsumerUsage(&usage); + ALOGW_IF(status != NO_ERROR, "Unable to query usage (%d)", status); + displayId = + getHwComposer().allocateVirtualDisplay(width, height, &format); + ALOGW_IF(status != NO_ERROR, "Unable to query usage (%d)", status); + if ((status == NO_ERROR) && canAllocateHwcDisplayIdForVDS(usage)) { + displayId = + getHwComposer().allocateVirtualDisplay(width, height, &format); + } + } } // TODO: Plumb requested format back up to consumer @@ -3522,6 +3537,12 @@ bool SurfaceFlinger::doComposeSurfaces(const sp& displayDevice, } case Hwc2::IComposerClient::Composition::CLIENT: { renderengine::LayerSettings layerSettings; + if (displayDevice->isVirtual() && + skipColorLayer(layer->getTypeId())) { + // We are not using h/w composer. + // Skip color (dim) layer for WFD direct streaming. + continue; + } bool prepared = layer->prepareClientLayer(renderArea, clip, clearRegion, supportProtectedContent, layerSettings); @@ -6216,6 +6237,28 @@ void SurfaceFlinger::setAllowedDisplayConfigsInternal(const sp& d setPreferredDisplayConfig(); } +bool SurfaceFlinger::canAllocateHwcDisplayIdForVDS(uint64_t usage) { + uint64_t flag_mask_pvt_wfd = ~0; + uint64_t flag_mask_hw_video = ~0; + char value[PROPERTY_VALUE_MAX] = {}; + property_get("vendor.display.vds_allow_hwc", value, "0"); + int allowHwcForVDS = atoi(value); + // Reserve hardware acceleration for WFD use-case + // GRALLOC_USAGE_PRIVATE_WFD + GRALLOC_USAGE_HW_VIDEO_ENCODER = WFD using HW composer. + flag_mask_pvt_wfd = GRALLOC_USAGE_PRIVATE_WFD; + flag_mask_hw_video = GRALLOC_USAGE_HW_VIDEO_ENCODER; + // GRALLOC_USAGE_PRIVATE_WFD + GRALLOC_USAGE_SW_READ_OFTEN + // WFD using GLES (directstreaming). + sDirectStreaming = ((usage & GRALLOC_USAGE_PRIVATE_WFD) && + (usage & GRALLOC_USAGE_SW_READ_OFTEN)); + return (allowHwcForVDS || ((usage & flag_mask_pvt_wfd) && + (usage & flag_mask_hw_video))); +} + +bool SurfaceFlinger::skipColorLayer(const char* layerType) { + return (sDirectStreaming && !strncmp(layerType, "ColorLayer", strlen("ColorLayer"))); +} + status_t SurfaceFlinger::setAllowedDisplayConfigs(const sp& displayToken, const std::vector& allowedConfigs) { ATRACE_CALL(); diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 974486217..08d9dd36a 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -232,6 +232,8 @@ public: static bool useContextPriority; + static bool sDirectStreaming; + // The data space and pixel format that SurfaceFlinger expects hardware composer // to composite efficiently. Meaning under most scenarios, hardware composer // will accept layers with the data space and pixel format. @@ -665,6 +667,9 @@ private: void traverseLayersInDisplay(const sp& display, const LayerVector::Visitor& visitor); + bool canAllocateHwcDisplayIdForVDS(uint64_t usage); + bool skipColorLayer(const char* layerType); + sp mStartPropertySetThread; /* ------------------------------------------------------------------------ -- cgit v1.2.3