diff options
author | John Reck <jreck@google.com> | 2019-01-10 14:37:17 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2019-01-10 15:34:49 -0800 |
commit | 6104cea3fb0bddd766f390f9f4e2db9fc00b410e (patch) | |
tree | 3493ab6e3dc09dd9ffd027bc1fa85cc84abb2635 | |
parent | 8b9351ba04eef507d4ff97a84d0c13df60507daf (diff) |
Fix leak/crash in exit
Bug: 120440607
Test: hwuimacro32 doesn't crash
Change-Id: I35b7a924e338efb314f07b923ba22ffcf98f75ee
-rw-r--r-- | libs/hwui/HardwareBitmapUploader.cpp | 13 | ||||
-rw-r--r-- | libs/hwui/HardwareBitmapUploader.h | 1 | ||||
-rw-r--r-- | libs/hwui/renderthread/EglManager.cpp | 4 | ||||
-rw-r--r-- | libs/hwui/tests/macrobench/main.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/thread/ThreadBase.h | 2 |
5 files changed, 22 insertions, 3 deletions
diff --git a/libs/hwui/HardwareBitmapUploader.cpp b/libs/hwui/HardwareBitmapUploader.cpp index b9860ada18fc..635d0ec66673 100644 --- a/libs/hwui/HardwareBitmapUploader.cpp +++ b/libs/hwui/HardwareBitmapUploader.cpp @@ -34,7 +34,7 @@ namespace android::uirenderer { static std::mutex sLock{}; -static ThreadBase* sUploadThread = nullptr; +static sp<ThreadBase> sUploadThread = nullptr; static renderthread::EglManager sEglManager; static int sPendingUploads = 0; static nsecs_t sLastUpload = 0; @@ -257,4 +257,15 @@ sk_sp<Bitmap> HardwareBitmapUploader::allocateHardwareBitmap(const SkBitmap& sou Bitmap::computePalette(bitmap)); } +void HardwareBitmapUploader::terminate() { + std::lock_guard _lock{sLock}; + LOG_ALWAYS_FATAL_IF(sPendingUploads, "terminate called while uploads in progress"); + if (sUploadThread) { + sUploadThread->requestExit(); + sUploadThread->join(); + sUploadThread = nullptr; + } + sEglManager.destroy(); +} + } // namespace android::uirenderer diff --git a/libs/hwui/HardwareBitmapUploader.h b/libs/hwui/HardwareBitmapUploader.h index 6298013bd263..40f2b0c7873c 100644 --- a/libs/hwui/HardwareBitmapUploader.h +++ b/libs/hwui/HardwareBitmapUploader.h @@ -23,6 +23,7 @@ namespace android::uirenderer { class HardwareBitmapUploader { public: static sk_sp<Bitmap> allocateHardwareBitmap(const SkBitmap& sourceBitmap); + static void terminate(); }; } // namespace android::uirenderer diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp index 56eedff4a6e6..8cd97ed20215 100644 --- a/libs/hwui/renderthread/EglManager.cpp +++ b/libs/hwui/renderthread/EglManager.cpp @@ -93,7 +93,9 @@ EglManager::EglManager() , mHasWideColorGamutSupport(false) {} EglManager::~EglManager() { - destroy(); + if (hasEglContext()) { + ALOGW("~EglManager() leaked an EGL context"); + } } void EglManager::initialize() { diff --git a/libs/hwui/tests/macrobench/main.cpp b/libs/hwui/tests/macrobench/main.cpp index 524dfb0fe4ef..174a14080eff 100644 --- a/libs/hwui/tests/macrobench/main.cpp +++ b/libs/hwui/tests/macrobench/main.cpp @@ -19,6 +19,8 @@ #include "Properties.h" #include "hwui/Typeface.h" +#include "HardwareBitmapUploader.h" +#include "renderthread/RenderProxy.h" #include <benchmark/benchmark.h> #include <getopt.h> @@ -353,6 +355,9 @@ int main(int argc, char* argv[]) { gBenchmarkReporter->Finalize(); } + renderthread::RenderProxy::trimMemory(100); + HardwareBitmapUploader::terminate(); + LeakChecker::checkForLeaks(); return 0; } diff --git a/libs/hwui/thread/ThreadBase.h b/libs/hwui/thread/ThreadBase.h index f9de8a5037e5..8cdcc46b97fb 100644 --- a/libs/hwui/thread/ThreadBase.h +++ b/libs/hwui/thread/ThreadBase.h @@ -27,7 +27,7 @@ namespace android::uirenderer { -class ThreadBase : protected Thread { +class ThreadBase : public Thread { PREVENT_COPY_AND_ASSIGN(ThreadBase); public: |