Loading libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragResizeInputListener.java +31 −24 Original line number Original line Diff line number Diff line Loading @@ -27,8 +27,8 @@ import android.hardware.input.InputManager; import android.os.Binder; import android.os.Binder; import android.os.Handler; import android.os.Handler; import android.os.IBinder; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.os.RemoteException; import android.view.Choreographer; import android.view.IWindowSession; import android.view.IWindowSession; import android.view.InputChannel; import android.view.InputChannel; import android.view.InputEvent; import android.view.InputEvent; Loading Loading @@ -97,7 +97,7 @@ class DragResizeInputListener implements AutoCloseable { e.rethrowFromSystemServer(); e.rethrowFromSystemServer(); } } mInputEventReceiver = new TaskResizeInputEventReceiver(mInputChannel, mHandler.getLooper()); mInputEventReceiver = new TaskResizeInputEventReceiver(mInputChannel, mHandler); mCallback = callback; mCallback = callback; } } Loading Loading @@ -154,10 +154,6 @@ class DragResizeInputListener implements AutoCloseable { } catch (RemoteException e) { } catch (RemoteException e) { e.rethrowFromSystemServer(); e.rethrowFromSystemServer(); } } // This marks all relevant components have handled the previous resize event and can take // the next one now. mInputEventReceiver.onHandledLastResizeEvent(); } } @Override @Override Loading @@ -171,28 +167,42 @@ class DragResizeInputListener implements AutoCloseable { } } private class TaskResizeInputEventReceiver extends InputEventReceiver { private class TaskResizeInputEventReceiver extends InputEventReceiver { private boolean mWaitingForLastResizeEventHandled; private final Choreographer mChoreographer; private final Runnable mConsumeBatchEventRunnable; private boolean mConsumeBatchEventScheduled; private TaskResizeInputEventReceiver(InputChannel inputChannel, Looper looper) { private TaskResizeInputEventReceiver(InputChannel inputChannel, Handler handler) { super(inputChannel, looper); super(inputChannel, handler.getLooper()); } private void onHandledLastResizeEvent() { final Choreographer[] choreographer = new Choreographer[1]; mWaitingForLastResizeEventHandled = false; handler.runWithScissors( consumeBatchedInputEvents(-1); () -> choreographer[0] = Choreographer.getInstance(), 0); mChoreographer = choreographer[0]; mConsumeBatchEventRunnable = () -> { mConsumeBatchEventScheduled = false; if (consumeBatchedInputEvents(mChoreographer.getFrameTimeNanos())) { // If we consumed a batch here, we want to go ahead and schedule the // consumption of batched input events on the next frame. Otherwise, we would // wait until we have more input events pending and might get starved by other // things occurring in the process. scheduleConsumeBatchEvent(); } }; } } @Override @Override public void onBatchedInputEventPending(int source) { public void onBatchedInputEventPending(int source) { // InputEventReceiver keeps continuous move events in a batched event until explicitly scheduleConsumeBatchEvent(); // consuming it or an incompatible event shows up (likely an up event in this case). We } // continue to keep move events in the next batched event until we receive a geometry // update so that we don't put too much pressure on the framework with excessive number private void scheduleConsumeBatchEvent() { // of input events if it can't handle them fast enough. It's more responsive to always if (mConsumeBatchEventScheduled) { // resize the task to the latest received coordinates. return; if (!mWaitingForLastResizeEventHandled) { consumeBatchedInputEvents(-1); } } mChoreographer.postCallback( Choreographer.CALLBACK_INPUT, mConsumeBatchEventRunnable, null); mConsumeBatchEventScheduled = true; } } @Override @Override Loading @@ -211,14 +221,12 @@ class DragResizeInputListener implements AutoCloseable { mDragPointerId = e.getPointerId(0); mDragPointerId = e.getPointerId(0); mCallback.onDragResizeStart( mCallback.onDragResizeStart( calculateCtrlType(e.getX(0), e.getY(0)), e.getRawX(0), e.getRawY(0)); calculateCtrlType(e.getX(0), e.getY(0)), e.getRawX(0), e.getRawY(0)); mWaitingForLastResizeEventHandled = false; break; break; } } case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: { int dragPointerIndex = e.findPointerIndex(mDragPointerId); int dragPointerIndex = e.findPointerIndex(mDragPointerId); mCallback.onDragResizeMove( mCallback.onDragResizeMove( e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); mWaitingForLastResizeEventHandled = true; break; break; } } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP: Loading @@ -226,7 +234,6 @@ class DragResizeInputListener implements AutoCloseable { int dragPointerIndex = e.findPointerIndex(mDragPointerId); int dragPointerIndex = e.findPointerIndex(mDragPointerId); mCallback.onDragResizeEnd( mCallback.onDragResizeEnd( e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); mWaitingForLastResizeEventHandled = false; mDragPointerId = -1; mDragPointerId = -1; break; break; } } Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DragResizeInputListener.java +31 −24 Original line number Original line Diff line number Diff line Loading @@ -27,8 +27,8 @@ import android.hardware.input.InputManager; import android.os.Binder; import android.os.Binder; import android.os.Handler; import android.os.Handler; import android.os.IBinder; import android.os.IBinder; import android.os.Looper; import android.os.RemoteException; import android.os.RemoteException; import android.view.Choreographer; import android.view.IWindowSession; import android.view.IWindowSession; import android.view.InputChannel; import android.view.InputChannel; import android.view.InputEvent; import android.view.InputEvent; Loading Loading @@ -97,7 +97,7 @@ class DragResizeInputListener implements AutoCloseable { e.rethrowFromSystemServer(); e.rethrowFromSystemServer(); } } mInputEventReceiver = new TaskResizeInputEventReceiver(mInputChannel, mHandler.getLooper()); mInputEventReceiver = new TaskResizeInputEventReceiver(mInputChannel, mHandler); mCallback = callback; mCallback = callback; } } Loading Loading @@ -154,10 +154,6 @@ class DragResizeInputListener implements AutoCloseable { } catch (RemoteException e) { } catch (RemoteException e) { e.rethrowFromSystemServer(); e.rethrowFromSystemServer(); } } // This marks all relevant components have handled the previous resize event and can take // the next one now. mInputEventReceiver.onHandledLastResizeEvent(); } } @Override @Override Loading @@ -171,28 +167,42 @@ class DragResizeInputListener implements AutoCloseable { } } private class TaskResizeInputEventReceiver extends InputEventReceiver { private class TaskResizeInputEventReceiver extends InputEventReceiver { private boolean mWaitingForLastResizeEventHandled; private final Choreographer mChoreographer; private final Runnable mConsumeBatchEventRunnable; private boolean mConsumeBatchEventScheduled; private TaskResizeInputEventReceiver(InputChannel inputChannel, Looper looper) { private TaskResizeInputEventReceiver(InputChannel inputChannel, Handler handler) { super(inputChannel, looper); super(inputChannel, handler.getLooper()); } private void onHandledLastResizeEvent() { final Choreographer[] choreographer = new Choreographer[1]; mWaitingForLastResizeEventHandled = false; handler.runWithScissors( consumeBatchedInputEvents(-1); () -> choreographer[0] = Choreographer.getInstance(), 0); mChoreographer = choreographer[0]; mConsumeBatchEventRunnable = () -> { mConsumeBatchEventScheduled = false; if (consumeBatchedInputEvents(mChoreographer.getFrameTimeNanos())) { // If we consumed a batch here, we want to go ahead and schedule the // consumption of batched input events on the next frame. Otherwise, we would // wait until we have more input events pending and might get starved by other // things occurring in the process. scheduleConsumeBatchEvent(); } }; } } @Override @Override public void onBatchedInputEventPending(int source) { public void onBatchedInputEventPending(int source) { // InputEventReceiver keeps continuous move events in a batched event until explicitly scheduleConsumeBatchEvent(); // consuming it or an incompatible event shows up (likely an up event in this case). We } // continue to keep move events in the next batched event until we receive a geometry // update so that we don't put too much pressure on the framework with excessive number private void scheduleConsumeBatchEvent() { // of input events if it can't handle them fast enough. It's more responsive to always if (mConsumeBatchEventScheduled) { // resize the task to the latest received coordinates. return; if (!mWaitingForLastResizeEventHandled) { consumeBatchedInputEvents(-1); } } mChoreographer.postCallback( Choreographer.CALLBACK_INPUT, mConsumeBatchEventRunnable, null); mConsumeBatchEventScheduled = true; } } @Override @Override Loading @@ -211,14 +221,12 @@ class DragResizeInputListener implements AutoCloseable { mDragPointerId = e.getPointerId(0); mDragPointerId = e.getPointerId(0); mCallback.onDragResizeStart( mCallback.onDragResizeStart( calculateCtrlType(e.getX(0), e.getY(0)), e.getRawX(0), e.getRawY(0)); calculateCtrlType(e.getX(0), e.getY(0)), e.getRawX(0), e.getRawY(0)); mWaitingForLastResizeEventHandled = false; break; break; } } case MotionEvent.ACTION_MOVE: { case MotionEvent.ACTION_MOVE: { int dragPointerIndex = e.findPointerIndex(mDragPointerId); int dragPointerIndex = e.findPointerIndex(mDragPointerId); mCallback.onDragResizeMove( mCallback.onDragResizeMove( e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); mWaitingForLastResizeEventHandled = true; break; break; } } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP: Loading @@ -226,7 +234,6 @@ class DragResizeInputListener implements AutoCloseable { int dragPointerIndex = e.findPointerIndex(mDragPointerId); int dragPointerIndex = e.findPointerIndex(mDragPointerId); mCallback.onDragResizeEnd( mCallback.onDragResizeEnd( e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); e.getRawX(dragPointerIndex), e.getRawY(dragPointerIndex)); mWaitingForLastResizeEventHandled = false; mDragPointerId = -1; mDragPointerId = -1; break; break; } } Loading