Chromium Code Reviews| Index: content/shell/android/shell_manager.cc |
| diff --git a/content/shell/android/shell_manager.cc b/content/shell/android/shell_manager.cc |
| index 5972409ed639f2463ced406399487a43f0d99606..2d2a2eb44e89def33da6ebebed263eb054a686cc 100644 |
| --- a/content/shell/android/shell_manager.cc |
| +++ b/content/shell/android/shell_manager.cc |
| @@ -7,24 +7,54 @@ |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| #include "base/android/scoped_java_ref.h" |
| +#include "base/bind.h" |
| #include "base/lazy_instance.h" |
| #include "content/shell/shell.h" |
| #include "content/shell/shell_browser_context.h" |
| #include "content/shell/shell_content_browser_client.h" |
| #include "googleurl/src/gurl.h" |
| #include "jni/ShellManager_jni.h" |
| +#include "content/public/browser/android/draw_delegate.h" |
|
jam
2012/07/31 22:46:15
nit: order
|
| +#include "content/public/browser/render_widget_host_view.h" |
| +#include "content/public/browser/web_contents.h" |
| +#include "content/shell/android/draw_context.h" |
| +#include "content/shell/shell.h" |
| +#include "ui/gfx/size.h" |
| + |
| +#include <android/native_window_jni.h> |
| using base::android::ScopedJavaLocalRef; |
| +using content::DrawContext; |
| +using content::DrawDelegate; |
| + |
| +namespace { |
| + |
| +struct GlobalState { |
| + GlobalState() |
| + : context(NULL) { |
| + } |
| + base::android::ScopedJavaGlobalRef<jobject> j_obj; |
| + DrawContext* context; |
| +}; |
| + |
| +base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; |
| + |
| +static void SurfaceUpdated( |
| + uint64 texture, |
| + content::RenderWidgetHostView* view, |
| + const DrawDelegate::SurfacePresentedCallback& callback) { |
| + uint32 sync_point = g_global_state.Get().context->Draw(texture); |
| + callback.Run(sync_point); |
| +} |
| -base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > |
| - g_content_shell_manager = LAZY_INSTANCE_INITIALIZER; |
| +} // anonymous namespace |
| namespace content { |
| jobject CreateShellView() { |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| return Java_ShellManager_createShell( |
| - env, g_content_shell_manager.Get().obj()).Release(); |
| + env, g_global_state.Get().j_obj.obj()).Release(); |
| } |
| // Register native methods |
| @@ -33,8 +63,36 @@ bool RegisterShellManager(JNIEnv* env) { |
| } |
| static void Init(JNIEnv* env, jclass clazz, jobject obj) { |
| - g_content_shell_manager.Get().Reset( |
| + g_global_state.Get().j_obj.Reset( |
| base::android::ScopedJavaLocalRef<jobject>(env, obj)); |
| + DrawDelegate::SurfaceUpdatedCallback cb = base::Bind( |
| + &SurfaceUpdated); |
| + DrawDelegate::GetInstance()->SetUpdateCallback(cb); |
| +} |
| + |
| +static void SurfaceCreated( |
| + JNIEnv* env, jclass clazz, jobject jsurface) { |
| + ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); |
| + if (native_window) { |
| + if (g_global_state.Get().context) |
| + delete g_global_state.Get().context; |
| + |
| + g_global_state.Get().context = new DrawContext(native_window); |
| + ANativeWindow_release(native_window); |
| + } |
| +} |
| + |
| +static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { |
| + if (g_global_state.Get().context) |
| + delete g_global_state.Get().context; |
| +} |
| + |
| +static void SurfaceSetSize( |
| + JNIEnv* env, jclass clazz, jint width, jint height) { |
| + gfx::Size size = gfx::Size(width, height); |
| + DrawDelegate::GetInstance()->SetBounds(size); |
| + DCHECK(g_global_state.Get().context); |
| + g_global_state.Get().context->Reshape(width, height); |
| } |
| void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) { |