OSDN Git Service

Remove almost-all android::Singleton users
authorJohn Reck <jreck@google.com>
Tue, 3 Nov 2015 18:09:59 +0000 (10:09 -0800)
committerJohn Reck <jreck@google.com>
Tue, 3 Nov 2015 18:09:59 +0000 (10:09 -0800)
Bug: 25426213
Change-Id: I88e6206e8915cce95c3a8a8a82a4bb8fbf668141

13 files changed:
libs/hwui/Caches.cpp
libs/hwui/Caches.h
libs/hwui/Extensions.cpp
libs/hwui/Extensions.h
libs/hwui/GradientCache.cpp
libs/hwui/PathCache.cpp
libs/hwui/Properties.cpp
libs/hwui/Properties.h
libs/hwui/RenderBufferCache.cpp
libs/hwui/renderthread/RenderProxy.cpp
libs/hwui/renderthread/RenderProxy.h
libs/hwui/renderthread/RenderThread.cpp
libs/hwui/renderthread/RenderThread.h

index 7c63e31..94a11f1 100644 (file)
@@ -23,6 +23,7 @@
 #include "ShadowTessellator.h"
 #include "utils/GLUtils.h"
 
+#include <cutils/properties.h>
 #include <utils/Log.h>
 #include <utils/String8.h>
 
index 61e958d..330dc29 100644 (file)
@@ -43,7 +43,6 @@
 #include <GLES3/gl3.h>
 
 #include <utils/KeyedVector.h>
-#include <utils/Singleton.h>
 
 #include <cutils/compiler.h>
 
index 06c8a21..6dd29ad 100644 (file)
@@ -20,6 +20,7 @@
 #include "Properties.h"
 #include "utils/StringUtils.h"
 
+#include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 #include <utils/Log.h>
 
index 0a30d16..6689b88 100644 (file)
 
 #include <cutils/compiler.h>
 
-#include <utils/Singleton.h>
-#include <utils/SortedVector.h>
-#include <utils/String8.h>
-
-#include <GLES2/gl2.h>
-
 namespace android {
 namespace uirenderer {
 
index aa105f9..8c46450 100644 (file)
@@ -21,6 +21,8 @@
 #include "GradientCache.h"
 #include "Properties.h"
 
+#include <cutils/properties.h>
+
 namespace android {
 namespace uirenderer {
 
index 4031f2e..fd9ab18 100644 (file)
@@ -30,6 +30,8 @@
 #include "thread/Signal.h"
 #include "thread/TaskProcessor.h"
 
+#include <cutils/properties.h>
+
 namespace android {
 namespace uirenderer {
 
index c0c61db..e818186 100644 (file)
 
 #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 {
index 74cd74b..1293c78 100644 (file)
@@ -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
index 8beed25..11d7a6a 100644 (file)
  * 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 {
 
index 15ccd6a..a1107f0 100644 (file)
@@ -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;
 }
 
index 338fab6..d0e601e 100644 (file)
@@ -117,9 +117,6 @@ private:
 
     DrawFrameTask mDrawFrameTask;
 
-    Mutex mSyncMutex;
-    Condition mSyncCondition;
-
     void destroyContext();
 
     void post(RenderTask* task);
index 8fcd109..526a848 100644 (file)
@@ -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) {
index f3444a8..d8c7e61 100644 (file)
 #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;