| 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.Bitmap; | 7 import android.graphics.Bitmap; |
| 8 import android.graphics.Point; | 8 import android.graphics.Point; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 /** Bitmap holding a copy of the latest video frame. Accessed on the UI and
graphics threads. */ | 45 /** Bitmap holding a copy of the latest video frame. Accessed on the UI and
graphics threads. */ |
| 46 private Bitmap mFrameBitmap; | 46 private Bitmap mFrameBitmap; |
| 47 | 47 |
| 48 /** Position of cursor hot-spot. Accessed on the graphics thread. */ | 48 /** Position of cursor hot-spot. Accessed on the graphics thread. */ |
| 49 private Point mCursorHotspot = new Point(); | 49 private Point mCursorHotspot = new Point(); |
| 50 | 50 |
| 51 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */ | 51 /** Bitmap holding the cursor shape. Accessed on the graphics thread. */ |
| 52 private Bitmap mCursorBitmap; | 52 private Bitmap mCursorBitmap; |
| 53 | 53 |
| 54 public Display() { | 54 private Display(long nativeDisplayHandler) { |
| 55 mNativeJniDisplayHandler = nativeInit(); | 55 mNativeJniDisplayHandler = nativeDisplayHandler; |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @return the pointer to the native C++ object. | 59 * @return the pointer to the native C++ object. |
| 60 */ | 60 */ |
| 61 public long getNativePointer() { | 61 public long getNativePointer() { |
| 62 return mNativeJniDisplayHandler; | 62 return mNativeJniDisplayHandler; |
| 63 } | 63 } |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Sets the redraw callback to the provided functor. Provide a value of null
whenever the | 66 * Sets the redraw callback to the provided functor. Provide a value of null
whenever the |
| 67 * window is no longer visible so that we don't continue to draw onto it. Ca
lled on the UI | 67 * window is no longer visible so that we don't continue to draw onto it. Ca
lled on the UI |
| 68 * thread. | 68 * thread. |
| 69 */ | 69 */ |
| 70 public void provideRedrawCallback(Runnable redrawCallback) { | 70 public void provideRedrawCallback(Runnable redrawCallback) { |
| 71 synchronized (mRedrawCallbackLock) { | 71 synchronized (mRedrawCallbackLock) { |
| 72 mRedrawCallback = redrawCallback; | 72 mRedrawCallback = redrawCallback; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Destroys its resources and the native counterpart. Called on the UI threa
d. | 77 * Invalidates this object and disconnects from the native display handler.
Called on the |
| 78 * display thread by the native code. |
| 78 */ | 79 */ |
| 79 public void destroy() { | 80 @CalledByNative |
| 81 private void invalidate() { |
| 80 // Drop the reference to free the Bitmap for GC. | 82 // Drop the reference to free the Bitmap for GC. |
| 81 synchronized (mFrameLock) { | 83 synchronized (mFrameLock) { |
| 82 mFrameBitmap = null; | 84 mFrameBitmap = null; |
| 83 } | 85 } |
| 84 | 86 |
| 85 provideRedrawCallback(null); | 87 provideRedrawCallback(null); |
| 86 nativeDestroy(mNativeJniDisplayHandler); | |
| 87 mNativeJniDisplayHandler = 0; | 88 mNativeJniDisplayHandler = 0; |
| 88 } | 89 } |
| 89 | 90 |
| 90 /** Forces the native graphics thread to redraw to the canvas. Called on the
UI thread. */ | 91 /** Forces the native graphics thread to redraw to the canvas. Called on the
UI thread. */ |
| 91 public boolean redrawGraphics() { | 92 public boolean redrawGraphics() { |
| 92 if (mRedrawCallback == null) return false; | 93 if (mRedrawCallback == null) return false; |
| 93 | 94 |
| 94 nativeScheduleRedraw(mNativeJniDisplayHandler); | 95 nativeScheduleRedraw(mNativeJniDisplayHandler); |
| 95 return true; | 96 return true; |
| 96 } | 97 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 /** Position of cursor hotspot within cursor image. Called on the graphics t
hread. */ | 165 /** Position of cursor hotspot within cursor image. Called on the graphics t
hread. */ |
| 165 public Point getCursorHotspot() { | 166 public Point getCursorHotspot() { |
| 166 return mCursorHotspot; | 167 return mCursorHotspot; |
| 167 } | 168 } |
| 168 | 169 |
| 169 /** Returns the current cursor shape. Called on the graphics thread. */ | 170 /** Returns the current cursor shape. Called on the graphics thread. */ |
| 170 public Bitmap getCursorBitmap() { | 171 public Bitmap getCursorBitmap() { |
| 171 return mCursorBitmap; | 172 return mCursorBitmap; |
| 172 } | 173 } |
| 173 | 174 |
| 174 private native long nativeInit(); | 175 @CalledByNative |
| 175 | 176 private static Display createJavaDisplayObject(long nativeDisplayHandler) { |
| 176 private native void nativeDestroy(long nativeJniDisplayHandler); | 177 return new Display(nativeDisplayHandler); |
| 178 } |
| 177 | 179 |
| 178 /** Schedules a redraw on the native graphics thread. */ | 180 /** Schedules a redraw on the native graphics thread. */ |
| 179 private native void nativeScheduleRedraw(long nativeJniDisplayHandler); | 181 private native void nativeScheduleRedraw(long nativeJniDisplayHandler); |
| 180 } | 182 } |
| OLD | NEW |