use of android.view.SurfaceControl in project platform_frameworks_base by android.
the class Session method performDrag.
public boolean performDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
}
synchronized (mService.mWindowMap) {
if (mService.mDragState == null) {
Slog.w(TAG_WM, "No drag prepared");
throw new IllegalStateException("performDrag() without prepareDrag()");
}
if (dragToken != mService.mDragState.mToken) {
Slog.w(TAG_WM, "Performing mismatched drag");
throw new IllegalStateException("performDrag() does not match prepareDrag()");
}
WindowState callingWin = mService.windowForClientLocked(null, window, false);
if (callingWin == null) {
Slog.w(TAG_WM, "Bad requesting window " + window);
// !!! TODO: throw here?
return false;
}
// !!! TODO: if input is not still focused on the initiating window, fail
// the drag initiation (e.g. an alarm window popped up just as the application
// called performDrag()
mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
// !!! TODO: extract the current touch (x, y) in screen coordinates. That
// will let us eliminate the (touchX,touchY) parameters from the API.
// !!! FIXME: put all this heavy stuff onto the mH looper, as well as
// the actual drag event dispatch stuff in the dragstate
final DisplayContent displayContent = callingWin.getDisplayContent();
if (displayContent == null) {
return false;
}
Display display = displayContent.getDisplay();
mService.mDragState.register(display);
mService.mInputMonitor.updateInputWindowsLw(true);
if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, mService.mDragState.mServerChannel)) {
Slog.e(TAG_WM, "Unable to transfer touch focus");
mService.mDragState.unregister();
mService.mDragState = null;
mService.mInputMonitor.updateInputWindowsLw(true);
return false;
}
mService.mDragState.mData = data;
mService.mDragState.broadcastDragStartedLw(touchX, touchY);
mService.mDragState.overridePointerIconLw(touchSource);
// remember the thumb offsets for later
mService.mDragState.mThumbOffsetX = thumbCenterX;
mService.mDragState.mThumbOffsetY = thumbCenterY;
// Make the surface visible at the proper location
final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, ">>> OPEN TRANSACTION performDrag");
SurfaceControl.openTransaction();
try {
surfaceControl.setPosition(touchX - thumbCenterX, touchY - thumbCenterY);
surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
surfaceControl.setLayerStack(display.getLayerStack());
surfaceControl.show();
} finally {
SurfaceControl.closeTransaction();
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
}
mService.mDragState.notifyLocationLw(touchX, touchY);
}
// success!
return true;
}
use of android.view.SurfaceControl in project android_frameworks_base by DirtyUnicorns.
the class Session method performDrag.
public boolean performDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
}
synchronized (mService.mWindowMap) {
if (mService.mDragState == null) {
Slog.w(TAG_WM, "No drag prepared");
throw new IllegalStateException("performDrag() without prepareDrag()");
}
if (dragToken != mService.mDragState.mToken) {
Slog.w(TAG_WM, "Performing mismatched drag");
throw new IllegalStateException("performDrag() does not match prepareDrag()");
}
WindowState callingWin = mService.windowForClientLocked(null, window, false);
if (callingWin == null) {
Slog.w(TAG_WM, "Bad requesting window " + window);
// !!! TODO: throw here?
return false;
}
// !!! TODO: if input is not still focused on the initiating window, fail
// the drag initiation (e.g. an alarm window popped up just as the application
// called performDrag()
mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
// !!! TODO: extract the current touch (x, y) in screen coordinates. That
// will let us eliminate the (touchX,touchY) parameters from the API.
// !!! FIXME: put all this heavy stuff onto the mH looper, as well as
// the actual drag event dispatch stuff in the dragstate
final DisplayContent displayContent = callingWin.getDisplayContent();
if (displayContent == null) {
return false;
}
Display display = displayContent.getDisplay();
mService.mDragState.register(display);
mService.mInputMonitor.updateInputWindowsLw(true);
if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, mService.mDragState.mServerChannel)) {
Slog.e(TAG_WM, "Unable to transfer touch focus");
mService.mDragState.unregister();
mService.mDragState = null;
mService.mInputMonitor.updateInputWindowsLw(true);
return false;
}
mService.mDragState.mData = data;
mService.mDragState.broadcastDragStartedLw(touchX, touchY);
mService.mDragState.overridePointerIconLw(touchSource);
// remember the thumb offsets for later
mService.mDragState.mThumbOffsetX = thumbCenterX;
mService.mDragState.mThumbOffsetY = thumbCenterY;
// Make the surface visible at the proper location
final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, ">>> OPEN TRANSACTION performDrag");
SurfaceControl.openTransaction();
try {
surfaceControl.setPosition(touchX - thumbCenterX, touchY - thumbCenterY);
surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
surfaceControl.setLayerStack(display.getLayerStack());
surfaceControl.show();
} finally {
SurfaceControl.closeTransaction();
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
}
mService.mDragState.notifyLocationLw(touchX, touchY);
}
// success!
return true;
}
use of android.view.SurfaceControl in project android_frameworks_base by DirtyUnicorns.
the class WindowManagerService method prepareDragSurface.
// -------------------------------------------------------------
// Drag and drop
// -------------------------------------------------------------
IBinder prepareDragSurface(IWindow window, SurfaceSession session, int flags, int width, int height, Surface outSurface) {
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "prepare drag surface: w=" + width + " h=" + height + " flags=" + Integer.toHexString(flags) + " win=" + window + " asbinder=" + window.asBinder());
}
final int callerPid = Binder.getCallingPid();
final int callerUid = Binder.getCallingUid();
final long origId = Binder.clearCallingIdentity();
IBinder token = null;
try {
synchronized (mWindowMap) {
try {
if (mDragState == null) {
// TODO(multi-display): support other displays
final DisplayContent displayContent = getDefaultDisplayContentLocked();
final Display display = displayContent.getDisplay();
SurfaceControl surface = new SurfaceControl(session, "drag surface", width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
surface.setLayerStack(display.getLayerStack());
float alpha = 1;
if ((flags & View.DRAG_FLAG_OPAQUE) == 0) {
alpha = DRAG_SHADOW_ALPHA_TRANSPARENT;
}
surface.setAlpha(alpha);
if (SHOW_TRANSACTIONS)
Slog.i(TAG_WM, " DRAG " + surface + ": CREATE");
outSurface.copyFrom(surface);
final IBinder winBinder = window.asBinder();
token = new Binder();
mDragState = new DragState(this, token, surface, flags, winBinder);
mDragState.mPid = callerPid;
mDragState.mUid = callerUid;
mDragState.mOriginalAlpha = alpha;
token = mDragState.mToken = new Binder();
// 5 second timeout for this window to actually begin the drag
mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
mH.sendMessageDelayed(msg, 5000);
} else {
Slog.w(TAG_WM, "Drag already in progress");
}
} catch (OutOfResourcesException e) {
Slog.e(TAG_WM, "Can't allocate drag surface w=" + width + " h=" + height, e);
if (mDragState != null) {
mDragState.reset();
mDragState = null;
}
}
}
} finally {
Binder.restoreCallingIdentity(origId);
}
return token;
}
use of android.view.SurfaceControl in project android_frameworks_base by ResurrectionRemix.
the class Session method performDrag.
public boolean performDrag(IWindow window, IBinder dragToken, int touchSource, float touchX, float touchY, float thumbCenterX, float thumbCenterY, ClipData data) {
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "perform drag: win=" + window + " data=" + data);
}
synchronized (mService.mWindowMap) {
if (mService.mDragState == null) {
Slog.w(TAG_WM, "No drag prepared");
throw new IllegalStateException("performDrag() without prepareDrag()");
}
if (dragToken != mService.mDragState.mToken) {
Slog.w(TAG_WM, "Performing mismatched drag");
throw new IllegalStateException("performDrag() does not match prepareDrag()");
}
WindowState callingWin = mService.windowForClientLocked(null, window, false);
if (callingWin == null) {
Slog.w(TAG_WM, "Bad requesting window " + window);
// !!! TODO: throw here?
return false;
}
// !!! TODO: if input is not still focused on the initiating window, fail
// the drag initiation (e.g. an alarm window popped up just as the application
// called performDrag()
mService.mH.removeMessages(H.DRAG_START_TIMEOUT, window.asBinder());
// !!! TODO: extract the current touch (x, y) in screen coordinates. That
// will let us eliminate the (touchX,touchY) parameters from the API.
// !!! FIXME: put all this heavy stuff onto the mH looper, as well as
// the actual drag event dispatch stuff in the dragstate
final DisplayContent displayContent = callingWin.getDisplayContent();
if (displayContent == null) {
return false;
}
Display display = displayContent.getDisplay();
mService.mDragState.register(display);
mService.mInputMonitor.updateInputWindowsLw(true);
if (!mService.mInputManager.transferTouchFocus(callingWin.mInputChannel, mService.mDragState.mServerChannel)) {
Slog.e(TAG_WM, "Unable to transfer touch focus");
mService.mDragState.unregister();
mService.mDragState = null;
mService.mInputMonitor.updateInputWindowsLw(true);
return false;
}
mService.mDragState.mData = data;
mService.mDragState.broadcastDragStartedLw(touchX, touchY);
mService.mDragState.overridePointerIconLw(touchSource);
// remember the thumb offsets for later
mService.mDragState.mThumbOffsetX = thumbCenterX;
mService.mDragState.mThumbOffsetY = thumbCenterY;
// Make the surface visible at the proper location
final SurfaceControl surfaceControl = mService.mDragState.mSurfaceControl;
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, ">>> OPEN TRANSACTION performDrag");
SurfaceControl.openTransaction();
try {
surfaceControl.setPosition(touchX - thumbCenterX, touchY - thumbCenterY);
surfaceControl.setLayer(mService.mDragState.getDragLayerLw());
surfaceControl.setLayerStack(display.getLayerStack());
surfaceControl.show();
} finally {
SurfaceControl.closeTransaction();
if (SHOW_LIGHT_TRANSACTIONS)
Slog.i(TAG_WM, "<<< CLOSE TRANSACTION performDrag");
}
mService.mDragState.notifyLocationLw(touchX, touchY);
}
// success!
return true;
}
use of android.view.SurfaceControl in project android_frameworks_base by ResurrectionRemix.
the class WindowManagerService method prepareDragSurface.
// -------------------------------------------------------------
// Drag and drop
// -------------------------------------------------------------
IBinder prepareDragSurface(IWindow window, SurfaceSession session, int flags, int width, int height, Surface outSurface) {
if (DEBUG_DRAG) {
Slog.d(TAG_WM, "prepare drag surface: w=" + width + " h=" + height + " flags=" + Integer.toHexString(flags) + " win=" + window + " asbinder=" + window.asBinder());
}
final int callerPid = Binder.getCallingPid();
final int callerUid = Binder.getCallingUid();
final long origId = Binder.clearCallingIdentity();
IBinder token = null;
try {
synchronized (mWindowMap) {
try {
if (mDragState == null) {
// TODO(multi-display): support other displays
final DisplayContent displayContent = getDefaultDisplayContentLocked();
final Display display = displayContent.getDisplay();
SurfaceControl surface = new SurfaceControl(session, "drag surface", width, height, PixelFormat.TRANSLUCENT, SurfaceControl.HIDDEN);
surface.setLayerStack(display.getLayerStack());
float alpha = 1;
if ((flags & View.DRAG_FLAG_OPAQUE) == 0) {
alpha = DRAG_SHADOW_ALPHA_TRANSPARENT;
}
surface.setAlpha(alpha);
if (SHOW_TRANSACTIONS)
Slog.i(TAG_WM, " DRAG " + surface + ": CREATE");
outSurface.copyFrom(surface);
final IBinder winBinder = window.asBinder();
token = new Binder();
mDragState = new DragState(this, token, surface, flags, winBinder);
mDragState.mPid = callerPid;
mDragState.mUid = callerUid;
mDragState.mOriginalAlpha = alpha;
token = mDragState.mToken = new Binder();
// 5 second timeout for this window to actually begin the drag
mH.removeMessages(H.DRAG_START_TIMEOUT, winBinder);
Message msg = mH.obtainMessage(H.DRAG_START_TIMEOUT, winBinder);
mH.sendMessageDelayed(msg, 5000);
} else {
Slog.w(TAG_WM, "Drag already in progress");
}
} catch (OutOfResourcesException e) {
Slog.e(TAG_WM, "Can't allocate drag surface w=" + width + " h=" + height, e);
if (mDragState != null) {
mDragState.reset();
mDragState = null;
}
}
}
} finally {
Binder.restoreCallingIdentity(origId);
}
return token;
}
Aggregations