Loading core/jni/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ cc_library_shared { "libmemunreachable", "libhidlbase", "libvintf", "libnativedisplay", "libnativewindow", "libdl", "libdl_android", Loading Loading @@ -438,6 +439,7 @@ cc_library_static { ], shared_libs: [ "libandroidfw", "libnativedisplay", "libnativewindow", "libgui", "libpdfium", Loading libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ cc_defaults { "libvulkan", "libui", "libgui", "libnativedisplay", "libnativewindow", "libprotobuf-cpp-lite", "libft2", Loading libs/hwui/DeviceInfo.cpp +40 −61 Original line number Diff line number Diff line Loading @@ -15,76 +15,23 @@ */ #include <DeviceInfo.h> #include "Properties.h" #include <gui/SurfaceComposerClient.h> #include <log/log.h> #include <ui/GraphicTypes.h> #include <mutex> #include <thread> #include <log/log.h> #include "Properties.h" namespace android { namespace uirenderer { static constexpr android::DisplayInfo sDummyDisplay{ 1080, // w 1920, // h 320.0, // xdpi 320.0, // ydpi 60.0, // fps 2.0, // density 0, // orientation false, // secure? 0, // appVsyncOffset 0, // presentationDeadline 1080, // viewportW 1920, // viewportH }; DeviceInfo* DeviceInfo::get() { static DeviceInfo sDeviceInfo; return &sDeviceInfo; } static DisplayInfo QueryDisplayInfo() { if (Properties::isolatedProcess) { return sDummyDisplay; } const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken(); LOG_ALWAYS_FATAL_IF(token == nullptr, "Failed to get display info because internal display is disconnected"); DisplayInfo displayInfo; status_t status = SurfaceComposerClient::getDisplayInfo(token, &displayInfo); LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status); return displayInfo; } static float QueryMaxRefreshRate() { if (Properties::isolatedProcess) { return sDummyDisplay.fps; } const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken(); LOG_ALWAYS_FATAL_IF(token == nullptr, "Failed to get display info because internal display is disconnected"); Vector<DisplayInfo> configs; configs.reserve(10); status_t status = SurfaceComposerClient::getDisplayConfigs(token, &configs); LOG_ALWAYS_FATAL_IF(status, "Failed to getDisplayConfigs, error %d", status); LOG_ALWAYS_FATAL_IF(configs.size() == 0, "getDisplayConfigs returned 0 configs?"); float max = 0.0f; for (auto& info : configs) { max = std::max(max, info.fps); } return max; } static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) { if (Properties::isolatedProcess) { *colorSpace = SkColorSpace::MakeSRGB(); Loading Loading @@ -123,15 +70,18 @@ static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkCol } } DeviceInfo::DeviceInfo() : mMaxRefreshRate(QueryMaxRefreshRate()) { DeviceInfo::DeviceInfo() { #if HWUI_NULL_GPU mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; #else mMaxTextureSize = -1; #endif mDisplayInfo = QueryDisplayInfo(); updateDisplayInfo(); queryWideColorGamutPreference(&mWideColorSpace, &mWideColorType); } DeviceInfo::~DeviceInfo() { ADisplay_release(mDisplays); } int DeviceInfo::maxTextureSize() const { LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); Loading @@ -143,7 +93,36 @@ void DeviceInfo::setMaxTextureSize(int maxTextureSize) { } void DeviceInfo::onDisplayConfigChanged() { mDisplayInfo = QueryDisplayInfo(); updateDisplayInfo(); } void DeviceInfo::updateDisplayInfo() { if (Properties::isolatedProcess) { return; } if (mCurrentConfig == nullptr) { mDisplaysSize = ADisplay_acquirePhysicalDisplays(&mDisplays); LOG_ALWAYS_FATAL_IF(mDisplays == nullptr || mDisplaysSize <= 0, "Failed to get physical displays: no connected display: %d!", mDisplaysSize); for (size_t i = 0; i < mDisplaysSize; i++) { ADisplayType type = ADisplay_getDisplayType(mDisplays[i]); if (type == ADisplayType::DISPLAY_TYPE_INTERNAL) { mPhysicalDisplayIndex = i; break; } } LOG_ALWAYS_FATAL_IF(mPhysicalDisplayIndex < 0, "Failed to find a connected physical display!"); mMaxRefreshRate = ADisplay_getMaxSupportedFps(mDisplays[mPhysicalDisplayIndex]); } status_t status = ADisplay_getCurrentConfig(mDisplays[mPhysicalDisplayIndex], &mCurrentConfig); LOG_ALWAYS_FATAL_IF(status, "Failed to get display config, error %d", status); mWidth = ADisplayConfig_getWidth(mCurrentConfig); mHeight = ADisplayConfig_getHeight(mCurrentConfig); mDensity = ADisplayConfig_getDensity(mCurrentConfig); mRefreshRate = ADisplayConfig_getFps(mCurrentConfig); mCompositorOffset = ADisplayConfig_getCompositorOffsetNanos(mCurrentConfig); mAppOffset = ADisplayConfig_getAppVsyncOffsetNanos(mCurrentConfig); } } /* namespace uirenderer */ Loading libs/hwui/DeviceInfo.h +21 −5 Original line number Diff line number Diff line Loading @@ -16,8 +16,8 @@ #ifndef DEVICEINFO_H #define DEVICEINFO_H #include <apex/display.h> #include <SkImageInfo.h> #include <ui/DisplayInfo.h> #include "utils/Macros.h" Loading @@ -33,28 +33,44 @@ class DeviceInfo { public: static DeviceInfo* get(); static float getMaxRefreshRate() { return get()->mMaxRefreshRate; } static int32_t getWidth() { return get()->mWidth; } static int32_t getHeight() { return get()->mHeight; } static float getDensity() { return get()->mDensity; } static float getRefreshRate() { return get()->mRefreshRate; } static int64_t getCompositorOffset() { return get()->mCompositorOffset; } static int64_t getAppOffset() { return get()->mAppOffset; } // this value is only valid after the GPU has been initialized and there is a valid graphics // context or if you are using the HWUI_NULL_GPU int maxTextureSize() const; const DisplayInfo& displayInfo() const { return mDisplayInfo; } sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; } SkColorType getWideColorType() const { return mWideColorType; } float getMaxRefreshRate() const { return mMaxRefreshRate; } void onDisplayConfigChanged(); private: friend class renderthread::RenderThread; static void setMaxTextureSize(int maxTextureSize); void updateDisplayInfo(); DeviceInfo(); ~DeviceInfo(); int mMaxTextureSize; DisplayInfo mDisplayInfo; sk_sp<SkColorSpace> mWideColorSpace; SkColorType mWideColorType; const float mMaxRefreshRate; ADisplayConfig* mCurrentConfig = nullptr; ADisplay** mDisplays = nullptr; int mDisplaysSize = 0; int mPhysicalDisplayIndex = -1; float mMaxRefreshRate = 60.0; int32_t mWidth = 1080; int32_t mHeight = 1920; float mDensity = 2.0; float mRefreshRate = 60.0; int64_t mCompositorOffset = 0; int64_t mAppOffset = 0; }; } /* namespace uirenderer */ Loading libs/hwui/JankTracker.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ #include "JankTracker.h" #include <cutils/ashmem.h> #include <errno.h> #include <inttypes.h> #include <log/log.h> #include <statslog.h> #include <sys/mman.h> Loading @@ -25,11 +27,9 @@ #include <cmath> #include <cstdio> #include <limits> #include <cutils/ashmem.h> #include <log/log.h> #include <sstream> #include "DeviceInfo.h" #include "Properties.h" #include "utils/TimeUtils.h" #include "utils/Trace.h" Loading Loading @@ -79,11 +79,11 @@ static const int64_t EXEMPT_FRAMES_FLAGS = FrameInfoFlags::SurfaceCanvas; // and filter it out of the frame profile data static FrameInfoIndex sFrameStart = FrameInfoIndex::IntendedVsync; JankTracker::JankTracker(ProfileDataContainer* globalData, const DisplayInfo& displayInfo) { JankTracker::JankTracker(ProfileDataContainer* globalData) { mGlobalData = globalData; nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1_s / displayInfo.fps); nsecs_t sfOffset = frameIntervalNanos - (displayInfo.presentationDeadline - 1_ms); nsecs_t offsetDelta = sfOffset - displayInfo.appVsyncOffset; nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1_s / DeviceInfo::getRefreshRate()); nsecs_t sfOffset = DeviceInfo::getCompositorOffset(); nsecs_t offsetDelta = sfOffset - DeviceInfo::getAppOffset(); // There are two different offset cases. If the offsetDelta is positive // and small, then the intention is to give apps extra time by leveraging // pipelining between the UI & RT threads. If the offsetDelta is large or Loading Loading
core/jni/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -259,6 +259,7 @@ cc_library_shared { "libmemunreachable", "libhidlbase", "libvintf", "libnativedisplay", "libnativewindow", "libdl", "libdl_android", Loading Loading @@ -438,6 +439,7 @@ cc_library_static { ], shared_libs: [ "libandroidfw", "libnativedisplay", "libnativewindow", "libgui", "libpdfium", Loading
libs/hwui/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -90,6 +90,7 @@ cc_defaults { "libvulkan", "libui", "libgui", "libnativedisplay", "libnativewindow", "libprotobuf-cpp-lite", "libft2", Loading
libs/hwui/DeviceInfo.cpp +40 −61 Original line number Diff line number Diff line Loading @@ -15,76 +15,23 @@ */ #include <DeviceInfo.h> #include "Properties.h" #include <gui/SurfaceComposerClient.h> #include <log/log.h> #include <ui/GraphicTypes.h> #include <mutex> #include <thread> #include <log/log.h> #include "Properties.h" namespace android { namespace uirenderer { static constexpr android::DisplayInfo sDummyDisplay{ 1080, // w 1920, // h 320.0, // xdpi 320.0, // ydpi 60.0, // fps 2.0, // density 0, // orientation false, // secure? 0, // appVsyncOffset 0, // presentationDeadline 1080, // viewportW 1920, // viewportH }; DeviceInfo* DeviceInfo::get() { static DeviceInfo sDeviceInfo; return &sDeviceInfo; } static DisplayInfo QueryDisplayInfo() { if (Properties::isolatedProcess) { return sDummyDisplay; } const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken(); LOG_ALWAYS_FATAL_IF(token == nullptr, "Failed to get display info because internal display is disconnected"); DisplayInfo displayInfo; status_t status = SurfaceComposerClient::getDisplayInfo(token, &displayInfo); LOG_ALWAYS_FATAL_IF(status, "Failed to get display info, error %d", status); return displayInfo; } static float QueryMaxRefreshRate() { if (Properties::isolatedProcess) { return sDummyDisplay.fps; } const sp<IBinder> token = SurfaceComposerClient::getInternalDisplayToken(); LOG_ALWAYS_FATAL_IF(token == nullptr, "Failed to get display info because internal display is disconnected"); Vector<DisplayInfo> configs; configs.reserve(10); status_t status = SurfaceComposerClient::getDisplayConfigs(token, &configs); LOG_ALWAYS_FATAL_IF(status, "Failed to getDisplayConfigs, error %d", status); LOG_ALWAYS_FATAL_IF(configs.size() == 0, "getDisplayConfigs returned 0 configs?"); float max = 0.0f; for (auto& info : configs) { max = std::max(max, info.fps); } return max; } static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) { if (Properties::isolatedProcess) { *colorSpace = SkColorSpace::MakeSRGB(); Loading Loading @@ -123,15 +70,18 @@ static void queryWideColorGamutPreference(sk_sp<SkColorSpace>* colorSpace, SkCol } } DeviceInfo::DeviceInfo() : mMaxRefreshRate(QueryMaxRefreshRate()) { DeviceInfo::DeviceInfo() { #if HWUI_NULL_GPU mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE; #else mMaxTextureSize = -1; #endif mDisplayInfo = QueryDisplayInfo(); updateDisplayInfo(); queryWideColorGamutPreference(&mWideColorSpace, &mWideColorType); } DeviceInfo::~DeviceInfo() { ADisplay_release(mDisplays); } int DeviceInfo::maxTextureSize() const { LOG_ALWAYS_FATAL_IF(mMaxTextureSize < 0, "MaxTextureSize has not been initialized yet."); Loading @@ -143,7 +93,36 @@ void DeviceInfo::setMaxTextureSize(int maxTextureSize) { } void DeviceInfo::onDisplayConfigChanged() { mDisplayInfo = QueryDisplayInfo(); updateDisplayInfo(); } void DeviceInfo::updateDisplayInfo() { if (Properties::isolatedProcess) { return; } if (mCurrentConfig == nullptr) { mDisplaysSize = ADisplay_acquirePhysicalDisplays(&mDisplays); LOG_ALWAYS_FATAL_IF(mDisplays == nullptr || mDisplaysSize <= 0, "Failed to get physical displays: no connected display: %d!", mDisplaysSize); for (size_t i = 0; i < mDisplaysSize; i++) { ADisplayType type = ADisplay_getDisplayType(mDisplays[i]); if (type == ADisplayType::DISPLAY_TYPE_INTERNAL) { mPhysicalDisplayIndex = i; break; } } LOG_ALWAYS_FATAL_IF(mPhysicalDisplayIndex < 0, "Failed to find a connected physical display!"); mMaxRefreshRate = ADisplay_getMaxSupportedFps(mDisplays[mPhysicalDisplayIndex]); } status_t status = ADisplay_getCurrentConfig(mDisplays[mPhysicalDisplayIndex], &mCurrentConfig); LOG_ALWAYS_FATAL_IF(status, "Failed to get display config, error %d", status); mWidth = ADisplayConfig_getWidth(mCurrentConfig); mHeight = ADisplayConfig_getHeight(mCurrentConfig); mDensity = ADisplayConfig_getDensity(mCurrentConfig); mRefreshRate = ADisplayConfig_getFps(mCurrentConfig); mCompositorOffset = ADisplayConfig_getCompositorOffsetNanos(mCurrentConfig); mAppOffset = ADisplayConfig_getAppVsyncOffsetNanos(mCurrentConfig); } } /* namespace uirenderer */ Loading
libs/hwui/DeviceInfo.h +21 −5 Original line number Diff line number Diff line Loading @@ -16,8 +16,8 @@ #ifndef DEVICEINFO_H #define DEVICEINFO_H #include <apex/display.h> #include <SkImageInfo.h> #include <ui/DisplayInfo.h> #include "utils/Macros.h" Loading @@ -33,28 +33,44 @@ class DeviceInfo { public: static DeviceInfo* get(); static float getMaxRefreshRate() { return get()->mMaxRefreshRate; } static int32_t getWidth() { return get()->mWidth; } static int32_t getHeight() { return get()->mHeight; } static float getDensity() { return get()->mDensity; } static float getRefreshRate() { return get()->mRefreshRate; } static int64_t getCompositorOffset() { return get()->mCompositorOffset; } static int64_t getAppOffset() { return get()->mAppOffset; } // this value is only valid after the GPU has been initialized and there is a valid graphics // context or if you are using the HWUI_NULL_GPU int maxTextureSize() const; const DisplayInfo& displayInfo() const { return mDisplayInfo; } sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; } SkColorType getWideColorType() const { return mWideColorType; } float getMaxRefreshRate() const { return mMaxRefreshRate; } void onDisplayConfigChanged(); private: friend class renderthread::RenderThread; static void setMaxTextureSize(int maxTextureSize); void updateDisplayInfo(); DeviceInfo(); ~DeviceInfo(); int mMaxTextureSize; DisplayInfo mDisplayInfo; sk_sp<SkColorSpace> mWideColorSpace; SkColorType mWideColorType; const float mMaxRefreshRate; ADisplayConfig* mCurrentConfig = nullptr; ADisplay** mDisplays = nullptr; int mDisplaysSize = 0; int mPhysicalDisplayIndex = -1; float mMaxRefreshRate = 60.0; int32_t mWidth = 1080; int32_t mHeight = 1920; float mDensity = 2.0; float mRefreshRate = 60.0; int64_t mCompositorOffset = 0; int64_t mAppOffset = 0; }; } /* namespace uirenderer */ Loading
libs/hwui/JankTracker.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -16,8 +16,10 @@ #include "JankTracker.h" #include <cutils/ashmem.h> #include <errno.h> #include <inttypes.h> #include <log/log.h> #include <statslog.h> #include <sys/mman.h> Loading @@ -25,11 +27,9 @@ #include <cmath> #include <cstdio> #include <limits> #include <cutils/ashmem.h> #include <log/log.h> #include <sstream> #include "DeviceInfo.h" #include "Properties.h" #include "utils/TimeUtils.h" #include "utils/Trace.h" Loading Loading @@ -79,11 +79,11 @@ static const int64_t EXEMPT_FRAMES_FLAGS = FrameInfoFlags::SurfaceCanvas; // and filter it out of the frame profile data static FrameInfoIndex sFrameStart = FrameInfoIndex::IntendedVsync; JankTracker::JankTracker(ProfileDataContainer* globalData, const DisplayInfo& displayInfo) { JankTracker::JankTracker(ProfileDataContainer* globalData) { mGlobalData = globalData; nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1_s / displayInfo.fps); nsecs_t sfOffset = frameIntervalNanos - (displayInfo.presentationDeadline - 1_ms); nsecs_t offsetDelta = sfOffset - displayInfo.appVsyncOffset; nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1_s / DeviceInfo::getRefreshRate()); nsecs_t sfOffset = DeviceInfo::getCompositorOffset(); nsecs_t offsetDelta = sfOffset - DeviceInfo::getAppOffset(); // There are two different offset cases. If the offsetDelta is positive // and small, then the intention is to give apps extra time by leveraging // pipelining between the UI & RT threads. If the offsetDelta is large or Loading