diff options
author | 2015-11-03 10:09:59 -0800 | |
---|---|---|
committer | 2015-11-03 10:09:59 -0800 | |
commit | 6b50780363d3bb8db600c770183fa07677509ae8 (patch) | |
tree | 0679f62b2f0f680d5eabd3589e89b1fc1ec9f866 | |
parent | 562bb9f3a7c100463505b5a91df13da3c72d628f (diff) |
Remove almost-all android::Singleton users
Bug: 25426213
Change-Id: I88e6206e8915cce95c3a8a8a82a4bb8fbf668141
-rw-r--r-- | libs/hwui/Caches.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/Caches.h | 1 | ||||
-rw-r--r-- | libs/hwui/Extensions.cpp | 1 | ||||
-rw-r--r-- | libs/hwui/Extensions.h | 6 | ||||
-rw-r--r-- | libs/hwui/GradientCache.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/PathCache.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/Properties.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/Properties.h | 2 | ||||
-rw-r--r-- | libs/hwui/RenderBufferCache.cpp | 6 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderProxy.h | 3 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 29 | ||||
-rw-r--r-- | libs/hwui/renderthread/RenderThread.h | 12 |
13 files changed, 43 insertions, 33 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index 7c63e316ba38..94a11f131229 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -23,6 +23,7 @@ #include "ShadowTessellator.h" #include "utils/GLUtils.h" +#include <cutils/properties.h> #include <utils/Log.h> #include <utils/String8.h> diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h index 61e958d42148..330dc2951ec9 100644 --- a/libs/hwui/Caches.h +++ b/libs/hwui/Caches.h @@ -43,7 +43,6 @@ #include <GLES3/gl3.h> #include <utils/KeyedVector.h> -#include <utils/Singleton.h> #include <cutils/compiler.h> diff --git a/libs/hwui/Extensions.cpp b/libs/hwui/Extensions.cpp index 06c8a21b019b..6dd29ad8c703 100644 --- a/libs/hwui/Extensions.cpp +++ b/libs/hwui/Extensions.cpp @@ -20,6 +20,7 @@ #include "Properties.h" #include "utils/StringUtils.h" +#include <GLES2/gl2.h> #include <GLES2/gl2ext.h> #include <utils/Log.h> diff --git a/libs/hwui/Extensions.h b/libs/hwui/Extensions.h index 0a30d162f2e8..6689b88f17e3 100644 --- a/libs/hwui/Extensions.h +++ b/libs/hwui/Extensions.h @@ -19,12 +19,6 @@ #include <cutils/compiler.h> -#include <utils/Singleton.h> -#include <utils/SortedVector.h> -#include <utils/String8.h> - -#include <GLES2/gl2.h> - namespace android { namespace uirenderer { diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp index aa105f9fec0a..8c4645092c97 100644 --- a/libs/hwui/GradientCache.cpp +++ b/libs/hwui/GradientCache.cpp @@ -21,6 +21,8 @@ #include "GradientCache.h" #include "Properties.h" +#include <cutils/properties.h> + namespace android { namespace uirenderer { diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp index 4031f2e13f39..fd9ab1847f0d 100644 --- a/libs/hwui/PathCache.cpp +++ b/libs/hwui/PathCache.cpp @@ -30,6 +30,8 @@ #include "thread/Signal.h" #include "thread/TaskProcessor.h" +#include <cutils/properties.h> + namespace android { namespace uirenderer { diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp index c0c61db0f5d1..e81818679f3e 100644 --- a/libs/hwui/Properties.cpp +++ b/libs/hwui/Properties.cpp @@ -17,8 +17,12 @@ #include "Debug.h" -#include <algorithm> +#include <cutils/compiler.h> #include <cutils/log.h> +#include <cutils/properties.h> + +#include <algorithm> +#include <cstdlib> namespace android { namespace uirenderer { diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h index 74cd74bde176..1293c786a0bd 100644 --- a/libs/hwui/Properties.h +++ b/libs/hwui/Properties.h @@ -18,8 +18,6 @@ #define ANDROID_HWUI_PROPERTIES_H #include <cutils/properties.h> -#include <stdlib.h> -#include <utils/Singleton.h> /** * This file contains the list of system properties used to configure diff --git a/libs/hwui/RenderBufferCache.cpp b/libs/hwui/RenderBufferCache.cpp index 8beed2540e1c..11d7a6af3a6a 100644 --- a/libs/hwui/RenderBufferCache.cpp +++ b/libs/hwui/RenderBufferCache.cpp @@ -14,12 +14,14 @@ * limitations under the License. */ -#include <utils/Log.h> - #include "Debug.h" #include "Properties.h" #include "RenderBufferCache.h" +#include <utils/Log.h> + +#include <cstdlib> + namespace android { namespace uirenderer { diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index 15ccd6ac5b6b..a1107f029691 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -563,10 +563,7 @@ void RenderProxy::post(RenderTask* task) { void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { void* retval; task->setReturnPtr(&retval); - SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); - AutoMutex _lock(mSyncMutex); - mRenderThread.queue(&syncTask); - mSyncCondition.wait(mSyncMutex); + mRenderThread.queueAndWait(task); return retval; } diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index 338fab650876..d0e601e09be6 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -117,9 +117,6 @@ private: DrawFrameTask mDrawFrameTask; - Mutex mSyncMutex; - Condition mSyncCondition; - void destroyContext(); void post(RenderTask* task); diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 8fcd10967e17..526a84861d98 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -28,9 +28,6 @@ #include <utils/Log.h> namespace android { -using namespace uirenderer::renderthread; -ANDROID_SINGLETON_STATIC_INSTANCE(RenderThread); - namespace uirenderer { namespace renderthread { @@ -136,7 +133,22 @@ public: } }; -RenderThread::RenderThread() : Thread(true), Singleton<RenderThread>() +static bool gHasRenderThreadInstance = false; + +bool RenderThread::hasInstance() { + return gHasRenderThreadInstance; +} + +RenderThread& RenderThread::getInstance() { + // This is a pointer because otherwise __cxa_finalize + // will try to delete it like a Good Citizen but that causes us to crash + // because we don't want to delete the RenderThread normally. + static RenderThread* sInstance = new RenderThread(); + gHasRenderThreadInstance = true; + return *sInstance; +} + +RenderThread::RenderThread() : Thread(true) , mNextWakeup(LLONG_MAX) , mDisplayEventReceiver(nullptr) , mVsyncRequested(false) @@ -313,13 +325,10 @@ void RenderThread::queue(RenderTask* task) { } void RenderThread::queueAndWait(RenderTask* task) { - Mutex mutex; - Condition condition; - SignalingRenderTask syncTask(task, &mutex, &condition); - - AutoMutex _lock(mutex); + SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); + AutoMutex _lock(mSyncMutex); queue(&syncTask); - condition.wait(mutex); + mSyncCondition.wait(mSyncMutex); } void RenderThread::queueAtFront(RenderTask* task) { diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index f3444a85a336..d8c7e61f34eb 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -25,11 +25,11 @@ #include <cutils/compiler.h> #include <ui/DisplayInfo.h> #include <utils/Looper.h> -#include <utils/Mutex.h> -#include <utils/Singleton.h> #include <utils/Thread.h> +#include <condition_variable> #include <memory> +#include <mutex> #include <set> namespace android { @@ -72,7 +72,7 @@ protected: ~IFrameCallback() {} }; -class ANDROID_API RenderThread : public Thread, protected Singleton<RenderThread> { +class ANDROID_API RenderThread : public Thread { public: // RenderThread takes complete ownership of tasks that are queued // and will delete them after they are run @@ -100,7 +100,6 @@ protected: virtual bool threadLoop() override; private: - friend class Singleton<RenderThread>; friend class DispatchFrameCallbacks; friend class RenderProxy; friend class android::uirenderer::TestUtils; @@ -108,6 +107,9 @@ private: RenderThread(); virtual ~RenderThread(); + static bool hasInstance(); + static RenderThread& getInstance(); + void initThreadLocals(); void initializeDisplayEventReceiver(); static int displayEventReceiverCallback(int fd, int events, void* data); @@ -125,6 +127,8 @@ private: nsecs_t mNextWakeup; TaskQueue mQueue; + Mutex mSyncMutex; + Condition mSyncCondition; DisplayInfo mDisplayInfo; |