forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaw_gl_functor.cc
86 lines (70 loc) · 2.66 KB
/
aw_gl_functor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/native/aw_gl_functor.h"
#include "android_webview/public/browser/draw_gl.h"
#include "content/public/browser/browser_thread.h"
#include "jni/AwGLFunctor_jni.h"
using base::android::AttachCurrentThread;
using content::BrowserThread;
extern "C" {
static AwDrawGLFunction DrawGLFunction;
static void DrawGLFunction(long view_context,
AwDrawGLInfo* draw_info,
void* spare) {
// |view_context| is the value that was returned from the java
// AwContents.onPrepareDrawGL; this cast must match the code there.
reinterpret_cast<android_webview::RenderThreadManager*>(view_context)
->DrawGL(draw_info);
}
}
namespace android_webview {
AwGLFunctor::AwGLFunctor(const JavaObjectWeakGlobalRef& java_ref)
: java_ref_(java_ref),
render_thread_manager_(
this,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)) {}
AwGLFunctor::~AwGLFunctor() {}
bool AwGLFunctor::RequestInvokeGL(bool wait_for_completion) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return false;
return Java_AwGLFunctor_requestInvokeGL(env, obj.obj(), wait_for_completion);
}
void AwGLFunctor::DetachFunctorFromView() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (!obj.is_null())
Java_AwGLFunctor_detachFunctorFromView(env, obj.obj());
}
void AwGLFunctor::Destroy(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
java_ref_.reset();
delete this;
}
void AwGLFunctor::DeleteHardwareRenderer(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
render_thread_manager_.DeleteHardwareRendererOnUI();
}
jlong AwGLFunctor::GetAwDrawGLViewContext(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj) {
return reinterpret_cast<intptr_t>(&render_thread_manager_);
}
static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) {
return reinterpret_cast<intptr_t>(&DrawGLFunction);
}
static jlong Create(JNIEnv* env,
const JavaParamRef<jclass>&,
const base::android::JavaParamRef<jobject>& obj) {
return reinterpret_cast<intptr_t>(
new AwGLFunctor(JavaObjectWeakGlobalRef(env, obj)));
}
bool RegisterAwGLFunctor(JNIEnv* env) {
return RegisterNativesImpl(env);
}
} // namespace android_webview