Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.graphics.Matrix; | 7 import android.graphics.Matrix; |
| 8 import android.graphics.PointF; | 8 import android.graphics.PointF; |
| 9 import android.view.Surface; | 9 import android.view.Surface; |
| 10 import android.view.SurfaceHolder; | 10 import android.view.SurfaceHolder; |
| 11 | 11 |
| 12 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
| 13 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
| 14 import org.chromium.chromoting.Desktop; | |
| 15 import org.chromium.chromoting.DesktopView; | 14 import org.chromium.chromoting.DesktopView; |
| 16 import org.chromium.chromoting.DesktopViewFactory; | |
| 17 import org.chromium.chromoting.Event; | 15 import org.chromium.chromoting.Event; |
| 18 import org.chromium.chromoting.GlDesktopView; | |
| 19 import org.chromium.chromoting.InputFeedbackRadiusMapper; | 16 import org.chromium.chromoting.InputFeedbackRadiusMapper; |
| 20 import org.chromium.chromoting.RenderStub; | 17 import org.chromium.chromoting.RenderStub; |
| 21 import org.chromium.chromoting.SizeChangedEventParameter; | 18 import org.chromium.chromoting.SizeChangedEventParameter; |
| 22 | 19 |
| 23 /** | 20 /** |
| 24 * This class is the JNI interface class that helps bridging GlDesktopView with the OpenGL renderer | 21 * This class is a RenderStub implementation that uses the OpenGL renderer in na tive code to render |
| 25 * in native code. The lifetime of this class is managed by the native JniGlDisp layHandler. | 22 * the remote desktop. The lifetime of this class is managed by the native JniGl DisplayHandler. |
| 26 * | 23 * |
| 27 * This class works entirely on the UI thread: | 24 * This class works entirely on the UI thread: |
| 28 * Functions should all be called on UI. | 25 * Functions should all be called on UI. |
| 29 * Events will only be triggered on UI. | 26 * Events will only be triggered on UI. |
| 30 */ | 27 */ |
| 31 @JNINamespace("remoting") | 28 @JNINamespace("remoting") |
| 32 public class GlDisplay implements SurfaceHolder.Callback, RenderStub { | 29 public class GlDisplay implements SurfaceHolder.Callback, RenderStub { |
| 33 private volatile long mNativeJniGlDisplay; | |
| 34 private final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChanged = | 30 private final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChanged = |
| 35 new Event.Raisable<>(); | 31 new Event.Raisable<>(); |
| 36 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged = | 32 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged = |
| 37 new Event.Raisable<>(); | 33 new Event.Raisable<>(); |
| 38 private final Event.Raisable<Void> mOnCanvasRendered = | 34 private final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable<>( ); |
| 39 new Event.Raisable<>(); | 35 |
| 36 private volatile long mNativeJniGlDisplay; | |
|
joedow
2016/09/12 19:55:08
Can you initialize |mNativeJniGlDisplay| to a reas
Yuwei
2016/09/12 20:57:18
It used to be 0 but Zijie thought it is unnecessar
joedow
2016/09/12 21:01:56
It isn't necessary but it documents intent. Proba
Hzj_jie
2016/09/12 21:28:04
Oh, I saw the initialization and definition of mos
Yuwei
2016/09/12 22:17:58
```
private GlDisplay(long nativeJniGlDisplay) {
| |
| 40 private InputFeedbackRadiusMapper mFeedbackRadiusMapper; | 37 private InputFeedbackRadiusMapper mFeedbackRadiusMapper; |
| 41 private float mScaleFactor = 0; | 38 private float mScaleFactor = 0; |
| 42 | 39 |
| 43 private GlDisplay(long nativeJniGlDisplay) { | 40 private GlDisplay(long nativeJniGlDisplay) { |
| 44 mNativeJniGlDisplay = nativeJniGlDisplay; | 41 mNativeJniGlDisplay = nativeJniGlDisplay; |
| 45 } | 42 } |
| 46 | 43 |
| 47 /** | 44 /** |
| 48 * Invalidates this object and disconnects from the native display handler. Called on the | 45 * Invalidates this object and disconnects from the native display handler. Called on the |
| 49 * display thread by the native code. | 46 * display thread by the native code. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 */ | 80 */ |
| 84 @Override | 81 @Override |
| 85 public void surfaceDestroyed(SurfaceHolder holder) { | 82 public void surfaceDestroyed(SurfaceHolder holder) { |
| 86 if (mNativeJniGlDisplay != 0) { | 83 if (mNativeJniGlDisplay != 0) { |
| 87 nativeOnSurfaceDestroyed(mNativeJniGlDisplay); | 84 nativeOnSurfaceDestroyed(mNativeJniGlDisplay); |
| 88 } | 85 } |
| 89 } | 86 } |
| 90 | 87 |
| 91 @Override | 88 @Override |
| 92 public void setDesktopView(DesktopView view) { | 89 public void setDesktopView(DesktopView view) { |
| 90 view.getHolder().addCallback(this); | |
| 93 mFeedbackRadiusMapper = new InputFeedbackRadiusMapper(view); | 91 mFeedbackRadiusMapper = new InputFeedbackRadiusMapper(view); |
| 94 } | 92 } |
| 95 | 93 |
| 96 /** | 94 /** |
| 97 * Sets the transformation matrix (in pixel coordinates). | 95 * Sets the transformation matrix (in pixel coordinates). |
| 98 * @param matrix the transformation matrix | 96 * @param matrix the transformation matrix |
| 99 */ | 97 */ |
| 100 @Override | 98 @Override |
| 101 public void setTransformation(Matrix matrix) { | 99 public void setTransformation(Matrix matrix) { |
| 102 if (mNativeJniGlDisplay != 0) { | 100 if (mNativeJniGlDisplay != 0) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 * Called by native code when a render request has been done by the OpenGL r enderer. This | 170 * Called by native code when a render request has been done by the OpenGL r enderer. This |
| 173 * will only be called when the render event callback is enabled. | 171 * will only be called when the render event callback is enabled. |
| 174 */ | 172 */ |
| 175 @CalledByNative | 173 @CalledByNative |
| 176 private void canvasRendered() { | 174 private void canvasRendered() { |
| 177 mOnCanvasRendered.raise(null); | 175 mOnCanvasRendered.raise(null); |
| 178 } | 176 } |
| 179 | 177 |
| 180 @CalledByNative | 178 @CalledByNative |
| 181 private void initializeClient(Client client) { | 179 private void initializeClient(Client client) { |
| 182 client.setDesktopViewFactory(new DesktopViewFactory() { | 180 client.setRenderStub(this); |
| 183 @Override | |
| 184 public DesktopView createDesktopView(Desktop desktop, Client client) { | |
| 185 return new GlDesktopView(GlDisplay.this, desktop, client); | |
| 186 } | |
| 187 }); | |
| 188 } | 181 } |
| 189 | 182 |
| 190 @CalledByNative | 183 @CalledByNative |
| 191 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) { | 184 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) { |
| 192 return new GlDisplay(nativeDisplayHandler); | 185 return new GlDisplay(nativeDisplayHandler); |
| 193 } | 186 } |
| 194 | 187 |
| 195 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface); | 188 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface); |
| 196 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler, | 189 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler, |
| 197 int width, int height); | 190 int width, int height); |
| 198 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ; | 191 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ; |
| 199 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler, | 192 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler, |
| 200 float[] matrix); | 193 float[] matrix); |
| 201 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler, | 194 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler, |
| 202 float x, float y); | 195 float x, float y); |
| 203 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er, | 196 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er, |
| 204 float x, float y, float diam eter); | 197 float x, float y, float diam eter); |
| 205 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler, | 198 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler, |
| 206 boolean visible); | 199 boolean visible); |
| 207 } | 200 } |
| OLD | NEW |