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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ContentReadbackHandler.java

Issue 1040393002: The Java Client should be aware of the readback status. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build errors Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 import android.graphics.Rect; 8 import android.graphics.Rect;
9 import android.util.SparseArray; 9 import android.util.SparseArray;
10 10
11 import org.chromium.base.CalledByNative; 11 import org.chromium.base.CalledByNative;
12 import org.chromium.base.JNINamespace; 12 import org.chromium.base.JNINamespace;
13 import org.chromium.base.ThreadUtils; 13 import org.chromium.base.ThreadUtils;
14 import org.chromium.content_public.browser.readback_types.ReadbackResponse;
14 import org.chromium.ui.base.WindowAndroid; 15 import org.chromium.ui.base.WindowAndroid;
15 16
16 /** 17 /**
17 * A class for reading back content. 18 * A class for reading back content.
18 */ 19 */
19 @JNINamespace("content") 20 @JNINamespace("content")
20 public abstract class ContentReadbackHandler { 21 public abstract class ContentReadbackHandler {
21 /** 22 /**
22 * A callback interface for content readback into a bitmap. 23 * A callback interface for content readback into a bitmap.
23 */ 24 */
24 public static interface GetBitmapCallback { 25 public static interface GetBitmapCallback {
25 /** 26 /**
26 * Called when the content readback finishes. 27 * Called when the content readback finishes.
27 * @param bitmap The {@link Bitmap} of the content. Null will be pa ssed for readback 28 * @param bitmap The {@link Bitmap} of the content. Null will be pa ssed for readback
28 * failure. 29 * failure.
29 */ 30 */
30 public void onFinishGetBitmap(Bitmap bitmap); 31 public void onFinishGetBitmap(Bitmap bitmap, int response);
31 } 32 }
32 33
33 private int mNextReadbackId = 1; 34 private int mNextReadbackId = 1;
34 private SparseArray<GetBitmapCallback> mGetBitmapRequests; 35 private SparseArray<GetBitmapCallback> mGetBitmapRequests;
35 36
36 private long mNativeContentReadbackHandler; 37 private long mNativeContentReadbackHandler;
37 38
38 /** 39 /**
39 * Creates a {@link ContentReadbackHandler}. 40 * Creates a {@link ContentReadbackHandler}.
40 */ 41 */
(...skipping 11 matching lines...) Expand all
52 /** 53 /**
53 * Should be called when the ContentReadackHandler is not needed anymore. 54 * Should be called when the ContentReadackHandler is not needed anymore.
54 */ 55 */
55 public void destroy() { 56 public void destroy() {
56 if (mNativeContentReadbackHandler != 0) nativeDestroy(mNativeContentRead backHandler); 57 if (mNativeContentReadbackHandler != 0) nativeDestroy(mNativeContentRead backHandler);
57 mNativeContentReadbackHandler = 0; 58 mNativeContentReadbackHandler = 0;
58 } 59 }
59 60
60 61
61 @CalledByNative 62 @CalledByNative
62 private void notifyGetBitmapFinished(int readbackId, Bitmap bitmap) { 63 private void notifyGetBitmapFinished(int readbackId, Bitmap bitmap, int resp onse) {
63 GetBitmapCallback callback = mGetBitmapRequests.get(readbackId); 64 GetBitmapCallback callback = mGetBitmapRequests.get(readbackId);
64 if (callback != null) { 65 if (callback != null) {
65 mGetBitmapRequests.delete(readbackId); 66 mGetBitmapRequests.delete(readbackId);
66 callback.onFinishGetBitmap(bitmap); 67 callback.onFinishGetBitmap(bitmap, response);
67 } else { 68 } else {
68 // readback Id is unregistered. 69 // readback Id is unregistered.
69 assert false : "Readback finished for unregistered Id: " + readbackI d; 70 assert false : "Readback finished for unregistered Id: " + readbackI d;
70 } 71 }
71 } 72 }
72 73
73 /** 74 /**
74 * Asynchronously, generate and grab a bitmap representing what is currently on the screen 75 * Asynchronously, generate and grab a bitmap representing what is currently on the screen
75 * for {@code view}. 76 * for {@code view}.
76 * 77 *
77 * @param scale The scale that should be applied to the content. 78 * @param scale The scale that should be applied to the content.
78 * @param srcRect A subrect of the original content to capture. If this is empty, it will grab 79 * @param srcRect A subrect of the original content to capture. If this is empty, it will grab
79 * the whole surface. 80 * the whole surface.
80 * @param view The {@link ContentViewCore} to grab the bitmap from. 81 * @param view The {@link ContentViewCore} to grab the bitmap from.
81 * @param callback The callback to be executed after readback completes. 82 * @param callback The callback to be executed after readback completes.
82 */ 83 */
83 public void getContentBitmapAsync(float scale, Rect srcRect, ContentViewCore view, 84 public void getContentBitmapAsync(float scale, Rect srcRect, ContentViewCore view,
84 GetBitmapCallback callback) { 85 GetBitmapCallback callback) {
85 if (!readyForReadback()) { 86 if (!readyForReadback()) {
86 callback.onFinishGetBitmap(null); 87 callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABL E);
87 return; 88 return;
88 } 89 }
89 ThreadUtils.assertOnUiThread(); 90 ThreadUtils.assertOnUiThread();
90 91
91 int readbackId = mNextReadbackId++; 92 int readbackId = mNextReadbackId++;
92 mGetBitmapRequests.put(readbackId, callback); 93 mGetBitmapRequests.put(readbackId, callback);
93 nativeGetContentBitmap(mNativeContentReadbackHandler, readbackId, scale, 94 nativeGetContentBitmap(mNativeContentReadbackHandler, readbackId, scale,
94 Bitmap.Config.ARGB_8888, srcRect.top, srcRect.left, srcRect.widt h(), 95 Bitmap.Config.ARGB_8888, srcRect.top, srcRect.left, srcRect.widt h(),
95 srcRect.height(), view); 96 srcRect.height(), view);
96 } 97 }
97 98
98 /** 99 /**
99 * Asynchronously, grab a bitmap of the current browser compositor root laye r. 100 * Asynchronously, grab a bitmap of the current browser compositor root laye r.
100 * 101 *
101 * @param windowAndroid The window that hosts the compositor. 102 * @param windowAndroid The window that hosts the compositor.
102 * @param callback The callback to be executed after readback completes . 103 * @param callback The callback to be executed after readback completes .
103 */ 104 */
104 public void getCompositorBitmapAsync(WindowAndroid windowAndroid, GetBitmapC allback callback) { 105 public void getCompositorBitmapAsync(WindowAndroid windowAndroid, GetBitmapC allback callback) {
105 if (!readyForReadback()) { 106 if (!readyForReadback()) {
106 callback.onFinishGetBitmap(null); 107 callback.onFinishGetBitmap(null, ReadbackResponse.SURFACE_UNAVAILABL E);
107 return; 108 return;
108 } 109 }
109 ThreadUtils.assertOnUiThread(); 110 ThreadUtils.assertOnUiThread();
110 111
111 int readbackId = mNextReadbackId++; 112 int readbackId = mNextReadbackId++;
112 mGetBitmapRequests.put(readbackId, callback); 113 mGetBitmapRequests.put(readbackId, callback);
113 nativeGetCompositorBitmap(mNativeContentReadbackHandler, readbackId, 114 nativeGetCompositorBitmap(mNativeContentReadbackHandler, readbackId,
114 windowAndroid.getNativePointer()); 115 windowAndroid.getNativePointer());
115 } 116 }
116 117
117 /** 118 /**
118 * Implemented by the owner of this class to signal whether readback is poss ible or not. 119 * Implemented by the owner of this class to signal whether readback is poss ible or not.
119 * @return Whether readback is possible or not. 120 * @return Whether readback is possible or not.
120 */ 121 */
121 protected abstract boolean readyForReadback(); 122 protected abstract boolean readyForReadback();
122 123
123 private native long nativeInit(); 124 private native long nativeInit();
124 private native void nativeDestroy(long nativeContentReadbackHandler); 125 private native void nativeDestroy(long nativeContentReadbackHandler);
125 private native void nativeGetContentBitmap(long nativeContentReadbackHandler , int readbackId, 126 private native void nativeGetContentBitmap(long nativeContentReadbackHandler , int readbackId,
126 float scale, Bitmap.Config config, float x, float y, float width, fl oat height, 127 float scale, Bitmap.Config config, float x, float y, float width, fl oat height,
127 Object contentViewCore); 128 Object contentViewCore);
128 private native void nativeGetCompositorBitmap(long nativeContentReadbackHand ler, 129 private native void nativeGetCompositorBitmap(long nativeContentReadbackHand ler,
129 int readbackId, long nativeWindowAndroid); 130 int readbackId, long nativeWindowAndroid);
130 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698