Chromium Code Reviews| Index: content/browser/android/content_readback_handler.cc |
| diff --git a/content/browser/android/content_readback_handler.cc b/content/browser/android/content_readback_handler.cc |
| index 432b23099ead6aaf2bf47bafe0c3745e1016469a..e1c14e658706240ea8b0ab374f898b0bab21c703 100644 |
| --- a/content/browser/android/content_readback_handler.cc |
| +++ b/content/browser/android/content_readback_handler.cc |
| @@ -6,9 +6,13 @@ |
| #include "base/android/jni_android.h" |
| #include "base/bind.h" |
| +#include "cc/output/copy_output_request.h" |
| +#include "cc/output/copy_output_result.h" |
| #include "content/browser/android/content_view_core_impl.h" |
| #include "jni/ContentReadbackHandler_jni.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| +#include "ui/base/android/window_android.h" |
| +#include "ui/base/android/window_android_compositor.h" |
| #include "ui/gfx/android/java_bitmap.h" |
| #include "ui/gfx/rect.h" |
| @@ -30,15 +34,15 @@ void ContentReadbackHandler::Destroy(JNIEnv* env, jobject obj) { |
| delete this; |
| } |
| -void ContentReadbackHandler::OnFinishContentReadback(int readback_id, |
| - bool success, |
| - const SkBitmap& bitmap) { |
| +void ContentReadbackHandler::OnFinishReadback(int readback_id, |
|
Ted C
2014/05/21 17:56:29
Just noticed, but the function ordering should mat
powei
2014/05/23 01:15:09
Done.
|
| + bool success, |
| + const SkBitmap& bitmap) { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| ScopedJavaLocalRef<jobject> java_bitmap; |
| if (success) |
| java_bitmap = gfx::ConvertToJavaBitmap(&bitmap); |
| - Java_ContentReadbackHandler_notifyGetContentBitmapFinished( |
| + Java_ContentReadbackHandler_notifyGetBitmapFinished( |
| env, java_obj_.obj(), readback_id, success, java_bitmap.obj()); |
| } |
| @@ -56,14 +60,53 @@ void ContentReadbackHandler::GetContentBitmap(JNIEnv* env, |
| ContentViewCore::GetNativeContentViewCore(env, content_view_core); |
| DCHECK(view); |
| - base::Callback<void(bool, const SkBitmap&)> result_callback = |
| - base::Bind(&ContentReadbackHandler::OnFinishContentReadback, |
| + ResultCallback result_callback = |
| + base::Bind(&ContentReadbackHandler::OnFinishReadback, |
| weak_factory_.GetWeakPtr(), |
| readback_id); |
| view->GetScaledContentBitmap( |
| scale, config, gfx::Rect(x, y, width, height), result_callback); |
| - return; |
| +} |
| + |
| +void ContentReadbackHandler::OnFinishCopyOutputRequest( |
| + const ResultCallback& result_callback, |
| + scoped_ptr<cc::CopyOutputResult> copy_output_result) { |
| + if (!copy_output_result->HasBitmap()) { |
| + result_callback.Run(false, SkBitmap()); |
| + return; |
| + } |
| + |
| + scoped_ptr<SkBitmap> bitmap = copy_output_result->TakeBitmap(); |
| + result_callback.Run(true, *bitmap.Pass()); |
| +} |
| + |
| +void ContentReadbackHandler::GetCompositorBitmap(JNIEnv* env, |
| + jobject obj, |
| + jint readback_id, |
| + jlong native_window_android) { |
| + ui::WindowAndroid* window_android = |
| + reinterpret_cast<ui::WindowAndroid*>(native_window_android); |
| + DCHECK(window_android); |
| + |
| + ResultCallback result_callback = |
| + base::Bind(&ContentReadbackHandler::OnFinishReadback, |
| + weak_factory_.GetWeakPtr(), |
| + readback_id); |
| + |
| + base::Callback<void(scoped_ptr<cc::CopyOutputResult>)> copy_output_callback = |
| + base::Bind(&ContentReadbackHandler::OnFinishCopyOutputRequest, |
| + result_callback); |
| + |
| + ui::WindowAndroidCompositor* compositor = window_android->GetCompositor(); |
| + |
| + if (!compositor) { |
| + copy_output_callback.Run(cc::CopyOutputResult::CreateEmptyResult()); |
| + return; |
| + } |
| + |
| + compositor->RequestCopyOfOutputOnRootLayer( |
| + cc::CopyOutputRequest::CreateBitmapRequest(copy_output_callback)); |
| } |
| // static |