Merge "Take app screenshots in 565." into nyc-dev

This commit is contained in:
Winson Chung
2016-04-15 00:56:18 +00:00
committed by Android (Google) Code Review
4 changed files with 46 additions and 12 deletions

View File

@@ -752,17 +752,32 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
getPremulBitmapCreateFlags(isMutable));
}
static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
static Bitmap* Bitmap_copyAshmemImpl(JNIEnv* env, SkBitmap& src, SkColorType& dstCT) {
SkBitmap result;
AshmemPixelAllocator allocator(env);
if (!src.copyTo(&result, &allocator)) {
if (!src.copyTo(&result, dstCT, &allocator)) {
return NULL;
}
Bitmap* bitmap = allocator.getStorageObjAndReset();
bitmap->peekAtPixelRef()->setImmutable();
return bitmap;
}
static jobject Bitmap_copyAshmem(JNIEnv* env, jobject, jlong srcHandle) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
SkColorType dstCT = src.colorType();
Bitmap* bitmap = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = GraphicsJNI::createBitmap(env, bitmap, getPremulBitmapCreateFlags(false));
return ret;
}
static jobject Bitmap_copyAshmemConfig(JNIEnv* env, jobject, jlong srcHandle, jint dstConfigHandle) {
SkBitmap src;
reinterpret_cast<Bitmap*>(srcHandle)->getSkBitmap(&src);
SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
Bitmap* bitmap = Bitmap_copyAshmemImpl(env, src, dstCT);
jobject ret = GraphicsJNI::createBitmap(env, bitmap, getPremulBitmapCreateFlags(false));
return ret;
}
@@ -1355,6 +1370,8 @@ static const JNINativeMethod gBitmapMethods[] = {
(void*)Bitmap_copy },
{ "nativeCopyAshmem", "(J)Landroid/graphics/Bitmap;",
(void*)Bitmap_copyAshmem },
{ "nativeCopyAshmemConfig", "(JI)Landroid/graphics/Bitmap;",
(void*)Bitmap_copyAshmemConfig },
{ "nativeGetNativeFinalizer", "()J", (void*)Bitmap_getNativeFinalizer },
{ "nativeRecycle", "(J)Z", (void*)Bitmap_recycle },
{ "nativeReconfigure", "(JIIIIZ)V", (void*)Bitmap_reconfigure },

View File

@@ -25,14 +25,14 @@ import android.os.Trace;
import android.util.DisplayMetrics;
import android.util.Log;
import libcore.util.NativeAllocationRegistry;
import java.io.OutputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import libcore.util.NativeAllocationRegistry;
public final class Bitmap implements Parcelable {
private static final String TAG = "Bitmap";
@@ -613,6 +613,22 @@ public final class Bitmap implements Parcelable {
return b;
}
/**
* Creates a new immutable bitmap backed by ashmem which can efficiently
* be passed between processes.
*
* @hide
*/
public Bitmap createAshmemBitmap(Config config) {
checkRecycled("Can't copy a recycled bitmap");
Bitmap b = nativeCopyAshmemConfig(mNativePtr, config.nativeInt);
if (b != null) {
b.setPremultiplied(mRequestPremultiplied);
b.mDensity = mDensity;
}
return b;
}
/**
* Creates a new bitmap, scaled from an existing bitmap, when possible. If the
* specified width and height are the same as the current width and height of
@@ -1675,6 +1691,7 @@ public final class Bitmap implements Parcelable {
private static native Bitmap nativeCopy(long nativeSrcBitmap, int nativeConfig,
boolean isMutable);
private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap);
private static native Bitmap nativeCopyAshmemConfig(long nativeSrcBitmap, int nativeConfig);
private static native long nativeGetNativeFinalizer();
private static native boolean nativeRecycle(long nativeBitmap);
private static native void nativeReconfigure(long nativeBitmap, int width, int height,

View File

@@ -99,6 +99,7 @@ public class SystemServicesProxy {
static {
sBitmapOptions = new BitmapFactory.Options();
sBitmapOptions.inMutable = true;
sBitmapOptions.inPreferredConfig = Bitmap.Config.RGB_565;
}
final static List<String> sRecentsBlacklist;

View File

@@ -6005,7 +6005,7 @@ public class WindowManagerService extends IWindowManager.Stub
@Override
public void run() {
Bitmap bm = screenshotApplicationsInner(null, Display.DEFAULT_DISPLAY, -1, -1,
true, 1f);
true, 1f, Bitmap.Config.ARGB_8888);
try {
receiver.send(bm);
} catch (RemoteException e) {
@@ -6018,8 +6018,7 @@ public class WindowManagerService extends IWindowManager.Stub
/**
* 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.
* In portrait mode, it grabs the full screenshot.
*
* @param displayId the Display to take a screenshot of.
* @param width the width of the target bitmap
@@ -6036,14 +6035,14 @@ public class WindowManagerService extends IWindowManager.Stub
try {
Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "screenshotApplications");
return screenshotApplicationsInner(appToken, displayId, width, height, false,
frameScale);
frameScale, Bitmap.Config.RGB_565);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
}
}
Bitmap screenshotApplicationsInner(IBinder appToken, int displayId, int width, int height,
boolean includeFullDisplay, float frameScale) {
boolean includeFullDisplay, float frameScale, Bitmap.Config config) {
final DisplayContent displayContent;
synchronized(mWindowMap) {
displayContent = getDisplayContentLocked(displayId);
@@ -6282,7 +6281,7 @@ public class WindowManagerService extends IWindowManager.Stub
// Create a copy of the screenshot that is immutable and backed in ashmem.
// This greatly reduces the overhead of passing the bitmap between processes.
Bitmap ret = bm.createAshmemBitmap();
Bitmap ret = bm.createAshmemBitmap(config);
bm.recycle();
return ret;
}