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; | 30 private volatile long mNativeJniGlDisplay; |
|
Hzj_jie
2016/09/10 02:06:32
Is this volatile useful? I have not seen this poin
Yuwei
2016/09/10 05:29:14
There is a small design issue with JniGlDisplayHan
Yuwei
2016/09/12 18:56:14
I'll consider fixing this problem after this CL is
Yuwei
2016/09/12 19:13:14
Looks like I was wrong with #2. The reason was to
Hzj_jie
2016/09/12 21:28:04
Emmm, interesting, code search won't display all r
Hzj_jie
2016/09/12 21:28:04
I have had a look at JniGlDisplayHandler, and have
Yuwei
2016/09/12 21:50:04
Something like that. Basically its WeakFactory liv
Hzj_jie
2016/09/13 18:00:13
I just guessed Activity.onDestroy() and View.onDes
Yuwei
2016/09/13 18:21:09
Should be now GlDisplay.invalidate() vs View.onDet
| |
| 34 private final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChanged = | 31 private final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChanged = |
| 35 new Event.Raisable<>(); | 32 new Event.Raisable<>(); |
| 36 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged = | 33 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged = |
| 37 new Event.Raisable<>(); | 34 new Event.Raisable<>(); |
| 38 private final Event.Raisable<Void> mOnCanvasRendered = | 35 private final Event.Raisable<Void> mOnCanvasRendered = new Event.Raisable<>( ); |
| 39 new Event.Raisable<>(); | |
| 40 private InputFeedbackRadiusMapper mFeedbackRadiusMapper; | 36 private InputFeedbackRadiusMapper mFeedbackRadiusMapper; |
|
Hzj_jie
2016/09/10 02:06:32
Move regular fields after final fields.
Yuwei
2016/09/12 18:56:14
Done. Just moving mNativeJniGlDisplay below?
Hzj_jie
2016/09/12 21:28:04
Since mNativeJniGlDisplay needs to be mutable, thi
Yuwei
2016/09/12 21:50:04
Acknowledged.
| |
| 41 private float mScaleFactor = 0; | 37 private float mScaleFactor = 0; |
| 42 | 38 |
| 43 private GlDisplay(long nativeJniGlDisplay) { | 39 private GlDisplay(long nativeJniGlDisplay) { |
| 44 mNativeJniGlDisplay = nativeJniGlDisplay; | 40 mNativeJniGlDisplay = nativeJniGlDisplay; |
| 45 } | 41 } |
| 46 | 42 |
| 47 /** | 43 /** |
| 48 * Invalidates this object and disconnects from the native display handler. Called on the | 44 * Invalidates this object and disconnects from the native display handler. Called on the |
| 49 * display thread by the native code. | 45 * display thread by the native code. |
| 50 */ | 46 */ |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 76 if (mNativeJniGlDisplay != 0) { | 72 if (mNativeJniGlDisplay != 0) { |
| 77 nativeOnSurfaceChanged(mNativeJniGlDisplay, width, height); | 73 nativeOnSurfaceChanged(mNativeJniGlDisplay, width, height); |
| 78 } | 74 } |
| 79 } | 75 } |
| 80 | 76 |
| 81 /** | 77 /** |
| 82 * Notifies the OpenGL renderer that the current surface being used is about to be destroyed. | 78 * Notifies the OpenGL renderer that the current surface being used is about to be destroyed. |
| 83 */ | 79 */ |
| 84 @Override | 80 @Override |
| 85 public void surfaceDestroyed(SurfaceHolder holder) { | 81 public void surfaceDestroyed(SurfaceHolder holder) { |
| 86 if (mNativeJniGlDisplay != 0) { | 82 if (mNativeJniGlDisplay != 0) { |
|
Hzj_jie
2016/09/10 02:06:32
Is there any chance mNativeJniGlDisplay == 0 / nul
Yuwei
2016/09/10 05:29:14
invalidate()
| |
| 87 nativeOnSurfaceDestroyed(mNativeJniGlDisplay); | 83 nativeOnSurfaceDestroyed(mNativeJniGlDisplay); |
| 88 } | 84 } |
| 89 } | 85 } |
| 90 | 86 |
| 91 @Override | 87 @Override |
| 92 public void setDesktopView(DesktopView view) { | 88 public void setDesktopView(DesktopView view) { |
| 89 view.getHolder().addCallback(this); | |
| 93 mFeedbackRadiusMapper = new InputFeedbackRadiusMapper(view); | 90 mFeedbackRadiusMapper = new InputFeedbackRadiusMapper(view); |
| 94 } | 91 } |
| 95 | 92 |
| 96 /** | 93 /** |
| 97 * Sets the transformation matrix (in pixel coordinates). | 94 * Sets the transformation matrix (in pixel coordinates). |
| 98 * @param matrix the transformation matrix | 95 * @param matrix the transformation matrix |
| 99 */ | 96 */ |
| 100 @Override | 97 @Override |
| 101 public void setTransformation(Matrix matrix) { | 98 public void setTransformation(Matrix matrix) { |
| 102 if (mNativeJniGlDisplay != 0) { | 99 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 | 169 * 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. | 170 * will only be called when the render event callback is enabled. |
| 174 */ | 171 */ |
| 175 @CalledByNative | 172 @CalledByNative |
| 176 private void canvasRendered() { | 173 private void canvasRendered() { |
| 177 mOnCanvasRendered.raise(null); | 174 mOnCanvasRendered.raise(null); |
| 178 } | 175 } |
| 179 | 176 |
| 180 @CalledByNative | 177 @CalledByNative |
| 181 private void initializeClient(Client client) { | 178 private void initializeClient(Client client) { |
| 182 client.setDesktopViewFactory(new DesktopViewFactory() { | 179 client.setRenderStub(this); |
| 183 @Override | |
| 184 public DesktopView createDesktopView(Desktop desktop, Client client) { | |
| 185 return new GlDesktopView(GlDisplay.this, desktop, client); | |
| 186 } | |
| 187 }); | |
| 188 } | 180 } |
| 189 | 181 |
| 190 @CalledByNative | 182 @CalledByNative |
| 191 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) { | 183 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) { |
| 192 return new GlDisplay(nativeDisplayHandler); | 184 return new GlDisplay(nativeDisplayHandler); |
| 193 } | 185 } |
| 194 | 186 |
| 195 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface); | 187 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface); |
| 196 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler, | 188 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler, |
| 197 int width, int height); | 189 int width, int height); |
| 198 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ; | 190 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ; |
| 199 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler, | 191 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler, |
| 200 float[] matrix); | 192 float[] matrix); |
| 201 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler, | 193 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler, |
| 202 float x, float y); | 194 float x, float y); |
| 203 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er, | 195 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er, |
| 204 float x, float y, float diam eter); | 196 float x, float y, float diam eter); |
| 205 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler, | 197 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler, |
| 206 boolean visible); | 198 boolean visible); |
| 207 } | 199 } |
| OLD | NEW |