| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chromoting; | |
| 6 | |
| 7 import android.graphics.Matrix; | |
| 8 import android.graphics.PointF; | |
| 9 import android.view.SurfaceHolder; | |
| 10 | |
| 11 import org.chromium.chromoting.jni.Client; | |
| 12 import org.chromium.chromoting.jni.GlDisplay; | |
| 13 | |
| 14 /** | |
| 15 * The user interface for viewing and interacting with a specific remote host. U
ses OpenGL to draw | |
| 16 * the desktop and cursor. Should be used entirely on the UI thread. | |
| 17 */ | |
| 18 public class GlDesktopView extends DesktopView implements SurfaceHolder.Callback
{ | |
| 19 private final GlDisplay mDisplay; | |
| 20 | |
| 21 private Object mOnHostSizeChangedListenerKey; | |
| 22 private Object mOnCanvasRenderedListenerKey; | |
| 23 | |
| 24 public GlDesktopView(GlDisplay display, Desktop desktop, Client client) { | |
| 25 super(desktop, client); | |
| 26 Preconditions.notNull(display); | |
| 27 mDisplay = display; | |
| 28 display.setDesktopView(this); | |
| 29 | |
| 30 getHolder().addCallback(this); | |
| 31 } | |
| 32 | |
| 33 @Override | |
| 34 public void showInputFeedback(RenderStub.InputFeedbackType feedbackToShow, P
ointF pos) { | |
| 35 mDisplay.showInputFeedback(feedbackToShow, pos); | |
| 36 } | |
| 37 | |
| 38 @Override | |
| 39 public void transformationChanged(Matrix matrix) { | |
| 40 mDisplay.setTransformation(matrix); | |
| 41 } | |
| 42 | |
| 43 @Override | |
| 44 public void cursorMoved(PointF position) { | |
| 45 mDisplay.moveCursor(position); | |
| 46 } | |
| 47 | |
| 48 @Override | |
| 49 public void cursorVisibilityChanged(boolean visible) { | |
| 50 mDisplay.setCursorVisibility(visible); | |
| 51 } | |
| 52 | |
| 53 @Override | |
| 54 public void surfaceCreated(SurfaceHolder holder) { | |
| 55 mOnHostSizeChangedListenerKey = mDisplay | |
| 56 .onHostSizeChanged().add(new Event.ParameterRunnable<SizeChanged
EventParameter>() { | |
| 57 @Override | |
| 58 public void run(SizeChangedEventParameter p) { | |
| 59 mOnHostSizeChanged.raise(p); | |
| 60 } | |
| 61 }); | |
| 62 | |
| 63 mOnCanvasRenderedListenerKey = mDisplay | |
| 64 .onCanvasRendered().add(new Event.ParameterRunnable<Void>() { | |
| 65 @Override | |
| 66 public void run(Void p) { | |
| 67 mOnCanvasRendered.raise(p); | |
| 68 } | |
| 69 }); | |
| 70 | |
| 71 mDisplay.surfaceCreated(holder); | |
| 72 } | |
| 73 | |
| 74 @Override | |
| 75 public void surfaceChanged(SurfaceHolder holder, int format, int width, int
height) { | |
| 76 mDisplay.surfaceChanged(holder, format, width, height); | |
| 77 mOnClientSizeChanged.raise(new SizeChangedEventParameter(width, height))
; | |
| 78 } | |
| 79 | |
| 80 @Override | |
| 81 public void surfaceDestroyed(SurfaceHolder holder) { | |
| 82 // GlDisplay's life time spans to the whole session while GlDesktopView
may be created and | |
| 83 // destroyed for multiple times (say when the phone is rotated). It is i
mportant to remove | |
| 84 // the listeners when the surface is about to be destroyed. | |
| 85 if (mOnHostSizeChangedListenerKey != null) { | |
| 86 mDisplay.onHostSizeChanged().remove(mOnHostSizeChangedListenerKey); | |
| 87 } | |
| 88 if (mOnCanvasRenderedListenerKey != null) { | |
| 89 mDisplay.onCanvasRendered().remove(mOnCanvasRenderedListenerKey); | |
| 90 } | |
| 91 mDisplay.surfaceDestroyed(holder); | |
| 92 } | |
| 93 } | |
| OLD | NEW |