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

Unified Diff: remoting/android/java/src/org/chromium/chromoting/jni/Client.java

Issue 2007123003: [Android Client] Break down multi-threaded classes by thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: remoting/android/java/src/org/chromium/chromoting/jni/Client.java
diff --git a/remoting/android/java/src/org/chromium/chromoting/jni/Client.java b/remoting/android/java/src/org/chromium/chromoting/jni/Client.java
index 24911e2833a5e8903c75339dbca075cefe068c67..e0444bb2aa98f58215416089842ccb838882f292 100644
--- a/remoting/android/java/src/org/chromium/chromoting/jni/Client.java
+++ b/remoting/android/java/src/org/chromium/chromoting/jni/Client.java
@@ -4,20 +4,12 @@
package org.chromium.chromoting.jni;
-import android.graphics.Bitmap;
-import android.graphics.Point;
-import android.os.Looper;
-
-import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.chromoting.CapabilityManager;
import org.chromium.chromoting.SessionAuthenticator;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
/**
* Class to manage a client connection to the host. This class controls the lifetime of the
* corresponding C++ object which implements the connection. A new object should be created for
@@ -26,11 +18,13 @@ import java.nio.ByteOrder;
*/
@JNINamespace("remoting")
public class Client {
- private static final String TAG = "Chromoting";
-
// Pointer to the C++ object, cast to a |long|.
private long mNativeJniClient;
+ // Reference has to be kept until the lifecycle of Client ends. Code may use getDisplay()
+ // without doing a null check.
+ private Display mDisplay;
+
// The global Client instance (may be null). This needs to be a global singleton so that the
// Client can be passed between Activities.
private static Client sClient;
@@ -45,6 +39,15 @@ public class Client {
mNativeJniClient = nativeInit();
}
+ /**
+ *
Lambros 2016/05/28 00:43:05 Better to provide a JavaDoc one-sentence summary,
Yuwei 2016/06/01 21:30:10 Done.
+ * @return the display object. It will be null before calling connectToHost() but won't be null
+ * after calling disconnectFromHost().
+ */
+ public Display getDisplay() {
+ return mDisplay;
+ }
+
// Called on the UI thread. Suppress FindBugs warning, since |sClient| is only used on the
// UI thread.
@SuppressFBWarnings("LI_LAZY_INIT_STATIC")
@@ -70,24 +73,6 @@ public class Client {
/** Notified upon successful connection or disconnection. Accessed on the UI thread. */
private ConnectionListener mConnectionListener;
- /**
- * Callback invoked on the graphics thread to repaint the desktop. Accessed on the UI and
- * graphics threads.
- */
- private Runnable mRedrawCallback;
-
- /** Bitmap holding a copy of the latest video frame. Accessed on the UI and graphics threads. */
- private Bitmap mFrameBitmap;
-
- /** Protects access to {@link mFrameBitmap}. */
- private final Object mFrameLock = new Object();
-
- /** Position of cursor hot-spot. Accessed on the graphics thread. */
- private Point mCursorHotspot = new Point();
-
- /** Bitmap holding the cursor shape. Accessed on the graphics thread. */
- private Bitmap mCursorBitmap;
-
/** Capability Manager through which capabilities and extensions are handled. */
private CapabilityManager mCapabilityManager = new CapabilityManager();
@@ -108,9 +93,11 @@ public class Client {
mConnectionListener = listener;
mAuthenticator = authenticator;
- nativeConnect(mNativeJniClient, username, authToken, hostJid, hostId, hostPubkey,
- mAuthenticator.getPairingId(hostId), mAuthenticator.getPairingSecret(hostId),
- mCapabilityManager.getLocalCapabilities(), flags);
+ mDisplay = new Display();
+ nativeConnect(mNativeJniClient, mDisplay.getNativePointer(), username, authToken, hostJid,
+ hostId, hostPubkey, mAuthenticator.getPairingId(hostId),
+ mAuthenticator.getPairingSecret(hostId), mCapabilityManager.getLocalCapabilities(),
+ flags);
mConnected = true;
}
@@ -137,10 +124,7 @@ public class Client {
mConnected = false;
mCapabilityManager.onHostDisconnect();
- // Drop the reference to free the Bitmap for GC.
- synchronized (mFrameLock) {
- mFrameBitmap = null;
- }
+ mDisplay.destroy();
}
/** Called on the UI thread whenever the connection status changes. */
@@ -252,96 +236,6 @@ public class Client {
nativeEnableVideoChannel(mNativeJniClient, enable);
}
- /**
- * Sets the redraw callback to the provided functor. Provide a value of null whenever the
- * window is no longer visible so that we don't continue to draw onto it. Called on the UI
- * thread.
- */
- public void provideRedrawCallback(Runnable redrawCallback) {
- mRedrawCallback = redrawCallback;
- }
-
- /** Forces the native graphics thread to redraw to the canvas. Called on the UI thread. */
- public boolean redrawGraphics() {
- if (!mConnected || mRedrawCallback == null) return false;
-
- nativeScheduleRedraw(mNativeJniClient);
- return true;
- }
-
- /**
- * Called on the graphics thread to perform the redrawing callback requested by
- * {@link #redrawGraphics}. This is a no-op if the window isn't visible (the callback is null).
- */
- @CalledByNative
- void redrawGraphicsInternal() {
- Runnable callback = mRedrawCallback;
- if (callback != null) {
- callback.run();
- }
- }
-
- /**
- * Returns a bitmap of the latest video frame. Called on the native graphics thread when
- * DesktopView is repainted.
- */
- public Bitmap getVideoFrame() {
- if (Looper.myLooper() == Looper.getMainLooper()) {
- Log.w(TAG, "Canvas being redrawn on UI thread");
- }
-
- synchronized (mFrameLock) {
- return mFrameBitmap;
- }
- }
-
- /**
- * Set a new video frame. Called on the native graphics thread when a new frame is allocated.
- */
- @CalledByNative
- void setVideoFrame(Bitmap bitmap) {
- if (Looper.myLooper() == Looper.getMainLooper()) {
- Log.w(TAG, "Video frame updated on UI thread");
- }
-
- synchronized (mFrameLock) {
- mFrameBitmap = bitmap;
- }
- }
-
- /**
- * Creates a new Bitmap to hold video frame pixels. The returned Bitmap is referenced by native
- * code which writes the decoded frame pixels to it.
- */
- @CalledByNative
- static Bitmap newBitmap(int width, int height) {
- return Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- }
-
- /**
- * Updates the cursor shape. This is called on the graphics thread when receiving a new cursor
- * shape from the host.
- */
- @CalledByNative
- void updateCursorShape(int width, int height, int hotspotX, int hotspotY, ByteBuffer buffer) {
- mCursorHotspot = new Point(hotspotX, hotspotY);
-
- int[] data = new int[width * height];
- buffer.order(ByteOrder.LITTLE_ENDIAN);
- buffer.asIntBuffer().get(data, 0, data.length);
- mCursorBitmap = Bitmap.createBitmap(data, width, height, Bitmap.Config.ARGB_8888);
- }
-
- /** Position of cursor hotspot within cursor image. Called on the graphics thread. */
- public Point getCursorHotspot() {
- return mCursorHotspot;
- }
-
- /** Returns the current cursor shape. Called on the graphics thread. */
- public Bitmap getCursorBitmap() {
- return mCursorBitmap;
- }
-
//
// Third Party Authentication
//
@@ -404,9 +298,9 @@ public class Client {
private native void nativeDestroy(long nativeJniClient);
/** Performs the native portion of the connection. */
- private native void nativeConnect(long nativeJniClient, String username, String authToken,
- String hostJid, String hostId, String hostPubkey, String pairId, String pairSecret,
- String capabilities, String flags);
+ private native void nativeConnect(long nativeJniClient, long nativeJniDisplayHandler,
+ String username, String authToken, String hostJid, String hostId, String hostPubkey,
+ String pairId, String pairSecret, String capabilities, String flags);
/** Native implementation of Client.handleAuthenticationResponse(). */
private native void nativeAuthenticationResponse(
@@ -415,9 +309,6 @@ public class Client {
/** Performs the native portion of the cleanup. */
private native void nativeDisconnect(long nativeJniClient);
- /** Schedules a redraw on the native graphics thread. */
- private native void nativeScheduleRedraw(long nativeJniClient);
-
/** Passes authentication data to the native handling code. */
private native void nativeOnThirdPartyTokenFetched(
long nativeJniClient, String token, String sharedSecret);

Powered by Google App Engine
This is Rietveld 408576698