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 "android_webview/native/aw_contents.h" | 5 #include "android_webview/native/aw_contents.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
10 #include "android_webview/browser/aw_browser_main_parts.h" | 10 #include "android_webview/browser/aw_browser_main_parts.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 // static | 153 // static |
154 AwBrowserPermissionRequestDelegate* AwBrowserPermissionRequestDelegate::FromID( | 154 AwBrowserPermissionRequestDelegate* AwBrowserPermissionRequestDelegate::FromID( |
155 int render_process_id, int render_view_id) { | 155 int render_process_id, int render_view_id) { |
156 AwContents* aw_contents = AwContents::FromID(render_process_id, | 156 AwContents* aw_contents = AwContents::FromID(render_process_id, |
157 render_view_id); | 157 render_view_id); |
158 return implicit_cast<AwBrowserPermissionRequestDelegate*>(aw_contents); | 158 return implicit_cast<AwBrowserPermissionRequestDelegate*>(aw_contents); |
159 } | 159 } |
160 | 160 |
161 AwContents::AwContents(scoped_ptr<WebContents> web_contents) | 161 AwContents::AwContents(scoped_ptr<WebContents> web_contents) |
162 : web_contents_(web_contents.Pass()), | 162 : web_contents_(web_contents.Pass()), |
163 shared_renderer_state_( | 163 compositor_proxy_( |
164 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | 164 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
165 this), | 165 this), |
166 browser_view_renderer_( | 166 browser_view_renderer_( |
167 this, | 167 this /* AwGLMethods */, |
168 &shared_renderer_state_, | 168 this /* BrowserViewRendererClient */, |
169 &compositor_proxy_, | |
169 web_contents_.get(), | 170 web_contents_.get(), |
170 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), | 171 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), |
171 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()) { | 172 renderer_manager_key_(GLViewRendererManager::GetInstance()->NullKey()) { |
172 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1); | 173 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, 1); |
174 compositor_proxy_.SetBrowserViewRenderer(&browser_view_renderer_); | |
boliu
2014/10/23 16:40:05
need to set it to null in the destructor, and in t
hush (inactive)
2014/10/24 21:31:33
yeah. We changed the object ownership model as dis
| |
173 icon_helper_.reset(new IconHelper(web_contents_.get())); | 175 icon_helper_.reset(new IconHelper(web_contents_.get())); |
174 icon_helper_->SetListener(this); | 176 icon_helper_->SetListener(this); |
175 web_contents_->SetUserData(kAwContentsUserDataKey, | 177 web_contents_->SetUserData(kAwContentsUserDataKey, |
176 new AwContentsUserData(this)); | 178 new AwContentsUserData(this)); |
177 render_view_host_ext_.reset( | 179 render_view_host_ext_.reset( |
178 new AwRenderViewHostExt(this, web_contents_.get())); | 180 new AwRenderViewHostExt(this, web_contents_.get())); |
179 | 181 |
180 permission_request_handler_.reset( | 182 permission_request_handler_.reset( |
181 new PermissionRequestHandler(this, web_contents_.get())); | 183 new PermissionRequestHandler(this, web_contents_.get())); |
182 | 184 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 LOG(ERROR) << "Received unexpected kModeProcessNoContext"; | 370 LOG(ERROR) << "Received unexpected kModeProcessNoContext"; |
369 } | 371 } |
370 | 372 |
371 // kModeProcessNoContext should never happen because we tear down hardware | 373 // kModeProcessNoContext should never happen because we tear down hardware |
372 // in onTrimMemory. However that guarantee is maintained outside of chromium | 374 // in onTrimMemory. However that guarantee is maintained outside of chromium |
373 // code. Not notifying shared state in kModeProcessNoContext can lead to | 375 // code. Not notifying shared state in kModeProcessNoContext can lead to |
374 // immediate deadlock, which is slightly more catastrophic than leaks or | 376 // immediate deadlock, which is slightly more catastrophic than leaks or |
375 // corruption. | 377 // corruption. |
376 if (draw_info->mode == AwDrawGLInfo::kModeProcess || | 378 if (draw_info->mode == AwDrawGLInfo::kModeProcess || |
377 draw_info->mode == AwDrawGLInfo::kModeProcessNoContext) { | 379 draw_info->mode == AwDrawGLInfo::kModeProcessNoContext) { |
378 shared_renderer_state_.DidDrawGLProcess(); | 380 compositor_proxy_.DidDrawGLProcess(); |
379 } | 381 } |
380 | 382 |
381 if (shared_renderer_state_.IsInsideHardwareRelease()) { | 383 if (compositor_proxy_.IsInsideHardwareRelease()) { |
382 hardware_renderer_.reset(); | 384 hardware_renderer_.reset(); |
383 // Flush the idle queue in tear down. | 385 // Flush the idle queue in tear down. |
384 DeferredGpuCommandService::GetInstance()->PerformAllIdleWork(); | 386 DeferredGpuCommandService::GetInstance()->PerformAllIdleWork(); |
385 return; | 387 return; |
386 } | 388 } |
387 | 389 |
388 if (draw_info->mode != AwDrawGLInfo::kModeDraw) { | 390 if (draw_info->mode != AwDrawGLInfo::kModeDraw) { |
389 if (draw_info->mode == AwDrawGLInfo::kModeProcess) { | 391 if (draw_info->mode == AwDrawGLInfo::kModeProcess) { |
390 DeferredGpuCommandService::GetInstance()->PerformIdleWork(true); | 392 DeferredGpuCommandService::GetInstance()->PerformIdleWork(true); |
391 } | 393 } |
392 return; | 394 return; |
393 } | 395 } |
394 | 396 |
395 if (!hardware_renderer_) { | 397 if (!hardware_renderer_) { |
396 hardware_renderer_.reset(new HardwareRenderer(&shared_renderer_state_)); | 398 hardware_renderer_.reset(new HardwareRenderer(&compositor_proxy_)); |
397 hardware_renderer_->CommitFrame(); | 399 hardware_renderer_->CommitFrame(); |
398 } | 400 } |
399 | 401 |
400 hardware_renderer_->DrawGL(state_restore.stencil_enabled(), | 402 hardware_renderer_->DrawGL(state_restore.stencil_enabled(), |
401 state_restore.framebuffer_binding_ext(), | 403 state_restore.framebuffer_binding_ext(), |
402 draw_info); | 404 draw_info); |
403 DeferredGpuCommandService::GetInstance()->PerformIdleWork(false); | 405 DeferredGpuCommandService::GetInstance()->PerformIdleWork(false); |
404 } | 406 } |
405 | 407 |
406 namespace { | 408 namespace { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
762 } | 764 } |
763 | 765 |
764 void AwContents::PostInvalidate() { | 766 void AwContents::PostInvalidate() { |
765 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 767 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
766 JNIEnv* env = AttachCurrentThread(); | 768 JNIEnv* env = AttachCurrentThread(); |
767 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 769 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
768 if (!obj.is_null()) | 770 if (!obj.is_null()) |
769 Java_AwContents_postInvalidateOnAnimation(env, obj.obj()); | 771 Java_AwContents_postInvalidateOnAnimation(env, obj.obj()); |
770 } | 772 } |
771 | 773 |
772 void AwContents::UpdateParentDrawConstraints() { | |
773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
774 browser_view_renderer_.UpdateParentDrawConstraints(); | |
775 } | |
776 | |
777 void AwContents::DidSkipCommitFrame() { | |
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
779 browser_view_renderer_.DidSkipCommitFrame(); | |
780 } | |
781 | |
782 void AwContents::OnNewPicture() { | 774 void AwContents::OnNewPicture() { |
783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
784 JNIEnv* env = AttachCurrentThread(); | 776 JNIEnv* env = AttachCurrentThread(); |
785 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 777 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
786 if (!obj.is_null()) { | 778 if (!obj.is_null()) { |
787 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( | 779 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( |
788 "onNewPicture"); | 780 "onNewPicture"); |
789 Java_AwContents_onNewPicture(env, obj.obj()); | 781 Java_AwContents_onNewPicture(env, obj.obj()); |
790 } | 782 } |
791 } | 783 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 void AwContents::OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h) { | 873 void AwContents::OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h) { |
882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 874 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
883 browser_view_renderer_.OnAttachedToWindow(w, h); | 875 browser_view_renderer_.OnAttachedToWindow(w, h); |
884 } | 876 } |
885 | 877 |
886 void AwContents::InitializeHardwareDrawIfNeeded() { | 878 void AwContents::InitializeHardwareDrawIfNeeded() { |
887 GLViewRendererManager* manager = GLViewRendererManager::GetInstance(); | 879 GLViewRendererManager* manager = GLViewRendererManager::GetInstance(); |
888 | 880 |
889 base::AutoLock lock(render_thread_lock_); | 881 base::AutoLock lock(render_thread_lock_); |
890 if (renderer_manager_key_ == manager->NullKey()) { | 882 if (renderer_manager_key_ == manager->NullKey()) { |
891 renderer_manager_key_ = manager->PushBack(&shared_renderer_state_); | 883 renderer_manager_key_ = manager->PushBack(&compositor_proxy_); |
892 DeferredGpuCommandService::SetInstance(); | 884 DeferredGpuCommandService::SetInstance(); |
893 } | 885 } |
894 } | 886 } |
895 | 887 |
896 void AwContents::OnDetachedFromWindow(JNIEnv* env, jobject obj) { | 888 void AwContents::OnDetachedFromWindow(JNIEnv* env, jobject obj) { |
897 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 889 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
898 ReleaseHardwareDrawIfNeeded(); | 890 ReleaseHardwareDrawIfNeeded(); |
899 browser_view_renderer_.OnDetachedFromWindow(); | 891 browser_view_renderer_.OnDetachedFromWindow(); |
900 } | 892 } |
901 | 893 |
902 void AwContents::ReleaseHardwareDrawIfNeeded() { | 894 void AwContents::ReleaseHardwareDrawIfNeeded() { |
903 InsideHardwareReleaseReset inside_reset(&shared_renderer_state_); | 895 InsideHardwareReleaseReset inside_reset(&compositor_proxy_); |
904 | 896 |
905 JNIEnv* env = AttachCurrentThread(); | 897 InvalidateOnFunctorDestroy(); |
906 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
907 if (!obj.is_null()) | |
908 Java_AwContents_invalidateOnFunctorDestroy(env, obj.obj()); | |
909 | 898 |
910 bool hardware_initialized = browser_view_renderer_.hardware_enabled(); | 899 bool hardware_initialized = browser_view_renderer_.hardware_enabled(); |
911 if (hardware_initialized) { | 900 if (hardware_initialized) { |
912 bool draw_functor_succeeded = RequestDrawGL(NULL, true); | 901 bool draw_functor_succeeded = RequestDrawGL(NULL, true); |
913 if (!draw_functor_succeeded) { | 902 if (!draw_functor_succeeded) { |
914 LOG(ERROR) << "Unable to free GL resources. Has the Window leaked?"; | 903 LOG(ERROR) << "Unable to free GL resources. Has the Window leaked?"; |
915 // Calling release on wrong thread intentionally. | 904 // Calling release on wrong thread intentionally. |
916 AwDrawGLInfo info; | 905 AwDrawGLInfo info; |
917 info.mode = AwDrawGLInfo::kModeProcess; | 906 info.mode = AwDrawGLInfo::kModeProcess; |
918 DrawGL(&info); | 907 DrawGL(&info); |
(...skipping 11 matching lines...) Expand all Loading... | |
930 renderer_manager_key_ = manager->NullKey(); | 919 renderer_manager_key_ = manager->NullKey(); |
931 } | 920 } |
932 } | 921 } |
933 | 922 |
934 if (hardware_initialized) { | 923 if (hardware_initialized) { |
935 // Flush any invoke functors that's caused by OnDetachedFromWindow. | 924 // Flush any invoke functors that's caused by OnDetachedFromWindow. |
936 RequestDrawGL(NULL, true); | 925 RequestDrawGL(NULL, true); |
937 } | 926 } |
938 } | 927 } |
939 | 928 |
929 void AwContents::InvalidateOnFunctorDestroy() { | |
930 JNIEnv* env = AttachCurrentThread(); | |
931 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
932 if (!obj.is_null()) | |
933 Java_AwContents_invalidateOnFunctorDestroy(env, obj.obj()); | |
934 } | |
935 | |
940 base::android::ScopedJavaLocalRef<jbyteArray> | 936 base::android::ScopedJavaLocalRef<jbyteArray> |
941 AwContents::GetOpaqueState(JNIEnv* env, jobject obj) { | 937 AwContents::GetOpaqueState(JNIEnv* env, jobject obj) { |
942 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 938 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
943 // Required optimization in WebViewClassic to not save any state if | 939 // Required optimization in WebViewClassic to not save any state if |
944 // there has been no navigations. | 940 // there has been no navigations. |
945 if (!web_contents_->GetController().GetEntryCount()) | 941 if (!web_contents_->GetController().GetEntryCount()) |
946 return ScopedJavaLocalRef<jbyteArray>(); | 942 return ScopedJavaLocalRef<jbyteArray>(); |
947 | 943 |
948 Pickle pickle; | 944 Pickle pickle; |
949 if (!WriteToPickle(*web_contents_, &pickle)) { | 945 if (!WriteToPickle(*web_contents_, &pickle)) { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 } | 1169 } |
1174 | 1170 |
1175 browser_view_renderer_.TrimMemory(level, visible); | 1171 browser_view_renderer_.TrimMemory(level, visible); |
1176 } | 1172 } |
1177 | 1173 |
1178 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { | 1174 void SetShouldDownloadFavicons(JNIEnv* env, jclass jclazz) { |
1179 g_should_download_favicons = true; | 1175 g_should_download_favicons = true; |
1180 } | 1176 } |
1181 | 1177 |
1182 } // namespace android_webview | 1178 } // namespace android_webview |
OLD | NEW |