summaryrefslogtreecommitdiffstats
path: root/ui/android
diff options
context:
space:
mode:
authorjdduke <jdduke@chromium.org>2015-03-24 12:54:12 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-24 19:55:13 +0000
commit764f31d287a4995f0c89915745f5749e1c7063af (patch)
tree2fb1b497a5a68de7e6c6449148550f3c0ca56df0 /ui/android
parent76a4b2c98512e8feed2b2d2ba40421496765d6bd (diff)
downloadchromium_src-764f31d287a4995f0c89915745f5749e1c7063af.zip
chromium_src-764f31d287a4995f0c89915745f5749e1c7063af.tar.gz
chromium_src-764f31d287a4995f0c89915745f5749e1c7063af.tar.bz2
[Android] Preserve the front buffer when the activity is paused
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 Review URL: https://codereview.chromium.org/1001573003 Cr-Commit-Position: refs/heads/master@{#322052}
Diffstat (limited to 'ui/android')
-rw-r--r--ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java16
-rw-r--r--ui/android/java/src/org/chromium/ui/base/WindowAndroid.java20
-rw-r--r--ui/android/window_android.cc13
-rw-r--r--ui/android/window_android.h3
-rw-r--r--ui/android/window_android_observer.h3
5 files changed, 54 insertions, 1 deletions
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 b32cd9b..aae1dcd 100644
--- a/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/base/ActivityWindowAndroid.java
@@ -10,6 +10,9 @@ 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;
/**
@@ -17,7 +20,8 @@ import java.lang.ref.WeakReference;
* Activity Instance.
* Only instantiate this class when you need the implemented features.
*/
-public class ActivityWindowAndroid extends WindowAndroid {
+public class ActivityWindowAndroid
+ extends WindowAndroid implements ApplicationStatus.ActivityStateListener {
// Constants used for intent request code bounding.
private static final int REQUEST_CODE_PREFIX = 1000;
private static final int REQUEST_CODE_RANGE_SIZE = 100;
@@ -29,6 +33,7 @@ public class ActivityWindowAndroid extends WindowAndroid {
public ActivityWindowAndroid(Activity activity) {
super(activity.getApplicationContext());
mActivityRef = new WeakReference<Activity>(activity);
+ ApplicationStatus.registerStateListenerForActivity(this, activity);
}
@Override
@@ -99,6 +104,15 @@ public class ActivityWindowAndroid extends WindowAndroid {
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 0870221..0bf7bd1 100644
--- a/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
+++ b/ui/android/java/src/org/chromium/ui/base/WindowAndroid.java
@@ -236,6 +236,24 @@ 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.
@@ -351,6 +369,8 @@ 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 cb163ff..7c920e2 100644
--- a/ui/android/window_android.cc
+++ b/ui/android/window_android.cc
@@ -43,6 +43,11 @@ void WindowAndroid::OnCompositingDidCommit() {
OnCompositingDidCommit());
}
+void WindowAndroid::OnVisibilityChanged(bool visible) {
+ FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_,
+ OnVisibilityChanged(visible));
+}
+
void WindowAndroid::AddObserver(WindowAndroidObserver* observer) {
if (!observer_list_.HasObserver(observer))
observer_list_.AddObserver(observer);
@@ -103,6 +108,14 @@ 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 cb201cd..73e7686 100644
--- a/ui/android/window_android.h
+++ b/ui/android/window_android.h
@@ -43,6 +43,7 @@ class UI_ANDROID_EXPORT WindowAndroid {
// Compositor callback relay.
void OnCompositingDidCommit();
+ void OnVisibilityChanged(bool visible);
void AttachCompositor(WindowAndroidCompositor* compositor);
void DetachCompositor();
@@ -59,6 +60,8 @@ 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 05db5ce..d845729 100644
--- a/ui/android/window_android_observer.h
+++ b/ui/android/window_android_observer.h
@@ -12,11 +12,14 @@ namespace ui {
class UI_ANDROID_EXPORT WindowAndroidObserver {
public:
virtual void OnCompositingDidCommit() = 0;
+ virtual void OnVisibilityChanged(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) {}
+ virtual void OnActivityPaused() = 0;
+ virtual void OnActivityResumed() = 0;
protected:
virtual ~WindowAndroidObserver() {}