Chromium Code Reviews| Index: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
| diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
| index 98169703d0080c961925d9db59dce9183f6a8be7..02cdf8d7eebdd1ea31c9c15e03efca467bef530e 100644 |
| --- a/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
| +++ b/remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java |
| @@ -110,6 +110,9 @@ public class JniInterface { |
| sProgressIndicator.dismiss(); |
| sProgressIndicator = null; |
| } |
| + |
| + // Drop the reference to free the Bitmap for GC. |
| + sFrameBitmap = null; |
| } |
| disconnectNative(); |
| @@ -136,17 +139,8 @@ public class JniInterface { |
| /** Callback to signal whenever we need to redraw. */ |
| private static Runnable sRedrawCallback = null; |
| - /** Screen width of the video feed. */ |
| - private static int sWidth = 0; |
| - |
| - /** Screen height of the video feed. */ |
| - private static int sHeight = 0; |
| - |
| - /** Bitmap holding the latest screen image. */ |
| - private static Bitmap sBitmap = null; |
| - |
| - /** Buffer holding the video feed. */ |
| - private static ByteBuffer sBuffer = null; |
| + /** Bitmap holding a copy of the latest video frame. */ |
| + private static Bitmap sFrameBitmap = null; |
| /** Position of cursor hot-spot. */ |
| private static Point sCursorHotspot = new Point(); |
| @@ -301,10 +295,10 @@ public class JniInterface { |
| } |
| /** |
| - * Obtains the image buffer. |
| - * This should not be called from the UI thread. (We prefer the native graphics thread.) |
| + * Returns a bitmap of the latest video frame. Called on the native graphics thread when |
| + * DesktopView is repainted. |
| */ |
| - public static Bitmap retrieveVideoFrame() { |
| + public static Bitmap getVideoFrame() { |
| if (Looper.myLooper() == Looper.getMainLooper()) { |
| Log.w("jniiface", "Canvas being redrawn on UI thread"); |
| } |
| @@ -313,19 +307,29 @@ public class JniInterface { |
| return null; |
| } |
| - // This is synchronized only to silence a findbugs warning about incorrect initialization of |
| - // |sBitmap|. |
| - // TODO(lambroslambrou): Annotate this class as @NotThreadSafe to prevent similar warnings |
| - // in future. |
| + return sFrameBitmap; |
| + } |
| + |
| + /** |
| + * Sets a new video frame. Called from native code on the native graphics thread when a new |
| + * frame is allocated. |
| + */ |
| + private static void setVideoFrame(Bitmap bitmap) { |
| + if (Looper.myLooper() == Looper.getMainLooper()) { |
| + Log.w("jniiface", "Video frame updated on UI thread"); |
| + } |
| + |
| synchronized (JniInterface.class) { |
|
Yaron
2013/10/09 06:42:30
I believe this will trigger a findbugs error. We d
Lambros
2013/10/10 01:35:58
There are already lots of these in this file. I've
|
| - if (sBitmap == null || sBitmap.getWidth() != sWidth || sBitmap.getHeight() != sHeight) { |
| - sBitmap = Bitmap.createBitmap(sWidth, sHeight, Bitmap.Config.ARGB_8888); |
| - } |
| + sFrameBitmap = bitmap; |
| } |
| + } |
| - sBuffer.rewind(); |
| - sBitmap.copyPixelsFromBuffer(sBuffer); |
| - return sBitmap; |
| + /** |
| + * Creates a new Bitmap to hold video frame pixels. Called by native code which stores a global |
| + * reference to the Bitmap and writes the decoded frame pixels to it. |
| + */ |
| + private static Bitmap newBitmap(int width, int height) { |
| + return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); |
| } |
| /** |