Chromium Code Reviews| 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 #include "android_webview/native/aw_gl_functor.h" | 5 #include "android_webview/native/aw_gl_functor.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/browser_view_renderer.h" | 7 #include "android_webview/browser/browser_view_renderer.h" |
| 8 #include "android_webview/public/browser/draw_gl.h" | 8 #include "android_webview/public/browser/draw_gl.h" |
| 9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
| 10 #include "jni/AwGLFunctor_jni.h" | 10 #include "jni/AwGLFunctor_jni.h" |
| 11 | 11 |
| 12 using base::android::AttachCurrentThread; | 12 using base::android::AttachCurrentThread; |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 | 14 |
| 15 extern "C" { | 15 extern "C" { |
| 16 static AwDrawGLFunction DrawGLFunction; | 16 static AwDrawGLFunction DrawGLFunction; |
| 17 static void DrawGLFunction(long view_context, | 17 static void DrawGLFunction(long view_context, |
| 18 AwDrawGLInfo* draw_info, | 18 AwDrawGLInfo* draw_info, |
| 19 void* spare) { | 19 void* spare) { |
| 20 // |view_context| is the value that was returned from the java | 20 // |view_context| is the value that was returned from the java |
| 21 // AwContents.onPrepareDrawGL; this cast must match the code there. | 21 // AwContents.onPrepareDrawGL; this cast must match the code there. |
| 22 reinterpret_cast<android_webview::RenderThreadManager*>(view_context) | 22 reinterpret_cast<android_webview::RenderThreadManager*>(view_context) |
| 23 ->DrawGL(draw_info); | 23 ->DrawGL(draw_info); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace android_webview { | 27 namespace android_webview { |
| 28 | 28 |
| 29 namespace { | |
| 30 int g_instance_count = 0; | |
| 31 } | |
| 32 | |
| 29 AwGLFunctor::AwGLFunctor(const JavaObjectWeakGlobalRef& java_ref) | 33 AwGLFunctor::AwGLFunctor(const JavaObjectWeakGlobalRef& java_ref) |
| 30 : java_ref_(java_ref), | 34 : java_ref_(java_ref), |
| 31 render_thread_manager_( | 35 render_thread_manager_( |
| 32 this, | 36 this, |
| 33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), | 37 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)), |
| 34 browser_view_renderer_(nullptr) {} | 38 browser_view_renderer_(nullptr) { |
| 39 ++g_instance_count; | |
|
boliu
2016/04/22 15:51:53
should add threadchecks to where g_instance_count
| |
| 40 } | |
| 35 | 41 |
| 36 AwGLFunctor::~AwGLFunctor() {} | 42 AwGLFunctor::~AwGLFunctor() { |
| 43 --g_instance_count; | |
| 44 } | |
| 37 | 45 |
| 38 void AwGLFunctor::OnParentDrawConstraintsUpdated() { | 46 void AwGLFunctor::OnParentDrawConstraintsUpdated() { |
| 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 40 if (browser_view_renderer_) | 48 if (browser_view_renderer_) |
| 41 browser_view_renderer_->OnParentDrawConstraintsUpdated(); | 49 browser_view_renderer_->OnParentDrawConstraintsUpdated(); |
| 42 } | 50 } |
| 43 | 51 |
| 44 bool AwGLFunctor::RequestInvokeGL(bool wait_for_completion) { | 52 bool AwGLFunctor::RequestInvokeGL(bool wait_for_completion) { |
| 45 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 53 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 46 JNIEnv* env = AttachCurrentThread(); | 54 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 75 const base::android::JavaParamRef<jobject>& obj) { | 83 const base::android::JavaParamRef<jobject>& obj) { |
| 76 render_thread_manager_.DeleteHardwareRendererOnUI(); | 84 render_thread_manager_.DeleteHardwareRendererOnUI(); |
| 77 } | 85 } |
| 78 | 86 |
| 79 jlong AwGLFunctor::GetAwDrawGLViewContext( | 87 jlong AwGLFunctor::GetAwDrawGLViewContext( |
| 80 JNIEnv* env, | 88 JNIEnv* env, |
| 81 const base::android::JavaParamRef<jobject>& obj) { | 89 const base::android::JavaParamRef<jobject>& obj) { |
| 82 return reinterpret_cast<intptr_t>(&render_thread_manager_); | 90 return reinterpret_cast<intptr_t>(&render_thread_manager_); |
| 83 } | 91 } |
| 84 | 92 |
| 93 // static | |
| 94 jint GetNativeInstanceCount(JNIEnv* env, const JavaParamRef<jclass>&) { | |
| 95 return g_instance_count; | |
| 96 } | |
| 97 | |
| 85 static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) { | 98 static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) { |
| 86 return reinterpret_cast<intptr_t>(&DrawGLFunction); | 99 return reinterpret_cast<intptr_t>(&DrawGLFunction); |
| 87 } | 100 } |
| 88 | 101 |
| 89 static jlong Create(JNIEnv* env, | 102 static jlong Create(JNIEnv* env, |
| 90 const JavaParamRef<jclass>&, | 103 const JavaParamRef<jclass>&, |
| 91 const base::android::JavaParamRef<jobject>& obj) { | 104 const base::android::JavaParamRef<jobject>& obj) { |
| 92 return reinterpret_cast<intptr_t>( | 105 return reinterpret_cast<intptr_t>( |
| 93 new AwGLFunctor(JavaObjectWeakGlobalRef(env, obj))); | 106 new AwGLFunctor(JavaObjectWeakGlobalRef(env, obj))); |
| 94 } | 107 } |
| 95 | 108 |
| 96 bool RegisterAwGLFunctor(JNIEnv* env) { | 109 bool RegisterAwGLFunctor(JNIEnv* env) { |
| 97 return RegisterNativesImpl(env); | 110 return RegisterNativesImpl(env); |
| 98 } | 111 } |
| 99 | 112 |
| 100 } // namespace android_webview | 113 } // namespace android_webview |
| OLD | NEW |