diff options
author | jdduke <jdduke@chromium.org> | 2015-04-27 12:04:03 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-27 19:04:13 +0000 |
commit | 631abee367dc1c119c559ef82e1601e790c2c37c (patch) | |
tree | 62c55f05f64329f1679ea3d3f745e9c233cbc710 | |
parent | 4169d03e08f5257c9a6017bec511399121ac28cd (diff) | |
download | chromium_src-631abee367dc1c119c559ef82e1601e790c2c37c.zip chromium_src-631abee367dc1c119c559ef82e1601e790c2c37c.tar.gz chromium_src-631abee367dc1c119c559ef82e1601e790c2c37c.tar.bz2 |
Revert of [Android] Stop hiding the RWHV layer subtree when hiding the widget (patchset #12 id:330001 of https://codereview.chromium.org/1001573003/)
Reason for revert:
Speculative fix for blank display after cold startup.
Original issue's description:
> Reland "[Android] Preserve the front buffer when the activity is paused"
>
> This change was reverted in r322170 due to WebView breakage. The
> ApplicationStatus dependency has been made optional, allowing
> WebView to opt-out of its use.
>
> Original description: ----------------------------
>
> Currently, when an activity is stopped, we explicitly hide the
> foreground Tab. This is problematic, as current hiding semantics
> might clear the visual front buffer before the window is hidden.
> This in turn causes an unpleasant flickering during activity
> transitions, e.g., when backgrounding Chrome or locking the screen.
>
> Wire Activity onPause/onResume notifications to WindowAndroidObservers,
> allowing the foreground tab to preserve its front buffer while hiding
> its web content. If the tab is explicitly hidden, or the root window
> is lost, the front buffer will be cleared as usual.
>
> BUG=462752,434401
>
> Committed: https://crrev.com/7954daf991a2adda234dc2e886b2d1ddf0049221
> Cr-Commit-Position: refs/heads/master@{#322228}
TBR=sievers@chromium.org,dtrainor@chromium.org,tedchoc@chromium.org,piman@chromium.org,boliu@chromium.org,torne@chromium.org
BUG=481450,481115,434401
Review URL: https://codereview.chromium.org/1109863003
Cr-Commit-Position: refs/heads/master@{#327092}
14 files changed, 64 insertions, 187 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 0a0e853..4a97cab 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -871,11 +871,9 @@ public class AwContents implements SmartClipProvider, WebContents webContents = nativeGetWebContents(mNativeAwContents); - // WebView does not currently initialize ApplicationStatus, crbug.com/470582. - final boolean listenToActivityState = false; Activity activity = ContentViewCore.activityFromContext(mContext); mWindowAndroid = activity != null - ? new ActivityWindowAndroid(activity, listenToActivityState) + ? new ActivityWindowAndroid(activity) : new WindowAndroid(mContext.getApplicationContext()); mContentViewCore = createAndInitializeContentViewCore( mContainerView, mContext, mInternalAccessAdapter, webContents, diff --git a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java index 5d24d1f6..7806061 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/Tab.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/Tab.java @@ -1213,6 +1213,13 @@ public class Tab implements ViewGroup.OnHierarchyChangeListener, } /** + * Called on the foreground tab when the Activity is stopped. + */ + public void onActivityStop() { + hide(); + } + + /** * Prepares the tab to be shown. This method is supposed to be called before the tab is * displayed. It restores the ContentView if it is not available after the cold start and * reloads the tab if its renderer has crashed. diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java index 4e77c83..a3130be 100644 --- a/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java +++ b/chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java @@ -82,8 +82,7 @@ public class ChromeShellActivity extends AppCompatActivity implements AppMenuPro new ActivityWindowAndroidFactory() { @Override public ActivityWindowAndroid getActivityWindowAndroid(Activity activity) { - final boolean listenToActivityState = true; - return new ActivityWindowAndroid(activity, listenToActivityState); + return new ActivityWindowAndroid(activity); } }; @@ -273,6 +272,9 @@ public class ChromeShellActivity extends AppCompatActivity implements AppMenuPro super.onStop(); if (mToolbar != null) mToolbar.hideSuggestions(); + + Tab activeTab = getActiveTab(); + if (activeTab != null) activeTab.onActivityStop(); } @Override diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index 4fe0555..d1c4d01 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -469,7 +469,6 @@ void CompositorImpl::SetVisible(bool visible) { CreateLayerTreeHost(); ui_resource_provider_.SetLayerTreeHost(host_.get()); } - root_window_->OnVisibilityChanged(visible); } void CompositorImpl::setDeviceScaleFactor(float factor) { diff --git a/content/browser/renderer_host/delegated_frame_evictor.cc b/content/browser/renderer_host/delegated_frame_evictor.cc index 65ae483..33d6b2c 100644 --- a/content/browser/renderer_host/delegated_frame_evictor.cc +++ b/content/browser/renderer_host/delegated_frame_evictor.cc @@ -10,13 +10,11 @@ namespace content { DelegatedFrameEvictor::DelegatedFrameEvictor( DelegatedFrameEvictorClient* client) - : client_(client), has_frame_(false), visible_(false) { -} + : client_(client), has_frame_(false) {} DelegatedFrameEvictor::~DelegatedFrameEvictor() { DiscardedFrame(); } void DelegatedFrameEvictor::SwappedFrame(bool visible) { - visible_ = visible; has_frame_ = true; RendererFrameManager::GetInstance()->AddFrame(this, visible); } @@ -27,14 +25,11 @@ void DelegatedFrameEvictor::DiscardedFrame() { } void DelegatedFrameEvictor::SetVisible(bool visible) { - if (visible_ == visible) - return; - visible_ = visible; if (has_frame_) { if (visible) { - LockFrame(); + RendererFrameManager::GetInstance()->LockFrame(this); } else { - UnlockFrame(); + RendererFrameManager::GetInstance()->UnlockFrame(this); } } } diff --git a/content/browser/renderer_host/delegated_frame_evictor.h b/content/browser/renderer_host/delegated_frame_evictor.h index 9e9f68a..796b6c2 100644 --- a/content/browser/renderer_host/delegated_frame_evictor.h +++ b/content/browser/renderer_host/delegated_frame_evictor.h @@ -35,7 +35,6 @@ class CONTENT_EXPORT DelegatedFrameEvictor : public RendererFrameManagerClient { DelegatedFrameEvictorClient* client_; bool has_frame_; - bool visible_; DISALLOW_COPY_AND_ASSIGN(DelegatedFrameEvictor); }; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index d56bee1..4d76399 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -583,7 +583,23 @@ void RenderWidgetHostViewAndroid::Show() { return; is_showing_ = true; - ShowInternal(); + if (layer_.get()) + layer_->SetHideLayerAndSubtree(false); + + if (overscroll_controller_) + overscroll_controller_->Enable(); + + frame_evictor_->SetVisible(true); + + if (!host_ || !host_->is_hidden()) + return; + + host_->WasShown(ui::LatencyInfo()); + + if (content_view_core_) { + StartObservingRootWindow(); + RequestVSyncUpdate(BEGIN_FRAME); + } } void RenderWidgetHostViewAndroid::Hide() { @@ -591,10 +607,27 @@ void RenderWidgetHostViewAndroid::Hide() { return; is_showing_ = false; + if (layer_.get() && locks_on_frame_count_ == 0) + layer_->SetHideLayerAndSubtree(true); + + if (overscroll_controller_) + overscroll_controller_->Disable(); + + frame_evictor_->SetVisible(false); + // We don't know if we will ever get a frame if we are hiding the renderer, so + // we need to cancel all requests + AbortPendingReadbackRequests(); + + RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); + + if (!host_ || host_->is_hidden()) + return; - bool hide_frontbuffer = true; - bool stop_observing_root_window = true; - HideInternal(hide_frontbuffer, stop_observing_root_window); + // Inform the renderer that we are being hidden so it can reduce its resource + // utilization. + host_->WasHidden(); + + StopObservingRootWindow(); } bool RenderWidgetHostViewAndroid::IsShowing() { @@ -1430,57 +1463,6 @@ void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { accelerated_surface_route_id_ = route_id; } -void RenderWidgetHostViewAndroid::ShowInternal() { - DCHECK(is_showing_); - if (!host_ || !host_->is_hidden()) - return; - - if (layer_.get()) - layer_->SetHideLayerAndSubtree(false); - - frame_evictor_->SetVisible(true); - - if (overscroll_controller_) - overscroll_controller_->Enable(); - - host_->WasShown(ui::LatencyInfo()); - - if (content_view_core_) { - StartObservingRootWindow(); - RequestVSyncUpdate(BEGIN_FRAME); - } -} - -void RenderWidgetHostViewAndroid::HideInternal( - bool hide_frontbuffer, - bool stop_observing_root_window) { - if (hide_frontbuffer) { - if (layer_.get() && locks_on_frame_count_ == 0) - layer_->SetHideLayerAndSubtree(true); - - frame_evictor_->SetVisible(false); - } - - if (stop_observing_root_window) - StopObservingRootWindow(); - - if (!host_ || host_->is_hidden()) - return; - - if (overscroll_controller_) - overscroll_controller_->Disable(); - - // We don't know if we will ever get a frame if we are hiding the renderer, so - // we need to cancel all requests - AbortPendingReadbackRequests(); - - RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); - - // Inform the renderer that we are being hidden so it can reduce its resource - // utilization. - host_->WasHidden(); -} - void RenderWidgetHostViewAndroid::AttachLayers() { if (!content_view_core_) return; @@ -1508,12 +1490,6 @@ void RenderWidgetHostViewAndroid::RemoveLayers() { void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { bool should_request_vsync = !outstanding_vsync_requests_ && requests; outstanding_vsync_requests_ |= requests; - - // If the host has been hidden, defer vsync requests until it is shown - // again via |Show()|. - if (!host_ || host_->is_hidden()) - return; - // Note that if we're not currently observing the root window, outstanding // vsync requests will be pushed if/when we resume observing in // |StartObservingRootWindow()|. @@ -1523,7 +1499,6 @@ void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { void RenderWidgetHostViewAndroid::StartObservingRootWindow() { DCHECK(content_view_core_); - DCHECK(is_showing_); if (observing_root_window_) return; @@ -1840,8 +1815,7 @@ void RenderWidgetHostViewAndroid::SetContentViewCore( if (!content_view_core_) return; - if (is_showing_) - StartObservingRootWindow(); + StartObservingRootWindow(); if (resize) WasResized(); @@ -1882,17 +1856,6 @@ void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); } -void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { - DCHECK(is_showing_); - if (visible) { - ShowInternal(); - } else { - bool hide_frontbuffer = true; - bool stop_observing_root_window = false; - HideInternal(hide_frontbuffer, stop_observing_root_window); - } -} - void RenderWidgetHostViewAndroid::OnAttachCompositor() { DCHECK(content_view_core_); if (!overscroll_controller_) @@ -1909,7 +1872,7 @@ void RenderWidgetHostViewAndroid::OnDetachCompositor() { void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, base::TimeDelta vsync_period) { TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); - if (!host_ || host_->is_hidden()) + if (!host_) return; if (outstanding_vsync_requests_ & FLUSH_INPUT) { @@ -1935,20 +1898,6 @@ void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { SetNeedsAnimate(); } -void RenderWidgetHostViewAndroid::OnActivityPaused() { - TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityPaused"); - DCHECK(is_showing_); - bool hide_frontbuffer = false; - bool stop_observing_root_window = false; - HideInternal(hide_frontbuffer, stop_observing_root_window); -} - -void RenderWidgetHostViewAndroid::OnActivityResumed() { - TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityResumed"); - DCHECK(is_showing_); - ShowInternal(); -} - void RenderWidgetHostViewAndroid::OnLostResources() { ReleaseLocksOnSurface(); if (layer_.get()) diff --git a/content/browser/renderer_host/render_widget_host_view_android.h b/content/browser/renderer_host/render_widget_host_view_android.h index 3aec51e34..f5eace1 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.h +++ b/content/browser/renderer_host/render_widget_host_view_android.h @@ -193,14 +193,11 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid // ui::WindowAndroidObserver implementation. void OnCompositingDidCommit() override; - void OnRootWindowVisibilityChanged(bool visible) override; void OnAttachCompositor() override; void OnDetachCompositor() override; void OnVSync(base::TimeTicks frame_time, base::TimeDelta vsync_period) override; void OnAnimate(base::TimeTicks begin_frame_time) override; - void OnActivityPaused() override; - void OnActivityResumed() override; // DelegatedFrameEvictor implementation void EvictDelegatedFrame() override; @@ -290,8 +287,6 @@ class CONTENT_EXPORT RenderWidgetHostViewAndroid const cc::CompositorFrameMetadata& frame_metadata); void ComputeContentsSize(const cc::CompositorFrameMetadata& frame_metadata); - void ShowInternal(); - void HideInternal(bool hide_frontbuffer, bool stop_observing_root_window); void AttachLayers(); void RemoveLayers(); diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java index a5a9471..bc460bf 100644 --- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java +++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java @@ -71,8 +71,7 @@ public class ContentShellActivity extends Activity { setContentView(R.layout.content_shell_activity); mShellManager = (ShellManager) findViewById(R.id.shell_container); - final boolean listenToActivityState = true; - mWindowAndroid = new ActivityWindowAndroid(this, listenToActivityState); + mWindowAndroid = new ActivityWindowAndroid(this); mWindowAndroid.restoreInstanceState(savedInstanceState); mShellManager.setWindow(mWindowAndroid); // Set up the animation placeholder to be the SurfaceView. This disables the @@ -184,6 +183,14 @@ public class ContentShellActivity extends Activity { } @Override + protected void onStop() { + super.onStop(); + + ContentViewCore contentViewCore = getActiveContentViewCore(); + if (contentViewCore != null) contentViewCore.onHide(); + } + + @Override protected void onStart() { super.onStart(); diff --git a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java index 5c20d72..b32cd9b 100644 --- a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java +++ b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java @@ -10,9 +10,6 @@ import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.IntentSender.SendIntentException; -import org.chromium.base.ActivityState; -import org.chromium.base.ApplicationStatus; - import java.lang.ref.WeakReference; /** @@ -20,8 +17,7 @@ import java.lang.ref.WeakReference; * Activity Instance. * Only instantiate this class when you need the implemented features. */ -public class ActivityWindowAndroid - extends WindowAndroid implements ApplicationStatus.ActivityStateListener { +public class ActivityWindowAndroid extends WindowAndroid { // Constants used for intent request code bounding. private static final int REQUEST_CODE_PREFIX = 1000; private static final int REQUEST_CODE_RANGE_SIZE = 100; @@ -30,27 +26,9 @@ public class ActivityWindowAndroid private final WeakReference<Activity> mActivityRef; private int mNextRequestCode = 0; - /** - * Creates an Activity-specific WindowAndroid with associated intent functionality. - * TODO(jdduke): Remove this overload when all callsites have been updated to - * indicate their activity state listening preference. - * @param activity The activity associated with the WindowAndroid. - */ public ActivityWindowAndroid(Activity activity) { - this(activity, true); - } - - /** - * Creates an Activity-specific WindowAndroid with associated intent functionality. - * @param activity The activity associated with the WindowAndroid. - * @param listenToActivityState Whether to listen to activity state changes. - */ - public ActivityWindowAndroid(Activity activity, boolean listenToActivityState) { super(activity.getApplicationContext()); mActivityRef = new WeakReference<Activity>(activity); - if (listenToActivityState) { - ApplicationStatus.registerStateListenerForActivity(this, activity); - } } @Override @@ -121,15 +99,6 @@ public class ActivityWindowAndroid return new WeakReference<Activity>(mActivityRef.get()); } - @Override - public void onActivityStateChange(Activity activity, int newState) { - if (newState == ActivityState.PAUSED) { - onActivityPaused(); - } else if (newState == ActivityState.RESUMED) { - onActivityResumed(); - } - } - private int generateNextRequestCode() { int requestCode = REQUEST_CODE_PREFIX + mNextRequestCode; mNextRequestCode = (mNextRequestCode + 1) % REQUEST_CODE_RANGE_SIZE; diff --git a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java index 0bf7bd1..0870221 100644 --- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java +++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java @@ -236,24 +236,6 @@ public class WindowAndroid { } /** - * For window instances associated with an activity, notifies any listeners - * that the activity has been paused. - */ - protected void onActivityPaused() { - if (mNativeWindowAndroid == 0) return; - nativeOnActivityPaused(mNativeWindowAndroid); - } - - /** - * For window instances associated with an activity, notifies any listeners - * that the activity has been paused. - */ - protected void onActivityResumed() { - if (mNativeWindowAndroid == 0) return; - nativeOnActivityResumed(mNativeWindowAndroid); - } - - /** * Responds to the intent result if the intent was created by the native window. * @param requestCode Request code of the requested intent. * @param resultCode Result code of the requested intent. @@ -369,8 +351,6 @@ public class WindowAndroid { private native void nativeOnVSync(long nativeWindowAndroid, long vsyncTimeMicros, long vsyncPeriodMicros); - private native void nativeOnActivityPaused(long nativeWindowAndroid); - private native void nativeOnActivityResumed(long nativeWindowAndroid); private native void nativeDestroy(long nativeWindowAndroid); } diff --git a/ui/android/window_android.cc b/ui/android/window_android.cc index 9a476892..d8623a5 100644 --- a/ui/android/window_android.cc +++ b/ui/android/window_android.cc @@ -43,11 +43,6 @@ void WindowAndroid::OnCompositingDidCommit() { OnCompositingDidCommit()); } -void WindowAndroid::OnVisibilityChanged(bool visible) { - FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, - OnRootWindowVisibilityChanged(visible)); -} - void WindowAndroid::AddObserver(WindowAndroidObserver* observer) { if (!observer_list_.HasObserver(observer)) observer_list_.AddObserver(observer); @@ -105,14 +100,6 @@ void WindowAndroid::OnVSync(JNIEnv* env, compositor_->OnVSync(frame_time, vsync_period); } -void WindowAndroid::OnActivityResumed(JNIEnv* env, jobject obj) { - FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityResumed()); -} - -void WindowAndroid::OnActivityPaused(JNIEnv* env, jobject obj) { - FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityPaused()); -} - // ---------------------------------------------------------------------------- // Native JNI methods // ---------------------------------------------------------------------------- diff --git a/ui/android/window_android.h b/ui/android/window_android.h index 005f4d6..f464a11 100644 --- a/ui/android/window_android.h +++ b/ui/android/window_android.h @@ -43,7 +43,6 @@ class UI_ANDROID_EXPORT WindowAndroid { // Compositor callback relay. void OnCompositingDidCommit(); - void OnVisibilityChanged(bool visible); void AttachCompositor(WindowAndroidCompositor* compositor); void DetachCompositor(); @@ -60,8 +59,6 @@ class UI_ANDROID_EXPORT WindowAndroid { jlong time_micros, jlong period_micros); void Animate(base::TimeTicks begin_frame_time); - void OnActivityPaused(JNIEnv* env, jobject obj); - void OnActivityResumed(JNIEnv* env, jobject obj); private: ~WindowAndroid(); diff --git a/ui/android/window_android_observer.h b/ui/android/window_android_observer.h index 4e97d2a..05db5ce 100644 --- a/ui/android/window_android_observer.h +++ b/ui/android/window_android_observer.h @@ -12,19 +12,12 @@ namespace ui { class UI_ANDROID_EXPORT WindowAndroidObserver { public: virtual void OnCompositingDidCommit() = 0; - virtual void OnRootWindowVisibilityChanged(bool visible) = 0; virtual void OnAttachCompositor() = 0; virtual void OnDetachCompositor() = 0; virtual void OnVSync(base::TimeTicks frame_time, base::TimeDelta vsync_period) = 0; virtual void OnAnimate(base::TimeTicks frame_begin_time) {} - // Note that activity state callbacks will only be made if the WindowAndroid - // has been explicitly subscribed to receive them. The observer instance - // should account for whether or not this is the case. - virtual void OnActivityPaused() = 0; - virtual void OnActivityResumed() = 0; - protected: virtual ~WindowAndroidObserver() {} }; |