OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/callback_helpers.h" | |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 17 #include "base/values.h" |
17 #include "cc/layers/layer.h" | 18 #include "cc/layers/layer.h" |
18 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
19 #include "content/browser/android/content_video_view.h" | 20 #include "content/browser/android/content_video_view.h" |
20 #include "content/browser/android/interstitial_page_delegate_android.h" | 21 #include "content/browser/android/interstitial_page_delegate_android.h" |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { | 585 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { |
585 JNIEnv* env = AttachCurrentThread(); | 586 JNIEnv* env = AttachCurrentThread(); |
586 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 587 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
587 if (obj.is_null()) | 588 if (obj.is_null()) |
588 return; | 589 return; |
589 Java_ContentViewCore_showPastePopup(env, obj.obj(), | 590 Java_ContentViewCore_showPastePopup(env, obj.obj(), |
590 static_cast<jint>(x_dip), | 591 static_cast<jint>(x_dip), |
591 static_cast<jint>(y_dip)); | 592 static_cast<jint>(y_dip)); |
592 } | 593 } |
593 | 594 |
594 unsigned int ContentViewCoreImpl::GetScaledContentTexture( | 595 void ContentViewCoreImpl::OnFinishGetScaledContentBitmap( |
595 float scale, | 596 const base::Callback<void(bool, const SkBitmap&)>& compositor_callback, |
596 gfx::Size* out_size) { | 597 bool success, |
598 const SkBitmap& bitmap) { | |
599 base::ScopedClosureRunner scoped_callback_runner( | |
600 base::Bind(compositor_callback, false, SkBitmap())); | |
601 | |
597 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 602 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
598 if (!view) | 603 if (!view) |
599 return 0; | 604 return; |
605 view->UnlockResources(); | |
600 | 606 |
601 return view->GetScaledContentTexture(scale, out_size); | 607 if (!success) |
608 return; | |
609 ignore_result(scoped_callback_runner.Release()); | |
610 compositor_callback.Run(success, bitmap); | |
611 } | |
612 | |
613 void ContentViewCoreImpl::GetScaledContentBitmap( | |
614 float scale, | |
615 gfx::Size* out_size, | |
616 const base::Callback<void(bool, const SkBitmap&)>& compositor_callback) { | |
617 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | |
618 if (!view || !view->IsSurfaceAvailableForCopy()) { | |
619 base::ScopedClosureRunner scoped_callback_runner( | |
620 base::Bind(compositor_callback, false, SkBitmap())); | |
no sievers
2014/01/28 20:47:21
nit: you can just do compositor_callback.Run(false
powei
2014/01/29 13:53:17
Done.
| |
621 return; | |
622 } | |
623 | |
624 base::Callback<void(bool, const SkBitmap&)> callback = | |
625 base::Bind(&ContentViewCoreImpl::OnFinishGetScaledContentBitmap, | |
626 base::Unretained(this), | |
no sievers
2014/01/28 20:47:21
The Unretained() is a problem, since the ContentVi
powei
2014/01/29 13:53:17
I took out the locks here, but I'm not sure how to
no sievers
2014/01/29 21:13:47
You lock the live layer in CopyFromCompositingSurf
| |
627 compositor_callback); | |
628 view->LockResources(); | |
629 view->GetScaledContentBitmap(scale, out_size, callback); | |
602 } | 630 } |
603 | 631 |
604 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { | 632 void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { |
605 JNIEnv* env = AttachCurrentThread(); | 633 JNIEnv* env = AttachCurrentThread(); |
606 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 634 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
607 if (j_obj.is_null()) | 635 if (j_obj.is_null()) |
608 return; | 636 return; |
609 ScopedJavaLocalRef<jstring> jcontent_url = | 637 ScopedJavaLocalRef<jstring> jcontent_url = |
610 ConvertUTF8ToJavaString(env, content_url.spec()); | 638 ConvertUTF8ToJavaString(env, content_url.spec()); |
611 Java_ContentViewCore_startContentIntent(env, | 639 Java_ContentViewCore_startContentIntent(env, |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1705 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1733 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1706 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1734 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1707 return reinterpret_cast<intptr_t>(view); | 1735 return reinterpret_cast<intptr_t>(view); |
1708 } | 1736 } |
1709 | 1737 |
1710 bool RegisterContentViewCore(JNIEnv* env) { | 1738 bool RegisterContentViewCore(JNIEnv* env) { |
1711 return RegisterNativesImpl(env); | 1739 return RegisterNativesImpl(env); |
1712 } | 1740 } |
1713 | 1741 |
1714 } // namespace content | 1742 } // namespace content |
OLD | NEW |