Loading core/java/android/view/SurfaceControl.java +16 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,8 @@ public class SurfaceControl { private static native void nativeScreenshot(IBinder displayToken, Surface consumer, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform); private static native void nativeCaptureLayers(IBinder layerHandleToken, Surface consumer, int rotation); private static native long nativeCreateTransaction(); private static native long nativeGetNativeTransactionFinalizer(); Loading Loading @@ -1150,6 +1152,20 @@ public class SurfaceControl { minLayer, maxLayer, allLayers, useIdentityTransform); } /** * Captures a layer and its children into the provided {@link Surface}. * * @param layerHandleToken The root layer to capture. * @param consumer The {@link Surface} to capture the layer into. * @param rotation Apply a custom clockwise rotation to the screenshot, i.e. * Surface.ROTATION_0,90,180,270. Surfaceflinger will always capture in its * native portrait orientation by default, so this is useful for returning * captures that are independent of device orientation. */ public static void captureLayers(IBinder layerHandleToken, Surface consumer, int rotation) { nativeCaptureLayers(layerHandleToken, consumer, rotation); } public static class Transaction implements Closeable { public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( Transaction.class.getClassLoader(), Loading core/jni/android_view_SurfaceControl.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,22 @@ static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj, } } static void nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken, jobject surfaceObj, int rotation) { sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); if (layerHandle == NULL) { return; } sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); if (consumer == NULL) { return; } ScreenshotClient::captureLayers(layerHandle, consumer->getIGraphicBufferProducer(), rotation); } static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) { auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); transaction->apply(sync); Loading Loading @@ -949,6 +965,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeScreenshotToBuffer", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", (void*)nativeScreenshotToBuffer }, {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/view/Surface;I)V", (void*)nativeCaptureLayers }, }; int register_android_view_SurfaceControl(JNIEnv* env) Loading Loading
core/java/android/view/SurfaceControl.java +16 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,8 @@ public class SurfaceControl { private static native void nativeScreenshot(IBinder displayToken, Surface consumer, Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean allLayers, boolean useIdentityTransform); private static native void nativeCaptureLayers(IBinder layerHandleToken, Surface consumer, int rotation); private static native long nativeCreateTransaction(); private static native long nativeGetNativeTransactionFinalizer(); Loading Loading @@ -1150,6 +1152,20 @@ public class SurfaceControl { minLayer, maxLayer, allLayers, useIdentityTransform); } /** * Captures a layer and its children into the provided {@link Surface}. * * @param layerHandleToken The root layer to capture. * @param consumer The {@link Surface} to capture the layer into. * @param rotation Apply a custom clockwise rotation to the screenshot, i.e. * Surface.ROTATION_0,90,180,270. Surfaceflinger will always capture in its * native portrait orientation by default, so this is useful for returning * captures that are independent of device orientation. */ public static void captureLayers(IBinder layerHandleToken, Surface consumer, int rotation) { nativeCaptureLayers(layerHandleToken, consumer, rotation); } public static class Transaction implements Closeable { public static final NativeAllocationRegistry sRegistry = new NativeAllocationRegistry( Transaction.class.getClassLoader(), Loading
core/jni/android_view_SurfaceControl.cpp +18 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,22 @@ static void nativeScreenshot(JNIEnv* env, jclass clazz, jobject displayTokenObj, } } static void nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken, jobject surfaceObj, int rotation) { sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); if (layerHandle == NULL) { return; } sp<Surface> consumer = android_view_Surface_getSurface(env, surfaceObj); if (consumer == NULL) { return; } ScreenshotClient::captureLayers(layerHandle, consumer->getIGraphicBufferProducer(), rotation); } static void nativeApplyTransaction(JNIEnv* env, jclass clazz, jlong transactionObj, jboolean sync) { auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj); transaction->apply(sync); Loading Loading @@ -949,6 +965,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = { {"nativeScreenshotToBuffer", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/GraphicBuffer;", (void*)nativeScreenshotToBuffer }, {"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/view/Surface;I)V", (void*)nativeCaptureLayers }, }; int register_android_view_SurfaceControl(JNIEnv* env) Loading