use of android.graphics.Rect in project android_frameworks_base by ParanoidAndroid.
the class DisplayMagnifier method onRectangleOnScreenRequestedLocked.
public void onRectangleOnScreenRequestedLocked(Rect rectangle, boolean immediate) {
if (DEBUG_RECTANGLE_REQUESTED) {
Slog.i(LOG_TAG, "Rectangle on screen requested: " + rectangle);
}
if (!mMagnifedViewport.isMagnifyingLocked()) {
return;
}
Rect magnifiedRegionBounds = mTempRect2;
mMagnifedViewport.getMagnifiedFrameInContentCoordsLocked(magnifiedRegionBounds);
if (magnifiedRegionBounds.contains(rectangle)) {
return;
}
SomeArgs args = SomeArgs.obtain();
args.argi1 = rectangle.left;
args.argi2 = rectangle.top;
args.argi3 = rectangle.right;
args.argi4 = rectangle.bottom;
mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_RECTANGLE_ON_SCREEN_REQUESTED, args).sendToTarget();
}
use of android.graphics.Rect in project android_frameworks_base by ParanoidAndroid.
the class InputMonitor method addInputWindowHandleLw.
private void addInputWindowHandleLw(final InputWindowHandle inputWindowHandle, final WindowState child, final int flags, final int type, final boolean isVisible, final boolean hasFocus, final boolean hasWallpaper) {
// Add a window to our list of input windows.
inputWindowHandle.name = child.toString();
inputWindowHandle.layoutParamsFlags = flags;
inputWindowHandle.layoutParamsType = type;
inputWindowHandle.dispatchingTimeoutNanos = child.getInputDispatchingTimeoutNanos();
inputWindowHandle.visible = isVisible;
inputWindowHandle.canReceiveKeys = child.canReceiveKeys();
inputWindowHandle.hasFocus = hasFocus;
inputWindowHandle.hasWallpaper = hasWallpaper;
inputWindowHandle.paused = child.mAppToken != null ? child.mAppToken.paused : false;
inputWindowHandle.layer = child.mLayer;
inputWindowHandle.ownerPid = child.mSession.mPid;
inputWindowHandle.ownerUid = child.mSession.mUid;
inputWindowHandle.inputFeatures = child.mAttrs.inputFeatures;
final Rect frame = child.mFrame;
inputWindowHandle.frameLeft = frame.left;
inputWindowHandle.frameTop = frame.top;
inputWindowHandle.frameRight = frame.right;
inputWindowHandle.frameBottom = frame.bottom;
if (child.mGlobalScale != 1) {
// If we are scaling the window, input coordinates need
// to be inversely scaled to map from what is on screen
// to what is actually being touched in the UI.
inputWindowHandle.scaleFactor = 1.0f / child.mGlobalScale;
} else {
inputWindowHandle.scaleFactor = 1;
}
child.getTouchableRegion(inputWindowHandle.touchableRegion);
addInputWindowHandleLw(inputWindowHandle);
}
use of android.graphics.Rect in project android_frameworks_base by ParanoidAndroid.
the class StrictModeFlash method drawIfNeeded.
private void drawIfNeeded() {
if (!mDrawNeeded) {
return;
}
mDrawNeeded = false;
final int dw = mLastDW;
final int dh = mLastDH;
Rect dirty = new Rect(0, 0, dw, dh);
Canvas c = null;
try {
c = mSurface.lockCanvas(dirty);
} catch (IllegalArgumentException e) {
} catch (Surface.OutOfResourcesException e) {
}
if (c == null) {
return;
}
// Top
c.clipRect(new Rect(0, 0, dw, mThickness), Region.Op.REPLACE);
c.drawColor(Color.RED);
// Left
c.clipRect(new Rect(0, 0, mThickness, dh), Region.Op.REPLACE);
c.drawColor(Color.RED);
// Right
c.clipRect(new Rect(dw - mThickness, 0, dw, dh), Region.Op.REPLACE);
c.drawColor(Color.RED);
// Bottom
c.clipRect(new Rect(0, dh - mThickness, dw, dh), Region.Op.REPLACE);
c.drawColor(Color.RED);
mSurface.unlockCanvasAndPost(c);
}
use of android.graphics.Rect in project android_frameworks_base by ParanoidAndroid.
the class Watermark method drawIfNeeded.
void drawIfNeeded() {
if (mDrawNeeded) {
final int dw = mLastDW;
final int dh = mLastDH;
mDrawNeeded = false;
Rect dirty = new Rect(0, 0, dw, dh);
Canvas c = null;
try {
c = mSurface.lockCanvas(dirty);
} catch (IllegalArgumentException e) {
} catch (OutOfResourcesException e) {
}
if (c != null) {
c.drawColor(0, PorterDuff.Mode.CLEAR);
int deltaX = mDeltaX;
int deltaY = mDeltaY;
// deltaX shouldn't be close to a round fraction of our
// x step, or else things will line up too much.
int div = (dw + mTextWidth) / deltaX;
int rem = (dw + mTextWidth) - (div * deltaX);
int qdelta = deltaX / 4;
if (rem < qdelta || rem > (deltaX - qdelta)) {
deltaX += deltaX / 3;
}
int y = -mTextHeight;
int x = -mTextWidth;
while (y < (dh + mTextHeight)) {
c.drawText(mText, x, y, mTextPaint);
x += deltaX;
if (x >= dw) {
x -= (dw + mTextWidth);
y += deltaY;
}
}
mSurface.unlockCanvasAndPost(c);
}
}
}
use of android.graphics.Rect in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method screenshotApplications.
/**
* Takes a snapshot of the screen. In landscape mode this grabs the whole screen.
* In portrait mode, it grabs the upper region of the screen based on the vertical dimension
* of the target image.
*
* @param displayId the Display to take a screenshot of.
* @param width the width of the target bitmap
* @param height the height of the target bitmap
*/
@Override
public Bitmap screenshotApplications(IBinder appToken, int displayId, int width, int height) {
if (!checkCallingPermission(android.Manifest.permission.READ_FRAME_BUFFER, "screenshotApplications()")) {
throw new SecurityException("Requires READ_FRAME_BUFFER permission");
}
Bitmap rawss = null;
int maxLayer = 0;
final Rect frame = new Rect();
float scale = 0;
int dw, dh;
int rot = Surface.ROTATION_0;
boolean screenshotReady;
int minLayer;
if (appToken == null) {
screenshotReady = true;
minLayer = 0;
} else {
screenshotReady = false;
minLayer = Integer.MAX_VALUE;
}
int retryCount = 0;
WindowState appWin = null;
do {
if (retryCount++ > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
synchronized (mWindowMap) {
final DisplayContent displayContent = getDisplayContentLocked(displayId);
if (displayContent == null) {
return null;
}
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
dw = displayInfo.logicalWidth;
dh = displayInfo.logicalHeight;
int aboveAppLayer = mPolicy.windowTypeToLayerLw(TYPE_APPLICATION) * TYPE_LAYER_MULTIPLIER + TYPE_LAYER_OFFSET;
aboveAppLayer += TYPE_LAYER_MULTIPLIER;
boolean isImeTarget = mInputMethodTarget != null && mInputMethodTarget.mAppToken != null && mInputMethodTarget.mAppToken.appToken != null && mInputMethodTarget.mAppToken.appToken.asBinder() == appToken;
// Figure out the part of the screen that is actually the app.
boolean including = false;
appWin = null;
final WindowList windows = displayContent.getWindowList();
for (int i = windows.size() - 1; i >= 0; i--) {
WindowState ws = windows.get(i);
if (!ws.mHasSurface) {
continue;
}
if (ws.mLayer >= aboveAppLayer) {
continue;
}
// taking a screenshot of a specific app.
if (!including && appToken != null) {
// is not the current IME target.
if (!ws.mIsImWindow || !isImeTarget) {
// is not associated with the screenshot app.
if (ws.mAppToken == null || ws.mAppToken.token != appToken) {
continue;
}
appWin = ws;
}
}
// We keep on including windows until we go past a full-screen
// window.
boolean fullscreen = ws.isFullscreen(dw, dh);
including = !ws.mIsImWindow && !fullscreen;
final WindowStateAnimator winAnim = ws.mWinAnimator;
if (maxLayer < winAnim.mSurfaceLayer) {
maxLayer = winAnim.mSurfaceLayer;
}
if (minLayer > winAnim.mSurfaceLayer) {
minLayer = winAnim.mSurfaceLayer;
}
// Don't include wallpaper in bounds calculation
if (!ws.mIsWallpaper) {
final Rect wf = ws.mFrame;
final Rect cr = ws.mContentInsets;
int left = wf.left + cr.left;
int top = wf.top + cr.top;
int right = wf.right - cr.right;
int bottom = wf.bottom - cr.bottom;
frame.union(left, top, right, bottom);
}
if (ws.mAppToken != null && ws.mAppToken.token == appToken && ws.isDisplayedLw()) {
screenshotReady = true;
}
if (fullscreen) {
// No point in continuing down through windows.
break;
}
}
if (appToken != null && appWin == null) {
// Can't find a window to snapshot.
if (DEBUG_SCREENSHOT)
Slog.i(TAG, "Screenshot: Couldn't find a surface matching " + appToken);
return null;
}
if (!screenshotReady) {
// Delay and hope that window gets drawn.
if (DEBUG_SCREENSHOT)
Slog.i(TAG, "Screenshot: No image ready for " + appToken + ", " + appWin + " drawState=" + appWin.mWinAnimator.mDrawState);
continue;
}
// Constrain frame to the screen size.
frame.intersect(0, 0, dw, dh);
if (frame.isEmpty() || maxLayer == 0) {
if (DEBUG_SCREENSHOT)
Slog.i(TAG, "Screenshot of " + appToken + ": returning null frame=" + frame.toShortString() + " maxLayer=" + maxLayer);
return null;
}
// The screenshot API does not apply the current screen rotation.
rot = getDefaultDisplayContentLocked().getDisplay().getRotation();
int fw = frame.width();
int fh = frame.height();
// Constrain thumbnail to smaller of screen width or height. Assumes aspect
// of thumbnail is the same as the screen (in landscape) or square.
float targetWidthScale = width / (float) fw;
float targetHeightScale = height / (float) fh;
if (dw <= dh) {
scale = targetWidthScale;
// select the slightly larger value so we fill the entire bitmap
if (targetHeightScale > scale && (int) (targetHeightScale * fw) == width) {
scale = targetHeightScale;
}
} else {
scale = targetHeightScale;
// select the slightly larger value so we fill the entire bitmap
if (targetWidthScale > scale && (int) (targetWidthScale * fh) == height) {
scale = targetWidthScale;
}
}
// The screen shot will contain the entire screen.
dw = (int) (dw * scale);
dh = (int) (dh * scale);
if (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270) {
int tmp = dw;
dw = dh;
dh = tmp;
rot = (rot == Surface.ROTATION_90) ? Surface.ROTATION_270 : Surface.ROTATION_90;
}
if (DEBUG_SCREENSHOT) {
Slog.i(TAG, "Screenshot: " + dw + "x" + dh + " from " + minLayer + " to " + maxLayer + " appToken=" + appToken);
for (int i = 0; i < windows.size(); i++) {
WindowState win = windows.get(i);
Slog.i(TAG, win + ": " + win.mLayer + " animLayer=" + win.mWinAnimator.mAnimLayer + " surfaceLayer=" + win.mWinAnimator.mSurfaceLayer);
}
}
rawss = SurfaceControl.screenshot(dw, dh, minLayer, maxLayer);
}
} while (!screenshotReady && retryCount <= MAX_SCREENSHOT_RETRIES);
if (retryCount > MAX_SCREENSHOT_RETRIES)
Slog.i(TAG, "Screenshot max retries " + retryCount + " of " + appToken + " appWin=" + (appWin == null ? "null" : (appWin + " drawState=" + appWin.mWinAnimator.mDrawState)));
if (rawss == null) {
Slog.w(TAG, "Screenshot failure taking screenshot for (" + dw + "x" + dh + ") to layer " + maxLayer);
return null;
}
Bitmap bm = Bitmap.createBitmap(width, height, rawss.getConfig());
Matrix matrix = new Matrix();
ScreenRotationAnimation.createRotationMatrix(rot, dw, dh, matrix);
matrix.postTranslate(-FloatMath.ceil(frame.left * scale), -FloatMath.ceil(frame.top * scale));
Canvas canvas = new Canvas(bm);
canvas.drawColor(0xFF000000);
canvas.drawBitmap(rawss, matrix, null);
canvas.setBitmap(null);
if (true || DEBUG_SCREENSHOT) {
// TEST IF IT's ALL BLACK
int[] buffer = new int[bm.getWidth() * bm.getHeight()];
bm.getPixels(buffer, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight());
boolean allBlack = true;
for (int i = 0; i < buffer.length; i++) {
if (buffer[i] != Color.BLACK) {
allBlack = false;
break;
}
}
if (allBlack) {
Slog.i(TAG, "Screenshot " + appWin + " was all black! mSurfaceLayer=" + (appWin != null ? appWin.mWinAnimator.mSurfaceLayer : "null") + " minLayer=" + minLayer + " maxLayer=" + maxLayer);
}
}
rawss.recycle();
return bm;
}
Aggregations