Loading core/java/android/view/Surface.java +23 −0 Original line number Diff line number Diff line Loading @@ -39,8 +39,10 @@ import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import android.view.flags.Flags; import dalvik.system.CloseGuard; import dalvik.system.VMRuntime; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading Loading @@ -101,6 +103,10 @@ public class Surface implements Parcelable { long nativeObject, float frameRate, int compatibility, int changeFrameRateStrategy); private static native void nativeDestroy(long nativeObject); // 5MB is a wild guess for what the average surface should be. On most new phones, a full-screen // surface is about 9MB... but not all surfaces are screen size. This should be a nice balance. private static final long SURFACE_NATIVE_ALLOCATION_SIZE_BYTES = 5_000_000; public static final @android.annotation.NonNull Parcelable.Creator<Surface> CREATOR = new Parcelable.Creator<Surface>() { @Override Loading Loading @@ -331,6 +337,7 @@ public class Surface implements Parcelable { */ @UnsupportedAppUsage public Surface() { registerNativeMemoryUsage(); } /** Loading @@ -343,6 +350,7 @@ public class Surface implements Parcelable { */ public Surface(@NonNull SurfaceControl from) { copyFrom(from); registerNativeMemoryUsage(); } /** Loading Loading @@ -370,6 +378,7 @@ public class Surface implements Parcelable { mName = surfaceTexture.toString(); setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture)); } registerNativeMemoryUsage(); } /* called from android_view_Surface_createFromIGraphicBufferProducer() */ Loading @@ -378,6 +387,7 @@ public class Surface implements Parcelable { synchronized (mLock) { setNativeObjectLocked(nativeObject); } registerNativeMemoryUsage(); } @Override Loading @@ -389,6 +399,7 @@ public class Surface implements Parcelable { release(); } finally { super.finalize(); freeNativeMemoryUsage(); } } Loading Loading @@ -1243,4 +1254,16 @@ public class Surface implements Parcelable { return mIsWideColorGamut; } } private static void registerNativeMemoryUsage() { if (Flags.enableSurfaceNativeAllocRegistration()) { VMRuntime.getRuntime().registerNativeAllocation(SURFACE_NATIVE_ALLOCATION_SIZE_BYTES); } } private static void freeNativeMemoryUsage() { if (Flags.enableSurfaceNativeAllocRegistration()) { VMRuntime.getRuntime().registerNativeFree(SURFACE_NATIVE_ALLOCATION_SIZE_BYTES); } } } Loading
core/java/android/view/Surface.java +23 −0 Original line number Diff line number Diff line Loading @@ -39,8 +39,10 @@ import android.os.Build; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; import android.view.flags.Flags; import dalvik.system.CloseGuard; import dalvik.system.VMRuntime; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; Loading Loading @@ -101,6 +103,10 @@ public class Surface implements Parcelable { long nativeObject, float frameRate, int compatibility, int changeFrameRateStrategy); private static native void nativeDestroy(long nativeObject); // 5MB is a wild guess for what the average surface should be. On most new phones, a full-screen // surface is about 9MB... but not all surfaces are screen size. This should be a nice balance. private static final long SURFACE_NATIVE_ALLOCATION_SIZE_BYTES = 5_000_000; public static final @android.annotation.NonNull Parcelable.Creator<Surface> CREATOR = new Parcelable.Creator<Surface>() { @Override Loading Loading @@ -331,6 +337,7 @@ public class Surface implements Parcelable { */ @UnsupportedAppUsage public Surface() { registerNativeMemoryUsage(); } /** Loading @@ -343,6 +350,7 @@ public class Surface implements Parcelable { */ public Surface(@NonNull SurfaceControl from) { copyFrom(from); registerNativeMemoryUsage(); } /** Loading Loading @@ -370,6 +378,7 @@ public class Surface implements Parcelable { mName = surfaceTexture.toString(); setNativeObjectLocked(nativeCreateFromSurfaceTexture(surfaceTexture)); } registerNativeMemoryUsage(); } /* called from android_view_Surface_createFromIGraphicBufferProducer() */ Loading @@ -378,6 +387,7 @@ public class Surface implements Parcelable { synchronized (mLock) { setNativeObjectLocked(nativeObject); } registerNativeMemoryUsage(); } @Override Loading @@ -389,6 +399,7 @@ public class Surface implements Parcelable { release(); } finally { super.finalize(); freeNativeMemoryUsage(); } } Loading Loading @@ -1243,4 +1254,16 @@ public class Surface implements Parcelable { return mIsWideColorGamut; } } private static void registerNativeMemoryUsage() { if (Flags.enableSurfaceNativeAllocRegistration()) { VMRuntime.getRuntime().registerNativeAllocation(SURFACE_NATIVE_ALLOCATION_SIZE_BYTES); } } private static void freeNativeMemoryUsage() { if (Flags.enableSurfaceNativeAllocRegistration()) { VMRuntime.getRuntime().registerNativeFree(SURFACE_NATIVE_ALLOCATION_SIZE_BYTES); } } }