Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.animation.Animator; | 7 import android.animation.Animator; |
| 8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
| 9 import android.annotation.SuppressLint; | 9 import android.annotation.SuppressLint; |
| 10 import android.annotation.TargetApi; | 10 import android.annotation.TargetApi; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 private final AccessibilityManager mAccessibilityManager; | 102 private final AccessibilityManager mAccessibilityManager; |
| 103 | 103 |
| 104 // Whether touch exploration is enabled. | 104 // Whether touch exploration is enabled. |
| 105 private boolean mIsTouchExplorationEnabled; | 105 private boolean mIsTouchExplorationEnabled; |
| 106 | 106 |
| 107 // On KitKat and higher, a class that monitors the touch exploration state. | 107 // On KitKat and higher, a class that monitors the touch exploration state. |
| 108 private TouchExplorationMonitor mTouchExplorationMonitor; | 108 private TouchExplorationMonitor mTouchExplorationMonitor; |
| 109 | 109 |
| 110 private AndroidPermissionDelegate mPermissionDelegate; | 110 private AndroidPermissionDelegate mPermissionDelegate; |
| 111 | 111 |
| 112 private boolean mPendingVSyncRequest; | |
|
boliu
2017/03/15 22:08:11
hmm.. reading over this, I think it makes more sen
mthiesse
2017/03/16 00:03:07
So it couldn't only live in BFS, or WindowAndroid:
boliu
2017/03/16 00:45:44
Actually, I see another issue with moving to nativ
mthiesse
2017/03/16 15:36:05
Done.
| |
| 113 private boolean mVSyncPaused; | |
| 114 | |
| 112 /** | 115 /** |
| 113 * An interface to notify listeners of changes in the soft keyboard's visibi lity. | 116 * An interface to notify listeners of changes in the soft keyboard's visibi lity. |
| 114 */ | 117 */ |
| 115 public interface KeyboardVisibilityListener { | 118 public interface KeyboardVisibilityListener { |
| 116 public void keyboardVisibilityChanged(boolean isShowing); | 119 public void keyboardVisibilityChanged(boolean isShowing); |
| 117 } | 120 } |
| 118 private LinkedList<KeyboardVisibilityListener> mKeyboardVisibilityListeners = | 121 private LinkedList<KeyboardVisibilityListener> mKeyboardVisibilityListeners = |
| 119 new LinkedList<>(); | 122 new LinkedList<>(); |
| 120 | 123 |
| 121 /** | 124 /** |
| 122 * An interface to notify listeners that a context menu is closed. | 125 * An interface to notify listeners that a context menu is closed. |
| 123 */ | 126 */ |
| 124 public interface OnCloseContextMenuListener { | 127 public interface OnCloseContextMenuListener { |
| 125 /** | 128 /** |
| 126 * Called when a context menu has been closed. | 129 * Called when a context menu has been closed. |
| 127 */ | 130 */ |
| 128 void onContextMenuClosed(); | 131 void onContextMenuClosed(); |
| 129 } | 132 } |
| 130 | 133 |
| 131 private final ObserverList<OnCloseContextMenuListener> mContextMenuCloseList eners = | 134 private final ObserverList<OnCloseContextMenuListener> mContextMenuCloseList eners = |
| 132 new ObserverList<>(); | 135 new ObserverList<>(); |
| 133 | 136 |
| 134 private final VSyncMonitor.Listener mVSyncListener = new VSyncMonitor.Listen er() { | 137 private final VSyncMonitor.Listener mVSyncListener = new VSyncMonitor.Listen er() { |
| 135 @Override | 138 @Override |
| 136 public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) { | 139 public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) { |
| 140 if (mVSyncPaused) { | |
| 141 mPendingVSyncRequest = true; | |
| 142 return; | |
| 143 } | |
| 137 if (mNativeWindowAndroid != 0) { | 144 if (mNativeWindowAndroid != 0) { |
| 138 nativeOnVSync(mNativeWindowAndroid, | 145 nativeOnVSync(mNativeWindowAndroid, |
| 139 vsyncTimeMicros, | 146 vsyncTimeMicros, |
| 140 mVSyncMonitor.getVSyncPeriodInMicroseconds()); | 147 mVSyncMonitor.getVSyncPeriodInMicroseconds()); |
| 141 } | 148 } |
| 142 } | 149 } |
| 143 }; | 150 }; |
| 144 | 151 |
| 145 /** | 152 /** |
| 146 * Extract the activity if the given Context either is or wraps one. | 153 * Extract the activity if the given Context either is or wraps one. |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 /** | 496 /** |
| 490 * For window instances associated with an activity, notifies any listeners | 497 * For window instances associated with an activity, notifies any listeners |
| 491 * that the activity has been started. | 498 * that the activity has been started. |
| 492 */ | 499 */ |
| 493 protected void onActivityStarted() { | 500 protected void onActivityStarted() { |
| 494 if (mNativeWindowAndroid == 0) return; | 501 if (mNativeWindowAndroid == 0) return; |
| 495 nativeOnActivityStarted(mNativeWindowAndroid); | 502 nativeOnActivityStarted(mNativeWindowAndroid); |
| 496 } | 503 } |
| 497 | 504 |
| 498 @CalledByNative | 505 @CalledByNative |
| 499 private void requestVSyncUpdate() { | 506 protected void requestVSyncUpdate() { |
|
boliu
2017/03/15 22:08:11
keep private
mthiesse
2017/03/16 00:03:07
Done.
| |
| 507 if (mVSyncPaused) { | |
| 508 mPendingVSyncRequest = true; | |
| 509 return; | |
| 510 } | |
| 500 mVSyncMonitor.requestUpdate(); | 511 mVSyncMonitor.requestUpdate(); |
| 501 } | 512 } |
| 502 | 513 |
| 503 /** | 514 /** |
| 504 * An interface that intent callback objects have to implement. | 515 * An interface that intent callback objects have to implement. |
| 505 */ | 516 */ |
| 506 public interface IntentCallback { | 517 public interface IntentCallback { |
| 507 /** | 518 /** |
| 508 * Handles the data returned by the requested intent. | 519 * Handles the data returned by the requested intent. |
| 509 * @param window A window reference. | 520 * @param window A window reference. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 550 } | 561 } |
| 551 | 562 |
| 552 /** | 563 /** |
| 553 * Returns a pointer to the c++ AndroidWindow object and calls the initializ er if | 564 * Returns a pointer to the c++ AndroidWindow object and calls the initializ er if |
| 554 * the object has not been previously initialized. | 565 * the object has not been previously initialized. |
| 555 * @return A pointer to the c++ AndroidWindow. | 566 * @return A pointer to the c++ AndroidWindow. |
| 556 */ | 567 */ |
| 557 public long getNativePointer() { | 568 public long getNativePointer() { |
| 558 if (mNativeWindowAndroid == 0) { | 569 if (mNativeWindowAndroid == 0) { |
| 559 mNativeWindowAndroid = nativeInit(mDisplayAndroid.getDisplayId()); | 570 mNativeWindowAndroid = nativeInit(mDisplayAndroid.getDisplayId()); |
| 571 if (mVSyncPaused) nativeSetVSyncPaused(mNativeWindowAndroid, true); | |
|
boliu
2017/03/15 22:08:11
hmm, this doesn't look correct to me, why is vsync
mthiesse
2017/03/16 00:03:07
Well, whatever paused it is responsible for unpaus
boliu
2017/03/16 00:45:44
Oh so the assumption is that native start out as u
mthiesse
2017/03/16 15:36:06
Done.
| |
| 560 } | 572 } |
| 561 return mNativeWindowAndroid; | 573 return mNativeWindowAndroid; |
| 562 } | 574 } |
| 563 | 575 |
| 564 /** | 576 /** |
| 565 * Set the animation placeholder view, which we set to 'draw' during animati ons, such that | 577 * Set the animation placeholder view, which we set to 'draw' during animati ons, such that |
| 566 * animations aren't clipped by the SurfaceView 'hole'. This can be the Surf aceView itself | 578 * animations aren't clipped by the SurfaceView 'hole'. This can be the Surf aceView itself |
| 567 * or a view directly on top of it. This could be extended to many views if we ever need it. | 579 * or a view directly on top of it. This could be extended to many views if we ever need it. |
| 568 */ | 580 */ |
| 569 public void setAnimationPlaceholderView(View view) { | 581 public void setAnimationPlaceholderView(View view) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf aceView, | 729 * setWillNotDraw(false) to ensure that the animation is drawn over the Surf aceView, |
| 718 * and otherwise we call setWillNotDraw(true). | 730 * and otherwise we call setWillNotDraw(true). |
| 719 */ | 731 */ |
| 720 private void refreshWillNotDraw() { | 732 private void refreshWillNotDraw() { |
| 721 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont ent.isEmpty(); | 733 boolean willNotDraw = !mIsTouchExplorationEnabled && mAnimationsOverCont ent.isEmpty(); |
| 722 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) { | 734 if (mAnimationPlaceholderView.willNotDraw() != willNotDraw) { |
| 723 mAnimationPlaceholderView.setWillNotDraw(willNotDraw); | 735 mAnimationPlaceholderView.setWillNotDraw(willNotDraw); |
| 724 } | 736 } |
| 725 } | 737 } |
| 726 | 738 |
| 739 /** | |
| 740 * Pauses/Unpauses the VSync loop. A paused VSync loop will stop the composi tor for this window, | |
|
boliu
2017/03/15 22:08:11
nit: it's not a loop (in my head at least).. so dr
mthiesse
2017/03/16 00:03:07
Done.
| |
| 741 * preventing requestAnimationFrame callbacks from firing, etc. | |
| 742 */ | |
| 743 public void setVSyncPaused(boolean paused) { | |
| 744 mVSyncPaused = paused; | |
|
boliu
2017/03/15 22:08:11
generally, these things have an early out when mVS
mthiesse
2017/03/16 00:03:07
Done.
| |
| 745 if (!mVSyncPaused && mPendingVSyncRequest) requestVSyncUpdate(); | |
| 746 if (mNativeWindowAndroid != 0) nativeSetVSyncPaused(mNativeWindowAndroid , paused); | |
| 747 } | |
| 748 | |
| 727 private native long nativeInit(int displayId); | 749 private native long nativeInit(int displayId); |
| 728 private native void nativeOnVSync(long nativeWindowAndroid, | 750 private native void nativeOnVSync(long nativeWindowAndroid, |
| 729 long vsyncTimeMicros, | 751 long vsyncTimeMicros, |
| 730 long vsyncPeriodMicros); | 752 long vsyncPeriodMicros); |
| 731 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool ean visible); | 753 private native void nativeOnVisibilityChanged(long nativeWindowAndroid, bool ean visible); |
| 732 private native void nativeOnActivityStopped(long nativeWindowAndroid); | 754 private native void nativeOnActivityStopped(long nativeWindowAndroid); |
| 733 private native void nativeOnActivityStarted(long nativeWindowAndroid); | 755 private native void nativeOnActivityStarted(long nativeWindowAndroid); |
| 756 private native void nativeSetVSyncPaused(long nativeWindowAndroid, boolean p aused); | |
| 734 private native void nativeDestroy(long nativeWindowAndroid); | 757 private native void nativeDestroy(long nativeWindowAndroid); |
| 735 | 758 |
| 736 } | 759 } |
| OLD | NEW |