OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/shell/android/shell_manager.h" | 5 #include "content/shell/android/shell_manager.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "base/bind.h" | |
10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
11 #include "content/shell/shell.h" | 12 #include "content/shell/shell.h" |
12 #include "content/shell/shell_browser_context.h" | 13 #include "content/shell/shell_browser_context.h" |
13 #include "content/shell/shell_content_browser_client.h" | 14 #include "content/shell/shell_content_browser_client.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "jni/ShellManager_jni.h" | 16 #include "jni/ShellManager_jni.h" |
17 #include "content/public/browser/android/draw_delegate.h" | |
18 #include "content/public/browser/render_widget_host_view.h" | |
19 #include "content/public/browser/web_contents.h" | |
20 #include "content/shell/android/draw_context.h" | |
21 #include "content/shell/shell.h" | |
22 #include "ui/gfx/size.h" | |
23 | |
24 #include <android/native_window_jni.h> | |
16 | 25 |
17 using base::android::ScopedJavaLocalRef; | 26 using base::android::ScopedJavaLocalRef; |
27 using content::DrawContext; | |
28 using content::DrawDelegate; | |
18 | 29 |
19 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > | 30 namespace { |
20 g_content_shell_manager = LAZY_INSTANCE_INITIALIZER; | 31 |
32 struct GlobalState { | |
33 GlobalState() | |
34 : context(NULL) { | |
35 } | |
36 base::android::ScopedJavaGlobalRef<jobject> j_obj; | |
37 DrawContext* context; | |
38 }; | |
39 | |
40 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; | |
41 | |
42 static void SurfaceUpdated( | |
43 uint64 texture, | |
44 content::RenderWidgetHostView* view, | |
45 const DrawDelegate::SurfacePresentedCallback& callback) { | |
46 uint32 sync_point = g_global_state.Get().context->Draw(texture); | |
47 callback.Run(sync_point); | |
48 } | |
49 | |
50 } // anonymous namespace | |
21 | 51 |
22 namespace content { | 52 namespace content { |
23 | 53 |
24 jobject CreateShellView() { | 54 jobject CreateShellView() { |
25 JNIEnv* env = base::android::AttachCurrentThread(); | 55 JNIEnv* env = base::android::AttachCurrentThread(); |
26 return Java_ShellManager_createShell( | 56 return Java_ShellManager_createShell( |
27 env, g_content_shell_manager.Get().obj()).Release(); | 57 env, g_global_state.Get().j_obj.obj()).Release(); |
28 } | 58 } |
29 | 59 |
30 // Register native methods | 60 // Register native methods |
31 bool RegisterShellManager(JNIEnv* env) { | 61 bool RegisterShellManager(JNIEnv* env) { |
32 return RegisterNativesImpl(env); | 62 return RegisterNativesImpl(env); |
33 } | 63 } |
34 | 64 |
35 static void Init(JNIEnv* env, jclass clazz, jobject obj) { | 65 static void Init(JNIEnv* env, jclass clazz, jobject obj) { |
36 g_content_shell_manager.Get().Reset( | 66 g_global_state.Get().j_obj.Reset( |
37 base::android::ScopedJavaLocalRef<jobject>(env, obj)); | 67 base::android::ScopedJavaLocalRef<jobject>(env, obj)); |
68 DrawDelegate::SurfaceUpdatedCallback cb = base::Bind( | |
69 &SurfaceUpdated); | |
70 DrawDelegate::GetInstance()->SetUpdateCallback(cb); | |
71 } | |
72 | |
73 static void SurfaceCreated( | |
74 JNIEnv* env, jclass clazz, jobject jsurface) { | |
75 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); | |
76 if (native_window) { | |
77 if (g_global_state.Get().context) | |
78 delete g_global_state.Get().context; | |
79 | |
80 g_global_state.Get().context = new DrawContext(native_window); | |
81 ANativeWindow_release(native_window); | |
82 } | |
83 } | |
84 | |
85 static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { | |
86 if (g_global_state.Get().context) | |
87 delete g_global_state.Get().context; | |
88 NOTIMPLEMENTED(); | |
Ted C
2012/07/31 20:58:05
this seems like a bit of a fib...maybe make this a
no sievers
2012/07/31 21:17:17
I'll remove the NOTIMPLEMENTED() here.
The problem
| |
89 } | |
90 | |
91 static void SurfaceSetSize( | |
92 JNIEnv* env, jclass clazz, jint width, jint height) { | |
93 gfx::Size size = gfx::Size(width, height); | |
94 DrawDelegate::GetInstance()->SetBounds(size); | |
95 DCHECK(g_global_state.Get().context); | |
96 g_global_state.Get().context->Reshape(width, height); | |
38 } | 97 } |
39 | 98 |
40 void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) { | 99 void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) { |
41 ShellBrowserContext* browserContext = | 100 ShellBrowserContext* browserContext = |
42 static_cast<ShellContentBrowserClient*>( | 101 static_cast<ShellContentBrowserClient*>( |
43 GetContentClient()->browser())->browser_context(); | 102 GetContentClient()->browser())->browser_context(); |
44 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 103 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
45 Shell::CreateNewWindow(browserContext, | 104 Shell::CreateNewWindow(browserContext, |
46 url, | 105 url, |
47 NULL, | 106 NULL, |
48 MSG_ROUTING_NONE, | 107 MSG_ROUTING_NONE, |
49 NULL); | 108 NULL); |
50 } | 109 } |
51 | 110 |
52 } // namespace content | 111 } // namespace content |
OLD | NEW |