From e07e103103d575789ad0a9d5a5212a000ad1f277 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 26 Nov 2018 12:55:53 -0800 Subject: SurfaceFlinger Input: Correct screen magnification. We need to pass the computed scaling factors through SurfaceFlinger as well as appropriately scaling the touchable region. We also need to be careful as to which axes we scale. In the past screen magnification has not lead to scaling of the TOUCH_MAJOR/MINOR axes, whereas whole-screen display compatibility scaling has. We preserve this behavior by differentiating between the global scale and a scale on any particular window. The window scale works like the global scale used to and the global scale is only used for additional scaling of the MAJOR/MINOR axes. Bug: 80101428 Bug: 113136004 Bug: 111440400 Change-Id: I97d809826f86b452f28443cb1046e8bfef1bbf9d --- libs/ui/Region.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libs/ui/Region.cpp') diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index fe4ae6c414..815093174c 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -325,6 +325,20 @@ Region& Region::translateSelf(int x, int y) { return *this; } +Region& Region::scaleSelf(int sx, int sy) { + size_t count = mStorage.size(); + Rect* rects = mStorage.editArray(); + while (count) { + rects->left *= sx; + rects->right *= sx; + rects->top *= sy; + rects->bottom *= sy; + rects++; + count--; + } + return *this; +} + // ---------------------------------------------------------------------------- const Region Region::merge(const Rect& rhs) const { -- cgit v1.2.3-59-g8ed1b From 39d4aa5bb18a14680347f6f6d1a34eed918e274b Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 30 Nov 2018 20:46:53 +0800 Subject: Fix empty region if the scale is smaller than 1 It may be used by Layer of SurfaceFlinger to calculate touchable region. It should be able to scale a window to a smaller size. Bug: 111440400 Test: manual - An input-associated surface with a scaling matrix that has dsdx, dsdy < 1. Use "dumpsys input" to observe its touchable region. Change-Id: I495bd16acec77f913fd39dcac90404eddc71cabb --- libs/ui/Region.cpp | 10 +++++----- libs/ui/include/ui/Region.h | 2 +- services/inputflinger/InputDispatcher.cpp | 2 +- services/surfaceflinger/Layer.cpp | 11 +++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'libs/ui/Region.cpp') diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 815093174c..618c7d62b1 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -325,14 +325,14 @@ Region& Region::translateSelf(int x, int y) { return *this; } -Region& Region::scaleSelf(int sx, int sy) { +Region& Region::scaleSelf(float sx, float sy) { size_t count = mStorage.size(); Rect* rects = mStorage.editArray(); while (count) { - rects->left *= sx; - rects->right *= sx; - rects->top *= sy; - rects->bottom *= sy; + rects->left = static_cast(rects->left * sx + 0.5f); + rects->right = static_cast(rects->right * sx + 0.5f); + rects->top = static_cast(rects->top * sy + 0.5f); + rects->bottom = static_cast(rects->bottom * sy + 0.5f); rects++; count--; } diff --git a/libs/ui/include/ui/Region.h b/libs/ui/include/ui/Region.h index c5e31c56f1..0a09960994 100644 --- a/libs/ui/include/ui/Region.h +++ b/libs/ui/include/ui/Region.h @@ -89,7 +89,7 @@ public: // these translate rhs first Region& translateSelf(int dx, int dy); - Region& scaleSelf(int sx, int sy); + Region& scaleSelf(float sx, float sy); Region& orSelf(const Region& rhs, int dx, int dy); Region& xorSelf(const Region& rhs, int dx, int dy); Region& andSelf(const Region& rhs, int dx, int dy); diff --git a/services/inputflinger/InputDispatcher.cpp b/services/inputflinger/InputDispatcher.cpp index bea4f911d9..0e258c8eb9 100644 --- a/services/inputflinger/InputDispatcher.cpp +++ b/services/inputflinger/InputDispatcher.cpp @@ -3518,7 +3518,7 @@ void InputDispatcher::dumpDispatchStateLocked(std::string& dump) { dump += StringPrintf(INDENT3 "%zu: name='%s', displayId=%d, " "paused=%s, hasFocus=%s, hasWallpaper=%s, " "visible=%s, canReceiveKeys=%s, flags=0x%08x, type=0x%08x, layer=%d, " - "frame=[%d,%d][%d,%d], globalScale=%f, windowScale=%f,%f" + "frame=[%d,%d][%d,%d], globalScale=%f, windowScale=(%f,%f), " "touchableRegion=", i, windowInfo->name.c_str(), windowInfo->displayId, toString(windowInfo->paused), diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 81456dfea9..58fd86618e 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -2069,10 +2069,13 @@ InputWindowInfo Layer::fillInputInfo(const Rect& screenBounds) { info.frameBottom = screenBounds.bottom - info.surfaceInset; ui::Transform t = getTransform(); - info.windowXScale *= 1.0f / t.sx(); - info.windowYScale *= 1.0f / t.sy(); - - info.touchableRegion.scaleSelf(t.sx(), t.sy()); + const float xScale = t.sx(); + const float yScale = t.sy(); + if (xScale != 1.0f || yScale != 1.0f) { + info.windowXScale *= 1.0f / xScale; + info.windowYScale *= 1.0f / yScale; + info.touchableRegion.scaleSelf(xScale, yScale); + } info.touchableRegion = info.touchableRegion.translate( screenBounds.left, -- cgit v1.2.3-59-g8ed1b From 5434a781d70df56cef2ecf6cbc9d6c7b8faf1ae8 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 5 Dec 2018 18:06:32 -0800 Subject: SurfaceFlinger: Get rid of String8 in dumpsys Test: build and gui/ui/renderengine/surfaceflinger tests and compare dumpsys SurfaceFlinger results Change-Id: Iafdaf73a0acbbbb8fbafc930ad86285106a07e13 --- libs/gui/Android.bp | 1 + libs/gui/FrameTimestamps.cpp | 54 +++--- libs/gui/GuiConfig.cpp | 3 +- libs/gui/LayerDebugInfo.cpp | 52 +++--- libs/gui/include/gui/FrameTimestamps.h | 5 +- libs/gui/include/gui/GuiConfig.h | 4 +- libs/gui/tests/Android.bp | 1 + libs/renderengine/Android.bp | 1 + libs/renderengine/gl/GLESRenderEngine.cpp | 25 +-- libs/renderengine/gl/GLESRenderEngine.h | 4 +- .../include/renderengine/RenderEngine.h | 3 +- libs/renderengine/tests/Android.bp | 1 + libs/ui/GraphicBufferAllocator.cpp | 41 ++--- libs/ui/Region.cpp | 15 +- libs/ui/UiConfig.cpp | 3 +- libs/ui/include/ui/GraphicBufferAllocator.h | 3 +- libs/ui/include/ui/Region.h | 9 +- libs/ui/include/ui/UiConfig.h | 4 +- services/surfaceflinger/Colorizer.h | 10 +- services/surfaceflinger/DisplayDevice.cpp | 41 ++--- services/surfaceflinger/DisplayDevice.h | 3 +- .../surfaceflinger/DisplayHardware/HWComposer.cpp | 4 +- .../surfaceflinger/DisplayHardware/HWComposer.h | 3 +- services/surfaceflinger/FrameTracker.cpp | 11 +- services/surfaceflinger/FrameTracker.h | 2 +- services/surfaceflinger/Layer.cpp | 39 +++-- services/surfaceflinger/Layer.h | 8 +- services/surfaceflinger/LayerBE.cpp | 11 +- services/surfaceflinger/LayerStats.cpp | 52 +++--- services/surfaceflinger/LayerStats.h | 3 +- services/surfaceflinger/Scheduler/DispSync.cpp | 53 +++--- services/surfaceflinger/Scheduler/DispSync.h | 5 +- services/surfaceflinger/Scheduler/EventThread.cpp | 20 ++- services/surfaceflinger/Scheduler/EventThread.h | 5 +- services/surfaceflinger/Scheduler/Scheduler.cpp | 2 +- services/surfaceflinger/Scheduler/Scheduler.h | 2 +- services/surfaceflinger/SurfaceFlinger.cpp | 188 ++++++++++----------- services/surfaceflinger/SurfaceFlinger.h | 22 +-- services/surfaceflinger/SurfaceTracing.cpp | 10 +- services/surfaceflinger/SurfaceTracing.h | 3 +- services/surfaceflinger/TimeStats/TimeStats.cpp | 6 +- services/surfaceflinger/TimeStats/TimeStats.h | 6 +- .../tests/unittests/SchedulerTest.cpp | 6 +- .../tests/unittests/TimeStatsTest.cpp | 5 +- .../tests/unittests/mock/MockDispSync.h | 3 +- .../tests/unittests/mock/MockEventThread.h | 2 +- .../unittests/mock/RenderEngine/MockRenderEngine.h | 2 +- 47 files changed, 367 insertions(+), 389 deletions(-) (limited to 'libs/ui/Region.cpp') diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index 908eee9e33..d1c732bc1f 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -122,6 +122,7 @@ cc_library_shared { shared_libs: [ "android.hardware.graphics.common@1.1", + "libbase", "libsync", "libbinder", "libbufferhub", diff --git a/libs/gui/FrameTimestamps.cpp b/libs/gui/FrameTimestamps.cpp index 85ae433e42..96e9a85fd2 100644 --- a/libs/gui/FrameTimestamps.cpp +++ b/libs/gui/FrameTimestamps.cpp @@ -18,10 +18,10 @@ #define LOG_TAG "FrameEvents" +#include #include // For CC_[UN]LIKELY #include #include -#include #include #include @@ -29,6 +29,7 @@ namespace android { +using base::StringAppendF; // ============================================================================ // FrameEvents @@ -86,50 +87,49 @@ void FrameEvents::checkFencesForCompletion() { releaseFence->getSignalTime(); } -static void dumpFenceTime(String8& outString, const char* name, - bool pending, const FenceTime& fenceTime) { - outString.appendFormat("--- %s", name); +static void dumpFenceTime(std::string& outString, const char* name, bool pending, + const FenceTime& fenceTime) { + StringAppendF(&outString, "--- %s", name); nsecs_t signalTime = fenceTime.getCachedSignalTime(); if (Fence::isValidTimestamp(signalTime)) { - outString.appendFormat("%" PRId64 "\n", signalTime); + StringAppendF(&outString, "%" PRId64 "\n", signalTime); } else if (pending || signalTime == Fence::SIGNAL_TIME_PENDING) { - outString.appendFormat("Pending\n"); + outString.append("Pending\n"); } else if (&fenceTime == FenceTime::NO_FENCE.get()){ - outString.appendFormat("N/A\n"); + outString.append("N/A\n"); } else { - outString.appendFormat("Error\n"); + outString.append("Error\n"); } } -void FrameEvents::dump(String8& outString) const -{ +void FrameEvents::dump(std::string& outString) const { if (!valid) { return; } - outString.appendFormat("-- Frame %" PRIu64 "\n", frameNumber); - outString.appendFormat("--- Posted \t%" PRId64 "\n", postedTime); - outString.appendFormat("--- Req. Present\t%" PRId64 "\n", requestedPresentTime); + StringAppendF(&outString, "-- Frame %" PRIu64 "\n", frameNumber); + StringAppendF(&outString, "--- Posted \t%" PRId64 "\n", postedTime); + StringAppendF(&outString, "--- Req. Present\t%" PRId64 "\n", requestedPresentTime); - outString.appendFormat("--- Latched \t"); + outString.append("--- Latched \t"); if (FrameEvents::isValidTimestamp(latchTime)) { - outString.appendFormat("%" PRId64 "\n", latchTime); + StringAppendF(&outString, "%" PRId64 "\n", latchTime); } else { - outString.appendFormat("Pending\n"); + outString.append("Pending\n"); } - outString.appendFormat("--- Refresh (First)\t"); + outString.append("--- Refresh (First)\t"); if (FrameEvents::isValidTimestamp(firstRefreshStartTime)) { - outString.appendFormat("%" PRId64 "\n", firstRefreshStartTime); + StringAppendF(&outString, "%" PRId64 "\n", firstRefreshStartTime); } else { - outString.appendFormat("Pending\n"); + outString.append("Pending\n"); } - outString.appendFormat("--- Refresh (Last)\t"); + outString.append("--- Refresh (Last)\t"); if (FrameEvents::isValidTimestamp(lastRefreshStartTime)) { - outString.appendFormat("%" PRId64 "\n", lastRefreshStartTime); + StringAppendF(&outString, "%" PRId64 "\n", lastRefreshStartTime); } else { - outString.appendFormat("Pending\n"); + outString.append("Pending\n"); } dumpFenceTime(outString, "Acquire \t", @@ -139,11 +139,11 @@ void FrameEvents::dump(String8& outString) const dumpFenceTime(outString, "Display Present \t", !addPostCompositeCalled, *displayPresentFence); - outString.appendFormat("--- DequeueReady \t"); + outString.append("--- DequeueReady \t"); if (FrameEvents::isValidTimestamp(dequeueReadyTime)) { - outString.appendFormat("%" PRId64 "\n", dequeueReadyTime); + StringAppendF(&outString, "%" PRId64 "\n", dequeueReadyTime); } else { - outString.appendFormat("Pending\n"); + outString.append("Pending\n"); } dumpFenceTime(outString, "Release \t", @@ -206,11 +206,11 @@ static bool FrameNumberLessThan( return lhs.valid; } -void FrameEventHistory::dump(String8& outString) const { +void FrameEventHistory::dump(std::string& outString) const { auto earliestFrame = std::min_element( mFrames.begin(), mFrames.end(), &FrameNumberLessThan); if (!earliestFrame->valid) { - outString.appendFormat("-- N/A\n"); + outString.append("-- N/A\n"); return; } for (auto frame = earliestFrame; frame != mFrames.end(); ++frame) { diff --git a/libs/gui/GuiConfig.cpp b/libs/gui/GuiConfig.cpp index bc0c83c557..3ec20ee0c0 100644 --- a/libs/gui/GuiConfig.cpp +++ b/libs/gui/GuiConfig.cpp @@ -18,8 +18,7 @@ namespace android { -void appendGuiConfigString(String8& configStr) -{ +void appendGuiConfigString(std::string& configStr) { static const char* config = " [libgui" #ifdef DONT_USE_FENCE_SYNC diff --git a/libs/gui/LayerDebugInfo.cpp b/libs/gui/LayerDebugInfo.cpp index ccde9e08e1..cdde9a2308 100644 --- a/libs/gui/LayerDebugInfo.cpp +++ b/libs/gui/LayerDebugInfo.cpp @@ -16,13 +16,14 @@ #include +#include + #include #include -#include - using namespace android; +using android::base::StringAppendF; #define RETURN_ON_ERROR(X) do {status_t res = (X); if (res != NO_ERROR) return res;} while(false) @@ -108,38 +109,37 @@ status_t LayerDebugInfo::readFromParcel(const Parcel* parcel) { } std::string to_string(const LayerDebugInfo& info) { - String8 result; + std::string result; - result.appendFormat("+ %s (%s)\n", info.mType.c_str(), info.mName.c_str()); + StringAppendF(&result, "+ %s (%s)\n", info.mType.c_str(), info.mName.c_str()); info.mTransparentRegion.dump(result, "TransparentRegion"); info.mVisibleRegion.dump(result, "VisibleRegion"); info.mSurfaceDamageRegion.dump(result, "SurfaceDamageRegion"); - result.appendFormat(" layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), ", - info.mLayerStack, info.mZ, static_cast(info.mX), static_cast(info.mY), - info.mWidth, info.mHeight); + StringAppendF(&result, " layerStack=%4d, z=%9d, pos=(%g,%g), size=(%4d,%4d), ", + info.mLayerStack, info.mZ, static_cast(info.mX), + static_cast(info.mY), info.mWidth, info.mHeight); - result.appendFormat("crop=%s, ", to_string(info.mCrop).c_str()); - result.appendFormat("isOpaque=%1d, invalidate=%1d, ", info.mIsOpaque, info.mContentDirty); - result.appendFormat("dataspace=%s, ", dataspaceDetails(info.mDataSpace).c_str()); - result.appendFormat("pixelformat=%s, ", decodePixelFormat(info.mPixelFormat).c_str()); - result.appendFormat("color=(%.3f,%.3f,%.3f,%.3f), flags=0x%08x, ", - static_cast(info.mColor.r), static_cast(info.mColor.g), - static_cast(info.mColor.b), static_cast(info.mColor.a), - info.mFlags); - result.appendFormat("tr=[%.2f, %.2f][%.2f, %.2f]", - static_cast(info.mMatrix[0][0]), static_cast(info.mMatrix[0][1]), - static_cast(info.mMatrix[1][0]), static_cast(info.mMatrix[1][1])); + StringAppendF(&result, "crop=%s, ", to_string(info.mCrop).c_str()); + StringAppendF(&result, "isOpaque=%1d, invalidate=%1d, ", info.mIsOpaque, info.mContentDirty); + StringAppendF(&result, "dataspace=%s, ", dataspaceDetails(info.mDataSpace).c_str()); + StringAppendF(&result, "pixelformat=%s, ", decodePixelFormat(info.mPixelFormat).c_str()); + StringAppendF(&result, "color=(%.3f,%.3f,%.3f,%.3f), flags=0x%08x, ", + static_cast(info.mColor.r), static_cast(info.mColor.g), + static_cast(info.mColor.b), static_cast(info.mColor.a), + info.mFlags); + StringAppendF(&result, "tr=[%.2f, %.2f][%.2f, %.2f]", static_cast(info.mMatrix[0][0]), + static_cast(info.mMatrix[0][1]), static_cast(info.mMatrix[1][0]), + static_cast(info.mMatrix[1][1])); result.append("\n"); - result.appendFormat(" parent=%s\n", info.mParentName.c_str()); - result.appendFormat(" activeBuffer=[%4ux%4u:%4u,%s],", - info.mActiveBufferWidth, info.mActiveBufferHeight, - info.mActiveBufferStride, - decodePixelFormat(info.mActiveBufferFormat).c_str()); - result.appendFormat(" queued-frames=%d, mRefreshPending=%d", - info.mNumQueuedFrames, info.mRefreshPending); + StringAppendF(&result, " parent=%s\n", info.mParentName.c_str()); + StringAppendF(&result, " activeBuffer=[%4ux%4u:%4u,%s],", info.mActiveBufferWidth, + info.mActiveBufferHeight, info.mActiveBufferStride, + decodePixelFormat(info.mActiveBufferFormat).c_str()); + StringAppendF(&result, " queued-frames=%d, mRefreshPending=%d", info.mNumQueuedFrames, + info.mRefreshPending); result.append("\n"); - return std::string(result.c_str()); + return result; } } // android diff --git a/libs/gui/include/gui/FrameTimestamps.h b/libs/gui/include/gui/FrameTimestamps.h index e06e40f2a6..df02494bf4 100644 --- a/libs/gui/include/gui/FrameTimestamps.h +++ b/libs/gui/include/gui/FrameTimestamps.h @@ -30,7 +30,6 @@ namespace android { struct FrameEvents; class FrameEventHistoryDelta; -class String8; // Identifiers for all the events that may be recorded or reported. @@ -72,7 +71,7 @@ struct FrameEvents { bool hasDequeueReadyInfo() const; void checkFencesForCompletion(); - void dump(String8& outString) const; + void dump(std::string& outString) const; bool valid{false}; int connectId{0}; @@ -112,7 +111,7 @@ public: FrameEvents* getFrame(uint64_t frameNumber); FrameEvents* getFrame(uint64_t frameNumber, size_t* iHint); void checkFencesForCompletion(); - void dump(String8& outString) const; + void dump(std::string& outString) const; static constexpr size_t MAX_FRAME_HISTORY = 8; diff --git a/libs/gui/include/gui/GuiConfig.h b/libs/gui/include/gui/GuiConfig.h index b020ed9b6a..7aa54321fd 100644 --- a/libs/gui/include/gui/GuiConfig.h +++ b/libs/gui/include/gui/GuiConfig.h @@ -17,12 +17,12 @@ #ifndef ANDROID_GUI_CONFIG_H #define ANDROID_GUI_CONFIG_H -#include +#include namespace android { // Append the libgui configuration details to configStr. -void appendGuiConfigString(String8& configStr); +void appendGuiConfigString(std::string& configStr); }; // namespace android diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp index 6de641d0e0..f020a4067d 100644 --- a/libs/gui/tests/Android.bp +++ b/libs/gui/tests/Android.bp @@ -37,6 +37,7 @@ cc_test { shared_libs: [ "android.hardware.configstore@1.0", "android.hardware.configstore-utils", + "libbase", "liblog", "libEGL", "libGLESv1_CM", diff --git a/libs/renderengine/Android.bp b/libs/renderengine/Android.bp index 997ae90c69..d872f0264e 100644 --- a/libs/renderengine/Android.bp +++ b/libs/renderengine/Android.bp @@ -18,6 +18,7 @@ cc_defaults { "-DEGL_EGLEXT_PROTOTYPES", ], shared_libs: [ + "libbase", "libcutils", "libEGL", "libGLESv1_CM", diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp index 8a9e7bd823..1395551642 100644 --- a/libs/renderengine/gl/GLESRenderEngine.cpp +++ b/libs/renderengine/gl/GLESRenderEngine.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -36,7 +37,6 @@ #include #include #include -#include #include #include "GLExtensions.h" #include "GLFramebuffer.h" @@ -109,6 +109,7 @@ namespace android { namespace renderengine { namespace gl { +using base::StringAppendF; using ui::Dataspace; static status_t selectConfigForAttribute(EGLDisplay dpy, EGLint const* attrs, EGLint attribute, @@ -854,22 +855,22 @@ size_t GLESRenderEngine::getMaxViewportDims() const { return mMaxViewportDims[0] < mMaxViewportDims[1] ? mMaxViewportDims[0] : mMaxViewportDims[1]; } -void GLESRenderEngine::dump(String8& result) { +void GLESRenderEngine::dump(std::string& result) { const GLExtensions& extensions = GLExtensions::getInstance(); - result.appendFormat("EGL implementation : %s\n", extensions.getEGLVersion()); - result.appendFormat("%s\n", extensions.getEGLExtensions()); + StringAppendF(&result, "EGL implementation : %s\n", extensions.getEGLVersion()); + StringAppendF(&result, "%s\n", extensions.getEGLExtensions()); - result.appendFormat("GLES: %s, %s, %s\n", extensions.getVendor(), extensions.getRenderer(), - extensions.getVersion()); - result.appendFormat("%s\n", extensions.getExtensions()); + StringAppendF(&result, "GLES: %s, %s, %s\n", extensions.getVendor(), extensions.getRenderer(), + extensions.getVersion()); + StringAppendF(&result, "%s\n", extensions.getExtensions()); - result.appendFormat("RenderEngine program cache size: %zu\n", - ProgramCache::getInstance().getSize()); + StringAppendF(&result, "RenderEngine program cache size: %zu\n", + ProgramCache::getInstance().getSize()); - result.appendFormat("RenderEngine last dataspace conversion: (%s) to (%s)\n", - dataspaceDetails(static_cast(mDataSpace)).c_str(), - dataspaceDetails(static_cast(mOutputDataSpace)).c_str()); + StringAppendF(&result, "RenderEngine last dataspace conversion: (%s) to (%s)\n", + dataspaceDetails(static_cast(mDataSpace)).c_str(), + dataspaceDetails(static_cast(mOutputDataSpace)).c_str()); } GLESRenderEngine::GlesVersion GLESRenderEngine::parseGlesVersion(const char* str) { diff --git a/libs/renderengine/gl/GLESRenderEngine.h b/libs/renderengine/gl/GLESRenderEngine.h index 8876d66c9e..21d5b8197d 100644 --- a/libs/renderengine/gl/GLESRenderEngine.h +++ b/libs/renderengine/gl/GLESRenderEngine.h @@ -30,8 +30,6 @@ namespace android { -class String8; - namespace renderengine { class Mesh; @@ -79,7 +77,7 @@ public: EGLConfig getEGLConfig() const { return mEGLConfig; } protected: - void dump(String8& result) override; + void dump(std::string& result) override; void setViewportAndProjection(size_t vpw, size_t vph, Rect sourceCrop, ui::Transform::orientation_flags rotation) override; void setupLayerBlending(bool premultipliedAlpha, bool opaque, bool disableTexture, diff --git a/libs/renderengine/include/renderengine/RenderEngine.h b/libs/renderengine/include/renderengine/RenderEngine.h index bb7f4dfb71..8eaa2d296b 100644 --- a/libs/renderengine/include/renderengine/RenderEngine.h +++ b/libs/renderengine/include/renderengine/RenderEngine.h @@ -39,7 +39,6 @@ struct ANativeWindowBuffer; namespace android { -class String8; class Rect; class Region; @@ -76,7 +75,7 @@ public: virtual void primeCache() const = 0; // dump the extension strings. always call the base class. - virtual void dump(String8& result) = 0; + virtual void dump(std::string& result) = 0; virtual bool useNativeFenceSync() const = 0; virtual bool useWaitSync() const = 0; diff --git a/libs/renderengine/tests/Android.bp b/libs/renderengine/tests/Android.bp index 65b7c82a0f..051b8b6212 100644 --- a/libs/renderengine/tests/Android.bp +++ b/libs/renderengine/tests/Android.bp @@ -24,6 +24,7 @@ cc_test { "librenderengine", ], shared_libs: [ + "libbase", "libcutils", "libEGL", "libGLESv2", diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index eaba1ed1aa..a2f1783e58 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -24,9 +24,9 @@ #include +#include #include #include -#include #include #include @@ -35,6 +35,8 @@ namespace android { // --------------------------------------------------------------------------- +using base::StringAppendF; + ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferAllocator ) Mutex GraphicBufferAllocator::sLock; @@ -50,46 +52,37 @@ GraphicBufferAllocator::GraphicBufferAllocator() GraphicBufferAllocator::~GraphicBufferAllocator() {} -void GraphicBufferAllocator::dump(String8& result) const -{ +void GraphicBufferAllocator::dump(std::string& result) const { Mutex::Autolock _l(sLock); KeyedVector& list(sAllocList); size_t total = 0; - const size_t SIZE = 4096; - char buffer[SIZE]; - snprintf(buffer, SIZE, "Allocated buffers:\n"); - result.append(buffer); + result.append("Allocated buffers:\n"); const size_t c = list.size(); for (size_t i=0 ; idumpDebugInfo(); - result.append(deviceDump.c_str(), deviceDump.size()); + result.append(mAllocator->dumpDebugInfo()); } void GraphicBufferAllocator::dumpToSystemLog() { - String8 s; + std::string s; GraphicBufferAllocator::getInstance().dump(s); - ALOGD("%s", s.string()); + ALOGD("%s", s.c_str()); } status_t GraphicBufferAllocator::allocate(uint32_t width, uint32_t height, diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 618c7d62b1..3bd3748439 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -19,8 +19,9 @@ #include #include +#include + #include -#include #include #include @@ -41,6 +42,8 @@ namespace android { // ---------------------------------------------------------------------------- +using base::StringAppendF; + enum { op_nand = region_operator::op_nand, op_and = region_operator::op_and, @@ -868,16 +871,14 @@ Rect const* Region::getArray(size_t* count) const { // ---------------------------------------------------------------------------- -void Region::dump(String8& out, const char* what, uint32_t /* flags */) const -{ +void Region::dump(std::string& out, const char* what, uint32_t /* flags */) const { const_iterator head = begin(); const_iterator const tail = end(); - out.appendFormat(" Region %s (this=%p, count=%" PRIdPTR ")\n", - what, this, tail - head); + StringAppendF(&out, " Region %s (this=%p, count=%" PRIdPTR ")\n", what, this, tail - head); while (head != tail) { - out.appendFormat(" [%3d, %3d, %3d, %3d]\n", head->left, head->top, - head->right, head->bottom); + StringAppendF(&out, " [%3d, %3d, %3d, %3d]\n", head->left, head->top, head->right, + head->bottom); ++head; } } diff --git a/libs/ui/UiConfig.cpp b/libs/ui/UiConfig.cpp index 7730690cfd..0ac863d718 100644 --- a/libs/ui/UiConfig.cpp +++ b/libs/ui/UiConfig.cpp @@ -18,8 +18,7 @@ namespace android { -void appendUiConfigString(String8& configStr) -{ +void appendUiConfigString(std::string& configStr) { static const char* config = " [libui]"; configStr.append(config); diff --git a/libs/ui/include/ui/GraphicBufferAllocator.h b/libs/ui/include/ui/GraphicBufferAllocator.h index 14a865e16c..7e2b230fe9 100644 --- a/libs/ui/include/ui/GraphicBufferAllocator.h +++ b/libs/ui/include/ui/GraphicBufferAllocator.h @@ -39,7 +39,6 @@ class Allocator; } class GraphicBufferMapper; -class String8; class GraphicBufferAllocator : public Singleton { @@ -53,7 +52,7 @@ public: status_t free(buffer_handle_t handle); - void dump(String8& res) const; + void dump(std::string& res) const; static void dumpToSystemLog(); private: diff --git a/libs/ui/include/ui/Region.h b/libs/ui/include/ui/Region.h index 0a09960994..79642ae032 100644 --- a/libs/ui/include/ui/Region.h +++ b/libs/ui/include/ui/Region.h @@ -27,12 +27,11 @@ #include +#include + namespace android { // --------------------------------------------------------------------------- -class String8; - -// --------------------------------------------------------------------------- class Region : public LightFlattenable { public: @@ -144,8 +143,8 @@ public: status_t flatten(void* buffer, size_t size) const; status_t unflatten(void const* buffer, size_t size); - void dump(String8& out, const char* what, uint32_t flags=0) const; - void dump(const char* what, uint32_t flags=0) const; + void dump(std::string& out, const char* what, uint32_t flags=0) const; + void dump(const char* what, uint32_t flags=0) const; private: class rasterizer; diff --git a/libs/ui/include/ui/UiConfig.h b/libs/ui/include/ui/UiConfig.h index fcf8ed5d6b..d1d6014a7b 100644 --- a/libs/ui/include/ui/UiConfig.h +++ b/libs/ui/include/ui/UiConfig.h @@ -17,12 +17,12 @@ #ifndef ANDROID_UI_CONFIG_H #define ANDROID_UI_CONFIG_H -#include +#include namespace android { // Append the libui configuration details to configStr. -void appendUiConfigString(String8& configStr); +void appendUiConfigString(std::string& configStr); }; // namespace android diff --git a/services/surfaceflinger/Colorizer.h b/services/surfaceflinger/Colorizer.h index d56b1c8d9b..b7d61ce08e 100644 --- a/services/surfaceflinger/Colorizer.h +++ b/services/surfaceflinger/Colorizer.h @@ -17,7 +17,7 @@ #ifndef ANDROID_SURFACE_FLINGER_COLORIZER_H #define ANDROID_SURFACE_FLINGER_COLORIZER_H -#include +#include namespace android { @@ -40,19 +40,19 @@ public: : mEnabled(enabled) { } - void colorize(String8& out, color c) { + void colorize(std::string& out, color c) { if (mEnabled) { - out.appendFormat("\e[%dm", c); + base::StringAppendF(&out, "\e[%dm", c); } } - void bold(String8& out) { + void bold(std::string& out) { if (mEnabled) { out.append("\e[1m"); } } - void reset(String8& out) { + void reset(std::string& out) { if (mEnabled) { out.append("\e[0m"); } diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 1215bd9057..b83b84a281 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -54,6 +54,7 @@ namespace android { // retrieve triple buffer setting from configstore using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; +using android::base::StringAppendF; using android::ui::ColorMode; using android::ui::Dataspace; using android::ui::Hdr; @@ -715,33 +716,33 @@ std::string DisplayDevice::getDebugName() const { mDisplayName.c_str()); } -void DisplayDevice::dump(String8& result) const { +void DisplayDevice::dump(std::string& result) const { const ui::Transform& tr(mGlobalTransform); ANativeWindow* const window = mNativeWindow.get(); - result.appendFormat("+ %s\n", getDebugName().c_str()); - result.appendFormat(" layerStack=%u, (%4dx%4d), ANativeWindow=%p " - "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, " - "powerMode=%d, activeConfig=%d, numLayers=%zu\n", - mLayerStack, mDisplayWidth, mDisplayHeight, window, - ANativeWindow_getFormat(window), mOrientation, tr.getType(), - getPageFlipCount(), mIsSecure, mPowerMode, mActiveConfig, - mVisibleLayersSortedByZ.size()); - result.appendFormat(" v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," - "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", - mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, - mFrame.left, mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, - mScissor.top, mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], - tr[0][1], tr[1][1], tr[2][1], tr[0][2], tr[1][2], tr[2][2]); + StringAppendF(&result, "+ %s\n", getDebugName().c_str()); + StringAppendF(&result, + " layerStack=%u, (%4dx%4d), ANativeWindow=%p " + "format=%d, orient=%2d (type=%08x), flips=%u, isSecure=%d, " + "powerMode=%d, activeConfig=%d, numLayers=%zu\n", + mLayerStack, mDisplayWidth, mDisplayHeight, window, + ANativeWindow_getFormat(window), mOrientation, tr.getType(), getPageFlipCount(), + mIsSecure, mPowerMode, mActiveConfig, mVisibleLayersSortedByZ.size()); + StringAppendF(&result, + " v:[%d,%d,%d,%d], f:[%d,%d,%d,%d], s:[%d,%d,%d,%d]," + "transform:[[%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f][%0.3f,%0.3f,%0.3f]]\n", + mViewport.left, mViewport.top, mViewport.right, mViewport.bottom, mFrame.left, + mFrame.top, mFrame.right, mFrame.bottom, mScissor.left, mScissor.top, + mScissor.right, mScissor.bottom, tr[0][0], tr[1][0], tr[2][0], tr[0][1], tr[1][1], + tr[2][1], tr[0][2], tr[1][2], tr[2][2]); auto const surface = static_cast(window); ui::Dataspace dataspace = surface->getBuffersDataSpace(); - result.appendFormat(" wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", - mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), - dataspaceDetails(static_cast(dataspace)).c_str(), - dataspace); + StringAppendF(&result, " wideColorGamut=%d, hdr10=%d, colorMode=%s, dataspace: %s (%d)\n", + mHasWideColorGamut, mHasHdr10, decodeColorMode(mActiveColorMode).c_str(), + dataspaceDetails(static_cast(dataspace)).c_str(), dataspace); String8 surfaceDump; mDisplaySurface->dumpAsString(surfaceDump); - result.append(surfaceDump); + result.append(surfaceDump.string(), surfaceDump.size()); } // Map dataspace/intent to the best matched dataspace/colorMode/renderIntent diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index eb2c5c3f94..83572282bc 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "DisplayHardware/DisplayIdentification.h" @@ -201,7 +200,7 @@ public: */ uint32_t getPageFlipCount() const; std::string getDebugName() const; - void dump(String8& result) const; + void dump(std::string& result) const; private: const sp mFlinger; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index b27344d48e..0aa0dfb5c3 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -774,11 +774,11 @@ bool HWComposer::isUsingVrComposer() const { return getComposer()->isUsingVrComposer(); } -void HWComposer::dump(String8& result) const { +void HWComposer::dump(std::string& result) const { // TODO: In order to provide a dump equivalent to HWC1, we need to shadow // all the state going into the layers. This is probably better done in // Layer itself, but it's going to take a bit of work to get there. - result.append(mHwcDevice->dump().c_str()); + result.append(mHwcDevice->dump()); } std::optional HWComposer::toPhysicalDisplayId(hwc2_display_t hwcDisplayId) const { diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 3f1328e90e..aaa6e8c255 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -37,7 +37,6 @@ namespace android { class GraphicBuffer; -class String8; class TestableSurfaceFlinger; struct CompositionInfo; @@ -161,7 +160,7 @@ public: bool isUsingVrComposer() const; // for debugging ---------------------------------------------------------- - void dump(String8& out) const; + void dump(std::string& out) const; Hwc2::Composer* getComposer() const { return mHwcDevice->getComposer(); } diff --git a/services/surfaceflinger/FrameTracker.cpp b/services/surfaceflinger/FrameTracker.cpp index 1539873aaa..f4cc49b851 100644 --- a/services/surfaceflinger/FrameTracker.cpp +++ b/services/surfaceflinger/FrameTracker.cpp @@ -19,6 +19,7 @@ #include +#include #include #include @@ -230,17 +231,17 @@ bool FrameTracker::isFrameValidLocked(size_t idx) const { mFrameRecords[idx].actualPresentTime < INT64_MAX; } -void FrameTracker::dumpStats(String8& result) const { +void FrameTracker::dumpStats(std::string& result) const { Mutex::Autolock lock(mMutex); processFencesLocked(); const size_t o = mOffset; for (size_t i = 1; i < NUM_FRAME_RECORDS; i++) { const size_t index = (o+i) % NUM_FRAME_RECORDS; - result.appendFormat("%" PRId64 "\t%" PRId64 "\t%" PRId64 "\n", - mFrameRecords[index].desiredPresentTime, - mFrameRecords[index].actualPresentTime, - mFrameRecords[index].frameReadyTime); + base::StringAppendF(&result, "%" PRId64 "\t%" PRId64 "\t%" PRId64 "\n", + mFrameRecords[index].desiredPresentTime, + mFrameRecords[index].actualPresentTime, + mFrameRecords[index].frameReadyTime); } result.append("\n"); } diff --git a/services/surfaceflinger/FrameTracker.h b/services/surfaceflinger/FrameTracker.h index b4a9fd68fb..555dcc1d1f 100644 --- a/services/surfaceflinger/FrameTracker.h +++ b/services/surfaceflinger/FrameTracker.h @@ -90,7 +90,7 @@ public: void logAndResetStats(const String8& name); // dumpStats dump appends the current frame display time history to the result string. - void dumpStats(String8& result) const; + void dumpStats(std::string& result) const; private: struct FrameRecord { diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index f53ffae570..8e7be473a6 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -25,6 +25,8 @@ #include #include +#include + #include #include #include @@ -63,6 +65,8 @@ namespace android { +using base::StringAppendF; + std::atomic Layer::sSequence{1}; Layer::Layer(const LayerCreationArgs& args) @@ -1399,7 +1403,7 @@ LayerDebugInfo Layer::getLayerDebugInfo() const { info.mName = getName(); sp parent = getParent(); info.mParentName = (parent == nullptr ? std::string("none") : parent->getName().string()); - info.mType = String8(getTypeId()); + info.mType = std::string(getTypeId()); info.mTransparentRegion = ds.activeTransparentRegion_legacy; info.mVisibleRegion = visibleRegion; info.mSurfaceDamageRegion = surfaceDamageRegion; @@ -1439,7 +1443,7 @@ LayerDebugInfo Layer::getLayerDebugInfo() const { return info; } -void Layer::miniDumpHeader(String8& result) { +void Layer::miniDumpHeader(std::string& result) { result.append("-------------------------------"); result.append("-------------------------------"); result.append("-----------------------------\n"); @@ -1454,50 +1458,51 @@ void Layer::miniDumpHeader(String8& result) { result.append("-----------------------------\n"); } -void Layer::miniDump(String8& result, DisplayId displayId) const { +void Layer::miniDump(std::string& result, DisplayId displayId) const { if (!hasHwcLayer(displayId)) { return; } - String8 name; + std::string name; if (mName.length() > 77) { std::string shortened; shortened.append(mName.string(), 36); shortened.append("[...]"); shortened.append(mName.string() + (mName.length() - 36), 36); - name = shortened.c_str(); + name = shortened; } else { - name = mName; + name = std::string(mName.string(), mName.size()); } - result.appendFormat(" %s\n", name.string()); + StringAppendF(&result, " %s\n", name.c_str()); const State& layerState(getDrawingState()); const LayerBE::HWCInfo& hwcInfo = getBE().mHwcLayers.at(displayId); if (layerState.zOrderRelativeOf != nullptr || mDrawingParent != nullptr) { - result.appendFormat(" rel %6d | ", layerState.z); + StringAppendF(&result, " rel %6d | ", layerState.z); } else { - result.appendFormat(" %10d | ", layerState.z); + StringAppendF(&result, " %10d | ", layerState.z); } - result.appendFormat("%10s | ", to_string(getCompositionType(displayId)).c_str()); - result.appendFormat("%10s | ", to_string(hwcInfo.transform).c_str()); + StringAppendF(&result, "%10s | ", to_string(getCompositionType(displayId)).c_str()); + StringAppendF(&result, "%10s | ", to_string(hwcInfo.transform).c_str()); const Rect& frame = hwcInfo.displayFrame; - result.appendFormat("%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); + StringAppendF(&result, "%4d %4d %4d %4d | ", frame.left, frame.top, frame.right, frame.bottom); const FloatRect& crop = hwcInfo.sourceCrop; - result.appendFormat("%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, crop.bottom); + StringAppendF(&result, "%6.1f %6.1f %6.1f %6.1f\n", crop.left, crop.top, crop.right, + crop.bottom); result.append("- - - - - - - - - - - - - - - -\n"); std::string compositionInfoStr; getBE().compositionInfo.dump(compositionInfoStr, "compositionInfo"); - result.append(compositionInfoStr.c_str()); + result.append(compositionInfoStr); result.append("- - - - - - - - - - - - - - - -"); result.append("- - - - - - - - - - - - - - - -"); result.append("- - - - - - - - - - - - - - -\n"); } -void Layer::dumpFrameStats(String8& result) const { +void Layer::dumpFrameStats(std::string& result) const { mFrameTracker.dumpStats(result); } @@ -1513,8 +1518,8 @@ void Layer::getFrameStats(FrameStats* outStats) const { mFrameTracker.getStats(outStats); } -void Layer::dumpFrameEvents(String8& result) { - result.appendFormat("- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this); +void Layer::dumpFrameEvents(std::string& result) { + StringAppendF(&result, "- Layer %s (%s, %p)\n", getName().string(), getTypeId(), this); Mutex::Autolock lock(mFrameEventHistoryMutex); mFrameEventHistory.checkFencesForCompletion(); mFrameEventHistory.dump(result); diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index 6ea80c7ab4..4d95c4061e 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -565,10 +565,10 @@ public: LayerDebugInfo getLayerDebugInfo() const; /* always call base class first */ - static void miniDumpHeader(String8& result); - void miniDump(String8& result, DisplayId displayId) const; - void dumpFrameStats(String8& result) const; - void dumpFrameEvents(String8& result); + static void miniDumpHeader(std::string& result); + void miniDump(std::string& result, DisplayId displayId) const; + void dumpFrameStats(std::string& result) const; + void dumpFrameEvents(std::string& result); void clearFrameStats(); void logFrameStats(); void getFrameStats(FrameStats* outStats) const; diff --git a/services/surfaceflinger/LayerBE.cpp b/services/surfaceflinger/LayerBE.cpp index 70b00dd22a..e39babe117 100644 --- a/services/surfaceflinger/LayerBE.cpp +++ b/services/surfaceflinger/LayerBE.cpp @@ -101,15 +101,8 @@ void CompositionInfo::dumpHwc(std::string& result, const char* tag) const { result += base::StringPrintf("\tsourceCrop=%6.1f %6.1f %6.1f %6.1f\n", hwc.sourceCrop.left, hwc.sourceCrop.top, hwc.sourceCrop.right, hwc.sourceCrop.bottom); - { - // - // Keep a conversion from std::string to String8 and back until Region can use std::string - // - String8 regionString; - hwc.visibleRegion.dump(regionString, "visibleRegion"); - hwc.surfaceDamage.dump(regionString, "surfaceDamage"); - result += regionString.string(); - } + hwc.visibleRegion.dump(result, "visibleRegion"); + hwc.surfaceDamage.dump(result, "surfaceDamage"); result += base::StringPrintf("\tcolor transform matrix:\n" "\t\t[%f, %f, %f, %f,\n" diff --git a/services/surfaceflinger/LayerStats.cpp b/services/surfaceflinger/LayerStats.cpp index c0174aec60..a2d1feb40d 100644 --- a/services/surfaceflinger/LayerStats.cpp +++ b/services/surfaceflinger/LayerStats.cpp @@ -23,11 +23,13 @@ #include #include -#include #include namespace android { +using base::StringAppendF; +using base::StringPrintf; + void LayerStats::enable() { ATRACE_CALL(); std::lock_guard lock(mMutex); @@ -64,26 +66,24 @@ void LayerStats::traverseLayerTreeStatsLocked( if (!layer) continue; traverseLayerTreeStatsLocked(layer->children, layerGlobal, outLayerShapeVec); std::string key = ""; - base::StringAppendF(&key, ",%s", layer->type.c_str()); - base::StringAppendF(&key, ",%s", layerCompositionType(layer->hwcCompositionType)); - base::StringAppendF(&key, ",%d", layer->isProtected); - base::StringAppendF(&key, ",%s", layerTransform(layer->hwcTransform)); - base::StringAppendF(&key, ",%s", layerPixelFormat(layer->activeBuffer.format).c_str()); - base::StringAppendF(&key, ",%s", layer->dataspace.c_str()); - base::StringAppendF(&key, ",%s", - destinationLocation(layer->hwcFrame.left, layerGlobal.resolution[0], - true)); - base::StringAppendF(&key, ",%s", - destinationLocation(layer->hwcFrame.top, layerGlobal.resolution[1], - false)); - base::StringAppendF(&key, ",%s", - destinationSize(layer->hwcFrame.right - layer->hwcFrame.left, - layerGlobal.resolution[0], true)); - base::StringAppendF(&key, ",%s", - destinationSize(layer->hwcFrame.bottom - layer->hwcFrame.top, - layerGlobal.resolution[1], false)); - base::StringAppendF(&key, ",%s", scaleRatioWH(layer).c_str()); - base::StringAppendF(&key, ",%s", alpha(static_cast(layer->color.a))); + StringAppendF(&key, ",%s", layer->type.c_str()); + StringAppendF(&key, ",%s", layerCompositionType(layer->hwcCompositionType)); + StringAppendF(&key, ",%d", layer->isProtected); + StringAppendF(&key, ",%s", layerTransform(layer->hwcTransform)); + StringAppendF(&key, ",%s", layerPixelFormat(layer->activeBuffer.format).c_str()); + StringAppendF(&key, ",%s", layer->dataspace.c_str()); + StringAppendF(&key, ",%s", + destinationLocation(layer->hwcFrame.left, layerGlobal.resolution[0], true)); + StringAppendF(&key, ",%s", + destinationLocation(layer->hwcFrame.top, layerGlobal.resolution[1], false)); + StringAppendF(&key, ",%s", + destinationSize(layer->hwcFrame.right - layer->hwcFrame.left, + layerGlobal.resolution[0], true)); + StringAppendF(&key, ",%s", + destinationSize(layer->hwcFrame.bottom - layer->hwcFrame.top, + layerGlobal.resolution[1], false)); + StringAppendF(&key, ",%s", scaleRatioWH(layer).c_str()); + StringAppendF(&key, ",%s", alpha(static_cast(layer->color.a))); outLayerShapeVec->push_back(key); ALOGV("%s", key.c_str()); @@ -101,9 +101,9 @@ void LayerStats::logLayerStats(const LayersProto& layersProto) { traverseLayerTreeStatsLocked(layerTree.topLevelLayers, layerGlobal, &layerShapeVec); std::string layerShapeKey = - base::StringPrintf("%d,%s,%s,%s", static_cast(layerShapeVec.size()), - layerGlobal.colorMode.c_str(), layerGlobal.colorTransform.c_str(), - layerTransform(layerGlobal.globalTransform)); + StringPrintf("%d,%s,%s,%s", static_cast(layerShapeVec.size()), + layerGlobal.colorMode.c_str(), layerGlobal.colorTransform.c_str(), + layerTransform(layerGlobal.globalTransform)); ALOGV("%s", layerShapeKey.c_str()); std::sort(layerShapeVec.begin(), layerShapeVec.end(), std::greater()); @@ -114,7 +114,7 @@ void LayerStats::logLayerStats(const LayersProto& layersProto) { mLayerShapeStatsMap[layerShapeKey]++; } -void LayerStats::dump(String8& result) { +void LayerStats::dump(std::string& result) { ATRACE_CALL(); ALOGD("Dumping"); std::lock_guard lock(mMutex); @@ -122,7 +122,7 @@ void LayerStats::dump(String8& result) { result.append("LayerType,CompositionType,IsProtected,Transform,PixelFormat,Dataspace,"); result.append("DstX,DstY,DstWidth,DstHeight,WScale,HScale,Alpha\n"); for (auto& u : mLayerShapeStatsMap) { - result.appendFormat("%u,%s\n", u.second, u.first.c_str()); + StringAppendF(&result, "%u,%s\n", u.second, u.first.c_str()); } } diff --git a/services/surfaceflinger/LayerStats.h b/services/surfaceflinger/LayerStats.h index 9de9cce8bf..62b2688936 100644 --- a/services/surfaceflinger/LayerStats.h +++ b/services/surfaceflinger/LayerStats.h @@ -24,7 +24,6 @@ using namespace android::surfaceflinger; namespace android { -class String8; class LayerStats { public: @@ -33,7 +32,7 @@ public: void clear(); bool isEnabled(); void logLayerStats(const LayersProto& layersProto); - void dump(String8& result); + void dump(std::string& result); private: // Traverse layer tree to get all visible layers' stats diff --git a/services/surfaceflinger/Scheduler/DispSync.cpp b/services/surfaceflinger/Scheduler/DispSync.cpp index 172c4184f9..b74b9010d2 100644 --- a/services/surfaceflinger/Scheduler/DispSync.cpp +++ b/services/surfaceflinger/Scheduler/DispSync.cpp @@ -24,9 +24,9 @@ #include -#include +#include #include -#include +#include #include #include @@ -36,6 +36,7 @@ #include "EventLog/EventLog.h" #include "SurfaceFlinger.h" +using android::base::StringAppendF; using std::max; using std::min; @@ -667,54 +668,56 @@ void DispSync::setIgnorePresentFences(bool ignore) { } } -void DispSync::dump(String8& result) const { +void DispSync::dump(std::string& result) const { Mutex::Autolock lock(mMutex); - result.appendFormat("present fences are %s\n", mIgnorePresentFences ? "ignored" : "used"); - result.appendFormat("mPeriod: %" PRId64 " ns (%.3f fps; skipCount=%d)\n", mPeriod, - 1000000000.0 / mPeriod, mRefreshSkipCount); - result.appendFormat("mPhase: %" PRId64 " ns\n", mPhase); - result.appendFormat("mError: %" PRId64 " ns (sqrt=%.1f)\n", mError, sqrt(mError)); - result.appendFormat("mNumResyncSamplesSincePresent: %d (limit %d)\n", - mNumResyncSamplesSincePresent, MAX_RESYNC_SAMPLES_WITHOUT_PRESENT); - result.appendFormat("mNumResyncSamples: %zd (max %d)\n", mNumResyncSamples, MAX_RESYNC_SAMPLES); - - result.appendFormat("mResyncSamples:\n"); + StringAppendF(&result, "present fences are %s\n", mIgnorePresentFences ? "ignored" : "used"); + StringAppendF(&result, "mPeriod: %" PRId64 " ns (%.3f fps; skipCount=%d)\n", mPeriod, + 1000000000.0 / mPeriod, mRefreshSkipCount); + StringAppendF(&result, "mPhase: %" PRId64 " ns\n", mPhase); + StringAppendF(&result, "mError: %" PRId64 " ns (sqrt=%.1f)\n", mError, sqrt(mError)); + StringAppendF(&result, "mNumResyncSamplesSincePresent: %d (limit %d)\n", + mNumResyncSamplesSincePresent, MAX_RESYNC_SAMPLES_WITHOUT_PRESENT); + StringAppendF(&result, "mNumResyncSamples: %zd (max %d)\n", mNumResyncSamples, + MAX_RESYNC_SAMPLES); + + result.append("mResyncSamples:\n"); nsecs_t previous = -1; for (size_t i = 0; i < mNumResyncSamples; i++) { size_t idx = (mFirstResyncSample + i) % MAX_RESYNC_SAMPLES; nsecs_t sampleTime = mResyncSamples[idx]; if (i == 0) { - result.appendFormat(" %" PRId64 "\n", sampleTime); + StringAppendF(&result, " %" PRId64 "\n", sampleTime); } else { - result.appendFormat(" %" PRId64 " (+%" PRId64 ")\n", sampleTime, - sampleTime - previous); + StringAppendF(&result, " %" PRId64 " (+%" PRId64 ")\n", sampleTime, + sampleTime - previous); } previous = sampleTime; } - result.appendFormat("mPresentFences [%d]:\n", NUM_PRESENT_SAMPLES); + StringAppendF(&result, "mPresentFences [%d]:\n", NUM_PRESENT_SAMPLES); nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); previous = Fence::SIGNAL_TIME_INVALID; for (size_t i = 0; i < NUM_PRESENT_SAMPLES; i++) { size_t idx = (i + mPresentSampleOffset) % NUM_PRESENT_SAMPLES; nsecs_t presentTime = mPresentFences[idx]->getSignalTime(); if (presentTime == Fence::SIGNAL_TIME_PENDING) { - result.appendFormat(" [unsignaled fence]\n"); + StringAppendF(&result, " [unsignaled fence]\n"); } else if (presentTime == Fence::SIGNAL_TIME_INVALID) { - result.appendFormat(" [invalid fence]\n"); + StringAppendF(&result, " [invalid fence]\n"); } else if (previous == Fence::SIGNAL_TIME_PENDING || previous == Fence::SIGNAL_TIME_INVALID) { - result.appendFormat(" %" PRId64 " (%.3f ms ago)\n", presentTime, - (now - presentTime) / 1000000.0); + StringAppendF(&result, " %" PRId64 " (%.3f ms ago)\n", presentTime, + (now - presentTime) / 1000000.0); } else { - result.appendFormat(" %" PRId64 " (+%" PRId64 " / %.3f) (%.3f ms ago)\n", presentTime, - presentTime - previous, (presentTime - previous) / (double)mPeriod, - (now - presentTime) / 1000000.0); + StringAppendF(&result, " %" PRId64 " (+%" PRId64 " / %.3f) (%.3f ms ago)\n", + presentTime, presentTime - previous, + (presentTime - previous) / (double)mPeriod, + (now - presentTime) / 1000000.0); } previous = presentTime; } - result.appendFormat("current monotonic time: %" PRId64 "\n", now); + StringAppendF(&result, "current monotonic time: %" PRId64 "\n", now); } // TODO(b/113612090): Figure out how much of this is still relevant. diff --git a/services/surfaceflinger/Scheduler/DispSync.h b/services/surfaceflinger/Scheduler/DispSync.h index 5d19093edb..4a90f10215 100644 --- a/services/surfaceflinger/Scheduler/DispSync.h +++ b/services/surfaceflinger/Scheduler/DispSync.h @@ -29,7 +29,6 @@ namespace android { -class String8; class FenceTime; class DispSync { @@ -57,7 +56,7 @@ public: virtual void setIgnorePresentFences(bool ignore) = 0; virtual nsecs_t expectedPresentTime() = 0; - virtual void dump(String8& result) const = 0; + virtual void dump(std::string& result) const = 0; }; namespace impl { @@ -161,7 +160,7 @@ public: nsecs_t expectedPresentTime(); // dump appends human-readable debug info to the result string. - void dump(String8& result) const override; + void dump(std::string& result) const override; private: void updateModelLocked(); diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp index 9bee9a3499..49e7ef6f7b 100644 --- a/services/surfaceflinger/Scheduler/EventThread.cpp +++ b/services/surfaceflinger/Scheduler/EventThread.cpp @@ -22,18 +22,20 @@ #include #include +#include + #include #include #include #include -#include #include #include "EventThread.h" using namespace std::chrono_literals; +using android::base::StringAppendF; // --------------------------------------------------------------------------- @@ -384,18 +386,18 @@ void EventThread::disableVSyncLocked() { } } -void EventThread::dump(String8& result) const { +void EventThread::dump(std::string& result) const { std::lock_guard lock(mMutex); - result.appendFormat("VSYNC state: %s\n", mDebugVsyncEnabled ? "enabled" : "disabled"); - result.appendFormat(" soft-vsync: %s\n", mUseSoftwareVSync ? "enabled" : "disabled"); - result.appendFormat(" numListeners=%zu,\n events-delivered: %u\n", - mDisplayEventConnections.size(), mVSyncEvent[0].vsync.count); + StringAppendF(&result, "VSYNC state: %s\n", mDebugVsyncEnabled ? "enabled" : "disabled"); + StringAppendF(&result, " soft-vsync: %s\n", mUseSoftwareVSync ? "enabled" : "disabled"); + StringAppendF(&result, " numListeners=%zu,\n events-delivered: %u\n", + mDisplayEventConnections.size(), mVSyncEvent[0].vsync.count); for (const wp& weak : mDisplayEventConnections) { sp connection = weak.promote(); - result.appendFormat(" %p: count=%d\n", connection.get(), - connection != nullptr ? connection->count : 0); + StringAppendF(&result, " %p: count=%d\n", connection.get(), + connection != nullptr ? connection->count : 0); } - result.appendFormat(" other-events-pending: %zu\n", mPendingEvents.size()); + StringAppendF(&result, " other-events-pending: %zu\n", mPendingEvents.size()); } // --------------------------------------------------------------------------- diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h index 5e7ed13d92..15b5bba428 100644 --- a/services/surfaceflinger/Scheduler/EventThread.h +++ b/services/surfaceflinger/Scheduler/EventThread.h @@ -40,7 +40,6 @@ namespace android { class EventThreadTest; class SurfaceFlinger; -class String8; // --------------------------------------------------------------------------- @@ -76,7 +75,7 @@ public: // called when receiving a hotplug event virtual void onHotplugReceived(DisplayType displayType, bool connected) = 0; - virtual void dump(String8& result) const = 0; + virtual void dump(std::string& result) const = 0; virtual void setPhaseOffset(nsecs_t phaseOffset) = 0; }; @@ -131,7 +130,7 @@ public: // called when receiving a hotplug event void onHotplugReceived(DisplayType displayType, bool connected) override; - void dump(String8& result) const override; + void dump(std::string& result) const override; void setPhaseOffset(nsecs_t phaseOffset) override; diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index 4457f723c0..5b8cc10a46 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -133,7 +133,7 @@ void Scheduler::onScreenReleased(const sp& handle) mConnections[handle->id]->thread->onScreenReleased(); } -void Scheduler::dump(const sp& handle, String8& result) const { +void Scheduler::dump(const sp& handle, std::string& result) const { RETURN_IF_INVALID(); mConnections.at(handle->id)->thread->dump(result); } diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h index 764ad00115..ea9082456b 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.h +++ b/services/surfaceflinger/Scheduler/Scheduler.h @@ -91,7 +91,7 @@ public: void onScreenReleased(const sp& handle); // Should be called when dumpsys command is received. - void dump(const sp& handle, String8& result) const; + void dump(const sp& handle, std::string& result) const; // Offers ability to modify phase offset in the event thread. void setPhaseOffset(const sp& handle, nsecs_t phaseOffset); diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 0bda020a8a..8170d4c4a6 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -113,6 +113,7 @@ namespace android { using namespace android::hardware::configstore; using namespace android::hardware::configstore::V1_0; +using base::StringAppendF; using ui::ColorMode; using ui::Dataspace; using ui::Hdr; @@ -4094,7 +4095,7 @@ void SurfaceFlinger::setPowerMode(const sp& displayToken, int mode) { status_t SurfaceFlinger::doDump(int fd, const Vector& args, bool asProto) NO_THREAD_SAFETY_ANALYSIS { - String8 result; + std::string result; IPCThreadState* ipc = IPCThreadState::self(); const int pid = ipc->getCallingPid(); @@ -4102,8 +4103,8 @@ status_t SurfaceFlinger::doDump(int fd, const Vector& args, bool asPro if ((uid != AID_SHELL) && !PermissionCache::checkPermission(sDump, pid, uid)) { - result.appendFormat("Permission Denial: " - "can't dump SurfaceFlinger from pid=%d, uid=%d\n", pid, uid); + StringAppendF(&result, "Permission Denial: can't dump SurfaceFlinger from pid=%d, uid=%d\n", + pid, uid); } else { // Try to get the main lock, but give up after one second // (this would indicate SF is stuck, but we want to be able to @@ -4111,9 +4112,10 @@ status_t SurfaceFlinger::doDump(int fd, const Vector& args, bool asPro status_t err = mStateLock.timedLock(s2ns(1)); bool locked = (err == NO_ERROR); if (!locked) { - result.appendFormat( - "SurfaceFlinger appears to be unresponsive (%s [%d]), " - "dumping anyways (no locks held)\n", strerror(-err), err); + StringAppendF(&result, + "SurfaceFlinger appears to be unresponsive (%s [%d]), dumping anyways " + "(no locks held)\n", + strerror(-err), err); } bool dumpAll = true; @@ -4231,21 +4233,18 @@ status_t SurfaceFlinger::doDump(int fd, const Vector& args, bool asPro mStateLock.unlock(); } } - write(fd, result.string(), result.size()); + write(fd, result.c_str(), result.size()); return NO_ERROR; } -void SurfaceFlinger::listLayersLocked(const Vector& /* args */, - size_t& /* index */, String8& result) const -{ - mCurrentState.traverseInZOrder([&](Layer* layer) { - result.appendFormat("%s\n", layer->getName().string()); - }); +void SurfaceFlinger::listLayersLocked(const Vector& /* args */, size_t& /* index */, + std::string& result) const { + mCurrentState.traverseInZOrder( + [&](Layer* layer) { StringAppendF(&result, "%s\n", layer->getName().string()); }); } void SurfaceFlinger::dumpStatsLocked(const Vector& args, size_t& index, - String8& result) const -{ + std::string& result) const { String8 name; if (index < args.size()) { name = String8(args[index]); @@ -4256,7 +4255,7 @@ void SurfaceFlinger::dumpStatsLocked(const Vector& args, size_t& index displayId && getHwComposer().isConnected(*displayId)) { const auto activeConfig = getHwComposer().getActiveConfig(*displayId); const nsecs_t period = activeConfig->getVsyncPeriod(); - result.appendFormat("%" PRId64 "\n", period); + StringAppendF(&result, "%" PRId64 "\n", period); } if (name.isEmpty()) { @@ -4271,8 +4270,7 @@ void SurfaceFlinger::dumpStatsLocked(const Vector& args, size_t& index } void SurfaceFlinger::clearStatsLocked(const Vector& args, size_t& index, - String8& /* result */) -{ + std::string& /* result */) { String8 name; if (index < args.size()) { name = String8(args[index]); @@ -4298,37 +4296,34 @@ void SurfaceFlinger::logFrameStats() { mAnimFrameTracker.logAndResetStats(String8("")); } -void SurfaceFlinger::appendSfConfigString(String8& result) const -{ +void SurfaceFlinger::appendSfConfigString(std::string& result) const { result.append(" [sf"); if (isLayerTripleBufferingDisabled()) result.append(" DISABLE_TRIPLE_BUFFERING"); - result.appendFormat(" PRESENT_TIME_OFFSET=%" PRId64 , dispSyncPresentTimeOffset); - result.appendFormat(" FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); - result.appendFormat(" MAX_VIRT_DISPLAY_DIM=%" PRIu64, maxVirtualDisplaySize); - result.appendFormat(" RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); - result.appendFormat(" NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, - maxFrameBufferAcquiredBuffers); + StringAppendF(&result, " PRESENT_TIME_OFFSET=%" PRId64, dispSyncPresentTimeOffset); + StringAppendF(&result, " FORCE_HWC_FOR_RBG_TO_YUV=%d", useHwcForRgbToYuv); + StringAppendF(&result, " MAX_VIRT_DISPLAY_DIM=%" PRIu64, maxVirtualDisplaySize); + StringAppendF(&result, " RUNNING_WITHOUT_SYNC_FRAMEWORK=%d", !hasSyncFramework); + StringAppendF(&result, " NUM_FRAMEBUFFER_SURFACE_BUFFERS=%" PRId64, + maxFrameBufferAcquiredBuffers); result.append("]"); } -void SurfaceFlinger::dumpStaticScreenStats(String8& result) const -{ - result.appendFormat("Static screen stats:\n"); +void SurfaceFlinger::dumpStaticScreenStats(std::string& result) const { + result.append("Static screen stats:\n"); for (size_t b = 0; b < SurfaceFlingerBE::NUM_BUCKETS - 1; ++b) { float bucketTimeSec = getBE().mFrameBuckets[b] / 1e9; float percent = 100.0f * static_cast(getBE().mFrameBuckets[b]) / getBE().mTotalTime; - result.appendFormat(" < %zd frames: %.3f s (%.1f%%)\n", - b + 1, bucketTimeSec, percent); + StringAppendF(&result, " < %zd frames: %.3f s (%.1f%%)\n", b + 1, bucketTimeSec, percent); } float bucketTimeSec = getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1] / 1e9; float percent = 100.0f * static_cast(getBE().mFrameBuckets[SurfaceFlingerBE::NUM_BUCKETS - 1]) / getBE().mTotalTime; - result.appendFormat(" %zd+ frames: %.3f s (%.1f%%)\n", - SurfaceFlingerBE::NUM_BUCKETS - 1, bucketTimeSec, percent); + StringAppendF(&result, " %zd+ frames: %.3f s (%.1f%%)\n", SurfaceFlingerBE::NUM_BUCKETS - 1, + bucketTimeSec, percent); } void SurfaceFlinger::recordBufferingStats(const char* layerName, @@ -4349,8 +4344,8 @@ void SurfaceFlinger::recordBufferingStats(const char* layerName, } } -void SurfaceFlinger::dumpFrameEventsLocked(String8& result) { - result.appendFormat("Layer frame timestamps:\n"); +void SurfaceFlinger::dumpFrameEventsLocked(std::string& result) { + result.append("Layer frame timestamps:\n"); const LayerVector& currentLayers = mCurrentState.layersSortedByZ; const size_t count = currentLayers.size(); @@ -4359,7 +4354,7 @@ void SurfaceFlinger::dumpFrameEventsLocked(String8& result) { } } -void SurfaceFlinger::dumpBufferingStats(String8& result) const { +void SurfaceFlinger::dumpBufferingStats(std::string& result) const { result.append("Buffering stats:\n"); result.append(" [Layer name] " " \n"); @@ -4385,15 +4380,13 @@ void SurfaceFlinger::dumpBufferingStats(String8& result) const { for (const auto& sortedPair : sorted) { float activeTime = sortedPair.first; const BufferTuple& values = sortedPair.second; - result.appendFormat(" [%s] %.2f %.3f %.3f %.3f\n", - std::get<0>(values).c_str(), activeTime, - std::get<1>(values), std::get<2>(values), - std::get<3>(values)); + StringAppendF(&result, " [%s] %.2f %.3f %.3f %.3f\n", std::get<0>(values).c_str(), + activeTime, std::get<1>(values), std::get<2>(values), std::get<3>(values)); } result.append("\n"); } -void SurfaceFlinger::dumpDisplayIdentificationData(String8& result) const { +void SurfaceFlinger::dumpDisplayIdentificationData(std::string& result) const { for (const auto& [token, display] : mDisplays) { const auto displayId = display->getId(); if (!displayId) { @@ -4404,8 +4397,9 @@ void SurfaceFlinger::dumpDisplayIdentificationData(String8& result) const { continue; } - result.appendFormat("Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), - *hwcDisplayId); + StringAppendF(&result, + "Display %s (HWC display %" PRIu64 "): ", to_string(*displayId).c_str(), + *hwcDisplayId); uint8_t port; DisplayIdentificationData data; if (!getHwComposer().getDisplayIdentificationData(*hwcDisplayId, &port, &data)) { @@ -4416,7 +4410,7 @@ void SurfaceFlinger::dumpDisplayIdentificationData(String8& result) const { if (!isEdid(data)) { result.append("unknown identification data: "); for (uint8_t byte : data) { - result.appendFormat("%x ", byte); + StringAppendF(&result, "%x ", byte); } result.append("\n"); continue; @@ -4426,23 +4420,23 @@ void SurfaceFlinger::dumpDisplayIdentificationData(String8& result) const { if (!edid) { result.append("invalid EDID: "); for (uint8_t byte : data) { - result.appendFormat("%x ", byte); + StringAppendF(&result, "%x ", byte); } result.append("\n"); continue; } - result.appendFormat("port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); + StringAppendF(&result, "port=%u pnpId=%s displayName=\"", port, edid->pnpId.data()); result.append(edid->displayName.data(), edid->displayName.length()); result.append("\"\n"); } } -void SurfaceFlinger::dumpWideColorInfo(String8& result) const { - result.appendFormat("Device has wide color display: %d\n", hasWideColorDisplay); - result.appendFormat("Device uses color management: %d\n", useColorManagement); - result.appendFormat("DisplayColorSetting: %s\n", - decodeDisplayColorSetting(mDisplayColorSetting).c_str()); +void SurfaceFlinger::dumpWideColorInfo(std::string& result) const { + StringAppendF(&result, "Device has wide color display: %d\n", hasWideColorDisplay); + StringAppendF(&result, "Device uses color management: %d\n", useColorManagement); + StringAppendF(&result, "DisplayColorSetting: %s\n", + decodeDisplayColorSetting(mDisplayColorSetting).c_str()); // TODO: print out if wide-color mode is active or not @@ -4452,22 +4446,20 @@ void SurfaceFlinger::dumpWideColorInfo(String8& result) const { continue; } - result.appendFormat("Display %s color modes:\n", to_string(*displayId).c_str()); + StringAppendF(&result, "Display %s color modes:\n", to_string(*displayId).c_str()); std::vector modes = getHwComposer().getColorModes(*displayId); for (auto&& mode : modes) { - result.appendFormat(" %s (%d)\n", decodeColorMode(mode).c_str(), mode); + StringAppendF(&result, " %s (%d)\n", decodeColorMode(mode).c_str(), mode); } ColorMode currentMode = display->getActiveColorMode(); - result.appendFormat(" Current color mode: %s (%d)\n", - decodeColorMode(currentMode).c_str(), currentMode); + StringAppendF(&result, " Current color mode: %s (%d)\n", + decodeColorMode(currentMode).c_str(), currentMode); } result.append("\n"); } -void SurfaceFlinger::dumpFrameCompositionInfo(String8& result) const { - std::string stringResult; - +void SurfaceFlinger::dumpFrameCompositionInfo(std::string& result) const { for (const auto& [token, display] : mDisplays) { const auto it = getBE().mEndOfFrameCompositionInfo.find(token); if (it == getBE().mEndOfFrameCompositionInfo.end()) { @@ -4475,15 +4467,13 @@ void SurfaceFlinger::dumpFrameCompositionInfo(String8& result) const { } const auto& compositionInfoList = it->second; - stringResult += base::StringPrintf("%s\n", display->getDebugName().c_str()); - stringResult += base::StringPrintf("numComponents: %zu\n", compositionInfoList.size()); + StringAppendF(&result, "%s\n", display->getDebugName().c_str()); + StringAppendF(&result, "numComponents: %zu\n", compositionInfoList.size()); for (const auto& compositionInfo : compositionInfoList) { - compositionInfo.dump(stringResult, nullptr); - stringResult += base::StringPrintf("\n"); + compositionInfo.dump(result, nullptr); + result.append("\n"); } } - - result.append(stringResult.c_str()); } LayersProto SurfaceFlinger::dumpProtoInfo(LayerVector::StateSet stateSet) const { @@ -4522,8 +4512,7 @@ LayersProto SurfaceFlinger::dumpVisibleLayersProtoInfo(const DisplayDevice& disp } void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, - String8& result) const -{ + std::string& result) const { bool colorize = false; if (index < args.size() && (args[index] == String16("--color"))) { @@ -4571,16 +4560,17 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, if (const auto displayId = getInternalDisplayId(); displayId && getHwComposer().isConnected(*displayId)) { const auto activeConfig = getHwComposer().getActiveConfig(*displayId); - result.appendFormat("Display %s: app phase %" PRId64 " ns, " - "sf phase %" PRId64 " ns, " - "early app phase %" PRId64 " ns, " - "early sf phase %" PRId64 " ns, " - "early app gl phase %" PRId64 " ns, " - "early sf gl phase %" PRId64 " ns, " - "present offset %" PRId64 " ns (refresh %" PRId64 " ns)", - to_string(*displayId).c_str(), vsyncPhaseOffsetNs, sfVsyncPhaseOffsetNs, - appEarlyOffset, sfEarlyOffset, appEarlyGlOffset, sfEarlyGlOffset, - dispSyncPresentTimeOffset, activeConfig->getVsyncPeriod()); + StringAppendF(&result, + "Display %s: app phase %" PRId64 " ns, " + "sf phase %" PRId64 " ns, " + "early app phase %" PRId64 " ns, " + "early sf phase %" PRId64 " ns, " + "early app gl phase %" PRId64 " ns, " + "early sf gl phase %" PRId64 " ns, " + "present offset %" PRId64 " ns (refresh %" PRId64 " ns)", + to_string(*displayId).c_str(), vsyncPhaseOffsetNs, sfVsyncPhaseOffsetNs, + appEarlyOffset, sfEarlyOffset, appEarlyGlOffset, sfEarlyGlOffset, + dispSyncPresentTimeOffset, activeConfig->getVsyncPeriod()); } result.append("\n"); @@ -4589,7 +4579,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, dumpStaticScreenStats(result); result.append("\n"); - result.appendFormat("Missed frame count: %u\n\n", mFrameMissedCount.load()); + StringAppendF(&result, "Missed frame count: %u\n\n", mFrameMissedCount.load()); dumpBufferingStats(result); @@ -4597,15 +4587,15 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, * Dump the visible layer list */ colorizer.bold(result); - result.appendFormat("Visible layers (count = %zu)\n", mNumLayers); - result.appendFormat("GraphicBufferProducers: %zu, max %zu\n", - mGraphicBufferProducerList.size(), mMaxGraphicBufferProducerListSize); + StringAppendF(&result, "Visible layers (count = %zu)\n", mNumLayers); + StringAppendF(&result, "GraphicBufferProducers: %zu, max %zu\n", + mGraphicBufferProducerList.size(), mMaxGraphicBufferProducerListSize); colorizer.reset(result); { LayersProto layersProto = dumpProtoInfo(LayerVector::StateSet::Current); auto layerTree = LayerProtoParser::generateLayerTree(layersProto); - result.append(LayerProtoParser::layerTreeToString(layerTree).c_str()); + result.append(LayerProtoParser::layerTreeToString(layerTree)); result.append("\n"); } @@ -4618,7 +4608,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, */ colorizer.bold(result); - result.appendFormat("Displays (%zu entries)\n", mDisplays.size()); + StringAppendF(&result, "Displays (%zu entries)\n", mDisplays.size()); colorizer.reset(result); for (const auto& [token, display] : mDisplays) { display->dump(result); @@ -4637,27 +4627,28 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, if (const auto display = getDefaultDisplayDeviceLocked()) { display->undefinedRegion.dump(result, "undefinedRegion"); - result.appendFormat(" orientation=%d, isPoweredOn=%d\n", display->getOrientation(), - display->isPoweredOn()); + StringAppendF(&result, " orientation=%d, isPoweredOn=%d\n", display->getOrientation(), + display->isPoweredOn()); } - result.appendFormat(" transaction-flags : %08x\n" - " gpu_to_cpu_unsupported : %d\n", - mTransactionFlags.load(), !mGpuToCpuSupported); + StringAppendF(&result, + " transaction-flags : %08x\n" + " gpu_to_cpu_unsupported : %d\n", + mTransactionFlags.load(), !mGpuToCpuSupported); if (const auto displayId = getInternalDisplayId(); displayId && getHwComposer().isConnected(*displayId)) { const auto activeConfig = getHwComposer().getActiveConfig(*displayId); - result.appendFormat(" refresh-rate : %f fps\n" - " x-dpi : %f\n" - " y-dpi : %f\n", - 1e9 / activeConfig->getVsyncPeriod(), activeConfig->getDpiX(), - activeConfig->getDpiY()); + StringAppendF(&result, + " refresh-rate : %f fps\n" + " x-dpi : %f\n" + " y-dpi : %f\n", + 1e9 / activeConfig->getVsyncPeriod(), activeConfig->getDpiX(), + activeConfig->getDpiY()); } - result.appendFormat(" transaction time: %f us\n", - inTransactionDuration/1000.0); + StringAppendF(&result, " transaction time: %f us\n", inTransactionDuration / 1000.0); - result.appendFormat(" use Scheduler: %s\n", mUseScheduler ? "true" : "false"); + StringAppendF(&result, " use Scheduler: %s\n", mUseScheduler ? "true" : "false"); /* * VSYNC state */ @@ -4683,7 +4674,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, continue; } - result.appendFormat("Display %s HWC layers:\n", to_string(*displayId).c_str()); + StringAppendF(&result, "Display %s HWC layers:\n", to_string(*displayId).c_str()); Layer::miniDumpHeader(result); mCurrentState.traverseInZOrder([&](Layer* layer) { layer->miniDump(result, *displayId); }); result.append("\n"); @@ -4696,8 +4687,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, result.append("h/w composer state:\n"); colorizer.reset(result); bool hwcDisabled = mDebugDisableHWC || mDebugRegion; - result.appendFormat(" h/w composer %s\n", - hwcDisabled ? "disabled" : "enabled"); + StringAppendF(&result, " h/w composer %s\n", hwcDisabled ? "disabled" : "enabled"); getHwComposer().dump(result); /* @@ -4711,7 +4701,7 @@ void SurfaceFlinger::dumpAllLocked(const Vector& args, size_t& index, */ if (mVrFlingerRequestsDisplay && mVrFlinger) { result.append("VrFlinger state:\n"); - result.append(mVrFlinger->Dump().c_str()); + result.append(mVrFlinger->Dump()); result.append("\n"); } } diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index fe2f1c2658..bff847e8a0 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -806,25 +806,25 @@ private: return hwcDisplayId ? getHwComposer().toPhysicalDisplayId(*hwcDisplayId) : std::nullopt; } - void listLayersLocked(const Vector& args, size_t& index, String8& result) const; - void dumpStatsLocked(const Vector& args, size_t& index, String8& result) const; - void clearStatsLocked(const Vector& args, size_t& index, String8& result); - void dumpAllLocked(const Vector& args, size_t& index, String8& result) const; + void listLayersLocked(const Vector& args, size_t& index, std::string& result) const; + void dumpStatsLocked(const Vector& args, size_t& index, std::string& result) const; + void clearStatsLocked(const Vector& args, size_t& index, std::string& result); + void dumpAllLocked(const Vector& args, size_t& index, std::string& result) const; bool startDdmConnection(); - void appendSfConfigString(String8& result) const; + void appendSfConfigString(std::string& result) const; void logFrameStats(); - void dumpStaticScreenStats(String8& result) const; + void dumpStaticScreenStats(std::string& result) const; // Not const because each Layer needs to query Fences and cache timestamps. - void dumpFrameEventsLocked(String8& result); + void dumpFrameEventsLocked(std::string& result); void recordBufferingStats(const char* layerName, std::vector&& history); - void dumpBufferingStats(String8& result) const; - void dumpDisplayIdentificationData(String8& result) const; - void dumpWideColorInfo(String8& result) const; - void dumpFrameCompositionInfo(String8& result) const; + void dumpBufferingStats(std::string& result) const; + void dumpDisplayIdentificationData(std::string& result) const; + void dumpWideColorInfo(std::string& result) const; + void dumpFrameCompositionInfo(std::string& result) const; LayersProto dumpProtoInfo(LayerVector::StateSet stateSet) const; LayersProto dumpVisibleLayersProtoInfo(const DisplayDevice& display) const; diff --git a/services/surfaceflinger/SurfaceTracing.cpp b/services/surfaceflinger/SurfaceTracing.cpp index 1835929940..b7e9a915fa 100644 --- a/services/surfaceflinger/SurfaceTracing.cpp +++ b/services/surfaceflinger/SurfaceTracing.cpp @@ -20,6 +20,7 @@ #include "SurfaceTracing.h" #include +#include #include #include #include @@ -120,12 +121,13 @@ status_t SurfaceTracing::writeProtoFileLocked() { return NO_ERROR; } -void SurfaceTracing::dump(String8& result) const { +void SurfaceTracing::dump(std::string& result) const { std::lock_guard protoGuard(mTraceMutex); - result.appendFormat("Tracing state: %s\n", mEnabled ? "enabled" : "disabled"); - result.appendFormat(" number of entries: %zu (%.2fMB / %.2fMB)\n", mBuffer.frameCount(), - float(mBuffer.used()) / float(1_MB), float(mBuffer.size()) / float(1_MB)); + base::StringAppendF(&result, "Tracing state: %s\n", mEnabled ? "enabled" : "disabled"); + base::StringAppendF(&result, " number of entries: %zu (%.2fMB / %.2fMB)\n", + mBuffer.frameCount(), float(mBuffer.used()) / float(1_MB), + float(mBuffer.size()) / float(1_MB)); } } // namespace android diff --git a/services/surfaceflinger/SurfaceTracing.h b/services/surfaceflinger/SurfaceTracing.h index ec01be7170..fd919af999 100644 --- a/services/surfaceflinger/SurfaceTracing.h +++ b/services/surfaceflinger/SurfaceTracing.h @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -43,7 +42,7 @@ public: void traceLayers(const char* where, LayersProto); bool isEnabled() const; - void dump(String8& result) const; + void dump(std::string& result) const; private: static constexpr auto kDefaultBufferCapInByte = 100_MB; diff --git a/services/surfaceflinger/TimeStats/TimeStats.cpp b/services/surfaceflinger/TimeStats/TimeStats.cpp index 2b9f5c8aef..6a5488aa2c 100644 --- a/services/surfaceflinger/TimeStats/TimeStats.cpp +++ b/services/surfaceflinger/TimeStats/TimeStats.cpp @@ -33,7 +33,7 @@ namespace android { void TimeStats::parseArgs(bool asProto, const Vector& args, size_t& index, - String8& result) { + std::string& result) { ATRACE_CALL(); if (args.size() > index + 10) { @@ -564,7 +564,7 @@ bool TimeStats::isEnabled() { return mEnabled.load(); } -void TimeStats::dump(bool asProto, std::optional maxLayers, String8& result) { +void TimeStats::dump(bool asProto, std::optional maxLayers, std::string& result) { ATRACE_CALL(); std::lock_guard lock(mMutex); @@ -582,7 +582,7 @@ void TimeStats::dump(bool asProto, std::optional maxLayers, String8& r result.append(timeStatsProto.SerializeAsString().c_str(), timeStatsProto.ByteSize()); } else { ALOGD("Dumping TimeStats as text"); - result.append(mTimeStats.toString(maxLayers).c_str()); + result.append(mTimeStats.toString(maxLayers)); result.append("\n"); } } diff --git a/services/surfaceflinger/TimeStats/TimeStats.h b/services/surfaceflinger/TimeStats/TimeStats.h index 0b24c46e0e..71c3ed7e8e 100644 --- a/services/surfaceflinger/TimeStats/TimeStats.h +++ b/services/surfaceflinger/TimeStats/TimeStats.h @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -35,7 +34,6 @@ using namespace android::surfaceflinger; namespace android { -class String8; class TimeStats { struct FrameTime { @@ -79,7 +77,7 @@ public: TimeStats() = default; ~TimeStats() = default; - void parseArgs(bool asProto, const Vector& args, size_t& index, String8& result); + void parseArgs(bool asProto, const Vector& args, size_t& index, std::string& result); bool isEnabled(); void incrementTotalFrames(); @@ -117,7 +115,7 @@ private: void enable(); void disable(); void clear(); - void dump(bool asProto, std::optional maxLayers, String8& result); + void dump(bool asProto, std::optional maxLayers, std::string& result); std::atomic mEnabled = false; std::mutex mMutex; diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index d0cf1b7421..35f30d7da8 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -117,7 +117,7 @@ TEST_F(SchedulerTest, testNullPtr) { mScheduler->hotplugReceived(nullptr, EventThread::DisplayType::Primary, false)); ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenAcquired(nullptr)); ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(nullptr)); - String8 testString; + std::string testString; ASSERT_NO_FATAL_FAILURE(mScheduler->dump(nullptr, testString)); EXPECT_TRUE(testString == ""); ASSERT_NO_FATAL_FAILURE(mScheduler->setPhaseOffset(nullptr, 10)); @@ -146,7 +146,7 @@ TEST_F(SchedulerTest, invalidConnectionHandle) { EXPECT_CALL(*mEventThread, onScreenReleased()).Times(0); ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(connectionHandle)); - String8 testString; + std::string testString; EXPECT_CALL(*mEventThread, dump(_)).Times(0); ASSERT_NO_FATAL_FAILURE(mScheduler->dump(connectionHandle, testString)); EXPECT_TRUE(testString == ""); @@ -176,7 +176,7 @@ TEST_F(SchedulerTest, validConnectionHandle) { EXPECT_CALL(*mEventThread, onScreenReleased()).Times(1); ASSERT_NO_FATAL_FAILURE(mScheduler->onScreenReleased(mConnectionHandle)); - String8 testString("dump"); + std::string testString("dump"); EXPECT_CALL(*mEventThread, dump(testString)).Times(1); ASSERT_NO_FATAL_FAILURE(mScheduler->dump(mConnectionHandle, testString)); EXPECT_TRUE(testString != ""); diff --git a/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp b/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp index 186ed7954b..bfd34cd4db 100644 --- a/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp +++ b/services/surfaceflinger/tests/unittests/TimeStatsTest.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include @@ -131,7 +130,7 @@ public: std::string TimeStatsTest::inputCommand(InputCommand cmd, bool useProto) { size_t index = 0; - String8 result; + std::string result; Vector args; switch (cmd) { @@ -162,7 +161,7 @@ std::string TimeStatsTest::inputCommand(InputCommand cmd, bool useProto) { } EXPECT_NO_FATAL_FAILURE(mTimeStats->parseArgs(useProto, args, index, result)); - return std::string(result.string(), result.size()); + return result; } static std::string genLayerName(int32_t layerID) { diff --git a/services/surfaceflinger/tests/unittests/mock/MockDispSync.h b/services/surfaceflinger/tests/unittests/mock/MockDispSync.h index 34e71cb32d..9213ae5fdf 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockDispSync.h +++ b/services/surfaceflinger/tests/unittests/mock/MockDispSync.h @@ -18,7 +18,6 @@ #include -#include #include "Scheduler/DispSync.h" namespace android { @@ -44,7 +43,7 @@ public: MOCK_METHOD1(setIgnorePresentFences, void(bool)); MOCK_METHOD0(expectedPresentTime, nsecs_t()); - MOCK_CONST_METHOD1(dump, void(String8&)); + MOCK_CONST_METHOD1(dump, void(std::string&)); }; } // namespace mock diff --git a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h index ad2463dac2..0a1c827f99 100644 --- a/services/surfaceflinger/tests/unittests/mock/MockEventThread.h +++ b/services/surfaceflinger/tests/unittests/mock/MockEventThread.h @@ -32,7 +32,7 @@ public: MOCK_METHOD0(onScreenReleased, void()); MOCK_METHOD0(onScreenAcquired, void()); MOCK_METHOD2(onHotplugReceived, void(DisplayType, bool)); - MOCK_CONST_METHOD1(dump, void(String8&)); + MOCK_CONST_METHOD1(dump, void(std::string&)); MOCK_METHOD1(setPhaseOffset, void(nsecs_t phaseOffset)); }; diff --git a/services/surfaceflinger/tests/unittests/mock/RenderEngine/MockRenderEngine.h b/services/surfaceflinger/tests/unittests/mock/RenderEngine/MockRenderEngine.h index a416808297..11e56317b0 100644 --- a/services/surfaceflinger/tests/unittests/mock/RenderEngine/MockRenderEngine.h +++ b/services/surfaceflinger/tests/unittests/mock/RenderEngine/MockRenderEngine.h @@ -38,7 +38,7 @@ public: MOCK_METHOD0(createFramebuffer, std::unique_ptr()); MOCK_METHOD0(createImage, std::unique_ptr()); MOCK_CONST_METHOD0(primeCache, void()); - MOCK_METHOD1(dump, void(String8&)); + MOCK_METHOD1(dump, void(std::string&)); MOCK_CONST_METHOD0(useNativeFenceSync, bool()); MOCK_CONST_METHOD0(useWaitSync, bool()); MOCK_CONST_METHOD0(isCurrent, bool()); -- cgit v1.2.3-59-g8ed1b From 48d7608aa5806192f18e2d572f56a6bc6a10a47c Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Sun, 24 Mar 2019 02:01:06 -0700 Subject: [libs/ui] Modernize codebase by replacing NULL with nullptr Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I240d39ef4328943447149700b3ece371681078d1 --- libs/ui/Fence.cpp | 2 +- libs/ui/GraphicBuffer.cpp | 16 ++++++++-------- libs/ui/Region.cpp | 2 +- libs/ui/tools/lutgen.cpp | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'libs/ui/Region.cpp') diff --git a/libs/ui/Fence.cpp b/libs/ui/Fence.cpp index ed7ccb0bed..4ce891e148 100644 --- a/libs/ui/Fence.cpp +++ b/libs/ui/Fence.cpp @@ -110,7 +110,7 @@ nsecs_t Fence::getSignalTime() const { } struct sync_file_info* finfo = sync_file_info(mFenceFd); - if (finfo == NULL) { + if (finfo == nullptr) { ALOGE("sync_file_info returned NULL for fd %d", mFenceFd.get()); return SIGNAL_TIME_INVALID; } diff --git a/libs/ui/GraphicBuffer.cpp b/libs/ui/GraphicBuffer.cpp index f800627ef7..a66dbc8527 100644 --- a/libs/ui/GraphicBuffer.cpp +++ b/libs/ui/GraphicBuffer.cpp @@ -76,7 +76,7 @@ GraphicBuffer::GraphicBuffer() usage_deprecated = 0; usage = 0; layerCount = 0; - handle = NULL; + handle = nullptr; } // deprecated @@ -143,7 +143,7 @@ void GraphicBuffer::free_handle() GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); allocator.free(handle); } - handle = NULL; + handle = nullptr; } status_t GraphicBuffer::initCheck() const { @@ -178,7 +178,7 @@ status_t GraphicBuffer::reallocate(uint32_t inWidth, uint32_t inHeight, if (handle) { GraphicBufferAllocator& allocator(GraphicBufferAllocator::get()); allocator.free(handle); - handle = 0; + handle = nullptr; } return initWithSize(inWidth, inHeight, inFormat, inLayerCount, inUsage, "[Reallocation]"); } @@ -452,7 +452,7 @@ status_t GraphicBuffer::unflatten( width = height = stride = format = usage_deprecated = 0; layerCount = 0; usage = 0; - handle = NULL; + handle = nullptr; ALOGE("unflatten: numFds or numInts is too large: %zd, %zd", numFds, numInts); return BAD_VALUE; } @@ -486,7 +486,7 @@ status_t GraphicBuffer::unflatten( width = height = stride = format = usage_deprecated = 0; layerCount = 0; usage = 0; - handle = NULL; + handle = nullptr; ALOGE("unflatten: native_handle_create failed"); return NO_MEMORY; } @@ -497,7 +497,7 @@ status_t GraphicBuffer::unflatten( width = height = stride = format = usage_deprecated = 0; layerCount = 0; usage = 0; - handle = NULL; + handle = nullptr; } mId = static_cast(buf[7]) << 32; @@ -507,7 +507,7 @@ status_t GraphicBuffer::unflatten( mOwner = ownHandle; - if (handle != 0) { + if (handle != nullptr) { buffer_handle_t importedHandle; status_t err = mBufferMapper.importBuffer(handle, uint32_t(width), uint32_t(height), uint32_t(layerCount), format, usage, uint32_t(stride), &importedHandle); @@ -515,7 +515,7 @@ status_t GraphicBuffer::unflatten( width = height = stride = format = usage_deprecated = 0; layerCount = 0; usage = 0; - handle = NULL; + handle = nullptr; ALOGE("unflatten: registerBuffer failed: %s (%d)", strerror(-err), err); return err; } diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 3bd3748439..224dc2c122 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -820,7 +820,7 @@ status_t Region::unflatten(void const* buffer, size_t size) { } if (numRects > (UINT32_MAX / sizeof(Rect))) { - android_errorWriteWithInfoLog(0x534e4554, "29983260", -1, NULL, 0); + android_errorWriteWithInfoLog(0x534e4554, "29983260", -1, nullptr, 0); return NO_MEMORY; } diff --git a/libs/ui/tools/lutgen.cpp b/libs/ui/tools/lutgen.cpp index 97b0822238..85a1cebe7a 100644 --- a/libs/ui/tools/lutgen.cpp +++ b/libs/ui/tools/lutgen.cpp @@ -85,11 +85,11 @@ static const ColorSpace findColorSpace(const string& name) { static int handleCommandLineArgments(int argc, char* argv[]) { static constexpr const char* OPTSTR = "h:d:s:t:"; static const struct option OPTIONS[] = { - { "help", no_argument, 0, 'h' }, - { "dimension", required_argument, 0, 'd' }, - { "source", required_argument, 0, 's' }, - { "target", required_argument, 0, 't' }, - { 0, 0, 0, 0 } // termination of the option list + { "help", no_argument, nullptr, 'h' }, + { "dimension", required_argument, nullptr, 'd' }, + { "source", required_argument, nullptr, 's' }, + { "target", required_argument, nullptr, 't' }, + { nullptr, 0, nullptr, 0 } // termination of the option list }; int opt; -- cgit v1.2.3-59-g8ed1b From 639a1e19fceab7909a5ad2df70483155910619bb Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Mon, 22 Apr 2019 14:01:20 -0700 Subject: link libutilscallstack only when VALIDATE_REGIONS is defined Add cc_defaults in Android.bp to enable this macro and add the lib. It is not an issue for system build as the lib always exist in system partition. However some apex builds may use vendor version of the binaries and we don't want to include unused libs into the apex, since they not only increase the apex size, but also incur runtime memory cost. Removing libutilscallstack from the deps will also get rid of its transitive dependencies such as libbacktrace, liblzma, liblibunwindstack and libutilscallstack. bug: 128894663 test: build; manually check that libbacktrace, liblzma, liblibunwindstack and libutilscallstack are not packaged into com.android.media.swcodec apex. Change-Id: Ib64b8aa29e8cefe8d1f9eb2bd095221eb5c9a174 --- libs/ui/Android.bp | 11 ++++++++++- libs/ui/Region.cpp | 33 +++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'libs/ui/Region.cpp') diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 755418e706..0407d8802c 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -82,6 +82,9 @@ cc_library_shared { "frameworks/native/include", ], + // Uncomment the following line to enable VALIDATE_REGIONS traces + //defaults: ["libui-validate-regions-defaults"], + shared_libs: [ "android.frameworks.bufferhub@1.0", "android.hardware.graphics.allocator@2.0", @@ -98,7 +101,6 @@ cc_library_shared { "libhwbinder", "libsync", "libutils", - "libutilscallstack", "liblog", ], @@ -175,6 +177,13 @@ cc_library_headers { ], } +// defaults to enable VALIDATE_REGIONS traces +cc_defaults { + name: "libui-validate-regions-defaults", + shared_libs: ["libutilscallstack"], + cflags: ["-DVALIDATE_REGIONS"], +} + subdirs = [ "tests", "tools", diff --git a/libs/ui/Region.cpp b/libs/ui/Region.cpp index 224dc2c122..55e3b99aa1 100644 --- a/libs/ui/Region.cpp +++ b/libs/ui/Region.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -31,10 +30,18 @@ #include // ---------------------------------------------------------------------------- -#define VALIDATE_REGIONS (false) + +// ### VALIDATE_REGIONS ### +// To enable VALIDATE_REGIONS traces, use the "libui-validate-regions-defaults" +// in Android.bp. Do not #define VALIDATE_REGIONS here as it requires extra libs. + #define VALIDATE_WITH_CORECG (false) // ---------------------------------------------------------------------------- +#if defined(VALIDATE_REGIONS) +#include +#endif + #if VALIDATE_WITH_CORECG #include #endif @@ -67,7 +74,7 @@ Region::Region() { Region::Region(const Region& rhs) : mStorage(rhs.mStorage) { -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(rhs, "rhs copy-ctor"); #endif } @@ -203,7 +210,7 @@ Region Region::createTJunctionFreeRegion(const Region& r) { outputRegion.mStorage, direction_LTR); outputRegion.mStorage.add(r.getBounds()); // to make region valid, mStorage must end with bounds -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(outputRegion, "T-Junction free region"); #endif @@ -212,7 +219,7 @@ Region Region::createTJunctionFreeRegion(const Region& r) { Region& Region::operator = (const Region& rhs) { -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(*this, "this->operator="); validate(rhs, "rhs.operator="); #endif @@ -599,10 +606,12 @@ bool Region::validate(const Region& reg, const char* name, bool silent) result = false; ALOGE_IF(!silent, "%s: mStorage size is 2, which is never valid", name); } +#if defined(VALIDATE_REGIONS) if (result == false && !silent) { reg.dump(name); CallStack stack(LOG_TAG); } +#endif return result; } @@ -610,7 +619,7 @@ void Region::boolean_operation(uint32_t op, Region& dst, const Region& lhs, const Region& rhs, int dx, int dy) { -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(lhs, "boolean_operation (before): lhs"); validate(rhs, "boolean_operation (before): rhs"); validate(dst, "boolean_operation (before): dst"); @@ -630,7 +639,7 @@ void Region::boolean_operation(uint32_t op, Region& dst, operation(r); } -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(lhs, "boolean_operation: lhs"); validate(rhs, "boolean_operation: rhs"); validate(dst, "boolean_operation: dst"); @@ -728,7 +737,7 @@ void Region::boolean_operation(uint32_t op, Region& dst, return; } -#if VALIDATE_WITH_CORECG || VALIDATE_REGIONS +#if VALIDATE_WITH_CORECG || defined(VALIDATE_REGIONS) boolean_operation(op, dst, lhs, Region(rhs), dx, dy); #else size_t lhs_count; @@ -760,7 +769,7 @@ void Region::boolean_operation(uint32_t op, Region& dst, void Region::translate(Region& reg, int dx, int dy) { if ((dx || dy) && !reg.isEmpty()) { -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(reg, "translate (before)"); #endif size_t count = reg.mStorage.size(); @@ -770,7 +779,7 @@ void Region::translate(Region& reg, int dx, int dy) rects++; count--; } -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(reg, "translate (after)"); #endif } @@ -789,7 +798,7 @@ size_t Region::getFlattenedSize() const { } status_t Region::flatten(void* buffer, size_t size) const { -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(*this, "Region::flatten"); #endif if (size < getFlattenedSize()) { @@ -836,7 +845,7 @@ status_t Region::unflatten(void const* buffer, size_t size) { result.mStorage.push_back(rect); } -#if VALIDATE_REGIONS +#if defined(VALIDATE_REGIONS) validate(result, "Region::unflatten"); #endif -- cgit v1.2.3-59-g8ed1b