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/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/bind.h" | |
9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
10 #include "jni/ShellManager_jni.h" | 11 #include "jni/ShellManager_jni.h" |
12 #include "content/public/browser/android/draw_delegate.h" | |
13 #include "content/public/browser/render_widget_host_view.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "content/shell/android/draw_context.h" | |
16 #include "content/shell/shell.h" | |
17 #include "ui/gfx/size.h" | |
18 | |
19 #include <android/native_window_jni.h> | |
11 | 20 |
12 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
22 using content::DrawDelegate; | |
13 | 23 |
14 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > | 24 namespace { |
15 g_content_shell_manager = LAZY_INSTANCE_INITIALIZER; | 25 |
26 struct GlobalState { | |
27 GlobalState() | |
28 : context(NULL) { | |
29 } | |
30 base::android::ScopedJavaGlobalRef<jobject> j_obj; | |
31 DrawContext* context; | |
32 }; | |
33 | |
34 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; | |
35 | |
36 static void SurfaceUpdated( | |
37 uint64 texture, | |
38 content::RenderWidgetHostView* view, | |
39 const DrawDelegate::SurfacePresentedCallback& callback) { | |
40 uint32 sync_point = g_global_state.Get().context->Draw(texture); | |
41 callback.Run(sync_point); | |
42 } | |
43 | |
44 } // anonymous namespace | |
16 | 45 |
17 namespace content { | 46 namespace content { |
18 | 47 |
19 jobject CreateShellView() { | 48 jobject CreateShellView() { |
20 JNIEnv* env = base::android::AttachCurrentThread(); | 49 JNIEnv* env = base::android::AttachCurrentThread(); |
21 return Java_ShellManager_createShell( | 50 return Java_ShellManager_createShell( |
22 env, g_content_shell_manager.Get().obj()).Release(); | 51 env, g_global_state.Get().j_obj.obj()).Release(); |
23 } | 52 } |
24 | 53 |
25 // Register native methods | 54 // Register native methods |
26 bool RegisterShellManager(JNIEnv* env) { | 55 bool RegisterShellManager(JNIEnv* env) { |
27 return RegisterNativesImpl(env); | 56 return RegisterNativesImpl(env); |
28 } | 57 } |
29 | 58 |
30 static void Init(JNIEnv* env, jclass clazz, jobject obj) { | 59 static void Init(JNIEnv* env, jclass clazz, jobject obj) { |
31 g_content_shell_manager.Get().Reset( | 60 g_global_state.Get().j_obj.Reset( |
32 base::android::ScopedJavaLocalRef<jobject>(env, obj)); | 61 base::android::ScopedJavaLocalRef<jobject>(env, obj)); |
62 DrawDelegate::SurfaceUpdatedCallback cb = base::Bind( | |
63 &SurfaceUpdated); | |
64 DrawDelegate::GetInstance()->SetUpdateCallback(cb); | |
65 } | |
66 | |
67 static void SurfaceCreated( | |
68 JNIEnv* env, jclass clazz, jobject jsurface) { | |
69 ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); | |
70 if (native_window) { | |
71 LOG(INFO) << "SurfaceCreated"; | |
Ted C
2012/07/27 20:31:15
remove log?
no sievers
2012/07/31 01:28:44
Done.
| |
72 | |
73 if (g_global_state.Get().context) | |
74 delete g_global_state.Get().context; | |
75 | |
76 g_global_state.Get().context = new DrawContext(native_window); | |
77 ANativeWindow_release(native_window); | |
78 } | |
79 } | |
80 | |
81 static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { | |
82 LOG(INFO) << "SurfaceDestroyed"; | |
83 NOTIMPLEMENTED(); | |
klobag.chromium
2012/07/27 19:42:22
Should we delete the context here as we can't touc
no sievers
2012/07/31 01:28:44
Done.
| |
84 } | |
85 | |
86 static void SurfaceSetSize( | |
87 JNIEnv* env, jclass clazz, jint width, jint height) { | |
88 std::vector<Shell*> shells = Shell::windows(); | |
89 for (size_t n = 0; n < shells.size(); n++) { | |
90 WebContents* contents = shells[n]->web_contents(); | |
91 RenderWidgetHostView* view = contents->GetRenderWidgetHostView(); | |
92 if (view) { | |
Ted C
2012/07/27 20:31:15
no braces needed
no sievers
2012/07/31 01:28:44
Done.
| |
93 view->SetSize(gfx::Size(width, height)); | |
94 } | |
95 } | |
96 | |
97 DCHECK(g_global_state.Get().context); | |
98 g_global_state.Get().context->Reshape(width, height); | |
33 } | 99 } |
34 | 100 |
35 } // namespace content | 101 } // namespace content |
OLD | NEW |