Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java

Issue 24072012: Hold video frame in Bitmap instead of keeping a ByteBuffer reference. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting.jni; 5 package org.chromium.chromoting.jni;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.app.ProgressDialog; 9 import android.app.ProgressDialog;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 /** Returns the current cursor shape. */ 130 /** Returns the current cursor shape. */
131 public static Bitmap getCursorBitmap() { return sCursorBitmap; } 131 public static Bitmap getCursorBitmap() { return sCursorBitmap; }
132 132
133 /* 133 /*
134 * Entry points *from* the native code. 134 * Entry points *from* the native code.
135 */ 135 */
136 /** Callback to signal whenever we need to redraw. */ 136 /** Callback to signal whenever we need to redraw. */
137 private static Runnable sRedrawCallback = null; 137 private static Runnable sRedrawCallback = null;
138 138
139 /** Screen width of the video feed. */ 139 /** Bitmap holding a copy of the latest video frame. */
140 private static int sWidth = 0; 140 private static Bitmap sFrameBitmap = null;
141
142 /** Screen height of the video feed. */
143 private static int sHeight = 0;
144
145 /** Buffer holding the video feed. */
146 private static ByteBuffer sBuffer = null;
147 141
148 /** Position of cursor hot-spot. */ 142 /** Position of cursor hot-spot. */
149 private static Point sCursorHotspot = new Point(); 143 private static Point sCursorHotspot = new Point();
150 144
151 /** Bitmap holding the cursor shape. */ 145 /** Bitmap holding the cursor shape. */
152 private static Bitmap sCursorBitmap = null; 146 private static Bitmap sCursorBitmap = null;
153 147
154 /** Reports whenever the connection status changes. */ 148 /** Reports whenever the connection status changes. */
155 private static void reportConnectionStatus(int state, int error) { 149 private static void reportConnectionStatus(int state, int error) {
156 if (state < SUCCESSFUL_CONNECTION && error == 0) { 150 if (state < SUCCESSFUL_CONNECTION && error == 0) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 return true; 285 return true;
292 } 286 }
293 287
294 /** Performs the redrawing callback. This is a no-op if the window isn't vis ible. */ 288 /** Performs the redrawing callback. This is a no-op if the window isn't vis ible. */
295 private static void redrawGraphicsInternal() { 289 private static void redrawGraphicsInternal() {
296 if (sRedrawCallback != null) 290 if (sRedrawCallback != null)
297 sRedrawCallback.run(); 291 sRedrawCallback.run();
298 } 292 }
299 293
300 /** 294 /**
301 * Obtains the image buffer. 295 * Returns a bitmap of the latest video frame. Called on the native graphics thread when
302 * This should not be called from the UI thread. (We prefer the native graph ics thread.) 296 * DesktopView is repainted.
303 */ 297 */
304 public static Bitmap retrieveVideoFrame() { 298 public static Bitmap getVideoFrame() {
305 if (Looper.myLooper() == Looper.getMainLooper()) { 299 if (Looper.myLooper() == Looper.getMainLooper()) {
306 Log.w("jniiface", "Canvas being redrawn on UI thread"); 300 Log.w("jniiface", "Canvas being redrawn on UI thread");
307 } 301 }
308 302
309 if (!sConnected) { 303 if (!sConnected) {
310 return null; 304 return null;
311 } 305 }
312 306
313 int[] frame = new int[sWidth * sHeight]; 307 return sFrameBitmap;
314
315 sBuffer.order(ByteOrder.LITTLE_ENDIAN);
316 sBuffer.asIntBuffer().get(frame, 0, frame.length);
317
318 return Bitmap.createBitmap(frame, 0, sWidth, sWidth, sHeight, Bitmap.Con fig.ARGB_8888);
319 } 308 }
320 309
321 /** 310 /**
311 * Sets a new video frame. Called from native code on the native graphics th read whenever a new
312 * frame has been decoded.
313 */
314 private static void setVideoFrame(int width, int height, ByteBuffer buffer) {
315 int[] frame = new int[width * height];
garykac 2013/09/23 19:47:43 Can you add a check here to ensure that this is be
Lambros 2013/09/25 23:15:11 Done.
316
317 buffer.order(ByteOrder.LITTLE_ENDIAN);
318 buffer.asIntBuffer().get(frame, 0, frame.length);
Sergey Ulanov 2013/09/25 23:32:08 This copies content of the buffer. I think we can
solb 2013/09/26 14:21:36 If I understand the patches correctly, https://cod
Lambros 2013/09/26 22:29:37 Yes - with these two CLs landed, there will only b
319
320 sFrameBitmap = Bitmap.createBitmap(frame, width, height, Bitmap.Config.A RGB_8888);
321 redrawGraphicsInternal();
322 }
323
324 /**
322 * Updates the cursor shape. This is called from native code on the graphics thread when 325 * Updates the cursor shape. This is called from native code on the graphics thread when
323 * receiving a new cursor shape from the host. 326 * receiving a new cursor shape from the host.
324 */ 327 */
325 public static void updateCursorShape(int width, int height, int hotspotX, in t hotspotY, 328 public static void updateCursorShape(int width, int height, int hotspotX, in t hotspotY,
326 ByteBuffer buffer) { 329 ByteBuffer buffer) {
327 sCursorHotspot = new Point(hotspotX, hotspotY); 330 sCursorHotspot = new Point(hotspotX, hotspotY);
328 331
329 int[] data = new int[width * height]; 332 int[] data = new int[width * height];
330 buffer.order(ByteOrder.LITTLE_ENDIAN); 333 buffer.order(ByteOrder.LITTLE_ENDIAN);
331 buffer.asIntBuffer().get(data, 0, data.length); 334 buffer.asIntBuffer().get(data, 0, data.length);
(...skipping 23 matching lines...) Expand all
355 358
356 /** Schedules a redraw on the native graphics thread. */ 359 /** Schedules a redraw on the native graphics thread. */
357 private static native void scheduleRedrawNative(); 360 private static native void scheduleRedrawNative();
358 361
359 /** Passes mouse information to the native handling code. */ 362 /** Passes mouse information to the native handling code. */
360 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown); 363 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown);
361 364
362 /** Passes key press information to the native handling code. */ 365 /** Passes key press information to the native handling code. */
363 private static native void keyboardActionNative(int keyCode, boolean keyDown ); 366 private static native void keyboardActionNative(int keyCode, boolean keyDown );
364 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698