diff options
Diffstat (limited to 'libs/graphicsenv/GraphicsEnv.cpp')
-rw-r--r-- | libs/graphicsenv/GraphicsEnv.cpp | 133 |
1 files changed, 71 insertions, 62 deletions
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 701a3b2f77..16315ed858 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -277,6 +277,57 @@ void GraphicsEnv::setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, sendGpuStatsLocked(api, isDriverLoaded, driverLoadingTime); } +// Hash function to calculate hash for null-terminated Vulkan extension names +// We store hash values of the extensions, rather than the actual names or +// indices to be able to support new extensions easily, avoid creating +// a table of 'known' extensions inside Android and reduce the runtime overhead. +static uint64_t calculateExtensionHash(const char* word) { + if (!word) { + return 0; + } + const size_t wordLen = strlen(word); + const uint32_t seed = 167; + uint64_t hash = 0; + for (size_t i = 0; i < wordLen; i++) { + hash = (hash * seed) + word[i]; + } + return hash; +} + +void GraphicsEnv::setVulkanInstanceExtensions(uint32_t enabledExtensionCount, + const char* const* ppEnabledExtensionNames) { + ATRACE_CALL(); + if (enabledExtensionCount == 0 || ppEnabledExtensionNames == nullptr) { + return; + } + + const uint32_t maxNumStats = android::GpuStatsAppInfo::MAX_NUM_EXTENSIONS; + uint64_t extensionHashes[maxNumStats]; + const uint32_t numStats = std::min(enabledExtensionCount, maxNumStats); + for(uint32_t i = 0; i < numStats; i++) { + extensionHashes[i] = calculateExtensionHash(ppEnabledExtensionNames[i]); + } + setTargetStatsArray(android::GpuStatsInfo::Stats::VULKAN_INSTANCE_EXTENSION, + extensionHashes, numStats); +} + +void GraphicsEnv::setVulkanDeviceExtensions(uint32_t enabledExtensionCount, + const char* const* ppEnabledExtensionNames) { + ATRACE_CALL(); + if (enabledExtensionCount == 0 || ppEnabledExtensionNames == nullptr) { + return; + } + + const uint32_t maxNumStats = android::GpuStatsAppInfo::MAX_NUM_EXTENSIONS; + uint64_t extensionHashes[maxNumStats]; + const uint32_t numStats = std::min(enabledExtensionCount, maxNumStats); + for(uint32_t i = 0; i < numStats; i++) { + extensionHashes[i] = calculateExtensionHash(ppEnabledExtensionNames[i]); + } + setTargetStatsArray(android::GpuStatsInfo::Stats::VULKAN_DEVICE_EXTENSION, + extensionHashes, numStats); +} + static sp<IGpuService> getGpuService() { static const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu")); if (!binder) { @@ -294,6 +345,11 @@ bool GraphicsEnv::readyToSendGpuStatsLocked() { } void GraphicsEnv::setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t value) { + return setTargetStatsArray(stats, &value, 1); +} + +void GraphicsEnv::setTargetStatsArray(const GpuStatsInfo::Stats stats, const uint64_t* values, + const uint32_t valueCount) { ATRACE_CALL(); std::lock_guard<std::mutex> lock(mStatsLock); @@ -301,8 +357,8 @@ void GraphicsEnv::setTargetStats(const GpuStatsInfo::Stats stats, const uint64_t const sp<IGpuService> gpuService = getGpuService(); if (gpuService) { - gpuService->setTargetStats(mGpuStats.appPackageName, mGpuStats.driverVersionCode, stats, - value); + gpuService->setTargetStatsArray(mGpuStats.appPackageName, mGpuStats.driverVersionCode, + stats, values, valueCount); } } @@ -395,61 +451,24 @@ bool GraphicsEnv::shouldUseAngle() { return (mUseAngle == YES) ? true : false; } -bool GraphicsEnv::angleIsSystemDriver() { - // Make sure we are init'ed - if (mAngleAppName.empty()) { - ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE."); - return false; - } - - return (mAngleIsSystemDriver == YES) ? true : false; -} - -bool GraphicsEnv::shouldForceLegacyDriver() { - // Make sure we are init'ed - if (mAngleAppName.empty()) { - ALOGV("App name is empty. setAngleInfo() has not been called to enable ANGLE."); - return false; - } - - return (mAngleIsSystemDriver == YES && mUseAngle == NO) ? true : false; -} - -std::string GraphicsEnv::getLegacySuffix() { - return mLegacyDriverSuffix; -} - void GraphicsEnv::updateUseAngle() { - mUseAngle = NO; - const char* ANGLE_PREFER_ANGLE = "angle"; - const char* ANGLE_PREFER_LEGACY = "legacy"; - // The following is a deprecated version of "legacy" const char* ANGLE_PREFER_NATIVE = "native"; mUseAngle = NO; if (mAngleDeveloperOptIn == ANGLE_PREFER_ANGLE) { - ALOGI("Using ANGLE, the %s GLES driver for package '%s'", - mAngleIsSystemDriver == YES ? "system" : "optional", mAngleAppName.c_str()); + ALOGV("User set \"Developer Options\" to force the use of ANGLE"); mUseAngle = YES; - } else if (mAngleDeveloperOptIn == ANGLE_PREFER_LEGACY || - mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) { - ALOGI("Using the (%s) Legacy GLES driver for package '%s'", - mAngleIsSystemDriver == YES ? "optional" : "system", mAngleAppName.c_str()); + } else if (mAngleDeveloperOptIn == ANGLE_PREFER_NATIVE) { + ALOGV("User set \"Developer Options\" to force the use of Native"); } else { ALOGV("User set invalid \"Developer Options\": '%s'", mAngleDeveloperOptIn.c_str()); } } void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName, - const bool angleIsSystemDriver, const std::string developerOptIn, + const std::string developerOptIn, const std::vector<std::string> eglFeatures) { - // Set whether ANGLE is the system driver: - mAngleIsSystemDriver = angleIsSystemDriver ? YES : NO; - - // Note: Given the current logic and lack of the old rules file processing, - // there seems to be little chance that mUseAngle != UNKNOWN. Leave this - // for now, even though it seems outdated. if (mUseAngle != UNKNOWN) { // We've already figured out an answer for this app, so just return. ALOGV("Already evaluated the rules file for '%s': use ANGLE = %s", appName.c_str(), @@ -470,25 +489,6 @@ void GraphicsEnv::setAngleInfo(const std::string path, const std::string appName updateUseAngle(); } -void GraphicsEnv::setLegacyDriverInfo(const std::string appName, const bool angleIsSystemDriver, - const std::string legacyDriverName) { - ALOGV("setting legacy app name to '%s'", appName.c_str()); - mAngleAppName = appName; - - // Force the use of the legacy driver instead of ANGLE - const char* ANGLE_PREFER_LEGACY = "legacy"; - mAngleDeveloperOptIn = ANGLE_PREFER_LEGACY; - ALOGV("setting ANGLE application opt-in to 'legacy'"); - - // Set whether ANGLE is the system driver: - mAngleIsSystemDriver = angleIsSystemDriver ? YES : NO; - - mLegacyDriverSuffix = legacyDriverName; - - // Update the current status of whether we should use ANGLE or not - updateUseAngle(); -} - void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) { if (mLayerPaths.empty()) { mLayerPaths = layerPaths; @@ -651,4 +651,13 @@ android_namespace_t* GraphicsEnv::getAngleNamespace() { return mAngleNamespace; } +void GraphicsEnv::nativeToggleAngleAsSystemDriver(bool enabled) { + const sp<IGpuService> gpuService = getGpuService(); + if (!gpuService) { + ALOGE("No GPU service"); + return; + } + gpuService->toggleAngleAsSystemDriver(enabled); +} + } // namespace android |