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

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

Issue 2282783003: [Remoting Android] Create Interfaces for GlDisplay (Closed)
Patch Set: Merge ToT again Created 4 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
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
8 import android.graphics.PointF;
7 import android.view.Surface; 9 import android.view.Surface;
10 import android.view.SurfaceHolder;
8 11
9 import org.chromium.base.annotations.CalledByNative; 12 import org.chromium.base.annotations.CalledByNative;
10 import org.chromium.base.annotations.JNINamespace; 13 import org.chromium.base.annotations.JNINamespace;
11 import org.chromium.chromoting.Desktop; 14 import org.chromium.chromoting.Desktop;
12 import org.chromium.chromoting.DesktopView; 15 import org.chromium.chromoting.DesktopView;
13 import org.chromium.chromoting.DesktopViewFactory; 16 import org.chromium.chromoting.DesktopViewFactory;
14 import org.chromium.chromoting.Event; 17 import org.chromium.chromoting.Event;
15 import org.chromium.chromoting.GlDesktopView; 18 import org.chromium.chromoting.GlDesktopView;
19 import org.chromium.chromoting.InputFeedbackRadiusMapper;
20 import org.chromium.chromoting.RenderStub;
16 import org.chromium.chromoting.SizeChangedEventParameter; 21 import org.chromium.chromoting.SizeChangedEventParameter;
17 22
18 /** 23 /**
19 * This class is the JNI interface class that helps bridging GlDesktopView with the OpenGL renderer 24 * This class is the JNI interface class that helps bridging GlDesktopView with the OpenGL renderer
20 * in native code. The lifetime of this class is managed by the native JniGlDisp layHandler. 25 * in native code. The lifetime of this class is managed by the native JniGlDisp layHandler.
21 * 26 *
22 * This class works entirely on the UI thread: 27 * This class works entirely on the UI thread:
23 * Functions should all be called on UI. 28 * Functions should all be called on UI.
24 * Events will only be triggered on UI. 29 * Events will only be triggered on UI.
25 */ 30 */
26 @JNINamespace("remoting") 31 @JNINamespace("remoting")
27 public class GlDisplay { 32 public class GlDisplay implements SurfaceHolder.Callback, RenderStub {
28 private volatile long mNativeJniGlDisplay; 33 private volatile long mNativeJniGlDisplay;
34 private final Event.Raisable<SizeChangedEventParameter> mOnClientSizeChanged =
35 new Event.Raisable<>();
29 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged = 36 private final Event.Raisable<SizeChangedEventParameter> mOnHostSizeChanged =
30 new Event.Raisable<>(); 37 new Event.Raisable<>();
31 private final Event.Raisable<Void> mOnCanvasRendered = 38 private final Event.Raisable<Void> mOnCanvasRendered =
32 new Event.Raisable<>(); 39 new Event.Raisable<>();
40 private InputFeedbackRadiusMapper mFeedbackRadiusMapper;
41 private float mScaleFactor = 0;
33 42
34 private GlDisplay(long nativeJniGlDisplay) { 43 private GlDisplay(long nativeJniGlDisplay) {
35 mNativeJniGlDisplay = nativeJniGlDisplay; 44 mNativeJniGlDisplay = nativeJniGlDisplay;
36 } 45 }
37 46
38 /** 47 /**
39 * Invalidates this object and disconnects from the native display handler. Called on the 48 * Invalidates this object and disconnects from the native display handler. Called on the
40 * display thread by the native code. 49 * display thread by the native code.
41 */ 50 */
42 @CalledByNative 51 @CalledByNative
43 private void invalidate() { 52 private void invalidate() {
44 mNativeJniGlDisplay = 0; 53 mNativeJniGlDisplay = 0;
45 } 54 }
46 55
47 /** 56 /**
48 * Notifies the OpenGL renderer that a surface for OpenGL to draw is created . 57 * Notifies the OpenGL renderer that a surface for OpenGL to draw is created .
49 * @param surface the surface to be drawn on 58 * @param holder the surface holder that holds the surface.
50 */ 59 */
51 public void surfaceCreated(Surface surface) { 60 @Override
61 public void surfaceCreated(SurfaceHolder holder) {
52 if (mNativeJniGlDisplay != 0) { 62 if (mNativeJniGlDisplay != 0) {
53 nativeOnSurfaceCreated(mNativeJniGlDisplay, surface); 63 nativeOnSurfaceCreated(mNativeJniGlDisplay, holder.getSurface());
54 } 64 }
55 } 65 }
56 66
57 /** 67 /**
58 * Notifies the OpenGL renderer the size of the surface. Should be called af ter surfaceCreated() 68 * Notifies the OpenGL renderer the size of the surface. Should be called af ter surfaceCreated()
59 * and before surfaceDestroyed(). 69 * and before surfaceDestroyed().
60 * @param width the width of the surface 70 * @param width the width of the surface
61 * @param height the height of the surface 71 * @param height the height of the surface
62 */ 72 */
63 public void surfaceChanged(int width, int height) { 73 @Override
74 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
75 mOnClientSizeChanged.raise(new SizeChangedEventParameter(width, height)) ;
64 if (mNativeJniGlDisplay != 0) { 76 if (mNativeJniGlDisplay != 0) {
65 nativeOnSurfaceChanged(mNativeJniGlDisplay, width, height); 77 nativeOnSurfaceChanged(mNativeJniGlDisplay, width, height);
66 } 78 }
67 } 79 }
68 80
69 /** 81 /**
70 * Notifies the OpenGL renderer that the current surface being used is about to be destroyed. 82 * Notifies the OpenGL renderer that the current surface being used is about to be destroyed.
71 */ 83 */
72 public void surfaceDestroyed() { 84 @Override
85 public void surfaceDestroyed(SurfaceHolder holder) {
73 if (mNativeJniGlDisplay != 0) { 86 if (mNativeJniGlDisplay != 0) {
74 nativeOnSurfaceDestroyed(mNativeJniGlDisplay); 87 nativeOnSurfaceDestroyed(mNativeJniGlDisplay);
75 } 88 }
76 } 89 }
77 90
91 @Override
92 public void setDesktopView(DesktopView view) {
93 mFeedbackRadiusMapper = new InputFeedbackRadiusMapper(view);
94 }
95
78 /** 96 /**
79 * Sets the transformation matrix (in pixel coordinates). 97 * Sets the transformation matrix (in pixel coordinates).
80 * @param matrix the transformation matrix 98 * @param matrix the transformation matrix
81 */ 99 */
82 public void pixelTransformationChanged(float[] matrix) { 100 @Override
101 public void setTransformation(Matrix matrix) {
83 if (mNativeJniGlDisplay != 0) { 102 if (mNativeJniGlDisplay != 0) {
84 nativeOnPixelTransformationChanged(mNativeJniGlDisplay, matrix); 103 float[] matrixArray = new float[9];
104 matrix.getValues(matrixArray);
105 nativeOnPixelTransformationChanged(mNativeJniGlDisplay, matrixArray) ;
106 mScaleFactor = matrix.mapRadius(1);
85 } 107 }
86 } 108 }
87 109
88 /** Moves the cursor to the corresponding location on the desktop. */ 110 /** Moves the cursor to the corresponding location on the desktop. */
89 public void cursorPixelPositionChanged(float x, float y) { 111 @Override
112 public void moveCursor(PointF position) {
90 if (mNativeJniGlDisplay != 0) { 113 if (mNativeJniGlDisplay != 0) {
91 nativeOnCursorPixelPositionChanged(mNativeJniGlDisplay, x, y); 114 nativeOnCursorPixelPositionChanged(mNativeJniGlDisplay, position.x, position.y);
92 } 115 }
93 } 116 }
94 117
95 /** 118 /**
96 * Decides whether the cursor should be shown on the canvas. 119 * Decides whether the cursor should be shown on the canvas.
97 */ 120 */
98 public void cursorVisibilityChanged(boolean visible) { 121 @Override
122 public void setCursorVisibility(boolean visible) {
99 if (mNativeJniGlDisplay != 0) { 123 if (mNativeJniGlDisplay != 0) {
100 nativeOnCursorVisibilityChanged(mNativeJniGlDisplay, visible); 124 nativeOnCursorVisibilityChanged(mNativeJniGlDisplay, visible);
101 } 125 }
102 } 126 }
103 127
104 /** 128 /**
129 * Shows the cursor input feedback animation with the given diameter at the given desktop
130 * location.
131 */
132 @Override
133 public void showInputFeedback(InputFeedbackType feedbackToShow, PointF pos) {
134 if (mNativeJniGlDisplay == 0 || feedbackToShow.equals(InputFeedbackType. NONE)) {
135 return;
136 }
137 float diameter = mFeedbackRadiusMapper
138 .getFeedbackRadius(feedbackToShow, mScaleFactor) * 2.0f;
139 if (diameter <= 0.0f) {
140 return;
141 }
142 nativeOnCursorInputFeedback(mNativeJniGlDisplay, pos.x, pos.y, diameter) ;
143 }
144
145 @Override
146 public Event<SizeChangedEventParameter> onClientSizeChanged() {
147 return mOnClientSizeChanged;
148 }
149
150 @Override
151 public Event<SizeChangedEventParameter> onHostSizeChanged() {
152 return mOnHostSizeChanged;
153 }
154
155 @Override
156 public Event<Void> onCanvasRendered() {
157 return mOnCanvasRendered;
158 }
159
160 /**
105 * Called by native code to notify GlDisplay that the size of the canvas (=s ize of desktop) has 161 * Called by native code to notify GlDisplay that the size of the canvas (=s ize of desktop) has
106 * changed. 162 * changed.
107 * @param width width of the canvas 163 * @param width width of the canvas
108 * @param height height of the canvas 164 * @param height height of the canvas
109 */ 165 */
110 @CalledByNative 166 @CalledByNative
111 private void changeCanvasSize(int width, int height) { 167 private void changeCanvasSize(int width, int height) {
112 mOnHostSizeChanged.raise(new SizeChangedEventParameter(width, height)); 168 mOnHostSizeChanged.raise(new SizeChangedEventParameter(width, height));
113 } 169 }
114 170
115 /** 171 /**
116 * An {@link Event} triggered when the size of the host desktop is changed.
117 */
118 public Event<SizeChangedEventParameter> onHostSizeChanged() {
119 return mOnHostSizeChanged;
120 }
121
122 /**
123 * Called by native code when a render request has been done by the OpenGL r enderer. This 172 * Called by native code when a render request has been done by the OpenGL r enderer. This
124 * will only be called when the render event callback is enabled. 173 * will only be called when the render event callback is enabled.
125 */ 174 */
126 @CalledByNative 175 @CalledByNative
127 private void canvasRendered() { 176 private void canvasRendered() {
128 mOnCanvasRendered.raise(null); 177 mOnCanvasRendered.raise(null);
129 } 178 }
130 179
131 /**
132 * An {@link} triggered when render event callback is enabled and a render r equest has been done
133 * by the OpenGL renderer.
134 */
135 public Event<Void> onCanvasRendered() {
136 return mOnCanvasRendered;
137 }
138
139 /**
140 * Shows the cursor input feedback animation with the given diameter at the given desktop
141 * location.
142 */
143 public void showCursorInputFeedback(float x, float y, float diameter) {
144 if (mNativeJniGlDisplay != 0) {
145 nativeOnCursorInputFeedback(mNativeJniGlDisplay, x, y, diameter);
146 }
147 }
148
149 @CalledByNative 180 @CalledByNative
150 private void initializeClient(Client client) { 181 private void initializeClient(Client client) {
151 client.setDesktopViewFactory(new DesktopViewFactory() { 182 client.setDesktopViewFactory(new DesktopViewFactory() {
152 @Override 183 @Override
153 public DesktopView createDesktopView(Desktop desktop, Client client) { 184 public DesktopView createDesktopView(Desktop desktop, Client client) {
154 return new GlDesktopView(GlDisplay.this, desktop, client); 185 return new GlDesktopView(GlDisplay.this, desktop, client);
155 } 186 }
156 }); 187 });
157 } 188 }
158 189
159 @CalledByNative 190 @CalledByNative
160 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) { 191 private static GlDisplay createJavaDisplayObject(long nativeDisplayHandler) {
161 return new GlDisplay(nativeDisplayHandler); 192 return new GlDisplay(nativeDisplayHandler);
162 } 193 }
163 194
164 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface); 195 private native void nativeOnSurfaceCreated(long nativeJniGlDisplayHandler, S urface surface);
165 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler, 196 private native void nativeOnSurfaceChanged(long nativeJniGlDisplayHandler,
166 int width, int height); 197 int width, int height);
167 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ; 198 private native void nativeOnSurfaceDestroyed(long nativeJniGlDisplayHandler) ;
168 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler, 199 private native void nativeOnPixelTransformationChanged(long nativeJniGlDispl ayHandler,
169 float[] matrix); 200 float[] matrix);
170 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler, 201 private native void nativeOnCursorPixelPositionChanged(long nativeJniGlDispl ayHandler,
171 float x, float y); 202 float x, float y);
172 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er, 203 private native void nativeOnCursorInputFeedback(long nativeJniGlDisplayHandl er,
173 float x, float y, float diam eter); 204 float x, float y, float diam eter);
174 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler, 205 private native void nativeOnCursorVisibilityChanged(long nativeJniGlDisplayH andler,
175 boolean visible); 206 boolean visible);
176 } 207 }
OLDNEW
« no previous file with comments | « remoting/android/java/src/org/chromium/chromoting/TrackpadInputStrategy.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698