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

Side by Side Diff: android_webview/native/aw_gl_functor.cc

Issue 1844343005: WIP - Control the lifetime of RenderThreadManager from Java. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Connect BVR and RTM Created 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "android_webview/native/aw_gl_functor.h"
6
7 #include "android_webview/public/browser/draw_gl.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "jni/AwGLFunctor_jni.h"
10
11 using base::android::AttachCurrentThread;
12 using content::BrowserThread;
13
14 extern "C" {
15 static AwDrawGLFunction DrawGLFunction;
16 static void DrawGLFunction(long view_context,
17 AwDrawGLInfo* draw_info,
18 void* spare) {
19 // |view_context| is the value that was returned from the java
20 // AwContents.onPrepareDrawGL; this cast must match the code there.
21 reinterpret_cast<android_webview::RenderThreadManager*>(view_context)
22 ->DrawGL(draw_info);
23 }
24 }
25
26 namespace android_webview {
27
28 AwGLFunctor::AwGLFunctor(const JavaObjectWeakGlobalRef& java_ref)
29 : java_ref_(java_ref),
30 render_thread_manager_(
31 this,
32 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) {}
33
34 AwGLFunctor::~AwGLFunctor() {}
35
36 void AwGLFunctor::OnParentDrawConstraintsUpdated() {
37 // if (client_) client_->OnParentDrawConstraintsUpdated();
38 }
39
40 bool AwGLFunctor::RequestDrawGL(bool wait_for_completion) {
41 DCHECK_CURRENTLY_ON(BrowserThread::UI);
42 JNIEnv* env = AttachCurrentThread();
43 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
44 if (obj.is_null())
45 return false;
46 return Java_AwGLFunctor_requestDrawGL(env, obj.obj(), wait_for_completion);
47 }
48
49 void AwGLFunctor::DetachFunctorFromView() {
50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 JNIEnv* env = AttachCurrentThread();
52 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
53 if (!obj.is_null())
54 Java_AwGLFunctor_detachFunctorFromView(env, obj.obj());
55 }
56
57 void AwGLFunctor::Destroy(JNIEnv* env,
58 const base::android::JavaParamRef<jobject>& obj) {
59 delete this;
60 }
61
62 void AwGLFunctor::DeleteHardwareRenderer(
63 JNIEnv* env,
64 const base::android::JavaParamRef<jobject>& obj) {
65 render_thread_manager_.DeleteHardwareRendererOnUI();
66 }
67
68 jlong AwGLFunctor::GetAwDrawGLViewContext(
69 JNIEnv* env,
70 const base::android::JavaParamRef<jobject>& obj) {
71 return reinterpret_cast<intptr_t>(&render_thread_manager_);
72 }
73
74 static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) {
75 return reinterpret_cast<intptr_t>(&DrawGLFunction);
76 }
77
78 static jlong Create(JNIEnv* env,
79 const JavaParamRef<jclass>&,
80 const base::android::JavaParamRef<jobject>& obj) {
81 return reinterpret_cast<intptr_t>(
82 new AwGLFunctor(JavaObjectWeakGlobalRef(env, obj)));
83 }
84
85 bool RegisterAwGLFunctor(JNIEnv* env) {
86 return RegisterNativesImpl(env);
87 }
88
89 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698