(1 of 2) add call to determine if picture is ready

This is a half-checkin. The other half is in frameworks/base.

Add WebViewCore::pictureReady(). This uses the last reported
progress when the picture was recorded, and checks to see if
the picture itself is blank. The caller can use this to show
a cached picture or switch to a new one.

http://b/issue?id=1802703
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index ba07c52..bfa83a9 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -293,6 +293,7 @@
     m_findIsUp = false;
     m_domtree_version = 0;
     m_check_domtree_version = true;
+    m_progressDone = false;
 }
 
 static bool layoutIfNeededRecursive(WebCore::Frame* f)
@@ -571,6 +572,18 @@
     return tookTooLong;
 }
 
+bool WebViewCore::pictureReady()
+{
+    bool done;
+    m_contentMutex.lock();
+    PictureSet copyContent = PictureSet(m_content);
+    done = m_progressDone;
+    m_contentMutex.unlock();
+    DBG_NAV_LOGD("done=%s empty=%s", done ? "true" : "false",
+        copyContent.isEmpty() ? "true" : "false");
+    return done || !copyContent.isEmpty();
+}
+
 SkPicture* WebViewCore::rebuildPicture(const SkIRect& inval)
 {
     WebCore::FrameView* view = m_mainFrame->view();
@@ -621,12 +634,13 @@
 bool WebViewCore::recordContent(SkRegion* region, SkIPoint* point)
 {
     DBG_SET_LOG("start");
+    float progress = (float) m_mainFrame->page()->progress()->estimatedProgress();
     m_contentMutex.lock();
     PictureSet contentCopy(m_content);
+    m_progressDone = progress <= 0.0f || progress >= 1.0f;
     m_contentMutex.unlock();
     recordPictureSet(&contentCopy);
-    float progress = (float) m_mainFrame->page()->progress()->estimatedProgress();
-    if (progress > 0.0f && progress < 1.0f && contentCopy.isEmpty()) {
+    if (!m_progressDone && contentCopy.isEmpty()) {
         DBG_SET_LOGD("empty (progress=%g)", progress);
         return false;
     }
@@ -2562,6 +2576,11 @@
     return viewImpl->drawContent(canvas, color);
 }
 
+static bool PictureReady(JNIEnv* env, jobject obj)
+{
+    return GET_NATIVE_VIEW(env, obj)->pictureReady();
+}
+
 // ----------------------------------------------------------------------------
 
 /*
@@ -2578,6 +2597,8 @@
         (void*) Key },
     { "nativeClick", "()Z",
         (void*) Click },
+    { "nativePictureReady", "()Z",
+        (void*) PictureReady } ,
     { "nativeSendListBoxChoices", "([ZI)V",
         (void*) SendListBoxChoices },
     { "nativeSendListBoxChoice", "(I)V",
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index ae2a90d..cf8cb8d 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -304,6 +304,7 @@
         
         // draw the picture set with the specified background color
         bool drawContent(SkCanvas* , SkColor );
+        bool pictureReady();
         
         // record the inval area, and the picture size
         bool recordContent(SkRegion* , SkIPoint* );
@@ -383,6 +384,7 @@
         WebCore::IntPoint m_mousePos;
         bool m_frameCacheOutOfDate;
         bool m_blockFocusChange;
+        bool m_progressDone;
         int m_lastPassed;
         int m_lastVelocity;
         CachedHistory m_history;