diff --git a/services/surfaceflinger/DisplayUtils.cpp b/services/surfaceflinger/DisplayUtils.cpp index e4e2183d7..83d84aa54 100644 --- a/services/surfaceflinger/DisplayUtils.cpp +++ b/services/surfaceflinger/DisplayUtils.cpp @@ -44,6 +44,9 @@ #include #include #include +#if QTI_BSP +#include +#endif namespace android { @@ -157,5 +160,17 @@ bool DisplayUtils::createV4L2BasedVirtualDisplay(HWComposer* hwc, int32_t &hwcDi return false; } +bool DisplayUtils::canAllocateHwcDisplayIdForVDS(int usage) { + // on AOSP builds with QTI_BSP disabled, we should allocate hwc display id for virtual display + int flag_mask = 0xffffffff; + +#if QTI_BSP + // Reserve hardware acceleration for WFD use-case + flag_mask = GRALLOC_USAGE_PRIVATE_WFD; +#endif + + return (usage & flag_mask); +} + }; // namespace android diff --git a/services/surfaceflinger/DisplayUtils.h b/services/surfaceflinger/DisplayUtils.h index cdf2b67fd..bb3d16bfc 100644 --- a/services/surfaceflinger/DisplayUtils.h +++ b/services/surfaceflinger/DisplayUtils.h @@ -61,6 +61,7 @@ class DisplayUtils { sp &producer, sp bqProducer, sp bqConsumer, String8 currentStateDisplayName, bool currentStateIsSecure, int currentStateType); + bool canAllocateHwcDisplayIdForVDS(int usage); DisplayUtils(); private: static DisplayUtils* sDisplayUtils; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 21c8aa5bd..5f37b0bd9 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1430,6 +1430,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) if (state.surface != NULL) { int width = 0; + DisplayUtils* displayUtils = DisplayUtils::getInstance(); int status = state.surface->query( NATIVE_WINDOW_WIDTH, &width); ALOGE_IF(status != NO_ERROR, @@ -1442,11 +1443,19 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags) if (MAX_VIRTUAL_DISPLAY_DIMENSION == 0 || (width <= MAX_VIRTUAL_DISPLAY_DIMENSION && height <= MAX_VIRTUAL_DISPLAY_DIMENSION)) { - hwcDisplayId = allocateHwcDisplayId(state.type); + int usage = 0; + status = state.surface->query( + NATIVE_WINDOW_CONSUMER_USAGE_BITS, &usage); + ALOGW_IF(status != NO_ERROR, + "Unable to query usage (%d)", status); + if ( (status == NO_ERROR) && + displayUtils->canAllocateHwcDisplayIdForVDS(usage)) { + hwcDisplayId = allocateHwcDisplayId(state.type); + } } - DisplayUtils::getInstance()->initVDSInstance(mHwc, hwcDisplayId, - state.surface, dispSurface, producer, bqProducer, bqConsumer, + displayUtils->initVDSInstance(mHwc, hwcDisplayId, state.surface, + dispSurface, producer, bqProducer, bqConsumer, state.displayName, state.isSecure, state.type); }