OSDN Git Service

fix race condition between HWUI cache and renderThread
authorThomas Buhot <thomas.buhot@intel.com>
Mon, 18 Jan 2016 09:31:58 +0000 (10:31 +0100)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 20 Jul 2016 09:53:25 +0000 (17:53 +0800)
This is based on the commit c0a0e1a66da20a18045d59451b59ec32685bcf18
that has been merged in Google's master branch.
See: https://android-review.googlesource.com/#/c/195743/

getMaximumBitmapWidth() and getMaximumBitmapHeight() of DisplayListCanvas
need HWUI cache instance. Since the initialization of the cache is
asynchronous it may crash if not yet ready. Add a staticFence() call
to guarantee the cache has been created prior issuing the call.

Change-Id: I5ed9e5cc084444c8d1872a77fef50e294ae14e93
Signed-off-by: Thomas Buhot <thomas.buhot@intel.com>
Tracked-On: https://jira01.devtools.intel.com/browse/OAM-15447
Reviewed-on: https://android.intel.com:443/456036

core/jni/android_view_DisplayListCanvas.cpp
libs/hwui/renderthread/RenderProxy.cpp
libs/hwui/renderthread/RenderProxy.h

index bb8ef83..ef1e4ab 100644 (file)
@@ -102,10 +102,16 @@ static void android_view_DisplayListCanvas_callDrawGLFunction(JNIEnv* env, jobje
 // ----------------------------------------------------------------------------
 
 static jint android_view_DisplayListCanvas_getMaxTextureWidth(JNIEnv* env, jobject clazz) {
+    if (!Caches::hasInstance()) {
+        android::uirenderer::renderthread::RenderProxy::staticFence();
+    }
     return Caches::getInstance().maxTextureSize;
 }
 
 static jint android_view_DisplayListCanvas_getMaxTextureHeight(JNIEnv* env, jobject clazz) {
+    if (!Caches::hasInstance()) {
+        android::uirenderer::renderthread::RenderProxy::staticFence();
+    }
     return Caches::getInstance().maxTextureSize;
 }
 
index 30f0073..e65cb11 100644 (file)
@@ -385,6 +385,12 @@ void RenderProxy::fence() {
     postAndWait(task);
 }
 
+void RenderProxy::staticFence() {
+    SETUP_TASK(fence);
+    UNUSED(args);
+    staticPostAndWait(task);
+}
+
 CREATE_BRIDGE1(stopDrawing, CanvasContext* context) {
     args->context->stopDrawing();
     return nullptr;
index db03b29..8a1f5bf 100644 (file)
@@ -94,6 +94,7 @@ public:
     ANDROID_API static void overrideProperty(const char* name, const char* value);
 
     ANDROID_API void fence();
+    ANDROID_API static void staticFence();
     ANDROID_API void stopDrawing();
     ANDROID_API void notifyFramePending();